r23902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23901‎ | r23902 | r23903 >
Date:14:12, 9 July 2007
Author:robchurch
Status:old
Tags:
Comment:
* Refactor; the version check for 1.7.0 meant that ExtensionFunctions.php was useless; ditched both, clean up various other bits
* Fixed broken user cache clearance
* Job::run() returns a bool; make RenameUserJob::run() compliant
Modified paths:
  • /trunk/extensions/Renameuser/RenameUserJob.php (modified) (history)
  • /trunk/extensions/Renameuser/SpecialRenameuser.php (modified) (history)
  • /trunk/extensions/Renameuser/SpecialRenameuser_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/RenameUserJob.php
@@ -1,20 +1,39 @@
22 <?php
33
 4+/**
 5+ * Custom job to perform updates on less important tables
 6+ * in busier environments
 7+ */
48 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 );
718 }
819
9 - function run() {
 20+ /**
 21+ * Execute the job
 22+ *
 23+ * @return bool
 24+ */
 25+ public function run() {
1026 $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__
1736 );
 37+ return true;
1838 }
19 -}
2039
21 -
 40+}
\ No newline at end of file
Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php
@@ -1,16 +1,27 @@
22 <?php
33
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' );
715 }
816
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 ) {
1023 global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang;
1124 global $wgVersion, $wgMaxNameChars, $wgCapitalLinks;
1225
13 - $fname = 'Renameuser::execute';
14 -
1526 $this->setHeaders();
1627
1728 if ( !$wgUser->isAllowed( 'renameuser' ) ) {
@@ -23,11 +34,6 @@
2435 return;
2536 }
2637
27 - if ( version_compare( $wgVersion, '1.7.0', '<' ) ) {
28 - $wgOut->versionRequired( '1.7.0' );
29 - return;
30 - }
31 -
3238 $showBlockLog = $wgRequest->getBool( 'submit-showBlockLog' );
3339 $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ), NS_USER );
3440 $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 @@
6672 if ( $wgUser->isAllowed( 'move' ) && version_compare( $wgVersion, '1.9alpha', '>=' ) ) {
6773 $wgOut->addHTML( "
6874 <tr>
69 - <td>
70 - &nbsp;
 75+ <td>&nbsp;
 76+
7177 </td>
7278 <td>" .
7379 Xml::checkLabel( wfMsg( 'renameusermove' ), 'movepages', 'movepages', $is_checked, array( 'tabindex' => '4' ) ) .
@@ -77,8 +83,8 @@
7884
7985 $wgOut->addHTML( "
8086 <tr>
81 - <td>
82 - &nbsp;
 87+ <td>&nbsp;
 88+
8389 </td>
8490 <td>" .
8591 Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', 'tabindex' => '5', 'id' => 'submit' ) ) .
@@ -307,10 +313,8 @@
308314 function rename() {
309315 global $wgMemc, $wgDBname, $wgAuth;
310316
311 - $fname = 'RenameuserSQL::rename';
 317+ wfProfileIn( __METHOD__ );
312318
313 - wfProfileIn( $fname );
314 -
315319 $dbw =& wfGetDB( DB_MASTER );
316320 // Rename and touch the user before re-attributing edits,
317321 // this avoids users still being login in and making new edits while
@@ -318,14 +322,14 @@
319323 $dbw->update( 'user',
320324 array( 'user_name' => $this->new, 'user_touched' => $dbw->timestamp() ),
321325 array( 'user_name' => $this->old ),
322 - $fname
 326+ __METHOD__
323327 );
324328
325329 foreach( $this->tables as $table => $field ) {
326330 $dbw->update( $table,
327331 array( $field => $this->new ),
328332 array( $field => $this->old ),
329 - $fname
 333+ __METHOD__
330334 #,array( $dbw->lowPriorityOption() )
331335 );
332336 }
@@ -380,14 +384,12 @@
381385 $dbw->freeResult( $res );
382386 }
383387
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
388389 $user = User::newFromId( $this->uid );
 390+ $user->invalidateCache();
389391 $wgAuth->updateExternalDB( $user );
390392
391 - wfProfileOut( $fname );
 393+ wfProfileOut( __METHOD__ );
392394 }
393395 }
394396
Index: trunk/extensions/Renameuser/SpecialRenameuser.php
@@ -39,8 +39,10 @@
4040 $wgLogHeaders['renameuser'] = 'renameuserlogpagetext';
4141 $wgLogActions['renameuser/renameuser'] = 'renameuserlogentry';
4242
43 -$wgJobClasses['renameUser'] = 'RenameUserJob';
 43+$wgAutoloadClasses['SpecialRenameuser'] = dirname( __FILE__ ) . '/SpecialRenameuser_body.php';
4444 $wgAutoloadClasses['RenameUserJob'] = dirname(__FILE__) . '/RenameUserJob.php';
 45+$wgSpecialPages['Renameuser'] = 'SpecialRenameuser';
 46+$wgJobClasses['renameUser'] = 'RenameUserJob';
4547
4648 /**
4749 * If this is set to true, then the archive table (deleted revisions) will
@@ -49,17 +51,10 @@
5052 */
5153 $wgRenameUserQuick = $wgMiserMode;
5254
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 -
5955 function wfSpecialRenameuser() {
6056 # Add messages
6157 global $wgMessageCache, $wgRenameuserMessages;
6258 foreach( $wgRenameuserMessages as $key => $value ) {
6359 $wgMessageCache->addMessages( $wgRenameuserMessages[$key], $key );
6460 }
65 -}
66 -
 61+}
\ No newline at end of file

Status & tagging log