r88234 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88233‎ | r88234 | r88235 >
Date:13:15, 16 May 2011
Author:ashley
Status:ok
Tags:
Comment:
peace, love and coding style
Modified paths:
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -109,7 +109,10 @@
110110 function listRevisions() {
111111 $dbr = wfGetDB( DB_SLAVE );
112112 $res = $dbr->select( 'archive',
113 - array( 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id' ),
 113+ array(
 114+ 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
 115+ 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id'
 116+ ),
114117 array( 'ar_namespace' => $this->title->getNamespace(),
115118 'ar_title' => $this->title->getDBkey() ),
116119 'PageArchive::listRevisions',
@@ -254,7 +257,7 @@
255258 if( is_null( $row->ar_text_id ) ) {
256259 // An old row from MediaWiki 1.4 or previous.
257260 // Text is embedded in this row in classic compression format.
258 - return Revision::getRevisionText( $row, "ar_" );
 261+ return Revision::getRevisionText( $row, 'ar_' );
259262 } else {
260263 // New-style: keyed to the text storage backend.
261264 $dbr = wfGetDB( DB_SLAVE );
@@ -266,7 +269,6 @@
267270 }
268271 }
269272
270 -
271273 /**
272274 * Fetch (and decompress if necessary) the stored text of the most
273275 * recently edited deleted revision of the page.
@@ -300,7 +302,7 @@
301303 $n = $dbr->selectField( 'archive', 'COUNT(ar_title)',
302304 array( 'ar_namespace' => $this->title->getNamespace(),
303305 'ar_title' => $this->title->getDBkey() ) );
304 - return ($n > 0);
 306+ return ( $n > 0 );
305307 }
306308
307309 /**
@@ -363,11 +365,12 @@
364366 return false;
365367 }
366368
367 - if( trim( $comment ) != '' )
 369+ if( trim( $comment ) != '' ) {
368370 $reason .= wfMsgForContent( 'colon-separator' ) . $comment;
 371+ }
369372 $log->addEntry( 'restore', $this->title, $reason );
370373
371 - return array($textRestored, $filesRestored, $reason);
 374+ return array( $textRestored, $filesRestored, $reason );
372375 }
373376
374377 /**
@@ -382,8 +385,9 @@
383386 * @return Mixed: number of revisions restored or false on failure
384387 */
385388 private function undeleteRevisions( $timestamps, $unsuppress = false, $comment = '' ) {
386 - if ( wfReadOnly() )
 389+ if ( wfReadOnly() ) {
387390 return false;
 391+ }
388392 $restoreAll = empty( $timestamps );
389393
390394 $dbw = wfGetDB( DB_MASTER );
@@ -458,7 +462,7 @@
459463 $ret = $dbw->resultObject( $result );
460464 $rev_count = $dbw->numRows( $result );
461465 if( !$rev_count ) {
462 - wfDebug( __METHOD__.": no revisions to restore\n" );
 466+ wfDebug( __METHOD__ . ": no revisions to restore\n" );
463467 return false; // ???
464468 }
465469
@@ -468,7 +472,7 @@
469473
470474 if( $makepage ) {
471475 // Check the state of the newest to-be version...
472 - if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) {
 476+ if( !$unsuppress && ( $row->ar_deleted & Revision::DELETED_TEXT ) ) {
473477 return false; // we can't leave the current revision like this!
474478 }
475479 // Safe to insert now...
@@ -478,7 +482,7 @@
479483 // Check if a deleted revision will become the current revision...
480484 if( $row->ar_timestamp > $previousTimestamp ) {
481485 // Check the state of the newest to-be version...
482 - if( !$unsuppress && ($row->ar_deleted & Revision::DELETED_TEXT) ) {
 486+ if( !$unsuppress && ( $row->ar_deleted & Revision::DELETED_TEXT ) ) {
483487 return false; // we can't leave the current revision like this!
484488 }
485489 }
@@ -490,8 +494,11 @@
491495 foreach ( $ret as $row ) {
492496 // Check for key dupes due to shitty archive integrity.
493497 if( $row->ar_rev_id ) {
494 - $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ );
495 - if( $exists ) continue; // don't throw DB errors
 498+ $exists = $dbw->selectField( 'revision', '1',
 499+ array( 'rev_id' => $row->ar_rev_id ), __METHOD__ );
 500+ if( $exists ) {
 501+ continue; // don't throw DB errors
 502+ }
496503 }
497504 // Insert one revision at a time...maintaining deletion status
498505 // unless we are specifically removing all restrictions...
@@ -594,7 +601,7 @@
595602 } elseif ( $wgUser->isAllowed( 'deletedtext' ) ) {
596603 $this->mAllowed = false; // user cannot restore
597604 $this->mCanView = true; // user can view content
598 - } else { // user can only view the list of revisions
 605+ } else { // user can only view the list of revisions
599606 $this->mAllowed = false;
600607 $this->mCanView = false;
601608 $this->mTimestamp = '';
@@ -632,9 +639,9 @@
633640 $this->loadRequest();
634641
635642 if ( $this->mAllowed ) {
636 - $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
 643+ $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
637644 } else {
638 - $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
 645+ $wgOut->setPageTitle( wfMsg( 'viewdeletedpage' ) );
639646 }
640647
641648 if( $par != '' ) {
@@ -648,7 +655,7 @@
649656 }
650657
651658 if( is_null( $this->mTargetObj ) ) {
652 - # Not all users can just browse every deleted page from the list
 659+ # Not all users can just browse every deleted page from the list
653660 if( $wgUser->isAllowed( 'browsearchive' ) ) {
654661 $this->showSearchForm();
655662
@@ -685,7 +692,7 @@
686693 return $this->showFile( $this->mFile );
687694 }
688695 }
689 - if( $this->mRestore && $this->mAction == "submit" ) {
 696+ if( $this->mRestore && $this->mAction == 'submit' ) {
690697 global $wgUploadMaintenance;
691698 if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
692699 $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
@@ -693,8 +700,8 @@
694701 }
695702 return $this->undelete();
696703 }
697 - if( $this->mInvert && $this->mAction == "submit" ) {
698 - return $this->showHistory( );
 704+ if( $this->mInvert && $this->mAction == 'submit' ) {
 705+ return $this->showHistory();
699706 }
700707 return $this->showHistory();
701708 }
@@ -757,7 +764,9 @@
758765
759766 $skin = $wgUser->getSkin();
760767
761 - if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
 768+ if( !preg_match( '/[0-9]{14}/', $timestamp ) ) {
 769+ return 0;
 770+ }
762771
763772 $archive = new PageArchive( $this->mTargetObj );
764773 $rev = $archive->getRevision( $timestamp );
@@ -767,8 +776,8 @@
768777 return;
769778 }
770779
771 - if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
772 - if( !$rev->userCan(Revision::DELETED_TEXT) ) {
 780+ if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
 781+ if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
773782 $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1\n</div>\n", 'rev-deleted-text-permission' );
774783 return;
775784 } else {
@@ -826,7 +835,7 @@
827836 wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
828837
829838 if( $this->mPreview ) {
830 - //Hide [edit]s
 839+ // Hide [edit]s
831840 $popts = $wgOut->parserOptions();
832841 $popts->setEditSection( false );
833842 $wgOut->parserOptions( $popts );
@@ -881,7 +890,7 @@
882891 function revDeleteLink( $rev ) {
883892 global $wgUser;
884893 $canHide = $wgUser->isAllowed( 'deleterevision' );
885 - if( $canHide || ($rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' )) ) {
 894+ if( $canHide || ( $rev->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
886895 $skin = $wgUser->getSkin();
887896 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
888897 $revdlink = $skin->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
@@ -948,7 +957,7 @@
949958
950959 /**
951960 * @param $rev Revision
952 - * @param $prefix
 961+ * @param $prefix
953962 * @return string
954963 */
955964 private function diffHeader( $rev, $prefix ) {
@@ -970,7 +979,7 @@
971980 // Add show/hide deletion links if available
972981 $del .= $this->revDeleteLink( $rev );
973982 return
974 - '<div id="mw-diff-'.$prefix.'title1"><strong>' .
 983+ '<div id="mw-diff-' . $prefix . 'title1"><strong>' .
975984 $sk->link(
976985 $targetPage,
977986 wfMsgHtml(
@@ -1004,7 +1013,7 @@
10051014 $wgOut->addHTML(
10061015 Xml::openElement( 'form', array(
10071016 'method' => 'POST',
1008 - 'action' => $this->getTitle()->getLocalUrl(
 1017+ 'action' => $this->getTitle()->getLocalURL(
10091018 'target=' . urlencode( $this->mTarget ) .
10101019 '&file=' . urlencode( $key ) .
10111020 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
@@ -1037,32 +1046,35 @@
10381047 wfStreamFile( $path );
10391048 }
10401049
1041 - private function showHistory( ) {
 1050+ private function showHistory() {
10421051 global $wgUser, $wgOut;
10431052
10441053 $sk = $wgUser->getSkin();
10451054 if( $this->mAllowed ) {
1046 - $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
 1055+ $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
10471056 } else {
1048 - $wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
 1057+ $wgOut->setPageTitle( wfMsg( 'viewdeletedpage' ) );
10491058 }
10501059
1051 - $wgOut->wrapWikiMsg( "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n", array ( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() ) );
 1060+ $wgOut->wrapWikiMsg(
 1061+ "<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
 1062+ array( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() )
 1063+ );
10521064
10531065 $archive = new PageArchive( $this->mTargetObj );
10541066 /*
10551067 $text = $archive->getLastRevisionText();
10561068 if( is_null( $text ) ) {
1057 - $wgOut->addWikiMsg( "nohistory" );
 1069+ $wgOut->addWikiMsg( 'nohistory' );
10581070 return;
10591071 }
10601072 */
10611073 $wgOut->addHTML( '<div class="mw-undelete-history">' );
10621074 if ( $this->mAllowed ) {
1063 - $wgOut->addWikiMsg( "undeletehistory" );
1064 - $wgOut->addWikiMsg( "undeleterevdel" );
 1075+ $wgOut->addWikiMsg( 'undeletehistory' );
 1076+ $wgOut->addWikiMsg( 'undeleterevdel' );
10651077 } else {
1066 - $wgOut->addWikiMsg( "undeletehistorynoadmin" );
 1078+ $wgOut->addWikiMsg( 'undeletehistorynoadmin' );
10671079 }
10681080 $wgOut->addHTML( '</div>' );
10691081
@@ -1117,12 +1129,12 @@
11181130 "<tr>
11191131 <td>&#160;</td>
11201132 <td class='mw-input'>" .
1121 - Xml::checkLabel( wfMsg('revdelete-unsuppress'), 'wpUnsuppress',
 1133+ Xml::checkLabel( wfMsg( 'revdelete-unsuppress' ), 'wpUnsuppress',
11221134 'mw-undelete-unsuppress', $this->mUnsuppress ).
11231135 "</td>
11241136 </tr>";
11251137 } else {
1126 - $unsuppressBox = "";
 1138+ $unsuppressBox = '';
11271139 }
11281140 $table =
11291141 Xml::fieldset( wfMsg( 'undelete-fieldset-title' ) ) .
@@ -1159,7 +1171,7 @@
11601172
11611173 if( $haveRevisions ) {
11621174 # The page's stored (deleted) history:
1163 - $wgOut->addHTML("<ul>");
 1175+ $wgOut->addHTML( '<ul>' );
11641176 $remaining = $revisions->numRows();
11651177 $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
11661178
@@ -1168,19 +1180,19 @@
11691181 $wgOut->addHTML( $this->formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) );
11701182 }
11711183 $revisions->free();
1172 - $wgOut->addHTML("</ul>");
 1184+ $wgOut->addHTML( '</ul>' );
11731185 } else {
1174 - $wgOut->addWikiMsg( "nohistory" );
 1186+ $wgOut->addWikiMsg( 'nohistory' );
11751187 }
11761188
11771189 if( $haveFiles ) {
11781190 $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
1179 - $wgOut->addHTML( "<ul>" );
 1191+ $wgOut->addHTML( '<ul>' );
11801192 foreach ( $files as $row ) {
11811193 $wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
11821194 }
11831195 $files->free();
1184 - $wgOut->addHTML( "</ul>" );
 1196+ $wgOut->addHTML( '</ul>' );
11851197 }
11861198
11871199 if ( $this->mAllowed ) {
@@ -1205,7 +1217,7 @@
12061218 if( $this->mAllowed ) {
12071219 if( $this->mInvert ) {
12081220 if( in_array( $ts, $this->mTargetTimestamp ) ) {
1209 - $checkBox = Xml::check( "ts$ts");
 1221+ $checkBox = Xml::check( "ts$ts" );
12101222 } else {
12111223 $checkBox = Xml::check( "ts$ts", true );
12121224 }
@@ -1221,12 +1233,12 @@
12221234 # Last link
12231235 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
12241236 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1225 - $last = wfMsgHtml('diff');
1226 - } else if( $remaining > 0 || ($earliestLiveTime && $ts > $earliestLiveTime) ) {
 1237+ $last = wfMsgHtml( 'diff' );
 1238+ } else if( $remaining > 0 || ( $earliestLiveTime && $ts > $earliestLiveTime ) ) {
12271239 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
12281240 $last = $sk->linkKnown(
12291241 $titleObj,
1230 - wfMsgHtml('diff'),
 1242+ wfMsgHtml( 'diff' ),
12311243 array(),
12321244 array(
12331245 'target' => $this->mTargetObj->getPrefixedText(),
@@ -1236,16 +1248,17 @@
12371249 );
12381250 } else {
12391251 $pageLink = $this->getPageLink( $rev, $titleObj, $ts, $sk );
1240 - $last = wfMsgHtml('diff');
 1252+ $last = wfMsgHtml( 'diff' );
12411253 }
12421254 } else {
12431255 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
1244 - $last = wfMsgHtml('diff');
 1256+ $last = wfMsgHtml( 'diff' );
12451257 }
12461258 // User links
12471259 $userLink = $sk->revUserTools( $rev );
12481260 // Revision text size
1249 - if( !is_null($size = $row->ar_len) ) {
 1261+ $size = $row->ar_len;
 1262+ if( !is_null( $size ) ) {
12501263 $stxt = $sk->formatRevisionSize( $size );
12511264 }
12521265 // Edit summary
@@ -1262,7 +1275,7 @@
12631276
12641277 $ts = wfTimestamp( TS_MW, $row->fa_timestamp );
12651278 if( $this->mAllowed && $row->fa_storage_key ) {
1266 - $checkBox = Xml::check( "fileid" . $row->fa_id );
 1279+ $checkBox = Xml::check( 'fileid' . $row->fa_id );
12671280 $key = urlencode( $row->fa_storage_key );
12681281 $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key, $sk );
12691282 } else {
@@ -1323,8 +1336,9 @@
13241337 'timestamp' => $ts
13251338 )
13261339 );
1327 - if( $rev->isDeleted(Revision::DELETED_TEXT) )
 1340+ if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
13281341 $link = '<span class="history-deleted">' . $link . '</span>';
 1342+ }
13291343 return $link;
13301344 }
13311345 }
@@ -1352,8 +1366,9 @@
13531367 'token' => $wgUser->editToken( $key )
13541368 )
13551369 );
1356 - if( $file->isDeleted(File::DELETED_FILE) )
 1370+ if( $file->isDeleted( File::DELETED_FILE ) ) {
13571371 $link = '<span class="history-deleted">' . $link . '</span>';
 1372+ }
13581373 return $link;
13591374 }
13601375 }
@@ -1371,8 +1386,9 @@
13721387 } else {
13731388 $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
13741389 $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
1375 - if( $file->isDeleted( File::DELETED_USER ) )
 1390+ if( $file->isDeleted( File::DELETED_USER ) ) {
13761391 $link = '<span class="history-deleted">' . $link . '</span>';
 1392+ }
13771393 return $link;
13781394 }
13791395 }
@@ -1386,11 +1402,13 @@
13871403 */
13881404 function getFileComment( $file, $sk ) {
13891405 if( !$file->userCan( File::DELETED_COMMENT ) ) {
1390 - return '<span class="history-deleted"><span class="comment">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
 1406+ return '<span class="history-deleted"><span class="comment">' .
 1407+ wfMsgHtml( 'rev-deleted-comment' ) . '</span></span>';
13911408 } else {
13921409 $link = $sk->commentBlock( $file->getRawDescription() );
1393 - if( $file->isDeleted(File::DELETED_COMMENT) )
 1410+ if( $file->isDeleted( File::DELETED_COMMENT ) ) {
13941411 $link = '<span class="history-deleted">' . $link . '</span>';
 1412+ }
13951413 return $link;
13961414 }
13971415 }
@@ -1409,17 +1427,18 @@
14101428 $this->mFileVersions,
14111429 $this->mUnsuppress );
14121430
1413 - if( is_array($ok) ) {
1414 - if ( $ok[1] ) // Undeleted file count
 1431+ if( is_array( $ok ) ) {
 1432+ if ( $ok[1] ) { // Undeleted file count
14151433 wfRunHooks( 'FileUndeleteComplete', array(
14161434 $this->mTargetObj, $this->mFileVersions,
1417 - $wgUser, $this->mComment) );
 1435+ $wgUser, $this->mComment ) );
 1436+ }
14181437
14191438 $skin = $wgUser->getSkin();
14201439 $link = $skin->linkKnown( $this->mTargetObj );
14211440 $wgOut->addWikiMsgArray( 'undeletedpage', array( $link ), array( 'replaceafter' ) );
14221441 } else {
1423 - $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
 1442+ $wgOut->showFatalError( wfMsg( 'cannotundelete' ) );
14241443 $wgOut->addWikiMsg( 'undeleterevdel' );
14251444 }
14261445
@@ -1429,7 +1448,7 @@
14301449 $wgOut->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) );
14311450 }
14321451 } else {
1433 - $wgOut->showFatalError( wfMsg( "cannotundelete" ) );
 1452+ $wgOut->showFatalError( wfMsg( 'cannotundelete' ) );
14341453 }
14351454 return false;
14361455 }

Status & tagging log