From ad708b10eb491091327bcc8a1702c2a2cbb21a3d Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 9 Feb 2009 22:27:25 +0000 Subject: [PATCH] Tweaks for bug 17060 * Don't show links to deleted revs in history for anyone (consistency) * Always hide deleted content from all users; it can be viewed via (show/hide) links --- includes/Article.php | 20 ++++++++++++-------- includes/PageHistory.php | 20 ++++++++------------ includes/diff/DifferenceEngine.php | 20 +++++++++++++------- includes/specials/SpecialRevisiondelete.php | 13 ++++++++----- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 084221bb1d..5c33c75e12 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -780,15 +780,17 @@ class Article { } $wgOut->setRobotPolicy( $policy ); + # Allow admins to see deleted content if explicitly requested + $delId = $diff ? $diff : $oldid; + $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $delId ); # If we got diff and oldid in the query, we want to see a # diff page instead of the article. if( !is_null( $diff ) ) { $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); - $diff = $wgRequest->getVal( 'diff' ); $htmldiff = $wgRequest->getVal( 'htmldiff' , false); - $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff); + $de = new DifferenceEngine( $this->mTitle, $oldid, $diff, $rcid, $purge, $htmldiff, $unhide ); // DifferenceEngine directly fetched the revision: $this->mRevIdFetched = $de->mNewid; $de->showDiffPage( $diffOnly ); @@ -913,8 +915,9 @@ class Article { // FIXME: This would be a nice place to load the 'no such page' text. } else { $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid ); + # Allow admins to see deleted content if explicitly requested if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) { - if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) { + if( !$unhide || !$this->mRevision->userCan(Revision::DELETED_TEXT) ) { $wgOut->addWikiMsg( 'rev-deleted-text-permission' ); $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); wfProfileOut( __METHOD__ ); @@ -2971,7 +2974,7 @@ class Article { * @param $oldid String: revision ID of this article revision */ public function setOldSubtitle( $oldid = 0 ) { - global $wgLang, $wgOut, $wgUser; + global $wgLang, $wgOut, $wgUser, $wgRequest; if( !wfRunHooks( 'DisplayOldSubtitle', array( &$this, &$oldid ) ) ) { return; @@ -3022,16 +3025,17 @@ class Article { } $cdel = "($cdel) "; } - # Show user links if allowed to see them. Normally they - # are hidden regardless, but since we can already see the text here... - $userlinks = $sk->revUserTools( $revision, false ); + $unhide = $wgRequest->getInt('unhide') == 1 && $wgUser->matchEditToken( $wgRequest->getVal('token'), $oldid ); + # Show user links if allowed to see them. If hidden, then show them only if requested... + $userlinks = $sk->revUserTools( $revision, !$unhide ); $m = wfMsg( 'revision-info-current' ); $infomsg = $current && !wfEmptyMsg( 'revision-info-current', $m ) && $m != '-' ? 'revision-info-current' : 'revision-info'; - $r = "\n\t\t\t\t
" . wfMsgExt( $infomsg, array( 'parseinline', 'replaceafter' ), $td, $userlinks, $revision->getID() ) . "
\n" . + $r = "\n\t\t\t\t
" . wfMsgExt( $infomsg, array( 'parseinline', 'replaceafter' ), + $td, $userlinks, $revision->getID() ) . "
\n" . "\n\t\t\t\t
" . $cdel . wfMsgHtml( 'revision-nav', $prevdiff, $prevlink, $lnk, $curdiff, $nextlink, $nextdiff ) . "
\n\t\t\t"; diff --git a/includes/PageHistory.php b/includes/PageHistory.php index bd3edbafd5..e21e499b80 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -315,11 +315,11 @@ class PageHistory { $s .= " $link"; $s .= " " . $this->mSkin->revUserTools( $rev, true ) . ""; - if( $row->rev_minor_edit ) { + if( $rev->isMinor() ) { $s .= ' ' . Xml::element( 'span', array( 'class' => 'minor' ), wfMsg( 'minoreditletter') ); } - if( !is_null( $size = $rev->getSize() ) && $rev->userCan( Revision::DELETED_TEXT ) ) { + if( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) { $s .= ' ' . $this->mSkin->formatRevisionSize( $size ); } @@ -381,14 +381,10 @@ class PageHistory { function revLink( $rev ) { global $wgLang; $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true ); - if( $rev->userCan( Revision::DELETED_TEXT ) ) { - $link = $this->mSkin->makeKnownLinkObj( - $this->mTitle, $date, "oldid=" . $rev->getId() ); + if( !$rev->isDeleted( Revision::DELETED_TEXT ) ) { + $link = $this->mSkin->makeKnownLinkObj( $this->mTitle, $date, "oldid=" . $rev->getId() ); } else { - $link = $date; - } - if( $rev->isDeleted( Revision::DELETED_TEXT ) ) { - return '' . $link . ''; + $link = '' . $date . ''; } return $link; } @@ -401,7 +397,7 @@ class PageHistory { */ function curLink( $rev, $latest ) { $cur = $this->message['cur']; - if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) { + if( $latest || $rev->isDeleted( Revision::DELETED_TEXT ) ) { return $cur; } else { return $this->mSkin->makeKnownLinkObj( $this->mTitle, $cur, @@ -427,7 +423,7 @@ class PageHistory { # Next row probably exists but is unknown, use an oldid=prev link return $this->mSkin->makeKnownLinkObj( $this->mTitle, $last, "diff=" . $prevRev->getId() . "&oldid=prev" ); - } elseif( !$prevRev->userCan(Revision::DELETED_TEXT) || !$nextRev->userCan(Revision::DELETED_TEXT) ) { + } elseif( $prevRev->isDeleted(Revision::DELETED_TEXT) || $nextRev->isDeleted(Revision::DELETED_TEXT) ) { return $last; } else { return $this->mSkin->makeKnownLinkObj( $this->mTitle, $last, @@ -454,7 +450,7 @@ class PageHistory { $checkmark = array( 'checked' => 'checked' ); } else { # Check visibility of old revisions - if( !$rev->userCan( Revision::DELETED_TEXT ) ) { + if( $rev->isDeleted( Revision::DELETED_TEXT ) ) { $radio['disabled'] = 'disabled'; $checkmark = array(); // We will check the next possible one } else if( $counter == 2 || !$this->mOldIdChecked ) { diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 15035c6e02..df3339d6fb 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -28,6 +28,8 @@ class DifferenceEngine { var $mRevisionsLoaded = false; // Have the revisions been loaded var $mTextLoaded = 0; // How many text blobs have been loaded, 0, 1 or 2? var $htmldiff; + + protected $unhide = false; /**#@-*/ /** @@ -38,8 +40,9 @@ class DifferenceEngine { * @param $rcid Integer: ??? FIXME (default 0) * @param $refreshCache boolean If set, refreshes the diff cache * @param $htmldiff boolean If set, output using HTMLDiff instead of raw wikicode diff + * @param $unhide boolean If set, allow viewing deleted revs */ - function __construct( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false , $htmldiff = false) { + function __construct( $titleObj = null, $old = 0, $new = 0, $rcid = 0, $refreshCache = false , $htmldiff = false, $unhide = false ) { $this->mTitle = $titleObj; wfDebug("DifferenceEngine old '$old' new '$new' rcid '$rcid'\n"); @@ -67,6 +70,7 @@ class DifferenceEngine { $this->mRcidMarkPatrolled = intval($rcid); # force it to be an integer $this->mRefreshCache = $refreshCache; $this->htmldiff = $htmldiff; + $this->unhide = $unhide; } function getTitle() { @@ -254,16 +258,18 @@ CONTROL; } $oldHeader = '
'.$this->mOldtitle.'
' . - '
' . $sk->revUserTools( $this->mOldRev, true ) . "
" . - '
' . $oldminor . $sk->revComment( $this->mOldRev, !$diffOnly, true ) . $ldel . "
" . + '
' . $sk->revUserTools( $this->mOldRev, !$this->unhide ) . "
" . + '
' . $oldminor . $sk->revComment( $this->mOldRev, !$diffOnly, !$this->unhide ).$ldel."
" . '
' . $prevlink .'
'; $newHeader = '
'.$this->mNewtitle.'
' . - '
' . $sk->revUserTools( $this->mNewRev, true ) . " $rollback
" . - '
' . $newminor . $sk->revComment( $this->mNewRev, !$diffOnly, true ) . $rdel . "
" . + '
' . $sk->revUserTools( $this->mNewRev, !$this->unhide ) . " $rollback
" . + '
' . $newminor . $sk->revComment( $this->mNewRev, !$diffOnly, !$this->unhide ).$rdel."
" . '
' . $nextlink . $patrol . '
'; - # Output the diff - if( !$this->mOldRev->userCan(Revision::DELETED_TEXT) || !$this->mNewRev->userCan(Revision::DELETED_TEXT) ) { + # Output the diff if allowed + $allowed = $this->mOldRev->userCan(Revision::DELETED_TEXT) && $this->mNewRev->userCan(Revision::DELETED_TEXT); + $deleted = $this->mOldRev->isDeleted(Revision::DELETED_TEXT) || $this->mNewRev->isDeleted(Revision::DELETED_TEXT); + if( $deleted && (!$this->unhide || !$allowed) ) { $this->showDiffStyle(); $multi = $this->getMultiNotice(); $wgOut->addHTML( $this->addHeader( '', $oldHeader, $newHeader, $multi ) ); diff --git a/includes/specials/SpecialRevisiondelete.php b/includes/specials/SpecialRevisiondelete.php index f39f80f611..7c5d6b64e2 100644 --- a/includes/specials/SpecialRevisiondelete.php +++ b/includes/specials/SpecialRevisiondelete.php @@ -542,15 +542,16 @@ class RevisionDeleteForm { * @returns string */ private function historyLine( $rev ) { - global $wgLang; + global $wgLang, $wgUser; $date = $wgLang->timeanddate( $rev->getTimestamp() ); $difflink = $del = ''; // Live revisions if( $this->deleteKey=='oldid' ) { - $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid=' . $rev->getId() ); + $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) ); + $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid='.$rev->getId() . $tokenParams ); $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'), - 'diff=' . $rev->getId() . '&oldid=prev' ) . ')'; + 'diff=' . $rev->getId() . '&oldid=prev' . $tokenParams ) . ')'; // Archived revisions } else { $undelete = SpecialPage::getTitleFor( 'Undelete' ); @@ -560,7 +561,7 @@ class RevisionDeleteForm { $difflink = '(' . $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml('diff'), "target=$target&diff=prev×tamp=" . $rev->getTimestamp() ) . ')'; } - + // Check permissions; items may be "suppressed" if( $rev->isDeleted(Revision::DELETED_TEXT) ) { $revlink = ''.$revlink.''; $del = ' ' . wfMsgHtml( 'deletedrev' ) . ''; @@ -569,8 +570,10 @@ class RevisionDeleteForm { $difflink = '(' . wfMsgHtml('diff') . ')'; } } + $userlink = $this->skin->revUserLink( $rev ); + $comment = $this->skin->revComment( $rev ); - return "
  • $difflink $revlink ".$this->skin->revUserLink( $rev )." ".$this->skin->revComment( $rev )."$del
  • "; + return "
  • $difflink $revlink $userlink $comment{$del}
  • "; } /** -- 2.20.1