X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FRevision.php;h=5f62e4d56ff7519b6fbe3c9a7959d9ffa9e149e1;hb=6b9ae314fd0e205a1fc1d6a52f962f68b6fb3680;hp=d556edc30264c97aab21ce80b88c53fdbe210bff;hpb=b394616ebd372b56d6b1ad890c5b2b216989d90f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Revision.php b/includes/Revision.php index d556edc302..5f62e4d56f 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -52,7 +52,7 @@ class Revision implements IDBAccessObject { protected $mContentFormat; /** - * @var Content + * @var Content|null|bool */ protected $mContent; @@ -124,7 +124,7 @@ class Revision implements IDBAccessObject { * Returns null if no such revision can be found. * * $flags include: - * Revision::READ_LATEST : Select the data from the master + * 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 @@ -493,13 +493,13 @@ class Revision implements IDBAccessObject { $this->mTimestamp = $row->rev_timestamp; $this->mDeleted = intval( $row->rev_deleted ); - if( !isset( $row->rev_parent_id ) ) { - $this->mParentId = is_null( $row->rev_parent_id ) ? null : 0; + if ( !isset( $row->rev_parent_id ) ) { + $this->mParentId = null; } else { $this->mParentId = intval( $row->rev_parent_id ); } - if( !isset( $row->rev_len ) || is_null( $row->rev_len ) ) { + if ( !isset( $row->rev_len ) ) { $this->mSize = null; } else { $this->mSize = intval( $row->rev_len ); @@ -982,27 +982,34 @@ class Revision implements IDBAccessObject { } /** - * Gets the content object for the revision + * Gets the content object for the revision (or null on failure). + * + * Note that for mutable Content objects, each call to this method will return a + * fresh clone. * * @since 1.21 - * @return Content + * @return Content|null the Revision's content, or null on failure. */ protected function getContentInternal() { if( is_null( $this->mContent ) ) { // Revision is immutable. Load on demand: - - $handler = $this->getContentHandler(); - $format = $this->getContentFormat(); - if( is_null( $this->mText ) ) { - // Load text on demand: $this->mText = $this->loadText(); } - $this->mContent = is_null( $this->mText ) ? null : $handler->unserializeContent( $this->mText, $format ); + if ( $this->mText !== null && $this->mText !== false ) { + // Unserialize content + $handler = $this->getContentHandler(); + $format = $this->getContentFormat(); + + $this->mContent = $handler->unserializeContent( $this->mText, $format ); + } else { + $this->mContent = false; // negative caching! + } } - return $this->mContent->copy(); // NOTE: copy() will return $this for immutable content objects + // NOTE: copy() will return $this for immutable content objects + return $this->mContent ? $this->mContent->copy() : null; } /** @@ -1141,9 +1148,13 @@ class Revision implements IDBAccessObject { * * @param $row Object: the text data * @param $prefix String: table prefix (default 'old_') + * @param $wiki String|false: 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_' ) { + public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) { wfProfileIn( __METHOD__ ); # Get data @@ -1171,7 +1182,7 @@ class Revision implements IDBAccessObject { wfProfileOut( __METHOD__ ); return false; } - $text = ExternalStore::fetchFromURL( $url ); + $text = ExternalStore::fetchFromURL( $url, array( 'wiki' => $wiki ) ); } // If the text was fetched without an error, convert it @@ -1377,7 +1388,7 @@ class Revision implements IDBAccessObject { $content = $this->getContent( Revision::RAW ); - if ( !$content->isValid() ) { + if ( !$content || !$content->isValid() ) { $t = $title->getPrefixedDBkey(); throw new MWException( "Content of $t is not valid! Content model is $model" ); @@ -1397,7 +1408,7 @@ class Revision implements IDBAccessObject { * Lazy-load the revision's text. * Currently hardcoded to the 'text' table storage engine. * - * @return String + * @return String|bool the revision's text, or false on failure */ protected function loadText() { wfProfileIn( __METHOD__ );