From 5ce6ddebb4290124ddd875f4b02e1152c5a69019 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Wed, 6 Jul 2011 16:47:29 +0000 Subject: [PATCH] (Bug 19725) Do not include suppressed edits in the "View X deleted edits" message, and when doing prefix search of special:undelete. I'm not 100% sure this is the right thing to do, see the bug for the details. But basically this doesn't include an edit in the count if its text is hidden and its hidden from admins. (Not sure if it should not be included only if everything is hidden). Its also weird to show people different things depending if they have suppress rights, without really indicating that. Minor db note: This causes the query to no longer use a covering index. I don't think that matters but just thought i'd mention. p.s. The upload page show deleted edits link is broken right now, (from before) I'll fix in a follow-up. --- RELEASE-NOTES-1.18 | 2 ++ includes/Skin.php | 4 +++- includes/SkinTemplate.php | 3 ++- includes/Title.php | 25 +++++++++++++++++++++---- includes/specials/SpecialUndelete.php | 8 ++++++++ includes/specials/SpecialUpload.php | 25 ++++++++++++++----------- 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/RELEASE-NOTES-1.18 b/RELEASE-NOTES-1.18 index 7b86b211c4..be122e7abf 100644 --- a/RELEASE-NOTES-1.18 +++ b/RELEASE-NOTES-1.18 @@ -257,6 +257,8 @@ production. environments * (bug 14977) Fixed $wgServer detection in cases where an IPv6 address is used as the server name. +* (bug 19725) Do not list suppressed edits in the "View X deleted edits" link + if user cannot view suppressed edits. === API changes in 1.18 === * (bug 26339) Throw warning when truncating an overlarge API result. diff --git a/includes/Skin.php b/includes/Skin.php index 39d6a4efd5..d57135028f 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -754,7 +754,9 @@ abstract class Skin { if ( $this->getContext()->getUser()->isAllowed( 'deletedhistory' ) && ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) { - $n = $this->getTitle()->isDeleted(); + + $includeSuppressed = $this->getContext()->getUser()->isAllowed( 'suppressrevision' ); + $n = $this->getTitle()->isDeleted( $includeSuppressed ); if ( $n ) { if ( $this->getContext()->getUser()->isAllowed( 'undelete' ) ) { diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index daa5fa1e37..8fef85f058 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -982,7 +982,8 @@ class SkinTemplate extends Skin { } else { // article doesn't exist or is deleted if ( $wgUser->isAllowed( 'deletedhistory' ) ) { - $n = $title->isDeleted(); + $includeSuppressed = $wgUser->isAllowed( 'suppressrevision' ); + $n = $title->isDeleted( $includeSuppressed ); if( $n ) { $undelTitle = SpecialPage::getTitleFor( 'Undelete' ); // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead diff --git a/includes/Title.php b/includes/Title.php index 5f7c151950..5dccdf93ef 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2344,20 +2344,37 @@ class Title { /** * Is there a version of this page in the deletion archive? * + * @param $includeSuppressed Boolean Include suppressed revisions? * @return Int the number of archived revisions */ - public function isDeleted() { + public function isDeleted( $includeSuppressed = false ) { if ( $this->getNamespace() < 0 ) { $n = 0; } else { $dbr = wfGetDB( DB_SLAVE ); + $conditions = array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ); + + if( !$includeSuppressed ) { + $suppressedTextBits = REVISION::DELETED_TEXT | REVISION::DELETED_RESTRICTED; + $conditions[] = $dbr->bitAnd('ar_deleted', $suppressedTextBits ) . + ' != ' . $suppressedTextBits; + } + $n = $dbr->selectField( 'archive', 'COUNT(*)', - array( 'ar_namespace' => $this->getNamespace(), 'ar_title' => $this->getDBkey() ), + $conditions, __METHOD__ ); if ( $this->getNamespace() == NS_FILE ) { - $n += $dbr->selectField( 'filearchive', 'COUNT(*)', - array( 'fa_name' => $this->getDBkey() ), + $fconditions = array( 'fa_name' => $this->getDBkey() ); + if( !$includeSuppressed ) { + $suppressedTextBits = FILE::DELETED_FILE | FILE::DELETED_RESTRICTED; + $fconditions[] = $dbr->bitAnd('fa_deleted', $suppressedTextBits ) . + ' != ' . $suppressedTextBits; + } + + $n += $dbr->selectField( 'filearchive', + 'COUNT(*)', + $fconditions, __METHOD__ ); } diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index 15a77c313d..c11b7c0ff5 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -62,6 +62,7 @@ class PageArchive { * @return ResultWrapper */ public static function listPagesByPrefix( $prefix ) { + global $wgUser; $dbr = wfGetDB( DB_SLAVE ); $title = Title::newFromText( $prefix ); @@ -77,6 +78,13 @@ class PageArchive { 'ar_namespace' => $ns, 'ar_title' . $dbr->buildLike( $prefix, $dbr->anyString() ), ); + + // bug 19725 + $suppressedText = REVISION::DELETED_TEXT | REVISION::DELETED_RESTRICTED; + if( !$wgUser->isAllowed( 'suppressrevision' ) ) { + $conds[] = $dbr->bitAnd('ar_deleted', $suppressedText ) . + ' != ' . $suppressedText; + } return self::listPages( $dbr, $conds ); } diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 34653f28fe..159cdd6103 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -314,17 +314,20 @@ class SpecialUpload extends SpecialPage { $title = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName ); // Show a subtitle link to deleted revisions (to sysops et al only) if( $title instanceof Title ) { - $count = $title->isDeleted(); - if ( $count > 0 && $wgUser->isAllowed( 'deletedhistory' ) ) { - $link = wfMsgExt( - $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted', - array( 'parse', 'replaceafter' ), - $this->getSkin()->linkKnown( - SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ), - wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count ) - ) - ); - $wgOut->addHTML( "
{$link}
" ); + if ( $wgUser->isAllowed( 'deletedhistory' ) ) { + $canViewSuppress = $wgUser->isAllowed( 'suppressrevision' ); + $count = $title->isDeleted( $canViewSuppress ); + if ( $count > 0 ) { + $link = wfMsgExt( + $wgUser->isAllowed( 'delete' ) ? 'thisisdeleted' : 'viewdeleted', + array( 'parse', 'replaceafter' ), + $this->getSkin()->linkKnown( + SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedText() ), + wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $count ) + ) + ); + $wgOut->addHTML( "
{$link}
" ); + } } } -- 2.20.1