* @fixme Does this belong in Image for fuller encapsulation?
*/
function listFiles() {
- $fname = __CLASS__ . '::' . __FUNCTION__;
if( $this->title->getNamespace() == NS_IMAGE ) {
$dbr =& wfGetDB( DB_SLAVE );
$res = $dbr->select( 'filearchive',
'fa_user_text',
'fa_timestamp' ),
array( 'fa_name' => $this->title->getDbKey() ),
- $fname,
+ __METHOD__,
array( 'ORDER BY' => 'fa_timestamp DESC' ) );
$ret = $dbr->resultObject( $res );
return $ret;
* revision of the page with the given timestamp.
*
* @return string
+ * @deprecated Use getRevision() for more flexible information
*/
function getRevisionText( $timestamp ) {
- $fname = 'PageArchive::getRevisionText';
+ $rev = $this->getRevision( $timestamp );
+ return $rev ? $rev->getText() : null;
+ }
+
+ /**
+ * Return a Revision object containing data for the deleted revision.
+ * Note that the result *may* or *may not* have a null page ID.
+ * @param string $timestamp
+ * @return Revision
+ */
+ function getRevision( $timestamp ) {
$dbr =& wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'archive',
- array( 'ar_text', 'ar_flags', 'ar_text_id' ),
+ array(
+ 'ar_rev_id',
+ 'ar_text',
+ 'ar_comment',
+ 'ar_user',
+ 'ar_user_text',
+ 'ar_timestamp',
+ 'ar_minor_edit',
+ 'ar_flags',
+ 'ar_text_id' ),
array( 'ar_namespace' => $this->title->getNamespace(),
'ar_title' => $this->title->getDbkey(),
'ar_timestamp' => $dbr->timestamp( $timestamp ) ),
- $fname );
+ __METHOD__ );
if( $row ) {
- return $this->getTextFromRow( $row );
+ return new Revision( array(
+ 'page' => $this->title->getArticleId(),
+ 'id' => $row->ar_rev_id,
+ 'text' => ($row->ar_text_id
+ ? null
+ : Revision::getRevisionText( $row, 'ar_' ) ),
+ 'comment' => $row->ar_comment,
+ 'user' => $row->ar_user,
+ 'user_text' => $row->ar_user_text,
+ 'timestamp' => $row->ar_timestamp,
+ 'minor_edit' => $row->ar_minor_edit,
+ 'text_id' => $row->ar_text_id ) );
} else {
return null;
}
* Get the text from an archive row containing ar_text, ar_flags and ar_text_id
*/
function getTextFromRow( $row ) {
- $fname = 'PageArchive::getTextFromRow';
-
if( is_null( $row->ar_text_id ) ) {
// An old row from MediaWiki 1.4 or previous.
// Text is embedded in this row in classic compression format.
$text = $dbr->selectRow( 'text',
array( 'old_text', 'old_flags' ),
array( 'old_id' => $row->ar_text_id ),
- $fname );
+ __METHOD__ );
return Revision::getRevisionText( $text );
}
}
* @return int number of revisions restored
*/
private function undeleteRevisions( $timestamps ) {
- global $wgParser, $wgDBtype;
+ global $wgDBtype;
- $fname = __CLASS__ . '::' . __FUNCTION__;
$restoreAll = empty( $timestamps );
$dbw =& wfGetDB( DB_MASTER );
- extract( $dbw->tableNames( 'page', 'archive' ) );
+ $page = $dbw->tableName( 'archive' );
# Does this page already exist? We'll have to update it...
$article = new Article( $this->title );
array( 'page_id', 'page_latest' ),
array( 'page_namespace' => $this->title->getNamespace(),
'page_title' => $this->title->getDBkey() ),
- $fname,
+ __METHOD__,
$options );
if( $page ) {
# Page already exists. Import the history, and if necessary
'ar_namespace' => $this->title->getNamespace(),
'ar_title' => $this->title->getDBkey(),
$oldones ),
- $fname,
+ __METHOD__,
/* options */ array(
'ORDER BY' => 'ar_timestamp' )
);
if( $dbw->numRows( $result ) < count( $timestamps ) ) {
- wfDebug( "$fname: couldn't find all requested rows\n" );
+ wfDebug( __METHOD__.": couldn't find all requested rows\n" );
return false;
}
$revision = null;
- $newRevId = $previousRevId;
$restored = 0;
while( $row = $dbw->fetchObject( $result ) ) {
'minor_edit' => $row->ar_minor_edit,
'text_id' => $row->ar_text_id,
) );
- $newRevId = $revision->insertOn( $dbw );
+ $revision->insertOn( $dbw );
$restored++;
}
if( $revision ) {
# FIXME: Update latest if newer as well...
if( $newid ) {
- # FIXME: update article count if changed...
+ // Attach the latest revision to the page...
$article->updateRevisionOn( $dbw, $revision, $previousRevId );
-
- # Finally, clean up the link tables
- $options = new ParserOptions;
- $parserOutput = $wgParser->parse( $revision->getText(), $this->title, $options,
- true, true, $newRevId );
- $u = new LinksUpdate( $this->title, $parserOutput );
- $u->doUpdate();
-
- #TODO: SearchUpdate, etc.
+
+ // Update site stats, link tables, etc
+ $article->createUpdates( $revision );
}
if( $newid ) {
'ar_namespace' => $this->title->getNamespace(),
'ar_title' => $this->title->getDBkey(),
$oldones ),
- $fname );
+ __METHOD__ );
return $restored;
}
function UndeleteForm( &$request, $par = "" ) {
global $wgUser;
- $this->mAction = $request->getText( 'action' );
- $this->mTarget = $request->getText( 'target' );
- $this->mTimestamp = $request->getText( 'timestamp' );
+ $this->mAction = $request->getVal( 'action' );
+ $this->mTarget = $request->getVal( 'target' );
+ $time = $request->getVal( 'timestamp' );
+ $this->mTimestamp = $time ? wfTimestamp( TS_MW, $time ) : '';
$this->mFile = $request->getVal( 'file' );
$posted = $request->wasPosted() &&
$timestamps = array();
$this->mFileVersions = array();
foreach( $_REQUEST as $key => $val ) {
+ $matches = array();
if( preg_match( '/^ts(\d{14})$/', $key, $matches ) ) {
array_push( $timestamps, $matches[1] );
}
/* private */ function showList() {
global $wgLang, $wgContLang, $wgUser, $wgOut;
- $fname = "UndeleteForm::showList";
# List undeletable articles
$result = PageArchive::listAllPages();
$wgOut->addWikiText( wfMsg( "undeletepagetext" ) );
$sk = $wgUser->getSkin();
- $undelete =& Title::makeTitle( NS_SPECIAL, 'Undelete' );
+ $undelete = SpecialPage::getTitleFor( 'Undelete' );
$wgOut->addHTML( "<ul>\n" );
while( $row = $result->fetchObject() ) {
- $n = ($row->ar_namespace ?
- ($wgContLang->getNsText( $row->ar_namespace ) . ":") : "").
- $row->ar_title;
- $link = $sk->makeKnownLinkObj( $undelete,
- htmlspecialchars( $n ), "target=" . urlencode( $n ) );
- $revisions = htmlspecialchars( wfMsg( "undeleterevisions",
- $wgLang->formatNum( $row->count ) ) );
- $wgOut->addHTML( "<li>$link ($revisions)</li>\n" );
+ $title = Title::makeTitleSafe( $row->ar_namespace, $row->ar_title );
+ $link = $sk->makeKnownLinkObj( $undelete, htmlspecialchars( $title->getPrefixedText() ), 'target=' . $title->getPrefixedUrl() );
+ $revs = wfMsgHtml( 'undeleterevisions', $wgLang->formatNum( $row->count ) );
+ $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
}
$result->free();
$wgOut->addHTML( "</ul>\n" );
/* private */ function showRevision( $timestamp ) {
global $wgLang, $wgUser, $wgOut;
- $fname = "UndeleteForm::showRevision";
if(!preg_match("/[0-9]{14}/",$timestamp)) return 0;
- $archive =& new PageArchive( $this->mTargetObj );
- $text = $archive->getRevisionText( $timestamp );
-
+ $archive = new PageArchive( $this->mTargetObj );
+ $rev = $archive->getRevision( $timestamp );
+
$wgOut->setPagetitle( wfMsg( "undeletepage" ) );
$wgOut->addWikiText( "(" . wfMsg( "undeleterevision",
$wgLang->date( $timestamp ) ) . ")\n" );
+ if( !$rev ) {
+ $wgOut->addWikiText( wfMsg( 'undeleterevision-missing' ) );
+ return;
+ }
+
+ wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
+
if( $this->mPreview ) {
$wgOut->addHtml( "<hr />\n" );
- $wgOut->addWikiText( $text );
+ $article = new Article ( $archive->title ); # OutputPage wants an Article obj
+ $wgOut->addPrimaryWikiText( $rev->getText(), $article, false );
}
- $self = Title::makeTitle( NS_SPECIAL, "Undelete" );
+ $self = SpecialPage::getTitleFor( "Undelete" );
$wgOut->addHtml(
wfElement( 'textarea', array(
'readonly' => true,
'cols' => intval( $wgUser->getOption( 'cols' ) ),
'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
- $text . "\n" ) .
+ $rev->getText() . "\n" ) .
wfOpenElement( 'div' ) .
wfOpenElement( 'form', array(
'method' => 'post',
}
$archive = new PageArchive( $this->mTargetObj );
- $text = $archive->getLastRevisionText();
/*
+ $text = $archive->getLastRevisionText();
if( is_null( $text ) ) {
$wgOut->addWikiText( wfMsg( "nohistory" ) );
return;
}
if ( $this->mAllowed ) {
- $titleObj = Title::makeTitle( NS_SPECIAL, "Undelete" );
+ $titleObj = SpecialPage::getTitleFor( "Undelete" );
$action = $titleObj->getLocalURL( "action=submit" );
# Start the form here
$top = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
# Show relevant lines from the deletion log:
$wgOut->addHTML( "<h2>" . htmlspecialchars( LogPage::logName( 'delete' ) ) . "</h2>\n" );
- require_once( 'SpecialLog.php' );
- $logViewer =& new LogViewer(
+ $logViewer = new LogViewer(
new LogReader(
new FauxRequest(
array( 'page' => $this->mTargetObj->getPrefixedText(),
global $wgOut, $wgUser;
if( !is_null( $this->mTargetObj ) ) {
$archive = new PageArchive( $this->mTargetObj );
- $ok = true;
$ok = $archive->undelete(
$this->mTargetTimestamp,