Index: trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Automatic Board Welcome -- automatically posts a welcome message on new |
| 5 | + * users' user boards on account creation. |
| 6 | + * The message is sent by a randomly-chosen administrator (one who is a member |
| 7 | + * of the 'sysop' group). |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @ingroup Extensions |
| 11 | + * @version 0.1 |
| 12 | + * @date 20 July 2011 |
| 13 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 14 | + * @license http://en.wikipedia.org/wiki/Public_domain Public domain |
| 15 | + */ |
| 16 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 17 | + die( 'This is not a valid entry point to MediaWiki.' ); |
| 18 | +} |
| 19 | + |
| 20 | +// Extension credits that will show up on Special:Version |
| 21 | +$wgExtensionCredits['other'][] = array( |
| 22 | + 'name' => 'Automatic Board Welcome', |
| 23 | + 'version' => '0.1', |
| 24 | + 'author' => 'Jack Phoenix', |
| 25 | + 'description' => 'Automatically posts [[MediaWiki:User-board-welcome-message|a welcome message]] on new users\' user boards after account creation', |
| 26 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Automatic_Board_Welcome', |
| 27 | +); |
| 28 | + |
| 29 | +$wgHooks['AddNewAccount'][] = 'wfSendUserBoardMessageOnRegistration'; |
| 30 | +/** |
| 31 | + * Send the message if the UserBoard class exists (duh!) and the welcome |
| 32 | + * message has some content. |
| 33 | + * |
| 34 | + * @param $user User: the new User object being created |
| 35 | + * @param $byEmail Boolean: true if the account was created by e-mail |
| 36 | + * @return Boolean: true |
| 37 | + */ |
| 38 | +function wfSendUserBoardMessageOnRegistration( $user, $byEmail ) { |
| 39 | + if ( class_exists( 'UserBoard' ) && $user instanceof User ) { |
| 40 | + $message = trim( wfMsgForContent( 'user-board-welcome-message' ) ); |
| 41 | + |
| 42 | + // If the welcome message is empty, short-circuit right away. |
| 43 | + if( wfEmptyMsg( 'user-board-welcome-message', $message ) ) { |
| 44 | + return true; |
| 45 | + } |
| 46 | + |
| 47 | + $dbr = wfGetDB( DB_SLAVE ); |
| 48 | + // Get all users who are in the 'sysop' group from the database |
| 49 | + $res = $dbr->select( |
| 50 | + 'user_groups', |
| 51 | + array( 'ug_group', 'ug_user' ), |
| 52 | + array( 'ug_group' => 'sysop' ), |
| 53 | + __METHOD__ |
| 54 | + ); |
| 55 | + |
| 56 | + $adminUids = array(); |
| 57 | + foreach ( $res as $row ) { |
| 58 | + $adminUids[] = $row->ug_user; |
| 59 | + } |
| 60 | + |
| 61 | + // Pick one UID from the array of admin user IDs |
| 62 | + $random = array_rand( array_flip( $adminUids ), 1 ); |
| 63 | + $sender = User::newFromId( $random ); |
| 64 | + |
| 65 | + // Ignore blocked users who have +sysop and only send out the message |
| 66 | + // when we can, i.e. when the DB is *not* locked |
| 67 | + if ( !$sender->isBlocked() && !wfReadOnly() ) { |
| 68 | + $senderUid = $sender->getId(); |
| 69 | + $senderName = $sender->getName(); |
| 70 | + |
| 71 | + $b = new UserBoard(); |
| 72 | + $b->sendBoardMessage( |
| 73 | + $senderUid, // sender's UID |
| 74 | + $senderName, // sender's name |
| 75 | + $user->getId(), |
| 76 | + $user->getName(), |
| 77 | + // passing the senderName as an argument here so that we can do |
| 78 | + // stuff like [[User talk:$1|contact me]] or w/e in the message |
| 79 | + wfMsgForContent( 'user-board-welcome-message', $senderName ) |
| 80 | + // the final argument is message type: 0 (default) for public |
| 81 | + ); |
| 82 | + } |
| 83 | + } |
| 84 | + return true; |
| 85 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/AutomaticBoardWelcome/AutomaticBoardWelcome.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 86 | + native |