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.
This commit is contained in:
Tim Starling 2008-09-24 09:44:45 +00:00
parent 6f6d09b0e4
commit 7410147d02
6 changed files with 80 additions and 30 deletions

View file

@ -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();

View file

@ -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 = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
} 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 = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
}

View file

@ -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

View file

@ -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);
}

View file

@ -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__ );
}
}
}

View file

@ -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 '<span class="history-deleted">' . wfMsgHtml( 'rev-deleted-user' ) . '</span>';
} 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 = '<span class="history-deleted">' . $link . '</span>';
return $link;