* @todo Does this belong in Image for fuller encapsulation?
*/
function listFiles() {
- if( $this->title->getNamespace() == NS_IMAGE ) {
+ if( $this->title->getNamespace() == NS_FILE ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'filearchive',
array(
$restoreText = $restoreAll || !empty( $timestamps );
$restoreFiles = $restoreAll || !empty( $fileVersions );
- if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
+ if( $restoreFiles && $this->title->getNamespace() == NS_FILE ) {
$img = wfLocalFile( $this->title );
$this->fileStatus = $img->restore( $fileVersions, $unsuppress );
$filesRestored = $this->fileStatus->successCount;
'ar_title' => $this->title->getDBkey(),
$oldones ),
__METHOD__,
- /* options */ array(
- 'ORDER BY' => 'ar_timestamp' )
+ /* options */ array( 'ORDER BY' => 'ar_timestamp' )
);
$ret = $dbw->resultObject( $result );
-
$rev_count = $dbw->numRows( $result );
- if( $rev_count ) {
- # We need to seek around as just using DESC in the ORDER BY
- # would leave the revisions inserted in the wrong order
- $first = $ret->fetchObject();
- $ret->seek( $rev_count - 1 );
- $last = $ret->fetchObject();
- // We don't handle well changing the top revision's settings
- if( !$unsuppress && $last->ar_deleted && $last->ar_timestamp > $previousTimestamp ) {
- wfDebug( __METHOD__.": restoration would result in a deleted top revision\n" );
- return false;
- }
- $ret->seek( 0 );
- }
if( $makepage ) {
$newid = $article->insertOn( $dbw );
if( $revision ) {
// Attach the latest revision to the page...
$wasnew = $article->updateIfNewerOn( $dbw, $revision, $previousRevId );
-
if( $newid || $wasnew ) {
// Update site stats, link tables, etc
$article->createUpdates( $revision );
+ // We don't handle well with top revision deleted
+ if( $revision->getVisibility() ) {
+ $dbw->update( 'revision',
+ array( 'rev_deleted' => 0 ),
+ array( 'rev_id' => $revision->getId() ),
+ __METHOD__
+ );
+ }
}
if( $newid ) {
Article::onArticleEdit( $this->title );
}
- if( $this->title->getNamespace() == NS_IMAGE ) {
+ if( $this->title->getNamespace() == NS_FILE ) {
$update = new HTMLCacheUpdate( $this->title, 'imagelinks' );
$update->doUpdate();
}
*/
class UndeleteForm {
var $mAction, $mTarget, $mTimestamp, $mRestore, $mInvert, $mTargetObj;
- var $mTargetTimestamp, $mAllowed, $mComment;
+ var $mTargetTimestamp, $mAllowed, $mComment, $mToken;
function UndeleteForm( $request, $par = "" ) {
global $wgUser;
$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->showList( $result );
}
} else {
- $wgOut->addWikiText( wfMsgHtml( 'undelete-header' ) );
+ $wgOut->addWikiMsg( 'undelete-header' );
}
return;
}
if( !$file->userCan( File::DELETED_FILE ) ) {
$wgOut->permissionRequired( 'suppressrevision' );
return false;
+ } elseif ( !$wgUser->matchEditToken( $this->mToken, $this->mFile ) ) {
+ $this->showFileConfirmationForm( $this->mFile );
+ return false;
} else {
return $this->showFile( $this->mFile );
}
global $wgOut, $wgScript;
$wgOut->addWikiMsg( 'undelete-header' );
- $wgOut->addHtml(
+ $wgOut->addHTML(
Xml::openElement( 'form', array(
'method' => 'get',
'action' => $wgScript ) ) .
- '<fieldset>' .
- Xml::element( 'legend', array(),
- wfMsg( 'undelete-search-box' ) ) .
+ Xml::fieldset( wfMsg( 'undelete-search-box' ) ) .
Xml::hidden( 'title',
SpecialPage::getTitleFor( 'Undelete' )->getPrefixedDbKey() ) .
Xml::inputLabel( wfMsg( 'undelete-search-prefix' ),
'prefix', 'prefix', 20,
- $this->mSearchPrefix ) .
+ $this->mSearchPrefix ) . ' ' .
Xml::submitButton( wfMsg( 'undelete-search-submit' ) ) .
- '</fieldset>' .
- '</form>' );
+ Xml::closeElement( 'fieldset' ) .
+ Xml::closeElement( 'form' )
+ );
}
// Generic list of deleted pages
return;
}
- $wgOut->addWikiMsg( "undeletepagetext" );
+ $wgOut->addWikiMsg( 'undeletepagetext', $wgLang->formatNum( $result->numRows() ) );
$sk = $wgUser->getSkin();
$undelete = SpecialPage::getTitleFor( 'Undelete' );
$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 ) );
$revs = wfMsgExt( 'undeleterevisions',
array( 'parseinline' ),
$wgLang->formatNum( $row->count ) );
- $wgOut->addHtml( "<li>{$link} ({$revs})</li>\n" );
+ $wgOut->addHTML( "<li>{$link} ({$revs})</li>\n" );
}
$result->free();
$wgOut->addHTML( "</ul>\n" );
if( $rev->isDeleted(Revision::DELETED_TEXT) ) {
if( !$rev->userCan(Revision::DELETED_TEXT) ) {
- $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
+ $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-permission' );
return;
} else {
- $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
+ $wgOut->wrapWikiMsg( "<div class='mw-warning plainlinks'>\n$1</div>\n", 'rev-deleted-text-view' );
$wgOut->addHTML( '<br/>' );
// and we are allowed to see...
}
if( $wgUser->getOption( 'diffonly' ) ) {
return;
} else {
- $wgOut->addHtml( '<hr />' );
+ $wgOut->addHTML( '<hr />' );
}
} else {
- $wgOut->addHtml( wfMsgHtml( 'undelete-nodiff' ) );
+ $wgOut->addWikiMsg( 'undelete-nodiff' );
}
}
$t = htmlspecialchars( $wgLang->time( $timestamp, true ) );
$user = $skin->revUserTools( $rev );
- $wgOut->addHtml( '<p>' . wfMsgHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</p>' );
+ if( $this->mPreview ) {
+ $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
+ } else {
+ $openDiv = '<div id="mw-undelete-revision">';
+ }
+ $wgOut->addHTML( $openDiv . wfMsgWikiHtml( 'undelete-revision', $link, $time, $user, $d, $t ) . '</div>' );
wfRunHooks( 'UndeleteShowRevision', array( $this->mTargetObj, $rev ) );
if( $this->mPreview ) {
- $wgOut->addHtml( "<hr />\n" );
-
//Hide [edit]s
$popts = $wgOut->parserOptions();
$popts->setEditSection( false );
$wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true );
}
- $wgOut->addHtml(
- wfElement( 'textarea', array(
+ $wgOut->addHTML(
+ Xml::element( 'textarea', array(
'readonly' => 'readonly',
'cols' => intval( $wgUser->getOption( 'cols' ) ),
'rows' => intval( $wgUser->getOption( 'rows' ) ) ),
$rev->getText( Revision::FOR_THIS_USER ) . "\n" ) .
- wfOpenElement( 'div' ) .
- wfOpenElement( 'form', array(
+ Xml::openElement( 'div' ) .
+ Xml::openElement( 'form', array(
'method' => 'post',
'action' => $self->getLocalURL( "action=submit" ) ) ) .
- wfElement( 'input', array(
+ Xml::element( 'input', array(
'type' => 'hidden',
'name' => 'target',
'value' => $this->mTargetObj->getPrefixedDbKey() ) ) .
- wfElement( 'input', array(
+ Xml::element( 'input', array(
'type' => 'hidden',
'name' => 'timestamp',
'value' => $timestamp ) ) .
- wfElement( 'input', array(
+ Xml::element( 'input', array(
'type' => 'hidden',
'name' => 'wpEditToken',
'value' => $wgUser->editToken() ) ) .
- wfElement( 'input', array(
+ Xml::element( 'input', array(
'type' => 'submit',
'name' => 'preview',
'value' => wfMsg( 'showpreview' ) ) ) .
- wfElement( 'input', array(
+ Xml::element( 'input', array(
'name' => 'diff',
'type' => 'submit',
'value' => wfMsg( 'showdiff' ) ) ) .
- wfCloseElement( 'form' ) .
- wfCloseElement( 'div' ) );
+ Xml::closeElement( 'form' ) .
+ Xml::closeElement( 'div' ) );
}
/**
* @return string HTML
*/
function showDiff( $previousRev, $currentRev ) {
- global $wgOut, $wgUser;
+ global $wgOut;
$diffEngine = new DifferenceEngine();
$diffEngine->showDiffStyle();
- $wgOut->addHtml(
+ $wgOut->addHTML(
"<div>" .
"<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" .
"<col class='diff-marker' />" .
if( $isDeleted ) {
/// @fixme $rev->getTitle() is null for deleted revs...?
$targetPage = SpecialPage::getTitleFor( 'Undelete' );
- $targetQuery = 'target=' .
- $this->mTargetObj->getPrefixedUrl() .
- '×tamp=' .
- wfTimestamp( TS_MW, $rev->getTimestamp() );
+ $targetQuery = array(
+ 'target' => $this->mTargetObj->getPrefixedUrl(),
+ 'timestamp' => wfTimestamp( TS_MW, $rev->getTimestamp() )
+ );
} else {
/// @fixme getId() may return non-zero for deleted revs...
$targetPage = $rev->getTitle();
- $targetQuery = 'oldid=' . $rev->getId();
+ $targetQuery = array( 'oldid' => $rev->getId() );
+ }
+ // Add show/hide link if available
+ if( $wgUser->isAllowed( 'deleterevision' ) ) {
+ // If revision was hidden from sysops
+ if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
+ $del = ' ' . Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
+ '(' . wfMsgHtml('rev-delundel') . ')' );
+ // Otherwise, show the link...
+ } else {
+ $query = array( 'target' => $this->mTargetObj->getPrefixedDbkey(),
+ 'artimestamp' => $rev->getTimestamp() );
+ $del = ' ' . $sk->revDeleteLink( $query,
+ $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
+ }
+ } else {
+ $del = '';
}
return
'<div id="mw-diff-'.$prefix.'title1"><strong>' .
- $sk->makeLinkObj( $targetPage,
- wfMsgHtml( 'revisionasof',
- $wgLang->timeanddate( $rev->getTimestamp(), true ) ),
- $targetQuery ) .
+ $sk->link(
+ $targetPage,
+ wfMsgHtml(
+ 'revisionasof',
+ htmlspecialchars( $wgLang->timeanddate( $rev->getTimestamp(), true ) )
+ ),
+ array(),
+ $targetQuery
+ ) .
( $isDeleted ? ' ' . wfMsgHtml( 'deletedrev' ) : '' ) .
'</strong></div>' .
'<div id="mw-diff-'.$prefix.'title2">' .
$sk->revUserTools( $rev ) . '<br/>' .
'</div>' .
'<div id="mw-diff-'.$prefix.'title3">' .
- $sk->revComment( $rev ) . '<br/>' .
+ $sk->revComment( $rev ) . $del . '<br/>' .
'</div>';
}
+ /**
+ * Show a form confirming whether a tokenless user really wants to see a file
+ */
+ private function showFileConfirmationForm( $key ) {
+ global $wgOut, $wgUser, $wgLang;
+ $file = new ArchivedFile( $this->mTargetObj, '', $this->mFile );
+ $wgOut->addWikiMsg( 'undelete-show-file-confirm',
+ $this->mTargetObj->getText(),
+ $wgLang->date( $file->getTimestamp() ),
+ $wgLang->time( $file->getTimestamp() ) );
+ $wgOut->addHTML(
+ Xml::openElement( 'form', array(
+ 'method' => 'POST',
+ 'action' => SpecialPage::getTitleFor( 'Undelete' )->getLocalUrl(
+ 'target=' . urlencode( $this->mTarget ) .
+ '&file=' . urlencode( $key ) .
+ '&token=' . urlencode( $wgUser->editToken( $key ) ) )
+ )
+ ) .
+ Xml::submitButton( wfMsg( 'undelete-show-file-submit' ) ) .
+ '</form>'
+ );
+ }
+
/**
* Show a deleted file version requested by the visitor.
*/
$wgOut->setPagetitle( wfMsg( 'viewdeletedpage' ) );
}
- $wgOut->addWikiText( wfMsgHtml( 'undeletepagetitle', $this->mTargetObj->getPrefixedText()) );
+ $wgOut->addWikiMsg( 'undeletepagetitle', $this->mTargetObj->getPrefixedText() );
$archive = new PageArchive( $this->mTargetObj );
/*
$action = $titleObj->getLocalURL( "action=submit" );
# Start the form here
$top = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'undelete' ) );
- $wgOut->addHtml( $top );
+ $wgOut->addHTML( $top );
}
# Show relevant lines from the deletion log:
$wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'delete' ) ) . "\n" );
LogEventsList::showLogExtract( $wgOut, 'delete', $this->mTargetObj->getPrefixedText() );
+ # Show relevant lines from the suppression log:
+ if( $wgUser->isAllowed( 'suppressionlog' ) ) {
+ $wgOut->addHTML( Xml::element( 'h2', null, LogPage::logName( 'suppress' ) ) . "\n" );
+ LogEventsList::showLogExtract( $wgOut, 'suppress', $this->mTargetObj->getPrefixedText() );
+ }
if( $this->mAllowed && ( $haveRevisions || $haveFiles ) ) {
# Format the user-visible controls (comment field, submission button)
$unsuppressBox = "";
}
$table =
- Xml::openElement( 'fieldset' ) .
- Xml::element( 'legend', null, wfMsg( 'undelete-fieldset-title' ) ).
+ Xml::fieldset( wfMsg( 'undelete-fieldset-title' ) ) .
Xml::openElement( 'table', array( 'id' => 'mw-undelete-table' ) ) .
"<tr>
<td colspan='2'>" .
<tr>
<td> </td>
<td class='mw-submit'>" .
- Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) .
- Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) .
+ Xml::submitButton( wfMsg( 'undeletebtn' ), array( 'name' => 'restore', 'id' => 'mw-undelete-submit' ) ) . ' ' .
+ Xml::element( 'input', array( 'type' => 'reset', 'value' => wfMsg( 'undeletereset' ), 'id' => 'mw-undelete-reset' ) ) . ' ' .
Xml::submitButton( wfMsg( 'undeleteinvert' ), array( 'name' => 'invert', 'id' => 'mw-undelete-invert' ) ) .
"</td>
</tr>" .
Xml::closeElement( 'table' ) .
Xml::closeElement( 'fieldset' );
- $wgOut->addHtml( $table );
+ $wgOut->addHTML( $table );
}
$wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'history' ) ) . "\n" );
$wgOut->addHTML("<ul>");
$target = urlencode( $this->mTarget );
$remaining = $revisions->numRows();
- $earliestLiveTime = $this->getEarliestTime( $this->mTargetObj );
+ $earliestLiveTime = $this->mTargetObj->getEarliestRevTime();
while( $row = $revisions->fetchObject() ) {
$remaining--;
}
if( $haveFiles ) {
- $wgOut->addHtml( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
- $wgOut->addHtml( "<ul>" );
+ $wgOut->addHTML( Xml::element( 'h2', null, wfMsg( 'filehist' ) ) . "\n" );
+ $wgOut->addHTML( "<ul>" );
while( $row = $files->fetchObject() ) {
$wgOut->addHTML( $this->formatFileRow( $row, $sk ) );
}
$misc = Xml::hidden( 'target', $this->mTarget );
$misc .= Xml::hidden( 'wpEditToken', $wgUser->editToken() );
$misc .= Xml::closeElement( 'form' );
- $wgOut->addHtml( $misc );
+ $wgOut->addHTML( $misc );
}
return true;
}
} else {
$checkBox = '';
- $pageLink = $wgLang->timeanddate( $ts, true );
+ $pageLink = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
$last = wfMsgHtml('diff');
}
$userLink = $sk->revUserTools( $rev );
$comment = $sk->revComment( $rev );
$revdlink = '';
if( $wgUser->isAllowed( 'deleterevision' ) ) {
- $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
// If revision was hidden from sysops
- $del = wfMsgHtml('rev-delundel');
+ $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ),
+ '('.wfMsgHtml('rev-delundel').')' );
} else {
- $ts = wfTimestamp( TS_MW, $row->ar_timestamp );
- $del = $sk->makeKnownLinkObj( $revdel,
- wfMsgHtml('rev-delundel'),
- 'target=' . $this->mTargetObj->getPrefixedUrl() . "&artimestamp=$ts" );
- // Bolden oversighted content
- if( $rev->isDeleted( Revision::DELETED_RESTRICTED ) )
- $del = "<strong>$del</strong>";
+ $query = array( 'target' => $this->mTargetObj->getPrefixedDBkey(),
+ 'artimestamp' => $ts
+ );
+ $revdlink = $sk->revDeleteLink( $query, $rev->isDeleted( Revision::DELETED_RESTRICTED ) );
}
- $revdlink = "<tt>(<small>$del</small>)</tt>";
}
return "<li>$checkBox $revdlink ($last) $pageLink . . $userLink $stxt $comment</li>";
$comment = $this->getFileComment( $file, $sk );
$revdlink = '';
if( $wgUser->isAllowed( 'deleterevision' ) ) {
- $revdel = SpecialPage::getTitleFor( 'Revisiondelete' );
if( !$file->userCan(File::DELETED_RESTRICTED ) ) {
// If revision was hidden from sysops
- $del = wfMsgHtml('rev-delundel');
+ $revdlink = Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), '('.wfMsgHtml('rev-delundel').')' );
} else {
- $del = $sk->makeKnownLinkObj( $revdel,
- wfMsgHtml('rev-delundel'),
- 'target=' . $this->mTargetObj->getPrefixedUrl() .
- '&fileid=' . $row->fa_id );
- // Bolden oversighted content
- if( $file->isDeleted( File::DELETED_RESTRICTED ) )
- $del = "<strong>$del</strong>";
+ $query = array( 'target' => $this->mTargetObj->getPrefixedDBkey(),
+ 'fileid' => $row->fa_id
+ );
+ $revdlink = $sk->revDeleteLink( $query, $file->isDeleted( File::DELETED_RESTRICTED ) );
}
- $revdlink = "<tt>(<small>$del</small>)</tt>";
}
return "<li>$checkBox $revdlink $pageLink . . $userLink $data $comment</li>\n";
}
- private function getEarliestTime( $title ) {
- $dbr = wfGetDB( DB_SLAVE );
- if( $title->exists() ) {
- $min = $dbr->selectField( 'revision',
- 'MIN(rev_timestamp)',
- array( 'rev_page' => $title->getArticleId() ),
- __METHOD__ );
- return wfTimestampOrNull( TS_MW, $min );
- }
- return null;
- }
-
/**
* Fetch revision text link if it's available to all users
* @return string
function getPageLink( $rev, $titleObj, $ts, $sk ) {
global $wgLang;
+ $time = htmlspecialchars( $wgLang->timeanddate( $ts, true ) );
+
if( !$rev->userCan(Revision::DELETED_TEXT) ) {
- return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
+ return '<span class="history-deleted">' . $time . '</span>';
} else {
- $link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
+ $link = $sk->makeKnownLinkObj( $titleObj, $time,
"target=".$this->mTargetObj->getPrefixedUrl()."×tamp=$ts" );
if( $rev->isDeleted(Revision::DELETED_TEXT) )
$link = '<span class="history-deleted">' . $link . '</span>';
* @return string
*/
function getFileLink( $file, $titleObj, $ts, $key, $sk ) {
- global $wgLang;
+ global $wgLang, $wgUser;
if( !$file->userCan(File::DELETED_FILE) ) {
return '<span class="history-deleted">' . $wgLang->timeanddate( $ts, true ) . '</span>';
} else {
$link = $sk->makeKnownLinkObj( $titleObj, $wgLang->timeanddate( $ts, true ),
- "target=".$this->mTargetObj->getPrefixedUrl()."&file=$key" );
+ "target=".$this->mTargetObj->getPrefixedUrl().
+ "&file=$key" .
+ "&token=" . urlencode( $wgUser->editToken( $key ) ) );
if( $file->isDeleted(File::DELETED_FILE) )
$link = '<span class="history-deleted">' . $link . '</span>';
return $link;
if( !$file->userCan(File::DELETED_USER) ) {
return '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
} else {
- $link = $sk->userLink( $file->getUser(), $file->getUserText() ) .
- $sk->userToolLinks( $file->getUser(), $file->getUserText() );
+ $link = $sk->userLink( $file->getRawUser(), $file->getRawUserText() ) .
+ $sk->userToolLinks( $file->getRawUser(), $file->getRawUserText() );
if( $file->isDeleted(File::DELETED_USER) )
$link = '<span class="history-deleted">' . $link . '</span>';
return $link;
$skin = $wgUser->getSkin();
$link = $skin->makeKnownLinkObj( $this->mTargetObj );
- $wgOut->addHtml( wfMsgWikiHtml( 'undeletedpage', $link ) );
+ $wgOut->addHTML( wfMsgWikiHtml( 'undeletedpage', $link ) );
} else {
$wgOut->showFatalError( wfMsg( "cannotundelete" ) );
- $wgOut->addHtml( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
+ $wgOut->addHTML( '<p>' . wfMsgHtml( "undeleterevdel" ) . '</p>' );
}
// Show file deletion warnings and errors