From d814431e594e88bde1a5f5a09df453385b1da52e Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 7 Nov 2011 18:30:22 +0000 Subject: [PATCH] * Added specific page header when showing "search deleted pages" form * Throw an exception directly instead of calling OutputPage::permissionRequired() * Removed unreachable code paths * Show nicer error messages when undeletion could not be executed * Pass the subpage parameter to loadRequest() and define $mTarget and $mTargetObj there --- includes/specials/SpecialUndelete.php | 163 ++++++++++++-------------- languages/messages/MessagesEn.php | 2 + languages/messages/MessagesQqq.php | 2 + maintenance/language/messages.inc | 2 + 4 files changed, 81 insertions(+), 88 deletions(-) diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index cfc59aeca0..3c08ee731e 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -581,12 +581,20 @@ class SpecialUndelete extends SpecialPage { parent::__construct( 'Undelete', 'deletedhistory' ); } - function loadRequest() { + function loadRequest( $par ) { $request = $this->getRequest(); $user = $this->getUser(); $this->mAction = $request->getVal( 'action' ); - $this->mTarget = $request->getVal( 'target' ); + if ( $par !== null && $par !== '' ) { + $this->mTarget = $par; + } else { + $this->mTarget = $request->getVal( 'target' ); + } + $this->mTargetObj = null; + if ( $this->mTarget !== null && $this->mTarget !== '' ) { + $this->mTargetObj = Title::newFromURL( $this->mTarget ); + } $this->mSearchPrefix = $request->getText( 'prefix' ); $time = $request->getVal( 'timestamp' ); $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : ''; @@ -608,6 +616,7 @@ class SpecialUndelete extends SpecialPage { } elseif ( $user->isAllowed( 'deletedtext' ) ) { $this->mAllowed = false; // user cannot restore $this->mCanView = true; // user can view content + $this->mRestore = false; } else { // user can only view the list of revisions $this->mAllowed = false; $this->mCanView = false; @@ -634,94 +643,68 @@ class SpecialUndelete extends SpecialPage { } function execute( $par ) { - $this->setHeaders(); - $user = $this->getUser(); if ( !$this->userCanExecute( $user ) ) { $this->displayRestrictionError(); return; } + $this->setHeaders(); $this->outputHeader(); - $this->loadRequest(); + $this->loadRequest( $par ); $out = $this->getOutput(); + if ( is_null( $this->mTargetObj ) ) { + $out->addWikiMsg( 'undelete-header' ); + + # Not all users can just browse every deleted page from the list + if ( $user->isAllowed( 'browsearchive' ) ) { + $this->showSearchForm(); + } + return; + } + if ( $this->mAllowed ) { $out->setPageTitle( $this->msg( 'undeletepage' ) ); } else { $out->setPageTitle( $this->msg( 'viewdeletedpage' ) ); } - if( $par != '' ) { - $this->mTarget = $par; - } - if ( $this->mTarget !== '' ) { - $this->mTargetObj = Title::newFromURL( $this->mTarget ); - $this->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( $user->isAllowed( 'browsearchive' ) ) { - $this->showSearchForm(); + $this->getSkin()->setRelevantTitle( $this->mTargetObj ); - # List undeletable articles - if( $this->mSearchPrefix ) { - $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix ); - $this->showList( $result ); - } - } else { - $out->addWikiMsg( 'undelete-header' ); - } - return; - } - if( $this->mTimestamp !== '' ) { - return $this->showRevision( $this->mTimestamp ); - } - if( $this->mFilename !== null ) { + if ( $this->mTimestamp !== '' ) { + $this->showRevision( $this->mTimestamp ); + } elseif ( $this->mFilename !== null ) { $file = new ArchivedFile( $this->mTargetObj, '', $this->mFilename ); // Check if user is allowed to see this file if ( !$file->exists() ) { $out->addWikiMsg( 'filedelete-nofile', $this->mFilename ); - return; - } elseif( !$file->userCan( File::DELETED_FILE, $user ) ) { + } elseif ( !$file->userCan( File::DELETED_FILE, $user ) ) { if( $file->isDeleted( File::DELETED_RESTRICTED ) ) { - $out->permissionRequired( 'suppressrevision' ); + throw new PermissionsError( 'suppressrevision' ); } else { - $out->permissionRequired( 'deletedtext' ); + throw new PermissionsError( 'deletedtext' ); } - return false; } elseif ( !$user->matchEditToken( $this->mToken, $this->mFilename ) ) { $this->showFileConfirmationForm( $this->mFilename ); - return false; } else { - return $this->showFile( $this->mFilename ); - } - } - if( $this->mRestore && $this->mAction == 'submit' ) { - global $wgUploadMaintenance; - if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) { - $out->wrapWikiMsg( "
\n$1\n
\n", array( 'filedelete-maintenance' ) ); - return; + $this->showFile( $this->mFilename ); } - return $this->undelete(); - } - if( $this->mInvert && $this->mAction == 'submit' ) { - return $this->showHistory(); + } elseif ( $this->mRestore && $this->mAction == 'submit' ) { + $this->undelete(); + } else { + $this->showHistory(); } - return $this->showHistory(); } function showSearchForm() { global $wgScript; - $this->getOutput()->addWikiMsg( 'undelete-header' ); - - $this->getOutput()->addHTML( + $out = $this->getOutput(); + $out->setPageTitle( $this->msg( 'undelete-search-title' ) ); + $out->addHTML( Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript ) ) . @@ -735,6 +718,12 @@ class SpecialUndelete extends SpecialPage { Xml::closeElement( 'fieldset' ) . Xml::closeElement( 'form' ) ); + + # List undeletable articles + if( $this->mSearchPrefix ) { + $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix ); + $this->showList( $result ); + } } /** @@ -802,8 +791,6 @@ class SpecialUndelete extends SpecialPage { } } - $out->setPageTitle( $this->msg( 'undeletepage' ) ); - if( $this->mDiff ) { $previousRev = $archive->getPreviousRevision( $timestamp ); if( $previousRev ) { @@ -1016,9 +1003,6 @@ class SpecialUndelete extends SpecialPage { $out = $this->getOutput(); if( $this->mAllowed ) { $out->addModules( 'mediawiki.special.undelete' ); - $out->setPageTitle( $this->msg( 'undeletepage' ) ); - } else { - $out->setPageTitle( $this->msg( 'viewdeletedpage' ) ); } $out->wrapWikiMsg( "
\n$1\n
\n", @@ -1369,41 +1353,44 @@ class SpecialUndelete extends SpecialPage { } function undelete() { + global $wgUploadMaintenance; + + if ( $wgUploadMaintenance && $this->mTargetObj->getNamespace() == NS_FILE ) { + throw new ErrorPageError( 'undelete-error', 'filedelete-maintenance' ); + } + if ( wfReadOnly() ) { throw new ReadOnlyError; } - if( !is_null( $this->mTargetObj ) ) { - $archive = new PageArchive( $this->mTargetObj ); - wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) ); - $ok = $archive->undelete( - $this->mTargetTimestamp, - $this->mComment, - $this->mFileVersions, - $this->mUnsuppress ); - - if( is_array( $ok ) ) { - if ( $ok[1] ) { // Undeleted file count - wfRunHooks( 'FileUndeleteComplete', array( - $this->mTargetObj, $this->mFileVersions, - $this->getUser(), $this->mComment ) ); - } - - $link = Linker::linkKnown( $this->mTargetObj ); - $this->getOutput()->addHTML( wfMessage( 'undeletedpage' )->rawParams( $link )->parse() ); - } else { - $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) ); - $this->getOutput()->addWikiMsg( 'undeleterevdel' ); + $out = $this->getOutput(); + $archive = new PageArchive( $this->mTargetObj ); + wfRunHooks( 'UndeleteForm::undelete', array( &$archive, $this->mTargetObj ) ); + $ok = $archive->undelete( + $this->mTargetTimestamp, + $this->mComment, + $this->mFileVersions, + $this->mUnsuppress ); + + if( is_array( $ok ) ) { + if ( $ok[1] ) { // Undeleted file count + wfRunHooks( 'FileUndeleteComplete', array( + $this->mTargetObj, $this->mFileVersions, + $this->getUser(), $this->mComment ) ); } - // Show file deletion warnings and errors - $status = $archive->getFileStatus(); - if( $status && !$status->isGood() ) { - $this->getOutput()->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) ); - } + $link = Linker::linkKnown( $this->mTargetObj ); + $out->addHTML( $this->msg( 'undeletedpage' )->rawParams( $link )->parse() ); } else { - $this->getOutput()->showFatalError( wfMsg( 'cannotundelete' ) ); + $out->setPageTitle( $this->msg( 'undelete-error' ) ); + $out->addWikiMsg( 'cannotundelete' ); + $out->addWikiMsg( 'undeleterevdel' ); + } + + // Show file deletion warnings and errors + $status = $archive->getFileStatus(); + if( $status && !$status->isGood() ) { + $out->addWikiText( $status->getWikiText( 'undelete-error-short', 'undelete-error-long' ) ); } - return false; } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index a6e77ad64f..2a6db98a24 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -2944,6 +2944,7 @@ someone else may have undeleted the page first.', Consult the [[Special:Log/delete|deletion log]] for a record of recent deletions and restorations.", 'undelete-header' => 'See [[Special:Log/delete|the deletion log]] for recently deleted pages.', +'undelete-search-title' => 'Search deleted pages', 'undelete-search-box' => 'Search deleted pages', 'undelete-search-prefix' => 'Show pages starting with:', 'undelete-search-submit' => 'Search', @@ -2953,6 +2954,7 @@ Consult the [[Special:Log/delete|deletion log]] for a record of recent deletions 'undelete-cleanup-error' => 'Error deleting unused archive file "$1".', 'undelete-missing-filearchive' => 'Unable to restore file archive ID $1 because it is not in the database. It may have already been undeleted.', +'undelete-error' => 'Error undeleting page', 'undelete-error-short' => 'Error undeleting file: $1', 'undelete-error-long' => 'Errors were encountered while undeleting the file: diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 0d4f07e946..4e1913bbc2 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -2622,7 +2622,9 @@ This message was something like "unlock move protection" in the past.', {{Identical|Reset}}', 'undeleteinvert' => '{{Identical|Invert selection}}', 'undeletecomment' => '{{Identical|Reason}}', +'undelete-search-title' => 'Page title when showing the search form in Special:Undelete', 'undelete-search-submit' => '{{Identical|Search}}', +'undelete-error' => 'Page title when a page could not be undeleted', 'undelete-show-file-confirm' => 'A confirmation message shown on Special:Undelete when the request does not contain a valid token (e.g. when a user clicks a link received in mail). * $1 is the name of the file being undeleted. * $2 is the date of the displayed revision. diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 40aed2d87a..e10785301c 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -1972,6 +1972,7 @@ $wgMessageStructure = array( 'cannotundelete', 'undeletedpage', 'undelete-header', + 'undelete-search-title', 'undelete-search-box', 'undelete-search-prefix', 'undelete-search-submit', @@ -1980,6 +1981,7 @@ $wgMessageStructure = array( 'undelete-bad-store-key', 'undelete-cleanup-error', 'undelete-missing-filearchive', + 'undelete-error', 'undelete-error-short', 'undelete-error-long', 'undelete-show-file-confirm', -- 2.20.1