Commenting and doc fixes around the spam regexes
[lhc/web/wiklou.git] / includes / Revision.php
index 47626a2..c09af74 100644 (file)
@@ -867,24 +867,37 @@ class Revision implements IDBAccessObject {
        }
 
        /**
-        * @return Integer rcid of the unpatrolled row, zero if there isn't one
+        * @return integer rcid of the unpatrolled row, zero if there isn't one
         */
        public function isUnpatrolled() {
                if ( $this->mUnpatrolled !== null ) {
                        return $this->mUnpatrolled;
                }
+               $rc = $this->getRecentChange();
+               if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == 0 ) {
+                       $this->mUnpatrolled = $rc->getAttribute( 'rc_id' );
+               } else {
+                       $this->mUnpatrolled = 0;
+               }
+               return $this->mUnpatrolled;
+       }
+
+       /**
+        * Get the RC object belonging to the current revision, if there's one
+        *
+        * @since 1.22
+        * @return RecentChange|null
+        */
+       public function getRecentChange() {
                $dbr = wfGetDB( DB_SLAVE );
-               $this->mUnpatrolled = $dbr->selectField( 'recentchanges',
-                       'rc_id',
-                       array( // Add redundant user,timestamp condition so we can use the existing index
+               return RecentChange::newFromConds(
+                       array(
                                'rc_user_text' => $this->getRawUserText(),
                                'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
-                               'rc_this_oldid' => $this->getId(),
-                               'rc_patrolled' => 0
+                               'rc_this_oldid' => $this->getId()
                        ),
                        __METHOD__
                );
-               return (int)$this->mUnpatrolled;
        }
 
        /**
@@ -983,6 +996,10 @@ class Revision implements IDBAccessObject {
         * @return String
         */
        public function getSerializedData() {
+               if ( is_null( $this->mText ) ) {
+                       $this->mText = $this->loadText();
+               }
+
                return $this->mText;
        }
 
@@ -1192,35 +1209,7 @@ class Revision implements IDBAccessObject {
 
                // If the text was fetched without an error, convert it
                if ( $text !== false ) {
-                       if ( in_array( 'gzip', $flags ) ) {
-                               # Deal with optional compression of archived pages.
-                               # This can be done periodically via maintenance/compressOld.php, and
-                               # as pages are saved if $wgCompressRevisions is set.
-                               $text = gzinflate( $text );
-                       }
-
-                       if ( in_array( 'object', $flags ) ) {
-                               # Generic compressed storage
-                               $obj = unserialize( $text );
-                               if ( !is_object( $obj ) ) {
-                                       // Invalid object
-                                       wfProfileOut( __METHOD__ );
-                                       return false;
-                               }
-                               $text = $obj->getText();
-                       }
-
-                       global $wgLegacyEncoding;
-                       if ( $text !== false && $wgLegacyEncoding
-                               && !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
-                               #  conversion scripts 2008-12-30)
-                               global $wgContLang;
-                               $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
-                       }
+                       $text = self::decompressRevisionText( $text, $flags );
                }
                wfProfileOut( __METHOD__ );
                return $text;
@@ -1255,6 +1244,46 @@ class Revision implements IDBAccessObject {
                return implode( ',', $flags );
        }
 
+       /**
+        * 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
+        */
+       public static function decompressRevisionText( $text, $flags ) {
+               if ( in_array( 'gzip', $flags ) ) {
+                       # Deal with optional compression of archived pages.
+                       # This can be done periodically via maintenance/compressOld.php, and
+                       # as pages are saved if $wgCompressRevisions is set.
+                       $text = gzinflate( $text );
+               }
+
+               if ( in_array( 'object', $flags ) ) {
+                       # Generic compressed storage
+                       $obj = unserialize( $text );
+                       if ( !is_object( $obj ) ) {
+                               // Invalid object
+                               return false;
+                       }
+                       $text = $obj->getText();
+               }
+
+               global $wgLegacyEncoding;
+               if ( $text !== false && $wgLegacyEncoding
+                       && !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
+                       #  conversion scripts 2008-12-30)
+                       global $wgContLang;
+                       $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
+               }
+
+               return $text;
+       }
+
        /**
         * Insert a new revision into the database, returning the new revision ID
         * number on success and dies horribly on failure.