(Bug 15936) New page's patrol button should always be visible
[lhc/web/wiklou.git] / includes / Revision.php
index a6147ba..458b312 100644 (file)
@@ -363,6 +363,7 @@ class Revision {
                } else {
                        throw new MWException( 'Revision constructor passed invalid row format.' );
                }
+               $this->mUnpatrolled = NULL;
        }
 
        /**#@+
@@ -536,6 +537,27 @@ class Revision {
        public function isMinor() {
                return (bool)$this->mMinorEdit;
        }
+       
+       /**
+        * @return int rcid of the unpatrolled row, zero if there isn't one
+        */
+       public function isUnpatrolled() {
+               if( $this->mUnpatrolled !== NULL ) {
+                       return $this->mUnpatrolled;
+               }
+               $dbr = wfGetDB( DB_SLAVE );
+               $this->mUnpatrolled = $dbr->selectField( 'recentchanges',
+                       'rc_id',
+                       array( // Add redundant user,timestamp condition so we can use the existing index
+                               'rc_user_text'  => $this->getRawUserText(),
+                               'rc_timestamp'  => $dbr->timestamp( $this->getTimestamp() ),
+                               'rc_this_oldid' => $this->getId(),
+                               'rc_patrolled'  => 0
+                       ),
+                       __METHOD__
+               );
+               return (int)$this->mUnpatrolled;
+       }
 
        /**
         * int $field one of DELETED_* bitfield constants
@@ -720,9 +742,11 @@ class Revision {
                        }
 
                        global $wgLegacyEncoding;
-                       if( $wgLegacyEncoding && !in_array( 'utf-8', $flags ) ) {
+                       if( $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 $wgInputEncoding, $wgContLang;
                                $text = $wgContLang->iconv( $wgLegacyEncoding, $wgInputEncoding, $text );
                        }
@@ -817,7 +841,8 @@ class Revision {
                                'rev_timestamp'  => $dbw->timestamp( $this->mTimestamp ),
                                'rev_deleted'    => $this->mDeleted,
                                'rev_len'            => $this->mSize,
-                               'rev_parent_id'  => $this->mParentId ? $this->mParentId : $this->getPreviousRevisionId( $dbw )
+                               'rev_parent_id'  => is_null($this->mParentId) ?
+                                       $this->getPreviousRevisionId( $dbw ) : $this->mParentId
                        ), __METHOD__
                );
 
@@ -959,6 +984,10 @@ class Revision {
         */
        static function getTimestampFromId( $title, $id ) {
                $dbr = wfGetDB( DB_SLAVE );
+               // Casting fix for DB2
+               if ($id == '') {
+                       $id = 0;
+               }
                $conds = array( 'rev_id' => $id );
                $conds['rev_page'] = $title->getArticleId();
                $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );