diff options
Diffstat (limited to 'includes/Revision.php')
-rw-r--r-- | includes/Revision.php | 517 |
1 files changed, 290 insertions, 227 deletions
diff --git a/includes/Revision.php b/includes/Revision.php index 233eac01..28a825d0 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -41,6 +41,11 @@ class Revision implements IDBAccessObject { protected $mParentId; protected $mComment; protected $mText; + protected $mTextId; + + /** + * @var stdClass|null + */ protected $mTextRow; /** @@ -86,9 +91,9 @@ class Revision implements IDBAccessObject { * Revision::READ_LATEST : Select the data from the master * Revision::READ_LOCKING : Select & lock the data from the master * - * @param $id Integer - * @param $flags Integer (optional) - * @return Revision or null + * @param int $id + * @param int $flags (optional) + * @return Revision|null */ public static function newFromId( $id, $flags = 0 ) { return self::newFromConds( array( 'rev_id' => intval( $id ) ), $flags ); @@ -103,10 +108,10 @@ class Revision implements IDBAccessObject { * Revision::READ_LATEST : Select the data from the master * Revision::READ_LOCKING : Select & lock the data from the master * - * @param $title Title - * @param $id Integer (optional) - * @param $flags Integer Bitfield (optional) - * @return Revision or null + * @param Title $title + * @param int $id (optional) + * @param int $flags Bitfield (optional) + * @return Revision|null */ public static function newFromTitle( $title, $id = 0, $flags = 0 ) { $conds = array( @@ -134,10 +139,10 @@ class Revision implements IDBAccessObject { * Revision::READ_LATEST : Select the data from the master (since 1.20) * Revision::READ_LOCKING : Select & lock the data from the master * - * @param $revId Integer - * @param $pageId Integer (optional) - * @param $flags Integer Bitfield (optional) - * @return Revision or null + * @param int $pageId + * @param int $revId (optional) + * @param int $flags Bitfield (optional) + * @return Revision|null */ public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) { $conds = array( 'page_id' => $pageId ); @@ -155,8 +160,8 @@ class Revision implements IDBAccessObject { * for permissions or even inserted (as in Special:Undelete) * @todo FIXME: Should be a subclass for RevisionDelete. [TS] * - * @param $row - * @param $overrides array + * @param object $row + * @param array $overrides * * @throws MWException * @return Revision @@ -205,7 +210,7 @@ class Revision implements IDBAccessObject { /** * @since 1.19 * - * @param $row + * @param object $row * @return Revision */ public static function newFromRow( $row ) { @@ -216,9 +221,9 @@ class Revision implements IDBAccessObject { * Load a page revision from a given revision ID number. * Returns null if no such revision can be found. * - * @param $db DatabaseBase - * @param $id Integer - * @return Revision or null + * @param DatabaseBase $db + * @param int $id + * @return Revision|null */ public static function loadFromId( $db, $id ) { return self::loadFromConds( $db, array( 'rev_id' => intval( $id ) ) ); @@ -229,10 +234,10 @@ class Revision implements IDBAccessObject { * that's attached to a given page. If not attached * to that page, will return null. * - * @param $db DatabaseBase - * @param $pageid Integer - * @param $id Integer - * @return Revision or null + * @param DatabaseBase $db + * @param int $pageid + * @param int $id + * @return Revision|null */ public static function loadFromPageId( $db, $pageid, $id = 0 ) { $conds = array( 'rev_page' => intval( $pageid ), 'page_id' => intval( $pageid ) ); @@ -249,10 +254,10 @@ class Revision implements IDBAccessObject { * that's attached to a given page. If not attached * to that page, will return null. * - * @param $db DatabaseBase - * @param $title Title - * @param $id Integer - * @return Revision or null + * @param DatabaseBase $db + * @param Title $title + * @param int $id + * @return Revision|null */ public static function loadFromTitle( $db, $title, $id = 0 ) { if ( $id ) { @@ -274,10 +279,10 @@ class Revision implements IDBAccessObject { * WARNING: Timestamps may in some circumstances not be unique, * so this isn't the best key to use. * - * @param $db DatabaseBase - * @param $title Title - * @param $timestamp String - * @return Revision or null + * @param DatabaseBase $db + * @param Title $title + * @param string $timestamp + * @return Revision|null */ public static function loadFromTimestamp( $db, $title, $timestamp ) { return self::loadFromConds( $db, @@ -292,14 +297,14 @@ class Revision implements IDBAccessObject { /** * Given a set of conditions, fetch a revision. * - * @param $conditions Array - * @param $flags integer (optional) - * @return Revision or null + * @param array $conditions + * @param int $flags (optional) + * @return Revision|null */ private static function newFromConds( $conditions, $flags = 0 ) { $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE ); $rev = self::loadFromConds( $db, $conditions, $flags ); - if ( is_null( $rev ) && wfGetLB()->getServerCount() > 1 ) { + if ( $rev === null && wfGetLB()->getServerCount() > 1 ) { if ( !( $flags & self::READ_LATEST ) ) { $dbw = wfGetDB( DB_MASTER ); $rev = self::loadFromConds( $dbw, $conditions, $flags ); @@ -315,10 +320,10 @@ class Revision implements IDBAccessObject { * Given a set of conditions, fetch a revision from * the given database connection. * - * @param $db DatabaseBase - * @param $conditions Array - * @param $flags integer (optional) - * @return Revision or null + * @param DatabaseBase $db + * @param array $conditions + * @param int $flags (optional) + * @return Revision|null */ private static function loadFromConds( $db, $conditions, $flags = 0 ) { $res = self::fetchFromConds( $db, $conditions, $flags ); @@ -338,7 +343,7 @@ class Revision implements IDBAccessObject { * fetch all of a given page's revisions in turn. * Each row can be fed to the constructor to get objects. * - * @param $title Title + * @param Title $title * @return ResultWrapper */ public static function fetchRevision( $title ) { @@ -357,9 +362,9 @@ class Revision implements IDBAccessObject { * which will return matching database rows with the * fields necessary to build Revision objects. * - * @param $db DatabaseBase - * @param $conditions Array - * @param $flags integer (optional) + * @param DatabaseBase $db + * @param array $conditions + * @param int $flags (optional) * @return ResultWrapper */ private static function fetchFromConds( $db, $conditions, $flags = 0 ) { @@ -386,7 +391,7 @@ class Revision implements IDBAccessObject { * Return the value of a select() JOIN conds array for the user table. * This will get user table rows for logged-in users. * @since 1.19 - * @return Array + * @return array */ public static function userJoinCond() { return array( 'LEFT JOIN', array( 'rev_user != 0', 'user_id = rev_user' ) ); @@ -396,7 +401,7 @@ class Revision implements IDBAccessObject { * Return the value of a select() page conds array for the page table. * This will assure that the revision(s) are not orphaned from live pages. * @since 1.19 - * @return Array + * @return array */ public static function pageJoinCond() { return array( 'INNER JOIN', array( 'page_id = rev_page' ) ); @@ -434,6 +439,37 @@ class Revision implements IDBAccessObject { } /** + * Return the list of revision fields that should be selected to create + * a new revision from an archive row. + * @return array + */ + public static function selectArchiveFields() { + global $wgContentHandlerUseDB; + $fields = array( + 'ar_id', + 'ar_page_id', + 'ar_rev_id', + 'ar_text', + 'ar_text_id', + 'ar_timestamp', + 'ar_comment', + 'ar_user_text', + 'ar_user', + 'ar_minor_edit', + 'ar_deleted', + 'ar_len', + 'ar_parent_id', + 'ar_sha1', + ); + + if ( $wgContentHandlerUseDB ) { + $fields[] = 'ar_content_format'; + $fields[] = 'ar_content_model'; + } + return $fields; + } + + /** * Return the list of text fields that should be selected to read the * revision text * @return array @@ -470,8 +506,8 @@ class Revision implements IDBAccessObject { /** * Do a batched query to get the parent revision lengths - * @param $db DatabaseBase - * @param $revIds Array + * @param DatabaseBase $db + * @param array $revIds * @return array */ public static function getParentLengths( $db, array $revIds ) { @@ -494,20 +530,20 @@ class Revision implements IDBAccessObject { /** * Constructor * - * @param $row Mixed: either a database row or an array + * @param object|array $row Either a database row or an array * @throws MWException * @access private */ function __construct( $row ) { if ( is_object( $row ) ) { - $this->mId = intval( $row->rev_id ); - $this->mPage = intval( $row->rev_page ); - $this->mTextId = intval( $row->rev_text_id ); - $this->mComment = $row->rev_comment; - $this->mUser = intval( $row->rev_user ); + $this->mId = intval( $row->rev_id ); + $this->mPage = intval( $row->rev_page ); + $this->mTextId = intval( $row->rev_text_id ); + $this->mComment = $row->rev_comment; + $this->mUser = intval( $row->rev_user ); $this->mMinorEdit = intval( $row->rev_minor_edit ); - $this->mTimestamp = $row->rev_timestamp; - $this->mDeleted = intval( $row->rev_deleted ); + $this->mTimestamp = $row->rev_timestamp; + $this->mDeleted = intval( $row->rev_deleted ); if ( !isset( $row->rev_parent_id ) ) { $this->mParentId = null; @@ -535,13 +571,13 @@ class Revision implements IDBAccessObject { $this->mTitle = null; } - if ( !isset( $row->rev_content_model ) || is_null( $row->rev_content_model ) ) { + if ( !isset( $row->rev_content_model ) ) { $this->mContentModel = null; # determine on demand if needed } else { $this->mContentModel = strval( $row->rev_content_model ); } - if ( !isset( $row->rev_content_format ) || is_null( $row->rev_content_format ) ) { + if ( !isset( $row->rev_content_format ) ) { $this->mContentFormat = null; # determine on demand if needed } else { $this->mContentFormat = strval( $row->rev_content_format ); @@ -582,27 +618,31 @@ class Revision implements IDBAccessObject { # also set text to null? } - $this->mId = isset( $row['id'] ) ? intval( $row['id'] ) : null; - $this->mPage = isset( $row['page'] ) ? intval( $row['page'] ) : null; - $this->mTextId = isset( $row['text_id'] ) ? intval( $row['text_id'] ) : null; - $this->mUserText = isset( $row['user_text'] ) ? strval( $row['user_text'] ) : $wgUser->getName(); - $this->mUser = isset( $row['user'] ) ? intval( $row['user'] ) : $wgUser->getId(); + $this->mId = isset( $row['id'] ) ? intval( $row['id'] ) : null; + $this->mPage = isset( $row['page'] ) ? intval( $row['page'] ) : null; + $this->mTextId = isset( $row['text_id'] ) ? intval( $row['text_id'] ) : null; + $this->mUserText = isset( $row['user_text'] ) + ? strval( $row['user_text'] ) : $wgUser->getName(); + $this->mUser = isset( $row['user'] ) ? intval( $row['user'] ) : $wgUser->getId(); $this->mMinorEdit = isset( $row['minor_edit'] ) ? intval( $row['minor_edit'] ) : 0; - $this->mTimestamp = isset( $row['timestamp'] ) ? strval( $row['timestamp'] ) : wfTimestampNow(); - $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0; - $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null; - $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null; - $this->mSha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null; - - $this->mContentModel = isset( $row['content_model'] ) ? strval( $row['content_model'] ) : null; - $this->mContentFormat = isset( $row['content_format'] ) ? strval( $row['content_format'] ) : null; + $this->mTimestamp = isset( $row['timestamp'] ) + ? strval( $row['timestamp'] ) : wfTimestampNow(); + $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0; + $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null; + $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null; + $this->mSha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null; + + $this->mContentModel = isset( $row['content_model'] ) + ? strval( $row['content_model'] ) : null; + $this->mContentFormat = isset( $row['content_format'] ) + ? strval( $row['content_format'] ) : null; // Enforce spacing trimming on supplied text - $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null; - $this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null; - $this->mTextRow = null; + $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null; + $this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null; + $this->mTextRow = null; - $this->mTitle = isset( $row['title'] ) ? $row['title'] : null; + $this->mTitle = isset( $row['title'] ) ? $row['title'] : null; // if we have a Content object, override mText and mContentModel if ( !empty( $row['content'] ) ) { @@ -617,7 +657,7 @@ class Revision implements IDBAccessObject { $this->mContentHandler = null; $this->mText = $handler->serializeContent( $row['content'], $this->getContentFormat() ); - } elseif ( !is_null( $this->mText ) ) { + } elseif ( $this->mText !== null ) { $handler = $this->getContentHandler(); $this->mContent = $handler->unserializeContent( $this->mText ); } @@ -639,7 +679,7 @@ class Revision implements IDBAccessObject { // If we still have no length, see it we have the text to figure it out if ( !$this->mSize ) { - if ( !is_null( $this->mContent ) ) { + if ( $this->mContent !== null ) { $this->mSize = $this->mContent->getSize(); } else { #NOTE: this should never happen if we have either text or content object! @@ -649,7 +689,7 @@ class Revision implements IDBAccessObject { // Same for sha1 if ( $this->mSha1 === null ) { - $this->mSha1 = is_null( $this->mText ) ? null : self::base36Sha1( $this->mText ); + $this->mSha1 = $this->mText === null ? null : self::base36Sha1( $this->mText ); } // force lazy init @@ -664,7 +704,7 @@ class Revision implements IDBAccessObject { /** * Get revision ID * - * @return Integer|null + * @return int|null */ public function getId() { return $this->mId; @@ -674,7 +714,7 @@ class Revision implements IDBAccessObject { * Set the revision ID * * @since 1.19 - * @param $id Integer + * @param int $id */ public function setId( $id ) { $this->mId = $id; @@ -683,7 +723,7 @@ class Revision implements IDBAccessObject { /** * Get text row ID * - * @return Integer|null + * @return int|null */ public function getTextId() { return $this->mTextId; @@ -692,7 +732,7 @@ class Revision implements IDBAccessObject { /** * Get parent revision ID (the original previous page revision) * - * @return Integer|null + * @return int|null */ public function getParentId() { return $this->mParentId; @@ -701,7 +741,7 @@ class Revision implements IDBAccessObject { /** * Returns the length of the text in this revision, or null if unknown. * - * @return Integer|null + * @return int|null */ public function getSize() { return $this->mSize; @@ -710,7 +750,7 @@ class Revision implements IDBAccessObject { /** * Returns the base36 sha1 of the text in this revision, or null if unknown. * - * @return String|null + * @return string|null */ public function getSha1() { return $this->mSha1; @@ -724,10 +764,11 @@ class Revision implements IDBAccessObject { * @return Title|null */ public function getTitle() { - if ( isset( $this->mTitle ) ) { + if ( $this->mTitle !== null ) { return $this->mTitle; } - if ( !is_null( $this->mId ) ) { //rev_id is defined as NOT NULL, but this revision may not yet have been inserted. + //rev_id is defined as NOT NULL, but this revision may not yet have been inserted. + if ( $this->mId !== null ) { $dbr = wfGetDB( DB_SLAVE ); $row = $dbr->selectRow( array( 'page', 'revision' ), @@ -740,7 +781,7 @@ class Revision implements IDBAccessObject { } } - if ( !$this->mTitle && !is_null( $this->mPage ) && $this->mPage > 0 ) { + if ( !$this->mTitle && $this->mPage !== null && $this->mPage > 0 ) { $this->mTitle = Title::newFromID( $this->mPage ); } @@ -750,7 +791,7 @@ class Revision implements IDBAccessObject { /** * Set the title of the revision * - * @param $title Title + * @param Title $title */ public function setTitle( $title ) { $this->mTitle = $title; @@ -759,7 +800,7 @@ class Revision implements IDBAccessObject { /** * Get the page ID * - * @return Integer|null + * @return int|null */ public function getPage() { return $this->mPage; @@ -770,13 +811,13 @@ class Revision implements IDBAccessObject { * If the specified audience does not have access to it, zero will be * returned. * - * @param $audience Integer: one of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the ID regardless of permissions - * @param $user User object to check for, only if FOR_THIS_USER is passed - * to the $audience parameter - * @return Integer + * @param int $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to the given user + * Revision::RAW get the ID regardless of permissions + * @param User $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter + * @return int */ public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) { if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) { @@ -791,7 +832,7 @@ class Revision implements IDBAccessObject { /** * Fetch revision's user id without regard for the current user's permissions * - * @return String + * @return string */ public function getRawUser() { return $this->mUser; @@ -802,12 +843,12 @@ class Revision implements IDBAccessObject { * If the specified audience does not have access to the username, an * empty string will be returned. * - * @param $audience Integer: one of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions - * @param $user User object to check for, only if FOR_THIS_USER is passed - * to the $audience parameter + * @param int $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to the given user + * Revision::RAW get the text regardless of permissions + * @param User $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @return string */ public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) { @@ -823,7 +864,7 @@ class Revision implements IDBAccessObject { /** * Fetch revision's username without regard for view restrictions * - * @return String + * @return string */ public function getRawUserText() { if ( $this->mUserText === null ) { @@ -842,13 +883,13 @@ class Revision implements IDBAccessObject { * If the specified audience does not have access to the comment, an * empty string will be returned. * - * @param $audience Integer: one of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions - * @param $user User object to check for, only if FOR_THIS_USER is passed - * to the $audience parameter - * @return String + * @param int $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to the given user + * Revision::RAW get the text regardless of permissions + * @param User $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter + * @return string */ function getComment( $audience = self::FOR_PUBLIC, User $user = null ) { if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) { @@ -863,21 +904,21 @@ class Revision implements IDBAccessObject { /** * Fetch revision comment without regard for the current user's permissions * - * @return String + * @return string */ public function getRawComment() { return $this->mComment; } /** - * @return Boolean + * @return bool */ public function isMinor() { return (bool)$this->mMinorEdit; } /** - * @return integer rcid of the unpatrolled row, zero if there isn't one + * @return int Rcid of the unpatrolled row, zero if there isn't one */ public function isUnpatrolled() { if ( $this->mUnpatrolled !== null ) { @@ -911,9 +952,9 @@ class Revision implements IDBAccessObject { } /** - * @param int $field one of DELETED_* bitfield constants + * @param int $field One of DELETED_* bitfield constants * - * @return Boolean + * @return bool */ public function isDeleted( $field ) { return ( $this->mDeleted & $field ) == $field; @@ -933,16 +974,16 @@ class Revision implements IDBAccessObject { * If the specified audience does not have the ability to view this * revision, an empty string will be returned. * - * @param $audience Integer: one of: - * Revision::FOR_PUBLIC to be displayed to all users - * Revision::FOR_THIS_USER to be displayed to the given user - * Revision::RAW get the text regardless of permissions - * @param $user User object to check for, only if FOR_THIS_USER is passed - * to the $audience parameter + * @param int $audience One of: + * Revision::FOR_PUBLIC to be displayed to all users + * Revision::FOR_THIS_USER to be displayed to the given user + * Revision::RAW get the text regardless of permissions + * @param User $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * - * @deprecated in 1.21, use getContent() instead + * @deprecated since 1.21, use getContent() instead * @todo Replace usage in core - * @return String + * @return string */ public function getText( $audience = self::FOR_PUBLIC, User $user = null ) { ContentHandler::deprecated( __METHOD__, '1.21' ); @@ -956,12 +997,12 @@ class Revision implements IDBAccessObject { * If the specified audience does not have the ability to view this * revision, null will be returned. * - * @param $audience Integer: 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 - * @param $user User object to check for, only if FOR_THIS_USER is passed - * to the $audience parameter + * @param int $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 + * @param User $user User object to check for, only if FOR_THIS_USER is passed + * to the $audience parameter * @since 1.21 * @return Content|null */ @@ -976,20 +1017,9 @@ class Revision implements IDBAccessObject { } /** - * Alias for getText(Revision::FOR_THIS_USER) - * - * @deprecated since 1.17 - * @return String - */ - public function revText() { - wfDeprecated( __METHOD__, '1.17' ); - return $this->getText( self::FOR_THIS_USER ); - } - - /** * Fetch revision text without regard for view restrictions * - * @return String + * @return string * * @deprecated since 1.21. Instead, use Revision::getContent( Revision::RAW ) * or Revision::getSerializedData() as appropriate. @@ -1003,10 +1033,10 @@ class Revision implements IDBAccessObject { * Fetch original serialized data without regard for view restrictions * * @since 1.21 - * @return String + * @return string */ public function getSerializedData() { - if ( is_null( $this->mText ) ) { + if ( $this->mText === null ) { $this->mText = $this->loadText(); } @@ -1020,12 +1050,12 @@ class Revision implements IDBAccessObject { * fresh clone. * * @since 1.21 - * @return Content|null the Revision's content, or null on failure. + * @return Content|null The Revision's content, or null on failure. */ protected function getContentInternal() { - if ( is_null( $this->mContent ) ) { + if ( $this->mContent === null ) { // Revision is immutable. Load on demand: - if ( is_null( $this->mText ) ) { + if ( $this->mText === null ) { $this->mText = $this->loadText(); } @@ -1051,7 +1081,8 @@ class Revision implements IDBAccessObject { * used to determine the content model to use. If no title is know, CONTENT_MODEL_WIKITEXT * is used as a last resort. * - * @return String the content model id associated with this revision, see the CONTENT_MODEL_XXX constants. + * @return string The content model id associated with this revision, + * see the CONTENT_MODEL_XXX constants. **/ public function getContentModel() { if ( !$this->mContentModel ) { @@ -1070,7 +1101,8 @@ class Revision implements IDBAccessObject { * If no content format was stored in the database, the default format for this * revision's content model is returned. * - * @return String the content format id associated with this revision, see the CONTENT_FORMAT_XXX constants. + * @return string The content format id associated with this revision, + * see the CONTENT_FORMAT_XXX constants. **/ public function getContentFormat() { if ( !$this->mContentFormat ) { @@ -1097,7 +1129,8 @@ class Revision implements IDBAccessObject { $format = $this->getContentFormat(); if ( !$this->mContentHandler->isSupportedFormat( $format ) ) { - throw new MWException( "Oops, the content format $format is not supported for this content model, $model" ); + throw new MWException( "Oops, the content format $format is not supported for " + . "this content model, $model" ); } } @@ -1105,14 +1138,14 @@ class Revision implements IDBAccessObject { } /** - * @return String + * @return string */ public function getTimestamp() { return wfTimestamp( TS_MW, $this->mTimestamp ); } /** - * @return Boolean + * @return bool */ public function isCurrent() { return $this->mCurrent; @@ -1136,7 +1169,7 @@ class Revision implements IDBAccessObject { /** * Get next revision for this title * - * @return Revision or null + * @return Revision|null */ public function getNext() { if ( $this->getTitle() ) { @@ -1152,11 +1185,11 @@ class Revision implements IDBAccessObject { * Get previous revision Id for this page_id * This is used to populate rev_parent_id on save * - * @param $db DatabaseBase - * @return Integer + * @param DatabaseBase $db + * @return int */ private function getPreviousRevisionId( $db ) { - if ( is_null( $this->mPage ) ) { + if ( $this->mPage === null ) { return 0; } # Use page_latest if ID is not given @@ -1174,18 +1207,18 @@ class Revision implements IDBAccessObject { } /** - * Get revision text associated with an old or archive row - * $row is usually an object from wfFetchRow(), both the flags and the text - * field must be included - * - * @param $row Object: the text data - * @param string $prefix table prefix (default 'old_') - * @param string|false $wiki the name of the wiki to load the revision text from - * (same as the the wiki $row was loaded from) or false to indicate the local - * wiki (this is the default). Otherwise, it must be a symbolic wiki database - * identifier as understood by the LoadBalancer class. - * @return String: text the text requested or false on failure - */ + * Get revision text associated with an old or archive row + * $row is usually an object from wfFetchRow(), both the flags and the text + * field must be included. + * + * @param stdClass $row The text data + * @param string $prefix Table prefix (default 'old_') + * @param string|bool $wiki The name of the wiki to load the revision text from + * (same as the the wiki $row was loaded from) or false to indicate the local + * wiki (this is the default). Otherwise, it must be a symbolic wiki database + * identifier as understood by the LoadBalancer class. + * @return string Text the text requested or false on failure + */ public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) { wfProfileIn( __METHOD__ ); @@ -1232,8 +1265,8 @@ class Revision implements IDBAccessObject { * data is compressed, and 'utf-8' if we're saving in UTF-8 * mode. * - * @param $text Mixed: reference to a text - * @return String + * @param mixed $text Reference to a text + * @return string */ public static function compressRevisionText( &$text ) { global $wgCompressRevisions; @@ -1257,9 +1290,9 @@ class Revision implements IDBAccessObject { /** * Re-converts revision text according to it's flags. * - * @param $text Mixed: reference to a text - * @param $flags array: compression flags - * @return String|bool decompressed text, or false on failure + * @param mixed $text Reference to a text + * @param array $flags Compression flags + * @return string|bool Decompressed text, or false on failure */ public static function decompressRevisionText( $text, $flags ) { if ( in_array( 'gzip', $flags ) ) { @@ -1281,8 +1314,8 @@ class Revision implements IDBAccessObject { global $wgLegacyEncoding; if ( $text !== false && $wgLegacyEncoding - && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) ) - { + && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) + ) { # Old revisions kept around in a legacy encoding? # Upconvert on demand. # ("utf8" checked for compatibility with some broken @@ -1298,9 +1331,9 @@ class Revision implements IDBAccessObject { * Insert a new revision into the database, returning the new revision ID * number on success and dies horribly on failure. * - * @param $dbw DatabaseBase: (master connection) + * @param DatabaseBase $dbw (master connection) * @throws MWException - * @return Integer + * @return int */ public function insertOn( $dbw ) { global $wgDefaultExternalStore, $wgContentHandlerUseDB; @@ -1327,7 +1360,7 @@ class Revision implements IDBAccessObject { } # Record the text (or external storage URL) to the text table - if ( !isset( $this->mTextId ) ) { + if ( $this->mTextId === null ) { $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' ); $dbw->insert( 'text', array( @@ -1344,7 +1377,7 @@ class Revision implements IDBAccessObject { } # Record the edit in revisions - $rev_id = isset( $this->mId ) + $rev_id = $this->mId !== null ? $this->mId : $dbw->nextSequenceValue( 'revision_rev_id_seq' ); $row = array( @@ -1358,17 +1391,18 @@ class Revision implements IDBAccessObject { 'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ), 'rev_deleted' => $this->mDeleted, 'rev_len' => $this->mSize, - 'rev_parent_id' => is_null( $this->mParentId ) + 'rev_parent_id' => $this->mParentId === null ? $this->getPreviousRevisionId( $dbw ) : $this->mParentId, - 'rev_sha1' => is_null( $this->mSha1 ) + 'rev_sha1' => $this->mSha1 === null ? Revision::base36Sha1( $this->mText ) : $this->mSha1, ); if ( $wgContentHandlerUseDB ) { //NOTE: Store null for the default model and format, to save space. - //XXX: Makes the DB sensitive to changed defaults. Make this behavior optional? Only in miser mode? + //XXX: Makes the DB sensitive to changed defaults. + // Make this behavior optional? Only in miser mode? $model = $this->getContentModel(); $format = $this->getContentFormat(); @@ -1377,7 +1411,8 @@ class Revision implements IDBAccessObject { if ( $title === null ) { wfProfileOut( __METHOD__ ); - throw new MWException( "Insufficient information to determine the title of the revision's page!" ); + throw new MWException( "Insufficient information to determine the title of the " + . "revision's page!" ); } $defaultModel = ContentHandler::getDefaultModelFor( $title ); @@ -1389,7 +1424,7 @@ class Revision implements IDBAccessObject { $dbw->insert( 'revision', $row, __METHOD__ ); - $this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId(); + $this->mId = $rev_id !== null ? $rev_id : $dbw->insertId(); wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) ); @@ -1413,7 +1448,8 @@ class Revision implements IDBAccessObject { } if ( !$wgContentHandlerUseDB && $title ) { - // if $wgContentHandlerUseDB is not set, all revisions must use the default content model and format. + // if $wgContentHandlerUseDB is not set, + // all revisions must use the default content model and format. $defaultModel = ContentHandler::getDefaultModelFor( $title ); $defaultHandler = ContentHandler::getForModelID( $defaultModel ); @@ -1422,15 +1458,17 @@ class Revision implements IDBAccessObject { if ( $this->getContentModel() != $defaultModel ) { $t = $title->getPrefixedDBkey(); - throw new MWException( "Can't save non-default content model with \$wgContentHandlerUseDB disabled: " - . "model is $model , default for $t is $defaultModel" ); + throw new MWException( "Can't save non-default content model with " + . "\$wgContentHandlerUseDB disabled: model is $model, " + . "default for $t is $defaultModel" ); } if ( $this->getContentFormat() != $defaultFormat ) { $t = $title->getPrefixedDBkey(); - throw new MWException( "Can't use non-default content format with \$wgContentHandlerUseDB disabled: " - . "format is $format, default for $t is $defaultFormat" ); + throw new MWException( "Can't use non-default content format with " + . "\$wgContentHandlerUseDB disabled: format is $format, " + . "default for $t is $defaultFormat" ); } } @@ -1445,8 +1483,8 @@ class Revision implements IDBAccessObject { /** * Get the base 36 SHA-1 value for a string of text - * @param $text String - * @return String + * @param string $text + * @return string */ public static function base36Sha1( $text ) { return wfBaseConvert( sha1( $text ), 16, 36, 31 ); @@ -1456,7 +1494,7 @@ class Revision implements IDBAccessObject { * Lazy-load the revision's text. * Currently hardcoded to the 'text' table storage engine. * - * @return String|bool the revision's text, or false on failure + * @return string|bool The revision's text, or false on failure */ protected function loadText() { wfProfileIn( __METHOD__ ); @@ -1475,7 +1513,7 @@ class Revision implements IDBAccessObject { } // If we kept data for lazy extraction, use it now... - if ( isset( $this->mTextRow ) ) { + if ( $this->mTextRow !== null ) { $row = $this->mTextRow; $this->mTextRow = null; } else { @@ -1530,13 +1568,14 @@ class Revision implements IDBAccessObject { * Such revisions can for instance identify page rename * operations and other such meta-modifications. * - * @param $dbw DatabaseBase - * @param $pageId Integer: ID number of the page to read from - * @param string $summary revision's summary - * @param $minor Boolean: whether the revision should be considered as minor - * @return Revision|null on error + * @param DatabaseBase $dbw + * @param int $pageId ID number of the page to read from + * @param string $summary Revision's summary + * @param bool $minor Whether the revision should be considered as minor + * @param User|null $user User object to use or null for $wgUser + * @return Revision|null Revision or null on error */ - public static function newNullRevision( $dbw, $pageId, $summary, $minor ) { + public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) { global $wgContentHandlerUseDB; wfProfileIn( __METHOD__ ); @@ -1559,8 +1598,15 @@ class Revision implements IDBAccessObject { __METHOD__ ); if ( $current ) { + if ( !$user ) { + global $wgUser; + $user = $wgUser; + } + $row = array( 'page' => $pageId, + 'user_text' => $user->getName(), + 'user' => $user->getId(), 'comment' => $summary, 'minor_edit' => $minor, 'text_id' => $current->rev_text_id, @@ -1588,11 +1634,11 @@ class Revision implements IDBAccessObject { * Determine if the current user is allowed to view a particular * field of this revision, if it's marked as deleted. * - * @param $field Integer:one of self::DELETED_TEXT, + * @param int $field One of self::DELETED_TEXT, * self::DELETED_COMMENT, * self::DELETED_USER - * @param $user User object to check, or null to use $wgUser - * @return Boolean + * @param User|null $user User object to check, or null to use $wgUser + * @return bool */ public function userCan( $field, User $user = null ) { return self::userCanBitfield( $this->mDeleted, $field, $user ); @@ -1603,28 +1649,44 @@ class Revision implements IDBAccessObject { * field of this revision, if it's marked as deleted. This is used * by various classes to avoid duplication. * - * @param $bitfield Integer: current field - * @param $field Integer: one of self::DELETED_TEXT = File::DELETED_FILE, + * @param int $bitfield Current field + * @param int $field One of self::DELETED_TEXT = File::DELETED_FILE, * self::DELETED_COMMENT = File::DELETED_COMMENT, * self::DELETED_USER = File::DELETED_USER - * @param $user User object to check, or null to use $wgUser - * @return Boolean - */ - public static function userCanBitfield( $bitfield, $field, User $user = null ) { + * @param User|null $user User object to check, or null to use $wgUser + * @param Title|null $title A Title object to check for per-page restrictions on, + * instead of just plain userrights + * @return bool + */ + public static function userCanBitfield( $bitfield, $field, User $user = null, + Title $title = null + ) { if ( $bitfield & $field ) { // aspect is deleted + if ( $user === null ) { + global $wgUser; + $user = $wgUser; + } if ( $bitfield & self::DELETED_RESTRICTED ) { - $permission = 'suppressrevision'; + $permissions = array( 'suppressrevision', 'viewsuppressed' ); } elseif ( $field & self::DELETED_TEXT ) { - $permission = 'deletedtext'; + $permissions = array( 'deletedtext' ); } else { - $permission = 'deletedhistory'; + $permissions = array( 'deletedhistory' ); } - wfDebug( "Checking for $permission due to $field match on $bitfield\n" ); - if ( $user === null ) { - global $wgUser; - $user = $wgUser; + $permissionlist = implode( ', ', $permissions ); + if ( $title === null ) { + wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" ); + return call_user_func_array( array( $user, 'isAllowedAny' ), $permissions ); + } else { + $text = $title->getPrefixedText(); + wfDebug( "Checking for $permissionlist on $text due to $field match on $bitfield\n" ); + foreach ( $permissions as $perm ) { + if ( $title->userCan( $perm, $user ) ) { + return true; + } + } + return false; } - return $user->isAllowed( $permission ); } else { return true; } @@ -1633,9 +1695,9 @@ class Revision implements IDBAccessObject { /** * Get rev_timestamp from rev_id, without loading the rest of the row * - * @param $title Title - * @param $id Integer - * @return String + * @param Title $title + * @param int $id + * @return string */ static function getTimestampFromId( $title, $id ) { $dbr = wfGetDB( DB_SLAVE ); @@ -1657,9 +1719,9 @@ class Revision implements IDBAccessObject { /** * Get count of revisions per page...not very efficient * - * @param $db DatabaseBase - * @param $id Integer: page id - * @return Integer + * @param DatabaseBase $db + * @param int $id Page id + * @return int */ static function countByPageId( $db, $id ) { $row = $db->selectRow( 'revision', array( 'revCount' => 'COUNT(*)' ), @@ -1673,9 +1735,9 @@ class Revision implements IDBAccessObject { /** * Get count of revisions per page...not very efficient * - * @param $db DatabaseBase - * @param $title Title - * @return Integer + * @param DatabaseBase $db + * @param Title $title + * @return int */ static function countByTitle( $db, $title ) { $id = $title->getArticleID(); @@ -1691,12 +1753,13 @@ class Revision implements IDBAccessObject { * 50 revisions for the sake of performance. * * @since 1.20 + * @deprecated since 1.24 * - * @param DatabaseBase|int $db the Database to perform the check on. May be given as a Database object or - * a database identifier usable with wfGetDB. - * @param int $pageId the ID of the page in question - * @param int $userId the ID of the user in question - * @param string $since look at edits since this time + * @param DatabaseBase|int $db The Database to perform the check on. May be given as a + * Database object or a database identifier usable with wfGetDB. + * @param int $pageId The ID of the page in question + * @param int $userId The ID of the user in question + * @param string $since Look at edits since this time * * @return bool True if the given user was the only one to edit since the given timestamp */ |