r90684 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90683‎ | r90684 | r90685 >
Date:00:11, 24 June 2011
Author:wikinaut
Status:deferred (Comments)
Tags:
Comment:
follow up patch to r90650 ; making most of it conforming to mw coding conventions
Modified paths:
  • /trunk/extensions/UserMerge/UserMerge.php (modified) (history)
  • /trunk/extensions/UserMerge/UserMerge_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UserMerge/UserMerge_body.php
@@ -10,6 +10,9 @@
1111 *
1212 * @ingroup Extensions
1313 * @author Tim Laqua <t.laqua@gmail.com>
 14+ * @author Thomas Gries <mail@tgries.de>
 15+ * @author Matthew April <Matthew.April@tbs-sct.gc.ca>
 16+ *
1417 */
1518
1619 class UserMerge extends SpecialPage {
@@ -78,8 +81,8 @@
7982 $objNewUser = User::newFromName( $newuser_text );
8083 $newuserID = $objNewUser->idForName();
8184
82 - if ( !is_object( $objNewUser ) || $newuserID == 0 ) {
83 - if ( $newuser_text == 'Anonymous' ) {
 85+ if ( !is_object( $objNewUser ) || $newuserID === 0 ) {
 86+ if ( $newuser_text === 'Anonymous' ) {
8487 // Merge to anonymous
8588 $validNewUser = true;
8689 $newuserID = 0;
@@ -102,7 +105,7 @@
103106 }
104107 } else {
105108 $validOldUser = false;
106 - $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsg('usermerge-noolduser') . "</span><br />\n" );
 109+ $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsg( 'usermerge-noolduser' ) . "</span><br />\n" );
107110 }
108111 } else {
109112 //NO POST data found
@@ -117,7 +120,7 @@
118121 Xml::label( wfMsg( 'usermerge-olduser' ), 'olduser' ) .
119122 "</td>
120123 <td class='mw-input'>" .
121 - Xml::input( 'olduser', 20, $olduser_text, array( 'type' => 'text', 'tabindex' => '1', 'onFocus' => "document.getElementById('olduser').select;" ) ) . ' ' .
 124+ Xml::input( 'olduser', 20, $olduser_text, array( 'type' => 'text', 'tabindex' => '1', 'onFocus' => "document.getElementById( 'olduser' ).select;" ) ) . ' ' .
122125 "</td>
123126 </tr>
124127 <tr>
@@ -125,7 +128,7 @@
126129 Xml::label( wfMsg( 'usermerge-newuser' ), 'newuser' ) .
127130 "</td>
128131 <td class='mw-input'>" .
129 - Xml::input( 'newuser', 20, $newuser_text, array( 'type' => 'text', 'tabindex' => '2', 'onFocus' => "document.getElementById('newuser').select;" ) ) .
 132+ Xml::input( 'newuser', 20, $newuser_text, array( 'type' => 'text', 'tabindex' => '2', 'onFocus' => "document.getElementById( 'newuser' ).select;" ) ) .
130133 "</td>
131134 </tr>
132135 <tr>
@@ -155,7 +158,7 @@
156159 $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsg( 'usermerge-badtoken' ) . "</span><br />\n" );
157160 } else {
158161 //good editToken
159 - $this->mergeEditcount( $newuserID,$olduserID );
 162+ $this->mergeEditcount( $newuserID, $olduserID );
160163 $this->mergeUser( $objNewUser, $newuser_text, $newuserID, $objOldUser, $olduser_text, $olduserID );
161164 if ( $wgRequest->getText( 'deleteuser' ) ) {
162165 $this->movePages( $newuser_text, $olduser_text );
@@ -241,7 +244,7 @@
242245
243246 foreach ( $idUpdateFields as $idUpdateField ) {
244247 $dbw->update( $idUpdateField[0], array( $idUpdateField[1] => $newuserID ), array( $idUpdateField[1] => $olduserID ) );
245 - $wgOut->addHTML( wfMsg('usermerge-updating', $idUpdateField[0], $olduserID, $newuserID ) . "<br />\n" );
 248+ $wgOut->addHTML( wfMsg( 'usermerge-updating', $idUpdateField[0], $olduserID, $newuserID ) . "<br />\n" );
246249 }
247250
248251 foreach ( $textUpdateFields as $textUpdateField ) {
@@ -251,7 +254,7 @@
252255
253256 $dbw->delete( 'user_newtalk', array( 'user_id' => $olduserID ));
254257
255 - $wgOut->addHTML("<hr />\n" . wfMsg( 'usermerge-success',$olduser_text, $olduserID, $newuser_text, $newuserID ) . "\n<br />");
 258+ $wgOut->addHTML( "<hr />\n" . wfMsg( 'usermerge-success', $olduser_text, $olduserID, $newuser_text, $newuserID ) . "\n<br />" );
256259
257260 $log = new LogPage( 'usermerge' );
258261 $log->addEntry( 'mergeuser', $wgUser->getUserPage(), '', array( $olduser_text, $olduserID, $newuser_text, $newuserID ) );
@@ -261,8 +264,10 @@
262265 return true;
263266 }
264267
265 - ///Function to add edit count
 268+
266269 /**
 270+ * Function to add edit count
 271+ *
267272 * Adds edit count of both users
268273 *
269274 * @param $newuserID int ID of user to merge references TO
@@ -275,15 +280,24 @@
276281 private function mergeEditcount( $newuserID, $olduserID ) {
277282 global $wgOut;
278283
279 - $dbw =& wfGetDB( DB_MASTER );
 284+ $dbw = wfGetDB( DB_MASTER );
280285
281286 # old user edit count
282 - $result = $dbw->select( 'user', array('user_editcount'), 'user_id ='.$olduserID );
 287+ $result = $dbw->selectField( 'user',
 288+ 'user_editcount',
 289+ array( 'user_id' => $olduserID ),
 290+ __METHOD__
 291+ );
283292 $row = $dbw->fetchRow($result);
 293+
284294 $oldEdits = $row[0];
285295
286296 # new user edit count
287 - $result = $dbw->select( 'user', array('user_editcount'), 'user_id ='.$newuserID );
 297+ $result = $dbw->selectField( 'user',
 298+ 'user_editcount',
 299+ array( 'user_id' => $newuserID ),
 300+ __METHOD__
 301+ );
288302 $row = $dbw->fetchRow($result);
289303 $newEdits = $row[0];
290304
@@ -293,13 +307,21 @@
294308 # don't run querys if neither user has any edits
295309 if( $totalEdits > 0 ) {
296310 # update new user with total edits
297 - $dbw->update( 'user', array('user_editcount' => $totalEdits), array('user_id' => $newuserID) );
 311+ $dbw->update( 'user',
 312+ array( 'user_editcount' => $totalEdits ),
 313+ array( 'user_id' => $newuserID ),
 314+ __METHOD__
 315+ );
298316
299317 #clear old users edits
300 - $dbw->update( 'user', array('user_editcount' => 0), array('user_id' => $olduserID) );
 318+ $dbw->update( 'user',
 319+ array( 'user_editcount' => 0 ),
 320+ array( 'user_id' => $olduserID ),
 321+ __METHOD__
 322+ );
301323 }
302324
303 - $wgOut->addHTML(wfMsgForContent('usermerge-editcount-success', $olduserID, $newuserID) . "<br />\n");
 325+ $wgOut->addHTML( wfMsgForContent( 'usermerge-editcount-success', $olduserID, $newuserID ) . "<br />\n" );
304326
305327 return true;
306328 }
@@ -331,81 +353,85 @@
332354 # select all user pages and sub-pages
333355 $dbr = wfGetDB( DB_SLAVE );
334356 $oldkey = $oldusername->getDBkey();
335 - $pages = $dbr->select(
336 - 'page',
337 - array( 'page_namespace', 'page_title' ),
338 - array(
339 - 'page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')',
340 - '(page_title LIKE ' .
341 - $dbr->addQuotes( $dbr->escapeLike( $oldusername->getDBkey() ) . '/%' ) .
342 - ' OR page_title = ' . $dbr->addQuotes( $oldusername->getDBkey() ) . ')'
343 - )
344 - );
 357+ $pages = $dbr->select( 'page',
 358+ array( 'page_namespace', 'page_title' ),
 359+ array( 'page_namespace IN (' . NS_USER . ',' . NS_USER_TALK . ')',
 360+ 'page_title' . $dbr->buildLike( $oldusername->getDBkey() . '/', $dbr->anyString() )
 361+ .' OR page_title = ' . $dbr->addQuotes( $oldusername->getDBkey() )
 362+ )
 363+ );
345364
346365 $output = '';
347 - $skin =& $wgUser->getSkin();
348 - while ( $row = $dbr->fetchObject( $pages ) ) {
 366+ $skin = $wgUser->getSkin();
 367+
 368+ foreach ( $pages as $row ) {
349369 $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
350370 $newPage = Title::makeTitleSafe( $row->page_namespace,
351371 preg_replace( '!^[^/]+!', $newusername->getDBkey(), $row->page_title ) );
352372
353373
354 - if( $newuser_text == "Anonymous" ) { # delete ALL old pages
 374+ if( $newuser_text === "Anonymous" ) { # delete ALL old pages
355375
356376 if( $oldPage->exists() ) {
357 - $oldPageArticle = new Article($oldPage);
358 - $oldPageArticle->doDeleteArticle( wfMsgHtml('usermerge-autopagedelete') );
 377+ $oldPageArticle = new Article( $oldPage, 0 );
 378+ $oldPageArticle->doDeleteArticle( wfMsgHtml( 'usermerge-autopagedelete' ) );
359379
360 - $oldLink = $skin->makeKnownLinkObj( $oldPage );
 380+ $oldLink = $skin->linkKnown( $oldPage );
361381 $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml( 'usermerge-page-deleted', $oldLink ) . '</li>';
362382 }
363383
364384 } elseif( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) && $newPage->getLength() > 0) { # delete old pages that can't be moved
365385
366 - $oldPageArticle = new Article($oldPage);
367 - $oldPageArticle->doDeleteArticle( wfMsgHtml('usermerge-autopagedelete') );
 386+ $oldPageArticle = new Article( $oldPage, 0 );
 387+ $oldPageArticle->doDeleteArticle( wfMsgHtml( 'usermerge-autopagedelete' ) );
368388
369 - $link = $skin->makeKnownLinkObj( $oldPage );
 389+ $link = $skin->linkKnown( $oldPage );
370390 $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml( 'usermerge-page-deleted', $link ) . '</li>';
371391
372392 } else { # move content to new page
373393
374394 # delete target page if it exists and is blank
375395 if( $newPage->exists() ) {
376 - $newPageArticle = new Article($newPage);
377 - $newPageArticle->doDeleteArticle('usermerge-autopagedelete');
 396+ $newPageArticle = new Article( $newPage, 0 );
 397+ $newPageArticle->doDeleteArticle( 'usermerge-autopagedelete' );
378398 }
379399
380400 # move to target location
381401 $success = $oldPage->moveTo( $newPage, false, wfMsgForContent( 'usermerge-move-log',
382402 $oldusername->getText(), $newusername->getText() ) );
383403 if( $success === true ) {
384 - $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
385 - $newLink = $skin->makeKnownLinkObj( $newPage );
 404+ $oldLink = $skin->linkKnown(
 405+ $oldPage,
 406+ null,
 407+ array(),
 408+ array( 'redirect' => 'no' )
 409+ );
 410+ $newLink = $skin->linkKnown( $newPage );
386411 $output .= '<li class="mw-renameuser-pm">' . wfMsgHtml( 'usermerge-page-moved', $oldLink, $newLink ) . '</li>';
387412 } else {
388 - $oldLink = $skin->makeKnownLinkObj( $oldPage );
389 - $newLink = $skin->makeLinkObj( $newPage );
 413+ $oldLink = $skin->linkKnown( $oldPage );
 414+ $newLink = $skin->linkKnown( $newPage );
390415 $output .= '<li class="mw-renameuser-pu">' . wfMsgHtml( 'usermerge-page-unmoved', $oldLink, $newLink ) . '</li>';
391416 }
392417
393418 # check if any pages link here
394 - $res = $dbr->select( 'pagelinks',
395 - 'pl_title' ,
396 - array( 'pl_title' => $olduser_text ),
397 - __METHOD__
398 - );
 419+ $res = $dbr->selectField( 'pagelinks',
 420+ 'pl_title',
 421+ array( 'pl_title' => $olduser_text ),
 422+ __METHOD__
 423+ );
399424 if( !$dbr->numRows( $res ) ) {
400425 # nothing links here, so delete unmoved page/redirect
401 - $oldPageArticle = new Article($oldPage);
402 - $oldPageArticle->doDeleteArticle( wfMsgHtml('usermerge-autopagedelete') );
 426+ $oldPageArticle = new Article( $oldPage, 0 );
 427+ $oldPageArticle->doDeleteArticle( wfMsgHtml( 'usermerge-autopagedelete' ) );
403428 }
404429
405430 }
406431 }
407432
408 - if( $output )
 433+ if ( $output ) {
409434 $wgOut->addHTML( '<ul>' . $output . '</ul>' );
 435+ }
410436
411437 return true;
412438 }
Index: trunk/extensions/UserMerge/UserMerge.php
@@ -36,7 +36,7 @@
3737 'url' => 'http://www.mediawiki.org/wiki/Extension:User_Merge_and_Delete',
3838 'author' => array( 'Tim Laqua', 'Thomas Gries', 'Matthew April' ),
3939 'descriptionmsg' => 'usermerge-desc',
40 - 'version' => '1.6.3'
 40+ 'version' => '1.6.31'
4141 );
4242
4343 $wgAvailableRights[] = 'usermerge';

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90650new version 1.6.3; adds edit count of fromUser to toUser; move; redirects use...wikinaut06:44, 23 June 2011

Comments

#Comment by 😂 (talk | contribs)   00:47, 21 July 2011

What did you mark this fixme for?

Status & tagging log