Merge "Change php extract() to explicit code"
[lhc/web/wiklou.git] / includes / page / PageArchive.php
index c03d6b2..0ef038f 100644 (file)
@@ -176,44 +176,32 @@ class PageArchive {
         * @return ResultWrapper
         */
        public function listRevisions() {
-               $dbr = wfGetDB( DB_REPLICA );
-               $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin();
-
-               $tables = [ 'archive' ] + $commentQuery['tables'];
-
-               $fields = [
-                       'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text',
-                       'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1',
-                       'ar_page_id'
-               ] + $commentQuery['fields'];
-
-               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
-                       $fields[] = 'ar_content_format';
-                       $fields[] = 'ar_content_model';
-               }
-
-               $conds = [ 'ar_namespace' => $this->title->getNamespace(),
-                       'ar_title' => $this->title->getDBkey() ];
+               $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
+               $queryInfo = $revisionStore->getArchiveQueryInfo();
 
+               $conds = [
+                       'ar_namespace' => $this->title->getNamespace(),
+                       'ar_title' => $this->title->getDBkey(),
+               ];
                $options = [ 'ORDER BY' => 'ar_timestamp DESC' ];
 
-               $join_conds = [] + $commentQuery['joins'];
-
                ChangeTags::modifyDisplayQuery(
-                       $tables,
-                       $fields,
+                       $queryInfo['tables'],
+                       $queryInfo['fields'],
                        $conds,
-                       $join_conds,
+                       $queryInfo['joins'],
                        $options,
                        ''
                );
 
-               return $dbr->select( $tables,
-                       $fields,
+               $dbr = wfGetDB( DB_REPLICA );
+               return $dbr->select(
+                       $queryInfo['tables'],
+                       $queryInfo['fields'],
                        $conds,
                        __METHOD__,
                        $options,
-                       $join_conds
+                       $queryInfo['joins']
                );
        }
 
@@ -267,7 +255,11 @@ class PageArchive {
                );
 
                if ( $row ) {
-                       return Revision::newFromArchiveRow( $row, [ 'title' => $this->title ] );
+                       return Revision::newFromArchiveRow(
+                               $row,
+                               [ 'title' => $this->title ],
+                               $this->title
+                       );
                }
 
                return null;
@@ -542,47 +534,23 @@ class PageArchive {
                        $oldWhere['ar_timestamp'] = array_map( [ &$dbw, 'timestamp' ], $timestamps );
                }
 
-               $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin();
-
-               $tables = [ 'archive', 'revision' ] + $commentQuery['tables'];
-
-               $fields = [
-                       'ar_id',
-                       'ar_rev_id',
-                       'rev_id',
-                       'ar_text',
-                       'ar_user',
-                       'ar_user_text',
-                       'ar_timestamp',
-                       'ar_minor_edit',
-                       'ar_flags',
-                       'ar_text_id',
-                       'ar_deleted',
-                       'ar_page_id',
-                       'ar_len',
-                       'ar_sha1'
-               ] + $commentQuery['fields'];
-
-               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
-                       $fields[] = 'ar_content_format';
-                       $fields[] = 'ar_content_model';
-               }
-
-               $join_conds = [
-                       'revision' => [ 'LEFT JOIN', 'ar_rev_id=rev_id' ],
-               ] + $commentQuery['joins'];
+               $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
+               $queryInfo = $revisionStore->getArchiveQueryInfo();
+               $queryInfo['tables'][] = 'revision';
+               $queryInfo['fields'][] = 'rev_id';
+               $queryInfo['joins']['revision'] = [ 'LEFT JOIN', 'ar_rev_id=rev_id' ];
 
                /**
                 * Select each archived revision...
                 */
                $result = $dbw->select(
-                       $tables,
-                       $fields,
+                       $queryInfo['tables'],
+                       $queryInfo['fields'],
                        $oldWhere,
                        __METHOD__,
                        /* options */
                        [ 'ORDER BY' => 'ar_timestamp' ],
-                       $join_conds
+                       $queryInfo['joins']
                );
 
                $rev_count = $result->numRows();
@@ -640,10 +608,12 @@ class PageArchive {
                        $oldPageId = (int)$latestRestorableRow->ar_page_id; // pass this to ArticleUndelete hook
 
                        // grab the content to check consistency with global state before restoring the page.
-                       $revision = Revision::newFromArchiveRow( $latestRestorableRow,
+                       $revision = Revision::newFromArchiveRow(
+                               $latestRestorableRow,
                                [
                                        'title' => $article->getTitle(), // used to derive default content model
-                               ]
+                               ],
+                               $article->getTitle()
                        );
                        $user = User::newFromName( $revision->getUserText( Revision::RAW ), false );
                        $content = $revision->getContent( Revision::RAW );
@@ -706,12 +676,15 @@ class PageArchive {
                                }
                                // Insert one revision at a time...maintaining deletion status
                                // unless we are specifically removing all restrictions...
-                               $revision = Revision::newFromArchiveRow( $row,
+                               $revision = Revision::newFromArchiveRow(
+                                       $row,
                                        [
                                                'page' => $pageId,
                                                'title' => $this->title,
                                                'deleted' => $unsuppress ? 0 : $row->ar_deleted
-                                       ] );
+                                       ],
+                                       $this->title
+                               );
 
                                // This will also copy the revision to ip_changes if it was an IP edit.
                                $revision->insertOn( $dbw );