From 3e219b7cbe5bb8c365a6c2fc33a4656dd32aa336 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Wed, 16 Jun 2010 19:02:12 +0000 Subject: [PATCH] * Modified Special:Undelete to extend SpecialPage instead of using wfSpecialUndelete() * Changed SpecialPage::getTitleFor( 'Undelete' ) to $this->getTitle() --- includes/SpecialPage.php | 2 +- includes/specials/SpecialUndelete.php | 150 +++++++++++++------------- 2 files changed, 78 insertions(+), 74 deletions(-) diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 3c3cc6c592..af12432182 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -171,7 +171,7 @@ class SpecialPage { # Page tools 'Export' => 'SpecialExport', 'Import' => 'SpecialImport', - 'Undelete' => array( 'SpecialPage', 'Undelete', 'deletedhistory' ), + 'Undelete' => 'UndeleteForm', 'Whatlinkshere' => 'SpecialWhatlinkshere', 'MergeHistory' => 'SpecialMergeHistory', diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index 4e5578dfe8..b581cebf98 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -1,23 +1,5 @@ execute(); -} - /** * Used to show archived pages and eventually restore them. * @ingroup SpecialPage @@ -28,7 +10,7 @@ class PageArchive { function __construct( $title ) { if( is_null( $title ) ) { - throw new MWException( 'Archiver() given a null title.'); + throw new MWException( __METHOD__ . ' given a null title.' ); } $this->title = $title; } @@ -286,7 +268,7 @@ class PageArchive { array( 'ar_text', 'ar_flags', 'ar_text_id' ), array( 'ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey() ), - 'PageArchive::getLastRevisionText', + __METHOD__, array( 'ORDER BY' => 'ar_timestamp DESC' ) ); if( $row ) { return $this->getTextFromRow( $row ); @@ -496,12 +478,12 @@ class PageArchive { } // Insert one revision at a time...maintaining deletion status // unless we are specifically removing all restrictions... - $revision = Revision::newFromArchiveRow( $row, - array( - 'page' => $pageId, + $revision = Revision::newFromArchiveRow( $row, + array( + 'page' => $pageId, 'deleted' => $unsuppress ? 0 : $row->ar_deleted ) ); - + $revision->insertOn( $dbw ); $restored++; @@ -514,7 +496,7 @@ class PageArchive { 'ar_title' => $this->title->getDBkey(), $oldones ), __METHOD__ ); - + // Was anything restored at all? if( $restored == 0 ) return 0; @@ -551,36 +533,45 @@ class PageArchive { } /** - * The HTML form for Special:Undelete, which allows users with the appropriate - * permissions to view and restore deleted content. + * Special page allowing users with the appropriate permissions to view + * and restore deleted content. + * * @ingroup SpecialPage */ -class UndeleteForm { +class UndeleteForm extends SpecialPage { var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj; - var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken; + var $mTargetTimestamp, $mAllowed, $mCanView, $mComment, $mToken, $mRequest; + + function __construct( $request = null ) { + parent::__construct( 'Undelete', 'deletedhistory' ); - function UndeleteForm( $request, $par = "" ) { + if ( $request === null ) { + global $wgRequest; + $this->mRequest = $wgRequest; + } else { + $this->mRequest = $request; + } + } + + function loadRequest() { global $wgUser; - $this->mAction = $request->getVal( 'action' ); - $this->mTarget = $request->getVal( 'target' ); - $this->mSearchPrefix = $request->getText( 'prefix' ); - $time = $request->getVal( 'timestamp' ); + $this->mAction = $this->mRequest->getVal( 'action' ); + $this->mTarget = $this->mRequest->getVal( 'target' ); + $this->mSearchPrefix = $this->mRequest->getText( 'prefix' ); + $time = $this->mRequest->getVal( 'timestamp' ); $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : ''; - $this->mFile = $request->getVal( 'file' ); - - $posted = $request->wasPosted() && - $wgUser->matchEditToken( $request->getVal( 'wpEditToken' ) ); - $this->mRestore = $request->getCheck( 'restore' ) && $posted; - $this->mInvert = $request->getCheck( 'invert' ) && $posted; - $this->mPreview = $request->getCheck( 'preview' ) && $posted; - $this->mDiff = $request->getCheck( 'diff' ); - $this->mComment = $request->getText( 'wpComment' ); - $this->mUnsuppress = $request->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); - $this->mToken = $request->getVal( 'token' ); - - if( $par != "" ) { - $this->mTarget = $par; - } + $this->mFile = $this->mRequest->getVal( 'file' ); + + $posted = $this->mRequest->wasPosted() && + $wgUser->matchEditToken( $this->mRequest->getVal( 'wpEditToken' ) ); + $this->mRestore = $this->mRequest->getCheck( 'restore' ) && $posted; + $this->mInvert = $this->mRequest->getCheck( 'invert' ) && $posted; + $this->mPreview = $this->mRequest->getCheck( 'preview' ) && $posted; + $this->mDiff = $this->mRequest->getCheck( 'diff' ); + $this->mComment = $this->mRequest->getText( 'wpComment' ); + $this->mUnsuppress = $this->mRequest->getVal( 'wpUnsuppress' ) && $wgUser->isAllowed( 'suppressrevision' ); + $this->mToken = $this->mRequest->getVal( 'token' ); + if ( $wgUser->isAllowed( 'undelete' ) && !$wgUser->isBlocked() ) { $this->mAllowed = true; // user can restore $this->mCanView = true; // user can view content @@ -593,11 +584,7 @@ class UndeleteForm { $this->mTimestamp = ''; $this->mRestore = false; } - if ( $this->mTarget !== "" ) { - $this->mTargetObj = Title::newFromURL( $this->mTarget ); - } else { - $this->mTargetObj = null; - } + if( $this->mRestore || $this->mInvert ) { $timestamps = array(); $this->mFileVersions = array(); @@ -616,14 +603,33 @@ class UndeleteForm { } } - function execute() { + function execute( $par ) { global $wgOut, $wgUser; + + $this->setHeaders(); + if ( !$this->userCanExecute( $wgUser ) ) { + $this->displayRestrictionError(); + return; + } + $this->outputHeader(); + + $this->loadRequest(); + if ( $this->mAllowed ) { $wgOut->setPagetitle( wfMsg( "undeletepage" ) ); } else { $wgOut->setPagetitle( wfMsg( "viewdeletedpage" ) ); } + if( $par != '' ) { + $this->mTarget = $par; + } + if ( $this->mTarget !== '' ) { + $this->mTargetObj = Title::newFromURL( $this->mTarget ); + } else { + $this->mTargetObj = null; + } + if( is_null( $this->mTargetObj ) ) { # Not all users can just browse every deleted page from the list if( $wgUser->isAllowed( 'browsearchive' ) ) { @@ -686,7 +692,7 @@ class UndeleteForm { 'action' => $wgScript ) ) . Xml::fieldset( wfMsg( 'undelete-search-box' ) ) . Xml::hidden( 'title', - SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) . + $this->getTitle()->getPrefixedDbKey() ) . Xml::inputLabel( wfMsg( 'undelete-search-prefix' ), 'prefix', 'prefix', 20, $this->mSearchPrefix ) . ' ' . @@ -708,7 +714,7 @@ class UndeleteForm { $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) ); $sk = $wgUser->getSkin(); - $undelete = SpecialPage::getTitleFor( 'Undelete' ); + $undelete = $this->getTitle(); $wgOut->addHTML( "