http://www.mediawiki.org/wiki/Special:Code/MediaWiki/93523
Revision: 93523 Author: ashley Date: 2011-07-30 13:55:27 +0000 (Sat, 30 Jul 2011) Log Message: ----------- Automatic Board Welcome extension -- automatically posts a welcome message on new users' user boards on account creation. The message is sent by a randomly-chosen administrator (one who is a member of the 'sysop' group), who is not blocked. Requires SocialProfile, obviously. Added Paths: ----------- trunk/extensions/AutomaticBoardWelcome/ trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php Added: trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php =================================================================== --- trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php (rev 0) +++ trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php 2011-07-30 13:55:27 UTC (rev 93523) @@ -0,0 +1,84 @@ +<?php +/** + * Automatic Board Welcome -- automatically posts a welcome message on new + * users' user boards on account creation. + * The message is sent by a randomly-chosen administrator (one who is a member + * of the 'sysop' group). + * + * @file + * @ingroup Extensions + * @version 0.1 + * @date 20 July 2011 + * @author Jack Phoenix <j...@countervandalism.net> + * @license http://en.wikipedia.org/wiki/Public_domain Public domain + */ +if ( !defined( 'MEDIAWIKI' ) ) { + die( 'This is not a valid entry point to MediaWiki.' ); +} + +// Extension credits that will show up on Special:Version +$wgExtensionCredits['other'][] = array( + 'name' => 'Automatic Board Welcome', + 'version' => '0.1', + 'author' => 'Jack Phoenix', + 'description' => 'Automatically posts [[MediaWiki:User-board-welcome-message|a welcome message]] on new users\' user boards after account creation', + 'url' => 'http://www.mediawiki.org/wiki/Extension:Automatic_Board_Welcome', +); + +$wgHooks['AddNewAccount'][] = 'wfSendUserBoardMessageOnRegistration'; +/** + * Send the message if the UserBoard class exists (duh!) and the welcome + * message has some content. + * + * @param $user User: the new User object being created + * @param $byEmail Boolean: true if the account was created by e-mail + * @return Boolean: true + */ +function wfSendUserBoardMessageOnRegistration( $user, $byEmail ) { + if ( class_exists( 'UserBoard' ) && $user instanceof User ) { + $message = trim( wfMsgForContent( 'user-board-welcome-message' ) ); + + // If the welcome message is empty, short-circuit right away. + if( wfEmptyMsg( 'user-board-welcome-message', $message ) ) { + return true; + } + + $dbr = wfGetDB( DB_SLAVE ); + // Get all users who are in the 'sysop' group from the database + $res = $dbr->select( + 'user_groups', + array( 'ug_group', 'ug_user' ), + array( 'ug_group' => 'sysop' ), + __METHOD__ + ); + + $adminUids = array(); + foreach ( $res as $row ) { + $adminUids[] = $row->ug_user; + } + + // Pick one UID from the array of admin user IDs + $random = array_rand( array_flip( $adminUids ), 1 ); + $sender = User::newFromId( $random ); + + // Ignore blocked users who have +sysop and only send out the message + // when we can, i.e. when the DB is *not* locked + if ( !$sender->isBlocked() && !wfReadOnly() ) { + $senderUid = $sender->getId(); + $senderName = $sender->getName(); + + $b = new UserBoard(); + $b->sendBoardMessage( + $senderUid, // sender's UID + $senderName, // sender's name + $user->getId(), + $user->getName(), + // passing the senderName as an argument here so that we can do + // stuff like [[User talk:$1|contact me]] or w/e in the message + wfMsgForContent( 'user-board-welcome-message', $senderName ) + // the final argument is message type: 0 (default) for public + ); + } + } + return true; +} \ No newline at end of file Property changes on: trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs