Truncate null revision comment for whole multibyte characters
[lhc/web/wiklou.git] / includes / Revision.php
index 6ec7eaf..327ff45 100644 (file)
@@ -121,7 +121,9 @@ class Revision implements IDBAccessObject {
                if ( $id ) {
                        // Use the specified ID
                        $conds['rev_id'] = $id;
-                       return self::newFromConds( $conds, (int)$flags );
+                       // This uses slave->master fallback with READ_NORMAL. Assuming revdelete,
+                       // moves, and merges are rare, callers can use this to reduce master queries.
+                       return self::newFromConds( $conds, $flags );
                } else {
                        // Use a join to get the latest revision
                        $conds[] = 'rev_id=page_latest';
@@ -148,11 +150,15 @@ class Revision implements IDBAccessObject {
                $conds = array( 'page_id' => $pageId );
                if ( $revId ) {
                        $conds['rev_id'] = $revId;
+                       // This uses slave->master fallback with READ_NORMAL. Assuming revdelete
+                       // and merges are rare, callers can use this to reduce master queries.
+                       return self::newFromConds( $conds, $flags );
                } else {
                        // Use a join to get the latest revision
                        $conds[] = 'rev_id = page_latest';
+                       $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
+                       return self::loadFromConds( $db, $conds, $flags );
                }
-               return self::newFromConds( $conds, (int)$flags );
        }
 
        /**
@@ -826,9 +832,11 @@ class Revision implements IDBAccessObject {
         * Fetch revision's user id without regard for the current user's permissions
         *
         * @return string
+        * @deprecated since 1.25, use getUser( Revision::RAW )
         */
        public function getRawUser() {
-               return $this->mUser;
+               wfDeprecated( __METHOD__, '1.25' );
+               return $this->getUser( self::RAW );
        }
 
        /**
@@ -850,7 +858,15 @@ class Revision implements IDBAccessObject {
                } elseif ( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER, $user ) ) {
                        return '';
                } else {
-                       return $this->getRawUserText();
+                       if ( $this->mUserText === null ) {
+                               $this->mUserText = User::whoIs( $this->mUser ); // load on demand
+                               if ( $this->mUserText === false ) {
+                                       # This shouldn't happen, but it can if the wiki was recovered
+                                       # via importing revs and there is no user table entry yet.
+                                       $this->mUserText = $this->mOrigUserText;
+                               }
+                       }
+                       return $this->mUserText;
                }
        }
 
@@ -858,17 +874,11 @@ class Revision implements IDBAccessObject {
         * Fetch revision's username without regard for view restrictions
         *
         * @return string
+        * @deprecated since 1.25, use getUserText( Revision::RAW )
         */
        public function getRawUserText() {
-               if ( $this->mUserText === null ) {
-                       $this->mUserText = User::whoIs( $this->mUser ); // load on demand
-                       if ( $this->mUserText === false ) {
-                               # This shouldn't happen, but it can if the wiki was recovered
-                               # via importing revs and there is no user table entry yet.
-                               $this->mUserText = $this->mOrigUserText;
-                       }
-               }
-               return $this->mUserText;
+               wfDeprecated( __METHOD__, '1.25' );
+               return $this->getUserText( self::RAW );
        }
 
        /**
@@ -898,9 +908,11 @@ class Revision implements IDBAccessObject {
         * Fetch revision comment without regard for the current user's permissions
         *
         * @return string
+        * @deprecated since 1.25, use getComment( Revision::RAW )
         */
        public function getRawComment() {
-               return $this->mComment;
+               wfDeprecated( __METHOD__, '1.25' );
+               return $this->getComment( self::RAW );
        }
 
        /**
@@ -936,7 +948,7 @@ class Revision implements IDBAccessObject {
                $dbr = wfGetDB( DB_SLAVE );
                return RecentChange::newFromConds(
                        array(
-                               'rc_user_text' => $this->getRawUserText(),
+                               'rc_user_text' => $this->getUserText( Revision::RAW ),
                                'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
                                'rc_this_oldid' => $this->getId()
                        ),
@@ -1325,7 +1337,6 @@ class Revision implements IDBAccessObject {
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
 
-
                $this->checkContentModel();
 
                $data = $this->mText;
@@ -1536,7 +1547,6 @@ class Revision implements IDBAccessObject {
                        $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
                }
 
-
                return $text;
        }
 
@@ -1556,8 +1566,7 @@ class Revision implements IDBAccessObject {
         * @return Revision|null Revision or null on error
         */
        public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
-               global $wgContentHandlerUseDB;
-
+               global $wgContentHandlerUseDB, $wgContLang;
 
                $fields = array( 'page_latest', 'page_namespace', 'page_title',
                                                'rev_text_id', 'rev_len', 'rev_sha1' );
@@ -1582,6 +1591,9 @@ class Revision implements IDBAccessObject {
                                $user = $wgUser;
                        }
 
+                       // Truncate for whole multibyte characters
+                       $summary = $wgContLang->truncate( $summary, 255 );
+
                        $row = array(
                                'page'       => $pageId,
                                'user_text'  => $user->getName(),