Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / specialpage / QueryPage.php
index 1beac43..3592500 100644 (file)
@@ -376,7 +376,7 @@ abstract class QueryPage extends SpecialPage {
         * @return IDatabase
         */
        function getRecacheDB() {
-               return wfGetDB( DB_SLAVE, [ $this->getName(), 'QueryPage::recache', 'vslow' ] );
+               return wfGetDB( DB_REPLICA, [ $this->getName(), 'QueryPage::recache', 'vslow' ] );
        }
 
        /**
@@ -453,7 +453,7 @@ abstract class QueryPage extends SpecialPage {
         * @since 1.18
         */
        public function fetchFromCache( $limit, $offset = false ) {
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
                $options = [];
                if ( $limit !== false ) {
                        $options['LIMIT'] = intval( $limit );
@@ -477,7 +477,7 @@ abstract class QueryPage extends SpecialPage {
 
        public function getCachedTimestamp() {
                if ( is_null( $this->cachedTimestamp ) ) {
-                       $dbr = wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_REPLICA );
                        $fname = get_class( $this ) . '::getCachedTimestamp';
                        $this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp',
                                [ 'qci_type' => $this->getName() ], $fname );
@@ -825,4 +825,28 @@ abstract class QueryPage extends SpecialPage {
        function feedUrl() {
                return $this->getPageTitle()->getFullURL();
        }
+
+       /**
+        * Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include
+        * title and optional the namespace field) and executes the batch. This operation will pre-cache
+        * LinkCache information like page existence and information for stub color and redirect hints.
+        *
+        * @param ResultWrapper $res The ResultWrapper object to process. Needs to include the title
+        *  field and namespace field, if the $ns parameter isn't set.
+        * @param null $ns Use this namespace for the given titles in the ResultWrapper object,
+        *  instead of the namespace value of $res.
+        */
+       protected function executeLBFromResultWrapper( ResultWrapper $res, $ns = null ) {
+               if ( !$res->numRows() ) {
+                       return;
+               }
+
+               $batch = new LinkBatch;
+               foreach ( $res as $row ) {
+                       $batch->add( $ns !== null ? $ns : $row->namespace, $row->title );
+               }
+               $batch->execute();
+
+               $res->seek( 0 );
+       }
 }