X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Fspecials%2FSpecialUndelete.php;h=e6137251b98834cc95758219243cb2231fdeff87;hb=90c703d61c485c633b214f78f48102c2848b82d8;hp=87c1921feef5bf95688e71dff589f630e689ccfa;hpb=b608000544498efc7a032941d59a7f7b451676b7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index 87c1921fee..e6137251b9 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -1,25 +1,29 @@ execute(); -} - /** * Used to show archived pages and eventually restore them. + * * @ingroup SpecialPage */ class PageArchive { @@ -28,7 +32,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 +290,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 ); @@ -488,7 +492,7 @@ class PageArchive { $revision = null; $restored = 0; - while( $row = $ret->fetchObject() ) { + foreach ( $ret as $row ) { // Check for key dupes due to shitty archive integrity. if( $row->ar_rev_id ) { $exists = $dbw->selectField( 'revision', '1', array('rev_id' => $row->ar_rev_id), __METHOD__ ); @@ -496,12 +500,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 +518,7 @@ class PageArchive { 'ar_title' => $this->title->getDBkey(), $oldones ), __METHOD__ ); - + // Was anything restored at all? if( $restored == 0 ) return 0; @@ -541,7 +545,8 @@ class PageArchive { } } else { // Revision couldn't be created. This is very weird - return self::UNDELETE_UNKNOWNERR; + wfDebug( "Undelete: unknown error...\n" ); + return false; } return $restored; @@ -551,36 +556,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 SpecialUndelete 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 +607,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 +626,34 @@ 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 ); + $wgUser->getSkin()->setRelevantTitle( $this->mTargetObj ); + } 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' ) ) { @@ -685,8 +715,8 @@ class UndeleteForm { 'method' => 'get', 'action' => $wgScript ) ) . Xml::fieldset( wfMsg( 'undelete-search-box' ) ) . - Xml::hidden( 'title', - SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) . + Html::hidden( 'title', + $this->getTitle()->getPrefixedDbKey() ) . Xml::inputLabel( wfMsg( 'undelete-search-prefix' ), 'prefix', 'prefix', 20, $this->mSearchPrefix ) . ' ' . @@ -698,7 +728,7 @@ class UndeleteForm { // Generic list of deleted pages private function showList( $result ) { - global $wgLang, $wgContLang, $wgUser, $wgOut; + global $wgLang, $wgUser, $wgOut; if( $result->numRows() == 0 ) { $wgOut->addWikiMsg( 'undelete-no-results' ); @@ -708,9 +738,9 @@ class UndeleteForm { $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) ); $sk = $wgUser->getSkin(); - $undelete = SpecialPage::getTitleFor( 'Undelete' ); + $undelete = $this->getTitle(); $wgOut->addHTML( "