$res = $dbr->select( 'archive',
array(
'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
- 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id'
+ 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1'
),
array( 'ar_namespace' => $this->title->getNamespace(),
'ar_title' => $this->title->getDBkey() ),
$dbw = wfGetDB( DB_MASTER );
# Does this page already exist? We'll have to update it...
- $article = new Article( $this->title );
+ $article = WikiPage::factory( $this->title );
# Load latest data for the current page (bug 31179)
$article->loadPageData( 'fromdbmaster' );
$oldcountable = $article->isCountable();
'ar_text_id',
'ar_deleted',
'ar_page_id',
- 'ar_len' ),
+ 'ar_len',
+ 'ar_sha1' ),
/* WHERE */ array(
'ar_namespace' => $this->title->getNamespace(),
'ar_title' => $this->title->getDBkey(),
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 ) : '';
} 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;
}
function execute( $par ) {
- $this->setHeaders();
-
+ $this->checkPermissions();
$user = $this->getUser();
- if ( !$this->userCanExecute( $user ) ) {
- $this->displayRestrictionError();
- return;
- }
+ $this->setHeaders();
$this->outputHeader();
- $this->loadRequest();
+ $this->loadRequest( $par );
$out = $this->getOutput();
- if ( $this->mAllowed ) {
- $out->setPageTitleMsg( 'undeletepage' );
- } else {
- $out->setPageTitleMsg( '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 ) ) {
+ 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' ) ) {
+ if ( $user->isAllowed( 'browsearchive' ) ) {
$this->showSearchForm();
-
- # 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->mAllowed ) {
+ $out->setPageTitle( $this->msg( 'undeletepage' ) );
+ } else {
+ $out->setPageTitle( $this->msg( 'viewdeletedpage' ) );
}
- if( $this->mFilename !== null ) {
+
+ $this->getSkin()->setRelevantTitle( $this->mTargetObj );
+
+ 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 );
+ $this->showFile( $this->mFilename );
}
+ } elseif ( $this->mRestore && $this->mAction == 'submit' ) {
+ $this->undelete();
+ } else {
+ $this->showHistory();
}
- if( $this->mRestore && $this->mAction == 'submit' ) {
- global $wgUploadMaintenance;
- if( $wgUploadMaintenance && $this->mTargetObj && $this->mTargetObj->getNamespace() == NS_FILE ) {
- $out->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
- return;
- }
- return $this->undelete();
- }
- if( $this->mInvert && $this->mAction == 'submit' ) {
- return $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 ) ) .
Xml::closeElement( 'fieldset' ) .
Xml::closeElement( 'form' )
);
+
+ # List undeletable articles
+ if( $this->mSearchPrefix ) {
+ $result = PageArchive::listPagesByPrefix( $this->mSearchPrefix );
+ $this->showList( $result );
+ }
}
/**
}
}
- $out->setPageTitleMsg( 'undeletepage' );
-
if( $this->mDiff ) {
$previousRev = $archive->getPreviousRevision( $timestamp );
if( $previousRev ) {
Xml::element( 'input', array(
'type' => 'hidden',
'name' => 'wpEditToken',
- 'value' => $user->editToken() ) ) .
+ 'value' => $user->getEditToken() ) ) .
Xml::element( 'input', array(
'type' => 'submit',
'name' => 'preview',
* @return String: HTML
*/
function showDiff( $previousRev, $currentRev ) {
- $diffEngine = new DifferenceEngine( $previousRev->getTitle() );
+ $diffEngine = new DifferenceEngine( $this->getContext() );
$diffEngine->showDiffStyle();
$this->getOutput()->addHTML(
"<div>" .
'action' => $this->getTitle()->getLocalURL(
'target=' . urlencode( $this->mTarget ) .
'&file=' . urlencode( $key ) .
- '&token=' . urlencode( $this->getUser()->editToken( $key ) ) )
+ '&token=' . urlencode( $this->getUser()->getEditToken( $key ) ) )
)
) .
Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
$out = $this->getOutput();
if( $this->mAllowed ) {
$out->addModules( 'mediawiki.special.undelete' );
- $out->setPageTitleMsg( 'undeletepage' );
- } else {
- $out->setPageTitleMsg( 'viewdeletedpage' );
}
$out->wrapWikiMsg(
"<div class='mw-undelete-pagetitle'>\n$1\n</div>\n",
if ( $this->mAllowed ) {
# Slip in the hidden controls here
$misc = Html::hidden( 'target', $this->mTarget );
- $misc .= Html::hidden( 'wpEditToken', $this->getUser()->editToken() );
+ $misc .= Html::hidden( 'wpEditToken', $this->getUser()->getEditToken() );
$misc .= Xml::closeElement( 'form' );
$out->addHTML( $misc );
}
array(
'target' => $this->mTargetObj->getPrefixedText(),
'file' => $key,
- 'token' => $this->getUser()->editToken( $key )
+ 'token' => $this->getUser()->getEditToken( $key )
)
);
if( $file->isDeleted( File::DELETED_FILE ) ) {
}
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;
}
}