From 7410147d02c8b77dafe5d974a58a131892329871 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 24 Sep 2008 09:44:45 +0000 Subject: [PATCH] Fixes for r41154 and r41155: * Boolean parameters are widely accepted to reduce readability. Replaced the new boolean parameters with class constant parameters instead. * Re-added Revision::revText(), for backwards compatibility * The getUser()/getUserText() changes near line 1223 of SpecialUndelete.php were incorrect, $file is an ArchivedFile not a Revision, and doesn't have any $isPublic parameters. --- includes/Article.php | 2 +- includes/Linker.php | 12 +++-- includes/Revision.php | 78 +++++++++++++++++++++------ includes/api/ApiParse.php | 2 +- includes/diff/DifferenceEngine.php | 8 +-- includes/specials/SpecialUndelete.php | 8 +-- 6 files changed, 80 insertions(+), 30 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 127a83d61f..06e3ecded2 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -448,7 +448,7 @@ class Article { // FIXME: Horrible, horrible! This content-loading interface just plain sucks. // We should instead work with the Revision object when we need it... - $this->mContent = $revision->getText( false ); // Loads if user is allowed + $this->mContent = $revision->getText( Revision::FOR_THIS_USER ); // Loads if user is allowed $this->mUser = $revision->getUser(); $this->mUserText = $revision->getUserText(); diff --git a/includes/Linker.php b/includes/Linker.php index 8e87fbf0e8..529891cafe 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1113,7 +1113,8 @@ class Linker { if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) { $link = wfMsgHtml( 'rev-deleted-user' ); } else if( $rev->userCan( Revision::DELETED_USER ) ) { - $link = $this->userLink( $rev->getUser(false), $rev->getUserText(false) ); + $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ), + $rev->getUserText( Revision::FOR_THIS_USER ) ); } else { $link = wfMsgHtml( 'rev-deleted-user' ); } @@ -1133,8 +1134,10 @@ class Linker { if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) { $link = wfMsgHtml( 'rev-deleted-user' ); } else if( $rev->userCan( Revision::DELETED_USER ) ) { - $link = $this->userLink( $rev->getUser(false), $rev->getUserText(false) ) . - ' ' . $this->userToolLinks( $rev->getUser(false), $rev->getUserText(false) ); + $userId = $rev->getUser( Revision::FOR_THIS_USER ); + $userText = $rev->getUserText( Revision::FOR_THIS_USER ); + $link = $this->userLink( $userId, $userText ) . + ' ' . $this->userToolLinks( $userId, $userText ); } else { $link = wfMsgHtml( 'rev-deleted-user' ); } @@ -1340,7 +1343,8 @@ class Linker { if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) { $block = " " . wfMsgHtml( 'rev-deleted-comment' ) . ""; } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) { - $block = $this->commentBlock( $rev->getComment(false), $rev->getTitle(), $local ); + $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ), + $rev->getTitle(), $local ); } else { $block = " " . wfMsgHtml( 'rev-deleted-comment' ) . ""; } diff --git a/includes/Revision.php b/includes/Revision.php index 8d1200685d..2661149bbf 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -13,6 +13,11 @@ class Revision { const DELETED_USER = 4; const DELETED_RESTRICTED = 8; + // Audience options for Revision::getText() + const FOR_PUBLIC = 1; + const FOR_THIS_USER = 2; + const RAW = 3; + /** * Load a page revision from a given revision ID number. * Returns null if no such revision can be found. @@ -427,13 +432,22 @@ class Revision { } /** - * Fetch revision's user id if it's available to all users + * Fetch revision's user id if it's available to the specified audience. + * If the specified audience does not have access to it, zero will be + * returned. + * + * @param integer $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::RAW get the ID regardless of permissions + * + * * @return int */ - public function getUser( $isPublic = true ) { - if( $isPublic && $this->isDeleted( self::DELETED_USER ) ) { + public function getUser( $audience = self::FOR_PUBLIC ) { + if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) { return 0; - } else if( !$this->userCan( self::DELETED_USER ) ) { + } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER ) ) { return 0; } else { return $this->mUser; @@ -449,13 +463,21 @@ class Revision { } /** - * Fetch revision's username if it's available to all users + * Fetch revision's username if it's available to the specified audience. + * If the specified audience does not have access to the username, an + * empty string will be returned. + * + * @param integer $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::RAW get the text regardless of permissions + * * @return string */ - public function getUserText( $isPublic = true ) { - if( $isPublic && $this->isDeleted( self::DELETED_USER ) ) { + public function getUserText( $audience = self::FOR_PUBLIC ) { + if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) { return ""; - } else if( !$this->userCan( self::DELETED_USER ) ) { + } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER ) ) { return ""; } else { return $this->mUserText; @@ -471,13 +493,21 @@ class Revision { } /** - * Fetch revision comment if it's available to all users + * Fetch revision comment if it's available to the specified audience. + * If the specified audience does not have access to the comment, an + * empty string will be returned. + * + * @param integer $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::RAW get the text regardless of permissions + * * @return string */ - function getComment( $isPublic = true ) { - if( $isPublic && $this->isDeleted( self::DELETED_COMMENT ) ) { + function getComment( $audience = self::FOR_PUBLIC ) { + if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) { return ""; - } else if( !$this->userCan( self::DELETED_COMMENT ) ) { + } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_COMMENT ) ) { return ""; } else { return $this->mComment; @@ -508,19 +538,35 @@ class Revision { } /** - * Fetch revision text if it's available to all users + * Fetch revision text if it's available to the specified audience. + * If the specified audience does not have the ability to view this + * revision, an empty string will be returned. + * + * @param integer $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to $wgUser + * Revision::RAW get the text regardless of permissions + * + * * @return string */ - public function getText( $isPublic = true ) { - if( $isPublic && $this->isDeleted( self::DELETED_TEXT ) ) { + public function getText( $audience = self::FOR_PUBLIC ) { + if( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_TEXT ) ) { return ""; - } else if( !$this->userCan( self::DELETED_TEXT ) ) { + } elseif( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_TEXT ) ) { return ""; } else { return $this->getRawText(); } } + /** + * Alias for getText(Revision::FOR_THIS_USER) + */ + public function revText() { + return $this->getText( self::FOR_THIS_USER ); + } + /** * Fetch revision text without regard for view restrictions * @return string diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 7151300b7b..7c1637b635 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -63,7 +63,7 @@ class ApiParse extends ApiBase { $this->dieUsage("There is no revision ID $oldid", 'missingrev'); if(!$rev->userCan(Revision::DELETED_TEXT)) $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied'); - $text = $rev->getText(false); + $text = $rev->getText( Revision::FOR_THIS_USER ); $titleObj = $rev->getTitle(); $p_result = $wgParser->parse($text, $titleObj, $popts); } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index a185b0a8b8..9697cd7a82 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -176,7 +176,7 @@ CONTROL; $change = RecentChange::newFromConds( array( // Add redundant user,timestamp condition so we can use the existing index - 'rc_user_text' => $this->mNewRev->getUserText(false), + 'rc_user_text' => $this->mNewRev->getUserText( Revision::FOR_THIS_USER ), 'rc_timestamp' => $db->timestamp( $this->mNewRev->getTimestamp() ), 'rc_this_oldid' => $this->mNewid, 'rc_last_oldid' => $this->mOldid, @@ -847,13 +847,13 @@ CONTROL; return false; } if ( $this->mOldRev ) { - $this->mOldtext = $this->mOldRev->getText( false ); + $this->mOldtext = $this->mOldRev->getText( Revision::FOR_THIS_USER ); if ( $this->mOldtext === false ) { return false; } } if ( $this->mNewRev ) { - $this->mNewtext = $this->mNewRev->getText( false ); + $this->mNewtext = $this->mNewRev->getText( Revision::FOR_THIS_USER ); if ( $this->mNewtext === false ) { return false; } @@ -2114,4 +2114,4 @@ class TableDiffFormatter extends DiffFormatter { } wfProfileOut( __METHOD__ ); } -} \ No newline at end of file +} diff --git a/includes/specials/SpecialUndelete.php b/includes/specials/SpecialUndelete.php index c802fd72f2..810b007771 100644 --- a/includes/specials/SpecialUndelete.php +++ b/includes/specials/SpecialUndelete.php @@ -787,7 +787,7 @@ class UndeleteForm { $popts = $wgOut->parserOptions(); $popts->setEditSection( false ); $wgOut->parserOptions( $popts ); - $wgOut->addWikiTextTitleTidy( $rev->getText( false ), $this->mTargetObj, true ); + $wgOut->addWikiTextTitleTidy( $rev->getText( Revision::FOR_THIS_USER ), $this->mTargetObj, true ); } $wgOut->addHtml( @@ -795,7 +795,7 @@ class UndeleteForm { 'readonly' => 'readonly', 'cols' => intval( $wgUser->getOption( 'cols' ) ), 'rows' => intval( $wgUser->getOption( 'rows' ) ) ), - $rev->getText( false ) . "\n" ) . + $rev->getText( Revision::FOR_THIS_USER ) . "\n" ) . wfOpenElement( 'div' ) . wfOpenElement( 'form', array( 'method' => 'post', @@ -1223,8 +1223,8 @@ class UndeleteForm { if( !$file->userCan(File::DELETED_USER) ) { return '' . wfMsgHtml( 'rev-deleted-user' ) . ''; } else { - $link = $sk->userLink( $file->getUser(false), $file->getUserText(false) ) . - $sk->userToolLinks( $file->getUser(false), $file->getUserText(false) ); + $link = $sk->userLink( $file->getUser(), $file->getUserText() ) . + $sk->userToolLinks( $file->getUser(), $file->getUserText() ); if( $file->isDeleted(File::DELETED_USER) ) $link = '' . $link . ''; return $link; -- 2.20.1