Pass $key into CommentStore methods and use MediawikiServices
[lhc/web/wiklou.git] / includes / Storage / RevisionStore.php
index 6c8cac9..b358631 100644 (file)
@@ -190,7 +190,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
 
                // rev_id is defined as NOT NULL, but this revision may not yet have been inserted.
                if ( !$title && $revId !== null && $revId > 0 ) {
-                       $dbr = $this->getDbConnectionRef( $dbMode );
+                       $dbr = $this->getDBConnectionRef( $dbMode );
                        // @todo: Title::getSelectFields(), or Title::getQueryInfo(), or something like that
                        $row = $dbr->selectRow(
                                [ 'revision', 'page' ],
@@ -360,7 +360,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                }
 
                list( $commentFields, $commentCallback ) =
-                       CommentStore::newKey( 'rev_comment' )->insertWithTempTable( $dbw, $comment );
+                       CommentStore::getStore()->insertWithTempTable( $dbw, 'rev_comment', $comment );
                $row += $commentFields;
 
                if ( $this->contentHandlerUseDB ) {
@@ -689,7 +689,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
 
                $content = null;
                $blobData = null;
-               $blobFlags = '';
+               $blobFlags = null;
 
                if ( is_object( $row ) ) {
                        // archive row
@@ -706,7 +706,11 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                        if ( isset( $row->old_text ) ) {
                                // this happens when the text-table gets joined directly, in the pre-1.30 schema
                                $blobData = isset( $row->old_text ) ? strval( $row->old_text ) : null;
-                               $blobFlags = isset( $row->old_flags ) ? strval( $row->old_flags ) : '';
+                               // Check against selects that might have not included old_flags
+                               if ( !property_exists( $row, 'old_flags' ) ) {
+                                       throw new InvalidArgumentException( 'old_flags was not set in $row' );
+                               }
+                               $blobFlags = ( $row->old_flags === null ) ? '' : $row->old_flags;
                        }
 
                        $mainSlotRow->slot_revision = intval( $row->rev_id );
@@ -735,7 +739,9 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                        $mainSlotRow->format_name = isset( $row['content_format'] )
                                ? strval( $row['content_format'] ) : null;
                        $blobData = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null;
-                       $blobFlags = isset( $row['flags'] ) ? trim( strval( $row['flags'] ) ) : '';
+                       // XXX: If the flags field is not set then $blobFlags should be null so that no
+                       // decoding will happen. An empty string will result in default decodings.
+                       $blobFlags = isset( $row['flags'] ) ? trim( strval( $row['flags'] ) ) : null;
 
                        // if we have a Content object, override mText and mContentModel
                        if ( !empty( $row['content'] ) ) {
@@ -797,7 +803,9 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         *
         * @param SlotRecord $slot The SlotRecord to load content for
         * @param string|null $blobData The content blob, in the form indicated by $blobFlags
-        * @param string $blobFlags Flags indicating how $blobData needs to be processed
+        * @param string|null $blobFlags Flags indicating how $blobData needs to be processed.
+        *        Use null if no processing should happen. That is in constrast to the empty string,
+        *        which causes the blob to be decoded according to the configured legacy encoding.
         * @param string|null $blobFormat MIME type indicating how $dataBlob is encoded
         * @param int $queryFlags
         *
@@ -807,23 +815,28 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
        private function loadSlotContent(
                SlotRecord $slot,
                $blobData = null,
-               $blobFlags = '',
+               $blobFlags = null,
                $blobFormat = null,
                $queryFlags = 0
        ) {
                if ( $blobData !== null ) {
                        Assert::parameterType( 'string', $blobData, '$blobData' );
-                       Assert::parameterType( 'string', $blobFlags, '$blobFlags' );
+                       Assert::parameterType( 'string|null', $blobFlags, '$blobFlags' );
 
                        $cacheKey = $slot->hasAddress() ? $slot->getAddress() : null;
 
-                       $data = $this->blobStore->expandBlob( $blobData, $blobFlags, $cacheKey );
-
-                       if ( $data === false ) {
-                               throw new RevisionAccessException(
-                                       "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
-                               );
+                       if ( $blobFlags === null ) {
+                               // No blob flags, so use the blob verbatim.
+                               $data = $blobData;
+                       } else {
+                               $data = $this->blobStore->expandBlob( $blobData, $blobFlags, $cacheKey );
+                               if ( $data === false ) {
+                                       throw new RevisionAccessException(
+                                               "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
+                                       );
+                               }
                        }
+
                } else {
                        $address = $slot->getAddress();
                        try {
@@ -1023,9 +1036,9 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
 
                $user = $this->getUserIdentityFromRowObject( $row, 'ar_' );
 
-               $comment = CommentStore::newKey( 'ar_comment' )
+               $comment = CommentStore::getStore()
                        // Legacy because $row may have come from self::selectFields()
-                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), $row, true );
+                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), 'ar_comment', $row, true );
 
                $mainSlot = $this->emulateMainSlot_1_29( $row, $queryFlags, $title );
                $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
@@ -1093,9 +1106,9 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
 
                $user = $this->getUserIdentityFromRowObject( $row );
 
-               $comment = CommentStore::newKey( 'rev_comment' )
+               $comment = CommentStore::getStore()
                        // Legacy because $row may have come from self::selectFields()
-                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), $row, true );
+                       ->getCommentLegacy( $this->getDBConnection( DB_REPLICA ), 'rev_comment', $row, true );
 
                $mainSlot = $this->emulateMainSlot_1_29( $row, $queryFlags, $title );
                $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
@@ -1568,7 +1581,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
                        'rev_sha1',
                ] );
 
-               $commentQuery = CommentStore::newKey( 'rev_comment' )->getJoin();
+               $commentQuery = CommentStore::getStore()->getJoin( 'rev_comment' );
                $ret['tables'] = array_merge( $ret['tables'], $commentQuery['tables'] );
                $ret['fields'] = array_merge( $ret['fields'], $commentQuery['fields'] );
                $ret['joins'] = array_merge( $ret['joins'], $commentQuery['joins'] );
@@ -1625,7 +1638,7 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         *   - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
         */
        public function getArchiveQueryInfo() {
-               $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin();
+               $commentQuery = CommentStore::getStore()->getJoin( 'ar_comment' );
                $ret = [
                        'tables' => [ 'archive' ] + $commentQuery['tables'],
                        'fields' => [