Index: trunk/extensions/UserMerge/UserMerge_body.php |
— | — | @@ -10,6 +10,9 @@ |
11 | 11 | * |
12 | 12 | * @ingroup Extensions |
13 | 13 | * @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 | + * |
14 | 17 | */ |
15 | 18 | |
16 | 19 | class UserMerge extends SpecialPage { |
— | — | @@ -78,8 +81,8 @@ |
79 | 82 | $objNewUser = User::newFromName( $newuser_text ); |
80 | 83 | $newuserID = $objNewUser->idForName(); |
81 | 84 | |
82 | | - if ( !is_object( $objNewUser ) || $newuserID == 0 ) { |
83 | | - if ( $newuser_text == 'Anonymous' ) { |
| 85 | + if ( !is_object( $objNewUser ) || $newuserID === 0 ) { |
| 86 | + if ( $newuser_text === 'Anonymous' ) { |
84 | 87 | // Merge to anonymous |
85 | 88 | $validNewUser = true; |
86 | 89 | $newuserID = 0; |
— | — | @@ -102,7 +105,7 @@ |
103 | 106 | } |
104 | 107 | } else { |
105 | 108 | $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" ); |
107 | 110 | } |
108 | 111 | } else { |
109 | 112 | //NO POST data found |
— | — | @@ -117,7 +120,7 @@ |
118 | 121 | Xml::label( wfMsg( 'usermerge-olduser' ), 'olduser' ) . |
119 | 122 | "</td> |
120 | 123 | <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;" ) ) . ' ' . |
122 | 125 | "</td> |
123 | 126 | </tr> |
124 | 127 | <tr> |
— | — | @@ -125,7 +128,7 @@ |
126 | 129 | Xml::label( wfMsg( 'usermerge-newuser' ), 'newuser' ) . |
127 | 130 | "</td> |
128 | 131 | <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;" ) ) . |
130 | 133 | "</td> |
131 | 134 | </tr> |
132 | 135 | <tr> |
— | — | @@ -155,7 +158,7 @@ |
156 | 159 | $wgOut->addHTML( "<span style=\"color: red;\">" . wfMsg( 'usermerge-badtoken' ) . "</span><br />\n" ); |
157 | 160 | } else { |
158 | 161 | //good editToken |
159 | | - $this->mergeEditcount( $newuserID,$olduserID ); |
| 162 | + $this->mergeEditcount( $newuserID, $olduserID ); |
160 | 163 | $this->mergeUser( $objNewUser, $newuser_text, $newuserID, $objOldUser, $olduser_text, $olduserID ); |
161 | 164 | if ( $wgRequest->getText( 'deleteuser' ) ) { |
162 | 165 | $this->movePages( $newuser_text, $olduser_text ); |
— | — | @@ -241,7 +244,7 @@ |
242 | 245 | |
243 | 246 | foreach ( $idUpdateFields as $idUpdateField ) { |
244 | 247 | $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" ); |
246 | 249 | } |
247 | 250 | |
248 | 251 | foreach ( $textUpdateFields as $textUpdateField ) { |
— | — | @@ -251,7 +254,7 @@ |
252 | 255 | |
253 | 256 | $dbw->delete( 'user_newtalk', array( 'user_id' => $olduserID )); |
254 | 257 | |
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 />" ); |
256 | 259 | |
257 | 260 | $log = new LogPage( 'usermerge' ); |
258 | 261 | $log->addEntry( 'mergeuser', $wgUser->getUserPage(), '', array( $olduser_text, $olduserID, $newuser_text, $newuserID ) ); |
— | — | @@ -261,8 +264,10 @@ |
262 | 265 | return true; |
263 | 266 | } |
264 | 267 | |
265 | | - ///Function to add edit count |
| 268 | + |
266 | 269 | /** |
| 270 | + * Function to add edit count |
| 271 | + * |
267 | 272 | * Adds edit count of both users |
268 | 273 | * |
269 | 274 | * @param $newuserID int ID of user to merge references TO |
— | — | @@ -275,15 +280,24 @@ |
276 | 281 | private function mergeEditcount( $newuserID, $olduserID ) { |
277 | 282 | global $wgOut; |
278 | 283 | |
279 | | - $dbw =& wfGetDB( DB_MASTER ); |
| 284 | + $dbw = wfGetDB( DB_MASTER ); |
280 | 285 | |
281 | 286 | # 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 | + ); |
283 | 292 | $row = $dbw->fetchRow($result); |
| 293 | + |
284 | 294 | $oldEdits = $row[0]; |
285 | 295 | |
286 | 296 | # 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 | + ); |
288 | 302 | $row = $dbw->fetchRow($result); |
289 | 303 | $newEdits = $row[0]; |
290 | 304 | |
— | — | @@ -293,13 +307,21 @@ |
294 | 308 | # don't run querys if neither user has any edits |
295 | 309 | if( $totalEdits > 0 ) { |
296 | 310 | # 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 | + ); |
298 | 316 | |
299 | 317 | #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 | + ); |
301 | 323 | } |
302 | 324 | |
303 | | - $wgOut->addHTML(wfMsgForContent('usermerge-editcount-success', $olduserID, $newuserID) . "<br />\n"); |
| 325 | + $wgOut->addHTML( wfMsgForContent( 'usermerge-editcount-success', $olduserID, $newuserID ) . "<br />\n" ); |
304 | 326 | |
305 | 327 | return true; |
306 | 328 | } |
— | — | @@ -331,81 +353,85 @@ |
332 | 354 | # select all user pages and sub-pages |
333 | 355 | $dbr = wfGetDB( DB_SLAVE ); |
334 | 356 | $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 | + ); |
345 | 364 | |
346 | 365 | $output = ''; |
347 | | - $skin =& $wgUser->getSkin(); |
348 | | - while ( $row = $dbr->fetchObject( $pages ) ) { |
| 366 | + $skin = $wgUser->getSkin(); |
| 367 | + |
| 368 | + foreach ( $pages as $row ) { |
349 | 369 | $oldPage = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
350 | 370 | $newPage = Title::makeTitleSafe( $row->page_namespace, |
351 | 371 | preg_replace( '!^[^/]+!', $newusername->getDBkey(), $row->page_title ) ); |
352 | 372 | |
353 | 373 | |
354 | | - if( $newuser_text == "Anonymous" ) { # delete ALL old pages |
| 374 | + if( $newuser_text === "Anonymous" ) { # delete ALL old pages |
355 | 375 | |
356 | 376 | 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' ) ); |
359 | 379 | |
360 | | - $oldLink = $skin->makeKnownLinkObj( $oldPage ); |
| 380 | + $oldLink = $skin->linkKnown( $oldPage ); |
361 | 381 | $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml( 'usermerge-page-deleted', $oldLink ) . '</li>'; |
362 | 382 | } |
363 | 383 | |
364 | 384 | } elseif( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) && $newPage->getLength() > 0) { # delete old pages that can't be moved |
365 | 385 | |
366 | | - $oldPageArticle = new Article($oldPage); |
367 | | - $oldPageArticle->doDeleteArticle( wfMsgHtml('usermerge-autopagedelete') ); |
| 386 | + $oldPageArticle = new Article( $oldPage, 0 ); |
| 387 | + $oldPageArticle->doDeleteArticle( wfMsgHtml( 'usermerge-autopagedelete' ) ); |
368 | 388 | |
369 | | - $link = $skin->makeKnownLinkObj( $oldPage ); |
| 389 | + $link = $skin->linkKnown( $oldPage ); |
370 | 390 | $output .= '<li class="mw-renameuser-pe">' . wfMsgHtml( 'usermerge-page-deleted', $link ) . '</li>'; |
371 | 391 | |
372 | 392 | } else { # move content to new page |
373 | 393 | |
374 | 394 | # delete target page if it exists and is blank |
375 | 395 | if( $newPage->exists() ) { |
376 | | - $newPageArticle = new Article($newPage); |
377 | | - $newPageArticle->doDeleteArticle('usermerge-autopagedelete'); |
| 396 | + $newPageArticle = new Article( $newPage, 0 ); |
| 397 | + $newPageArticle->doDeleteArticle( 'usermerge-autopagedelete' ); |
378 | 398 | } |
379 | 399 | |
380 | 400 | # move to target location |
381 | 401 | $success = $oldPage->moveTo( $newPage, false, wfMsgForContent( 'usermerge-move-log', |
382 | 402 | $oldusername->getText(), $newusername->getText() ) ); |
383 | 403 | 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 ); |
386 | 411 | $output .= '<li class="mw-renameuser-pm">' . wfMsgHtml( 'usermerge-page-moved', $oldLink, $newLink ) . '</li>'; |
387 | 412 | } else { |
388 | | - $oldLink = $skin->makeKnownLinkObj( $oldPage ); |
389 | | - $newLink = $skin->makeLinkObj( $newPage ); |
| 413 | + $oldLink = $skin->linkKnown( $oldPage ); |
| 414 | + $newLink = $skin->linkKnown( $newPage ); |
390 | 415 | $output .= '<li class="mw-renameuser-pu">' . wfMsgHtml( 'usermerge-page-unmoved', $oldLink, $newLink ) . '</li>'; |
391 | 416 | } |
392 | 417 | |
393 | 418 | # 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 | + ); |
399 | 424 | if( !$dbr->numRows( $res ) ) { |
400 | 425 | # 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' ) ); |
403 | 428 | } |
404 | 429 | |
405 | 430 | } |
406 | 431 | } |
407 | 432 | |
408 | | - if( $output ) |
| 433 | + if ( $output ) { |
409 | 434 | $wgOut->addHTML( '<ul>' . $output . '</ul>' ); |
| 435 | + } |
410 | 436 | |
411 | 437 | return true; |
412 | 438 | } |
Index: trunk/extensions/UserMerge/UserMerge.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | 'url' => 'http://www.mediawiki.org/wiki/Extension:User_Merge_and_Delete', |
38 | 38 | 'author' => array( 'Tim Laqua', 'Thomas Gries', 'Matthew April' ), |
39 | 39 | 'descriptionmsg' => 'usermerge-desc', |
40 | | - 'version' => '1.6.3' |
| 40 | + 'version' => '1.6.31' |
41 | 41 | ); |
42 | 42 | |
43 | 43 | $wgAvailableRights[] = 'usermerge'; |