r68129 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68128‎ | r68129 | r68130 >
Date:19:02, 16 June 2010
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Modified Special:Undelete to extend SpecialPage instead of using wfSpecialUndelete()
* Changed SpecialPage::getTitleFor( 'Undelete' ) to $this->getTitle()
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUndelete.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUndelete.php
@@ -1,24 +1,6 @@
22 <?php
33
44 /**
5 - * Special page allowing users with the appropriate permissions to view
6 - * and restore deleted content
7 - *
8 - * @file
9 - * @ingroup SpecialPage
10 - */
11 -
12 -/**
13 - * Constructor
14 - */
15 -function wfSpecialUndelete( $par ) {
16 - global $wgRequest;
17 -
18 - $form = new UndeleteForm( $wgRequest, $par );
19 - $form->execute();
20 -}
21 -
22 -/**
235 * Used to show archived pages and eventually restore them.
246 * @ingroup SpecialPage
257 */
@@ -28,7 +10,7 @@
2911
3012 function __construct( $title ) {
3113 if( is_null( $title ) ) {
32 - throw new MWException( 'Archiver() given a null title.');
 14+ throw new MWException( __METHOD__ . ' given a null title.' );
3315 }
3416 $this->title = $title;
3517 }
@@ -286,7 +268,7 @@
287269 array( 'ar_text', 'ar_flags', 'ar_text_id' ),
288270 array( 'ar_namespace' => $this->title->getNamespace(),
289271 'ar_title' => $this->title->getDBkey() ),
290 - 'PageArchive::getLastRevisionText',
 272+ __METHOD__,
291273 array( 'ORDER BY' => 'ar_timestamp DESC' ) );
292274 if( $row ) {
293275 return $this->getTextFromRow( $row );
@@ -496,12 +478,12 @@
497479 }
498480 // Insert one revision at a time...maintaining deletion status
499481 // unless we are specifically removing all restrictions...
500 - $revision = Revision::newFromArchiveRow( $row,
501 - array(
502 - 'page' => $pageId,
 482+ $revision = Revision::newFromArchiveRow( $row,
 483+ array(
 484+ 'page' => $pageId,
503485 'deleted' => $unsuppress ? 0 : $row->ar_deleted
504486 ) );
505 -
 487+
506488 $revision->insertOn( $dbw );
507489 $restored++;
508490
@@ -514,7 +496,7 @@
515497 'ar_title' => $this->title->getDBkey(),
516498 $oldones ),
517499 __METHOD__ );
518 -
 500+
519501 // Was anything restored at all?
520502 if( $restored == 0 )
521503 return 0;
@@ -551,36 +533,45 @@
552534 }
553535
554536 /**
555 - * The HTML form for Special:Undelete, which allows users with the appropriate
556 - * permissions to view and restore deleted content.
 537+ * Special page allowing users with the appropriate permissions to view
 538+ * and restore deleted content.
 539+ *
557540 * @ingroup SpecialPage
558541 */
559 -class UndeleteForm {
 542+class UndeleteForm extends SpecialPage {
560543 var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
561 - var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken;
 544+ var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken, $mRequest;
562545
563 - function UndeleteForm( $request, $par = "" ) {
 546+ function __construct( $request = null ) {
 547+ parent::__construct( 'Undelete', 'deletedhistory' );
 548+
 549+ if ( $request === null ) {
 550+ global $wgRequest;
 551+ $this->mRequest = $wgRequest;
 552+ } else {
 553+ $this->mRequest = $request;
 554+ }
 555+ }
 556+
 557+ function loadRequest() {
564558 global $wgUser;
565 - $this->mAction = $request->getVal( 'action' );
566 - $this->mTarget = $request->getVal( 'target' );
567 - $this->mSearchPrefix = $request->getText( 'prefix' );
568 - $time = $request->getVal( 'timestamp' );
 559+ $this->mAction = $this->mRequest->getVal( 'action' );
 560+ $this->mTarget = $this->mRequest->getVal( 'target' );
 561+ $this->mSearchPrefix = $this->mRequest->getText( 'prefix' );
 562+ $time = $this->mRequest->getVal( 'timestamp' );
569563 $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
570 - $this->mFile = $request->getVal( 'file' );
 564+ $this->mFile = $this->mRequest->getVal( 'file' );
571565
572 - $posted = $request->wasPosted() &&
573 - $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) );
574 - $this->mRestore = $request->getCheck( 'restore' ) && $posted;
575 - $this->mInvert = $request->getCheck( 'invert' ) && $posted;
576 - $this->mPreview = $request->getCheck( 'preview' ) && $posted;
577 - $this->mDiff = $request->getCheck( 'diff' );
578 - $this->mComment = $request->getText( 'wpComment' );
579 - $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
580 - $this->mToken = $request->getVal( 'token' );
 566+ $posted = $this->mRequest->wasPosted() &&
 567+ $wgUser->matchEditToken( $this->mRequest->getVal( 'wpEditToken' ) );
 568+ $this->mRestore = $this->mRequest->getCheck( 'restore' ) && $posted;
 569+ $this->mInvert = $this->mRequest->getCheck( 'invert' ) && $posted;
 570+ $this->mPreview = $this->mRequest->getCheck( 'preview' ) && $posted;
 571+ $this->mDiff = $this->mRequest->getCheck( 'diff' );
 572+ $this->mComment = $this->mRequest->getText( 'wpComment' );
 573+ $this->mUnsuppress = $this->mRequest->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' );
 574+ $this->mToken = $this->mRequest->getVal( 'token' );
581575
582 - if( $par != "" ) {
583 - $this->mTarget = $par;
584 - }
585576 if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) {
586577 $this->mAllowed = true; // user can restore
587578 $this->mCanView = true; // user can view content
@@ -593,11 +584,7 @@
594585 $this->mTimestamp = '';
595586 $this->mRestore = false;
596587 }
597 - if ( $this->mTarget !== "" ) {
598 - $this->mTargetObj = Title::newFromURL( $this->mTarget );
599 - } else {
600 - $this->mTargetObj = null;
601 - }
 588+
602589 if( $this->mRestore || $this->mInvert ) {
603590 $timestamps = array();
604591 $this->mFileVersions = array();
@@ -616,14 +603,33 @@
617604 }
618605 }
619606
620 - function execute() {
 607+ function execute( $par ) {
621608 global $wgOut, $wgUser;
 609+
 610+ $this->setHeaders();
 611+ if ( !$this->userCanExecute( $wgUser ) ) {
 612+ $this->displayRestrictionError();
 613+ return;
 614+ }
 615+ $this->outputHeader();
 616+
 617+ $this->loadRequest();
 618+
622619 if ( $this->mAllowed ) {
623620 $wgOut->setPagetitle( wfMsg( "undeletepage" ) );
624621 } else {
625622 $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) );
626623 }
627624
 625+ if( $par != '' ) {
 626+ $this->mTarget = $par;
 627+ }
 628+ if ( $this->mTarget !== '' ) {
 629+ $this->mTargetObj = Title::newFromURL( $this->mTarget );
 630+ } else {
 631+ $this->mTargetObj = null;
 632+ }
 633+
628634 if( is_null( $this->mTargetObj ) ) {
629635 # Not all users can just browse every deleted page from the list
630636 if( $wgUser->isAllowed( 'browsearchive' ) ) {
@@ -686,7 +692,7 @@
687693 'action' => $wgScript ) ) .
688694 Xml::fieldset( wfMsg( 'undelete-search-box' ) ) .
689695 Xml::hidden( 'title',
690 - SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
 696+ $this->getTitle()->getPrefixedDbKey() ) .
691697 Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
692698 'prefix', 'prefix', 20,
693699 $this->mSearchPrefix ) . ' ' .
@@ -708,7 +714,7 @@
709715 $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
710716
711717 $sk = $wgUser->getSkin();
712 - $undelete = SpecialPage::getTitleFor( 'Undelete' );
 718+ $undelete = $this->getTitle();
713719 $wgOut->addHTML( "<ul>\n" );
714720 while( $row = $result->fetchObject() ) {
715721 $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
@@ -731,7 +737,7 @@
732738
733739 private function showRevision( $timestamp ) {
734740 global $wgLang, $wgUser, $wgOut;
735 - $self = SpecialPage::getTitleFor( 'Undelete' );
 741+
736742 $skin = $wgUser->getSkin();
737743
738744 if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
@@ -758,7 +764,7 @@
759765 $wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
760766
761767 $link = $skin->linkKnown(
762 - SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
 768+ $this->getTitle( $this->mTargetObj->getPrefixedDBkey() ),
763769 htmlspecialchars( $this->mTargetObj->getPrefixedText() )
764770 );
765771
@@ -829,7 +835,7 @@
830836 Xml::openElement( 'div' ) .
831837 Xml::openElement( 'form', array(
832838 'method' => 'post',
833 - 'action' => $self->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
 839+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
834840 Xml::element( 'input', array(
835841 'type' => 'hidden',
836842 'name' => 'target',
@@ -895,7 +901,7 @@
896902 $isDeleted = !( $rev->getId() && $rev->getTitle() );
897903 if( $isDeleted ) {
898904 /// @todo Fixme: $rev->getTitle() is null for deleted revs...?
899 - $targetPage = SpecialPage::getTitleFor( 'Undelete' );
 905+ $targetPage = $this->getTitle();
900906 $targetQuery = array(
901907 'target' => $this->mTargetObj->getPrefixedText(),
902908 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
@@ -912,7 +918,7 @@
913919 if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
914920 $del .= $sk->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
915921 } else {
916 - $query = array(
 922+ $query = array(
917923 'type' => 'archive',
918924 'target' => $this->mTargetObj->getPrefixedDbkey(),
919925 'ids' => $rev->getTimestamp()
@@ -955,10 +961,10 @@
956962 $this->mTargetObj->getText(),
957963 $wgLang->date( $file->getTimestamp() ),
958964 $wgLang->time( $file->getTimestamp() ) );
959 - $wgOut->addHTML(
960 - Xml::openElement( 'form', array(
 965+ $wgOut->addHTML(
 966+ Xml::openElement( 'form', array(
961967 'method' => 'POST',
962 - 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
 968+ 'action' => $this->getTitle()->getLocalUrl(
963969 'target=' . urlencode( $this->mTarget ) .
964970 '&file=' . urlencode( $key ) .
965971 '&token=' . urlencode( $wgUser->editToken( $key ) ) )
@@ -986,7 +992,7 @@
987993
988994 global $IP;
989995 require_once( "$IP/includes/StreamFile.php" );
990 - $repo = RepoGroup::singleton()->getLocalRepo();
 996+ $repo = RepoGroup::singleton()->getLocalRepo();
991997 $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
992998 wfStreamFile( $path );
993999 }
@@ -1048,8 +1054,7 @@
10491055 }
10501056
10511057 if ( $this->mAllowed ) {
1052 - $titleObj = SpecialPage::getTitleFor( "Undelete" );
1053 - $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) );
 1058+ $action = $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) );
10541059 # Start the form here
10551060 $top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
10561061 $wgOut->addHTML( $top );
@@ -1153,7 +1158,7 @@
11541159 private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
11551160 global $wgUser, $wgLang;
11561161
1157 - $rev = Revision::newFromArchiveRow( $row,
 1162+ $rev = Revision::newFromArchiveRow( $row,
11581163 array( 'page' => $this->mTargetObj->getArticleId() ) );
11591164 $stxt = '';
11601165 $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
@@ -1173,7 +1178,7 @@
11741179 }
11751180 // Build page & diff links...
11761181 if( $this->mCanView ) {
1177 - $titleObj = SpecialPage::getTitleFor( "Undelete" );
 1182+ $titleObj = $this->getTitle();
11781183 # Last link
11791184 if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
11801185 $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
@@ -1236,13 +1241,12 @@
12371242 $checkBox = Xml::check( "fileid" . $row->fa_id );
12381243 $key = urlencode( $row->fa_storage_key );
12391244 $target = urlencode( $this->mTarget );
1240 - $titleObj = SpecialPage::getTitleFor( "Undelete" );
1241 - $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
 1245+ $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key, $sk );
12421246 } else {
12431247 $checkBox = '';
12441248 $pageLink = $wgLang->timeanddate( $ts, true );
12451249 }
1246 - $userLink = $this->getFileUser( $file, $sk );
 1250+ $userLink = $this->getFileUser( $file, $sk );
12471251 $data =
12481252 wfMsg( 'widthheight',
12491253 $wgLang->formatNum( $row->fa_width ),
Index: trunk/phase3/includes/SpecialPage.php
@@ -171,7 +171,7 @@
172172 # Page tools
173173 'Export' => 'SpecialExport',
174174 'Import' => 'SpecialImport',
175 - 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ),
 175+ 'Undelete' => 'UndeleteForm',
176176 'Whatlinkshere' => 'SpecialWhatlinkshere',
177177 'MergeHistory' => 'SpecialMergeHistory',
178178

Follow-up revisions

RevisionCommit summaryAuthorDate
r79643Followup r68129: rename UndeleteForm to SpecialUndelete per CR. Not used in a...demon13:20, 5 January 2011

Comments

#Comment by Happy-melon (talk | contribs)   15:44, 15 December 2010

UndeleteForm should be renamed to SpecialUndelete. You're already changing its structure enough that B/C is dubious, and it's very unlikely to actually be used anywhere.

Status & tagging log