Index: trunk/extensions/Renameuser/RenameUserJob.php |
— | — | @@ -1,20 +1,39 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +/** |
| 5 | + * Custom job to perform updates on less important tables |
| 6 | + * in busier environments |
| 7 | + */ |
4 | 8 | class RenameUserJob extends Job { |
5 | | - function __construct($title,$params) { |
6 | | - parent::__construct('renameUser', $title, $params); |
| 9 | + |
| 10 | + /** |
| 11 | + * Constructor |
| 12 | + * |
| 13 | + * @param Title $title Associated title |
| 14 | + * @param array $params Job parameters |
| 15 | + */ |
| 16 | + public function __construct( $title, $params ) { |
| 17 | + parent::__construct( 'renameUser', $title, $params ); |
7 | 18 | } |
8 | 19 | |
9 | | - function run() { |
| 20 | + /** |
| 21 | + * Execute the job |
| 22 | + * |
| 23 | + * @return bool |
| 24 | + */ |
| 25 | + public function run() { |
10 | 26 | $dbw = wfGetDB( DB_MASTER ); |
11 | | - // Our keyId param will be an array of ids |
12 | | - $dbw->update( $this->params['table'], |
13 | | - array( $this->params['column'] => $this->params['newname'] ), |
14 | | - array( $this->params['column'] => $this->params['oldname'], |
15 | | - $this->params['uniqueKey'] => $this->params['keyId'] ) |
16 | | - #,array( $dbw->lowPriorityOption() ) |
| 27 | + extract( $this->params ); |
| 28 | + $dbw->update( |
| 29 | + $table, |
| 30 | + array( $column => $newname ), |
| 31 | + array( |
| 32 | + $column => $oldname, |
| 33 | + $uniqueKey => $keyId, |
| 34 | + ), |
| 35 | + __METHOD__ |
17 | 36 | ); |
| 37 | + return true; |
18 | 38 | } |
19 | | -} |
20 | 39 | |
21 | | - |
| 40 | +} |
\ No newline at end of file |
Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php |
— | — | @@ -1,16 +1,27 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class Renameuser extends SpecialPage { |
5 | | - function Renameuser() { |
6 | | - SpecialPage::SpecialPage('Renameuser', 'renameuser'); |
| 4 | +/** |
| 5 | + * Special page allows authorised users to rename |
| 6 | + * user accounts |
| 7 | + */ |
| 8 | +class SpecialRenameuser extends SpecialPage { |
| 9 | + |
| 10 | + /** |
| 11 | + * Constructor |
| 12 | + */ |
| 13 | + public function __construct() { |
| 14 | + parent::__construct( 'Renameuser', 'renameuser' ); |
7 | 15 | } |
8 | 16 | |
9 | | - function execute( $par ) { |
| 17 | + /** |
| 18 | + * Show the special page |
| 19 | + * |
| 20 | + * @param mixed $par Parameter passed to the page |
| 21 | + */ |
| 22 | + public function execute( $par ) { |
10 | 23 | global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang; |
11 | 24 | global $wgVersion, $wgMaxNameChars, $wgCapitalLinks; |
12 | 25 | |
13 | | - $fname = 'Renameuser::execute'; |
14 | | - |
15 | 26 | $this->setHeaders(); |
16 | 27 | |
17 | 28 | if ( !$wgUser->isAllowed( 'renameuser' ) ) { |
— | — | @@ -23,11 +34,6 @@ |
24 | 35 | return; |
25 | 36 | } |
26 | 37 | |
27 | | - if ( version_compare( $wgVersion, '1.7.0', '<' ) ) { |
28 | | - $wgOut->versionRequired( '1.7.0' ); |
29 | | - return; |
30 | | - } |
31 | | - |
32 | 38 | $showBlockLog = $wgRequest->getBool( 'submit-showBlockLog' ); |
33 | 39 | $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ), NS_USER ); |
34 | 40 | $newusername = Title::newFromText( $wgContLang->ucfirst( $wgRequest->getText( 'newusername' ) ), NS_USER ); // Force uppercase of newusername otherweise wikis with wgCapitalLinks=false can create lc usernames |
— | — | @@ -65,8 +71,8 @@ |
66 | 72 | if ( $wgUser->isAllowed( 'move' ) && version_compare( $wgVersion, '1.9alpha', '>=' ) ) { |
67 | 73 | $wgOut->addHTML( " |
68 | 74 | <tr> |
69 | | - <td> |
70 | | - |
| 75 | + <td> |
| 76 | + |
71 | 77 | </td> |
72 | 78 | <td>" . |
73 | 79 | Xml::checkLabel( wfMsg( 'renameusermove' ), 'movepages', 'movepages', $is_checked, array( 'tabindex' => '4' ) ) . |
— | — | @@ -77,8 +83,8 @@ |
78 | 84 | |
79 | 85 | $wgOut->addHTML( " |
80 | 86 | <tr> |
81 | | - <td> |
82 | | - |
| 87 | + <td> |
| 88 | + |
83 | 89 | </td> |
84 | 90 | <td>" . |
85 | 91 | Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', 'tabindex' => '5', 'id' => 'submit' ) ) . |
— | — | @@ -307,10 +313,8 @@ |
308 | 314 | function rename() { |
309 | 315 | global $wgMemc, $wgDBname, $wgAuth; |
310 | 316 | |
311 | | - $fname = 'RenameuserSQL::rename'; |
| 317 | + wfProfileIn( __METHOD__ ); |
312 | 318 | |
313 | | - wfProfileIn( $fname ); |
314 | | - |
315 | 319 | $dbw =& wfGetDB( DB_MASTER ); |
316 | 320 | // Rename and touch the user before re-attributing edits, |
317 | 321 | // this avoids users still being login in and making new edits while |
— | — | @@ -318,14 +322,14 @@ |
319 | 323 | $dbw->update( 'user', |
320 | 324 | array( 'user_name' => $this->new, 'user_touched' => $dbw->timestamp() ), |
321 | 325 | array( 'user_name' => $this->old ), |
322 | | - $fname |
| 326 | + __METHOD__ |
323 | 327 | ); |
324 | 328 | |
325 | 329 | foreach( $this->tables as $table => $field ) { |
326 | 330 | $dbw->update( $table, |
327 | 331 | array( $field => $this->new ), |
328 | 332 | array( $field => $this->old ), |
329 | | - $fname |
| 333 | + __METHOD__ |
330 | 334 | #,array( $dbw->lowPriorityOption() ) |
331 | 335 | ); |
332 | 336 | } |
— | — | @@ -380,14 +384,12 @@ |
381 | 385 | $dbw->freeResult( $res ); |
382 | 386 | } |
383 | 387 | |
384 | | - // Clear the user cache |
385 | | - $wgMemc->delete( "$wgDBname:user:id:{$this->uid}" ); |
386 | | - |
387 | | - // Inform authentication plugin of the change |
| 388 | + // Clear caches and inform authentication plugins |
388 | 389 | $user = User::newFromId( $this->uid ); |
| 390 | + $user->invalidateCache(); |
389 | 391 | $wgAuth->updateExternalDB( $user ); |
390 | 392 | |
391 | | - wfProfileOut( $fname ); |
| 393 | + wfProfileOut( __METHOD__ ); |
392 | 394 | } |
393 | 395 | } |
394 | 396 | |
Index: trunk/extensions/Renameuser/SpecialRenameuser.php |
— | — | @@ -39,8 +39,10 @@ |
40 | 40 | $wgLogHeaders['renameuser'] = 'renameuserlogpagetext'; |
41 | 41 | $wgLogActions['renameuser/renameuser'] = 'renameuserlogentry'; |
42 | 42 | |
43 | | -$wgJobClasses['renameUser'] = 'RenameUserJob'; |
| 43 | +$wgAutoloadClasses['SpecialRenameuser'] = dirname( __FILE__ ) . '/SpecialRenameuser_body.php'; |
44 | 44 | $wgAutoloadClasses['RenameUserJob'] = dirname(__FILE__) . '/RenameUserJob.php'; |
| 45 | +$wgSpecialPages['Renameuser'] = 'SpecialRenameuser'; |
| 46 | +$wgJobClasses['renameUser'] = 'RenameUserJob'; |
45 | 47 | |
46 | 48 | /** |
47 | 49 | * If this is set to true, then the archive table (deleted revisions) will |
— | — | @@ -49,17 +51,10 @@ |
50 | 52 | */ |
51 | 53 | $wgRenameUserQuick = $wgMiserMode; |
52 | 54 | |
53 | | -# Register the special page |
54 | | -if ( !function_exists( 'extAddSpecialPage' ) ) { |
55 | | - require( dirname(__FILE__) . '/../ExtensionFunctions.php' ); |
56 | | -} |
57 | | -extAddSpecialPage( dirname(__FILE__) . '/SpecialRenameuser_body.php', 'Renameuser', 'Renameuser' ); |
58 | | - |
59 | 55 | function wfSpecialRenameuser() { |
60 | 56 | # Add messages |
61 | 57 | global $wgMessageCache, $wgRenameuserMessages; |
62 | 58 | foreach( $wgRenameuserMessages as $key => $value ) { |
63 | 59 | $wgMessageCache->addMessages( $wgRenameuserMessages[$key], $key ); |
64 | 60 | } |
65 | | -} |
66 | | - |
| 61 | +} |
\ No newline at end of file |