<?php
-/**
- * Special page allowing users with the appropriate permissions to view
- * and restore deleted content
- *
- * @file
- * @ingroup SpecialPage
- */
-
-/**
- * Constructor
- */
-function wfSpecialUndelete( $par ) {
- global $wgRequest;
-
- $form = new UndeleteForm( $wgRequest, $par );
- $form->execute();
-}
-
/**
* Used to show archived pages and eventually restore them.
* @ingroup SpecialPage
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;
}
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 );
}
// 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++;
'ar_title' => $this->title->getDBkey(),
$oldones ),
__METHOD__ );
-
+
// Was anything restored at all?
if( $restored == 0 )
return 0;
}
/**
- * 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
$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();
}
}
- 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' ) ) {
'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 ) . ' ' .
$wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
$sk = $wgUser->getSkin();
- $undelete = SpecialPage::getTitleFor( 'Undelete' );
+ $undelete = $this->getTitle();
$wgOut->addHTML( "<ul>\n" );
while( $row = $result->fetchObject() ) {
$title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
private function showRevision( $timestamp ) {
global $wgLang, $wgUser, $wgOut;
- $self = SpecialPage::getTitleFor( 'Undelete' );
+
$skin = $wgUser->getSkin();
if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
$wgOut->setPageTitle( wfMsg( 'undeletepage' ) );
$link = $skin->linkKnown(
- SpecialPage::getTitleFor( 'Undelete', $this->mTargetObj->getPrefixedDBkey() ),
+ $this->getTitle( $this->mTargetObj->getPrefixedDBkey() ),
htmlspecialchars( $this->mTargetObj->getPrefixedText() )
);
Xml::openElement( 'div' ) .
Xml::openElement( 'form', array(
'method' => 'post',
- 'action' => $self->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) ) ) ) .
Xml::element( 'input', array(
'type' => 'hidden',
'name' => 'target',
$isDeleted = !( $rev->getId() && $rev->getTitle() );
if( $isDeleted ) {
/// @todo Fixme: $rev->getTitle() is null for deleted revs...?
- $targetPage = SpecialPage::getTitleFor( 'Undelete' );
+ $targetPage = $this->getTitle();
$targetQuery = array(
'target' => $this->mTargetObj->getPrefixedText(),
'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
$del .= $sk->revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
} else {
- $query = array(
+ $query = array(
'type' => 'archive',
'target' => $this->mTargetObj->getPrefixedDbkey(),
'ids' => $rev->getTimestamp()
$this->mTargetObj->getText(),
$wgLang->date( $file->getTimestamp() ),
$wgLang->time( $file->getTimestamp() ) );
- $wgOut->addHTML(
- Xml::openElement( 'form', array(
+ $wgOut->addHTML(
+ Xml::openElement( 'form', array(
'method' => 'POST',
- 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
+ 'action' => $this->getTitle()->getLocalUrl(
'target=' . urlencode( $this->mTarget ) .
'&file=' . urlencode( $key ) .
'&token=' . urlencode( $wgUser->editToken( $key ) ) )
global $IP;
require_once( "$IP/includes/StreamFile.php" );
- $repo = RepoGroup::singleton()->getLocalRepo();
+ $repo = RepoGroup::singleton()->getLocalRepo();
$path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
wfStreamFile( $path );
}
}
if ( $this->mAllowed ) {
- $titleObj = SpecialPage::getTitleFor( "Undelete" );
- $action = $titleObj->getLocalURL( array( 'action' => 'submit' ) );
+ $action = $this->getTitle()->getLocalURL( array( 'action' => 'submit' ) );
# Start the form here
$top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
$wgOut->addHTML( $top );
private function formatRevisionRow( $row, $earliestLiveTime, $remaining, $sk ) {
global $wgUser, $wgLang;
- $rev = Revision::newFromArchiveRow( $row,
+ $rev = Revision::newFromArchiveRow( $row,
array( 'page' => $this->mTargetObj->getArticleId() ) );
$stxt = '';
$ts = wfTimestamp( TS_MW, $row->ar_timestamp );
}
// Build page & diff links...
if( $this->mCanView ) {
- $titleObj = SpecialPage::getTitleFor( "Undelete" );
+ $titleObj = $this->getTitle();
# Last link
if( !$rev->userCan( Revision::DELETED_TEXT ) ) {
$pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
$checkBox = Xml::check( "fileid" . $row->fa_id );
$key = urlencode( $row->fa_storage_key );
$target = urlencode( $this->mTarget );
- $titleObj = SpecialPage::getTitleFor( "Undelete" );
- $pageLink = $this->getFileLink( $file, $titleObj, $ts, $key, $sk );
+ $pageLink = $this->getFileLink( $file, $this->getTitle(), $ts, $key, $sk );
} else {
$checkBox = '';
$pageLink = $wgLang->timeanddate( $ts, true );
}
- $userLink = $this->getFileUser( $file, $sk );
+ $userLink = $this->getFileUser( $file, $sk );
$data =
wfMsg( 'widthheight',
$wgLang->formatNum( $row->fa_width ),