SECURITY: rate-limit and prevent blocked users from changing email
[lhc/web/wiklou.git] / includes / page / PageArchive.php
index af936cc..8b42020 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']
                );
        }
 
@@ -231,12 +219,14 @@ class PageArchive {
                }
 
                $dbr = wfGetDB( DB_REPLICA );
+               $fileQuery = ArchivedFile::getQueryInfo();
                return $dbr->select(
-                       'filearchive',
-                       ArchivedFile::selectFields(),
+                       $fileQuery['tables'],
+                       $fileQuery['fields'],
                        [ 'fa_name' => $this->title->getDBkey() ],
                        __METHOD__,
-                       [ 'ORDER BY' => 'fa_timestamp DESC' ]
+                       [ 'ORDER BY' => 'fa_timestamp DESC' ],
+                       $fileQuery['joins']
                );
        }
 
@@ -249,34 +239,11 @@ class PageArchive {
         */
        public function getRevision( $timestamp ) {
                $dbr = wfGetDB( DB_REPLICA );
-               $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin();
-
-               $tables = [ 'archive' ] + $commentQuery['tables'];
-
-               $fields = [
-                       'ar_rev_id',
-                       'ar_text',
-                       'ar_user',
-                       'ar_user_text',
-                       'ar_timestamp',
-                       'ar_minor_edit',
-                       'ar_flags',
-                       'ar_text_id',
-                       'ar_deleted',
-                       'ar_len',
-                       'ar_sha1',
-               ] + $commentQuery['fields'];
-
-               if ( $this->config->get( 'ContentHandlerUseDB' ) ) {
-                       $fields[] = 'ar_content_format';
-                       $fields[] = 'ar_content_model';
-               }
-
-               $join_conds = [] + $commentQuery['joins'];
+               $arQuery = Revision::getArchiveQueryInfo();
 
                $row = $dbr->selectRow(
-                       $tables,
-                       $fields,
+                       $arQuery['tables'],
+                       $arQuery['fields'],
                        [
                                'ar_namespace' => $this->title->getNamespace(),
                                'ar_title' => $this->title->getDBkey(),
@@ -284,7 +251,7 @@ class PageArchive {
                        ],
                        __METHOD__,
                        [],
-                       $join_conds
+                       $arQuery['joins']
                );
 
                if ( $row ) {
@@ -348,19 +315,13 @@ class PageArchive {
        }
 
        /**
-        * Get the text from an archive row containing ar_text, ar_flags and ar_text_id
+        * Get the text from an archive row containing ar_text_id
         *
+        * @deprecated since 1.31
         * @param object $row Database row
         * @return string
         */
        public function getTextFromRow( $row ) {
-               if ( is_null( $row->ar_text_id ) ) {
-                       // An old row from MediaWiki 1.4 or previous.
-                       // Text is embedded in this row in classic compression format.
-                       return Revision::getRevisionText( $row, 'ar_' );
-               }
-
-               // New-style: keyed to the text storage backend.
                $dbr = wfGetDB( DB_REPLICA );
                $text = $dbr->selectRow( 'text',
                        [ 'old_text', 'old_flags' ],
@@ -380,15 +341,18 @@ class PageArchive {
         */
        public function getLastRevisionText() {
                $dbr = wfGetDB( DB_REPLICA );
-               $row = $dbr->selectRow( 'archive',
-                       [ 'ar_text', 'ar_flags', 'ar_text_id' ],
+               $row = $dbr->selectRow(
+                       [ 'archive', 'text' ],
+                       [ 'old_text', 'old_flags' ],
                        [ 'ar_namespace' => $this->title->getNamespace(),
                                'ar_title' => $this->title->getDBkey() ],
                        __METHOD__,
-                       [ 'ORDER BY' => 'ar_timestamp DESC' ] );
+                       [ 'ORDER BY' => 'ar_timestamp DESC, ar_id DESC' ],
+                       [ 'text' => [ 'JOIN', 'old_id = ar_text_id' ] ]
+               );
 
                if ( $row ) {
-                       return $this->getTextFromRow( $row );
+                       return Revision::getRevisionText( $row );
                }
 
                return null;
@@ -563,47 +527,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();
@@ -785,7 +725,9 @@ class PageArchive {
                        Hooks::run( 'ArticleUndelete',
                                [ &$this->title, $created, $comment, $oldPageId, $restoredPages ] );
                        if ( $this->title->getNamespace() == NS_FILE ) {
-                               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->title, 'imagelinks' ) );
+                               DeferredUpdates::addUpdate(
+                                       new HTMLCacheUpdate( $this->title, 'imagelinks', 'file-restore' )
+                               );
                        }
                }