Revision: test and fix __construct exceptions
[lhc/web/wiklou.git] / includes / Revision.php
index 99d15a7..8855441 100644 (file)
@@ -362,7 +362,7 @@ class Revision implements IDBAccessObject {
                $row = self::fetchFromConds( $db, $conditions, $flags );
                if ( $row ) {
                        $rev = new Revision( $row );
-                       $rev->mWiki = $db->getWikiID();
+                       $rev->mWiki = $db->getDomainID();
 
                        return $rev;
                }
@@ -645,6 +645,10 @@ class Revision implements IDBAccessObject {
 
                        # if we have a content object, use it to set the model and type
                        if ( !empty( $row['content'] ) ) {
+                               if ( !( $row['content'] instanceof Content ) ) {
+                                       throw new MWException( '`content` field must contain a Content object.' );
+                               }
+
                                // @todo when is that set? test with external store setup! check out insertOn() [dk]
                                if ( !empty( $row['text_id'] ) ) {
                                        throw new MWException( "Text already stored in external store (id {$row['text_id']}), " .
@@ -685,10 +689,6 @@ class Revision implements IDBAccessObject {
 
                        // if we have a Content object, override mText and mContentModel
                        if ( !empty( $row['content'] ) ) {
-                               if ( !( $row['content'] instanceof Content ) ) {
-                                       throw new MWException( '`content` field must contain a Content object.' );
-                               }
-
                                $handler = $this->getContentHandler();
                                $this->mContent = $row['content'];
 
@@ -1401,7 +1401,7 @@ class Revision implements IDBAccessObject {
         *
         * @param IDatabase $dbw (master connection)
         * @throws MWException
-        * @return int
+        * @return int The revision ID
         */
        public function insertOn( $dbw ) {
                global $wgDefaultExternalStore, $wgContentHandlerUseDB;
@@ -1518,6 +1518,16 @@ class Revision implements IDBAccessObject {
                        );
                }
 
+               // Insert IP revision into ip_changes for use when querying for a range.
+               if ( $this->mUser === 0 && IP::isValid( $this->mUserText ) ) {
+                       $ipcRow = [
+                               'ipc_rev_id'        => $this->mId,
+                               'ipc_rev_timestamp' => $row['rev_timestamp'],
+                               'ipc_hex'           => IP::toHex( $row['rev_user_text'] ),
+                       ];
+                       $dbw->insert( 'ip_changes', $ipcRow, __METHOD__ );
+               }
+
                // Avoid PHP 7.1 warning of passing $this by reference
                $revision = $this;
                Hooks::run( 'RevisionInsertComplete', [ &$revision, $data, $flags ] );
@@ -1703,7 +1713,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, $wgContLang;
+               global $wgContentHandlerUseDB;
 
                $fields = [ 'page_latest', 'page_namespace', 'page_title',
                                                'rev_text_id', 'rev_len', 'rev_sha1' ];
@@ -1730,9 +1740,6 @@ class Revision implements IDBAccessObject {
                                $user = $wgUser;
                        }
 
-                       // Truncate for whole multibyte characters
-                       $summary = $wgContLang->truncate( $summary, 255 );
-
                        $row = [
                                'page'       => $pageId,
                                'user_text'  => $user->getName(),
@@ -1934,7 +1941,7 @@ class Revision implements IDBAccessObject {
                $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
                return $cache->getWithSetCallback(
                        // Page/rev IDs passed in from DB to reflect history merges
-                       $cache->makeGlobalKey( 'revision', $db->getWikiID(), $pageId, $revId ),
+                       $cache->makeGlobalKey( 'revision', $db->getDomainID(), $pageId, $revId ),
                        $cache::TTL_WEEK,
                        function ( $curValue, &$ttl, array &$setOpts ) use ( $db, $pageId, $revId ) {
                                $setOpts += Database::getCacheSetOptions( $db );