Add LinkCache::getSelectFields() and use it in a few places
authorKunal Mehta <legoktm@member.fsf.org>
Fri, 13 May 2016 07:00:39 +0000 (00:00 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Fri, 13 May 2016 07:25:07 +0000 (00:25 -0700)
Change-Id: Ic65b20cc2aa41f9b481e280918fe95c57da53221

includes/cache/LinkBatch.php
includes/cache/LinkCache.php
includes/parser/LinkHolderArray.php

index c5bd290..a7dd570 100644 (file)
@@ -179,8 +179,6 @@ class LinkBatch {
         * @return bool|ResultWrapper
         */
        public function doQuery() {
-               global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
-
                if ( $this->isEmpty() ) {
                        return false;
                }
@@ -188,15 +186,10 @@ class LinkBatch {
                // This is similar to LinkHolderArray::replaceInternal
                $dbr = wfGetDB( DB_SLAVE );
                $table = 'page';
-               $fields = [ 'page_id', 'page_namespace', 'page_title', 'page_len',
-                       'page_is_redirect', 'page_latest' ];
-
-               if ( $wgContentHandlerUseDB ) {
-                       $fields[] = 'page_content_model';
-               }
-               if ( $wgPageLanguageUseDB ) {
-                       $fields[] = 'page_lang';
-               }
+               $fields = array_merge(
+                       LinkCache::getSelectFields(),
+                       [ 'page_namespace', 'page_title' ]
+               );
 
                $conds = $this->constructSet( 'page', $dbr );
 
index 2c11247..de44f9b 100644 (file)
@@ -202,6 +202,26 @@ class LinkCache {
                return $this->addLinkObj( $nt );
        }
 
+       /**
+        * Fields that LinkCache needs to select
+        *
+        * @since 1.28
+        * @return array
+        */
+       public static function getSelectFields() {
+               global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
+
+               $fields = [ 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ];
+               if ( $wgContentHandlerUseDB ) {
+                       $fields[] = 'page_content_model';
+               }
+               if ( $wgPageLanguageUseDB ) {
+                       $fields[] = 'page_lang';
+               }
+
+               return $fields;
+       }
+
        /**
         * Add a title to the link cache, return the page_id or zero if non-existent
         *
@@ -209,8 +229,6 @@ class LinkCache {
         * @return int Page ID or zero
         */
        public function addLinkObj( LinkTarget $nt ) {
-               global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
-
                $key = $this->titleFormatter->getPrefixedDBkey( $nt );
                if ( $this->isBadLink( $key ) || $nt->isExternal() ) {
                        return 0;
@@ -227,15 +245,7 @@ class LinkCache {
                // Some fields heavily used for linking...
                $db = $this->mForUpdate ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
 
-               $fields = [ 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ];
-               if ( $wgContentHandlerUseDB ) {
-                       $fields[] = 'page_content_model';
-               }
-               if ( $wgPageLanguageUseDB ) {
-                       $fields[] = 'page_lang';
-               }
-
-               $row = $db->selectRow( 'page', $fields,
+               $row = $db->selectRow( 'page', self::getSelectFields(),
                        [ 'page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey() ],
                        __METHOD__
                );
index bd969a5..8575e69 100644 (file)
@@ -282,7 +282,7 @@ class LinkHolderArray {
                        return;
                }
 
-               global $wgContLang, $wgContentHandlerUseDB, $wgPageLanguageUseDB;
+               global $wgContLang;
 
                $colours = [];
                $linkCache = LinkCache::singleton();
@@ -333,15 +333,10 @@ class LinkHolderArray {
                        }
                }
                if ( !$lb->isEmpty() ) {
-                       $fields = [ 'page_id', 'page_namespace', 'page_title',
-                               'page_is_redirect', 'page_len', 'page_latest' ];
-
-                       if ( $wgContentHandlerUseDB ) {
-                               $fields[] = 'page_content_model';
-                       }
-                       if ( $wgPageLanguageUseDB ) {
-                               $fields[] = 'page_lang';
-                       }
+                       $fields = array_merge(
+                               LinkCache::getSelectFields(),
+                               [ 'page_namespace', 'page_title' ]
+                       );
 
                        $res = $dbr->select(
                                'page',
@@ -454,7 +449,7 @@ class LinkHolderArray {
         * @param array $colours
         */
        protected function doVariants( &$colours ) {
-               global $wgContLang, $wgContentHandlerUseDB, $wgPageLanguageUseDB;
+               global $wgContLang;
                $linkBatch = new LinkBatch();
                $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
                $output = $this->parent->getOutput();
@@ -540,15 +535,10 @@ class LinkHolderArray {
                if ( !$linkBatch->isEmpty() ) {
                        // construct query
                        $dbr = wfGetDB( DB_SLAVE );
-                       $fields = [ 'page_id', 'page_namespace', 'page_title',
-                               'page_is_redirect', 'page_len', 'page_latest' ];
-
-                       if ( $wgContentHandlerUseDB ) {
-                               $fields[] = 'page_content_model';
-                       }
-                       if ( $wgPageLanguageUseDB ) {
-                               $fields[] = 'page_lang';
-                       }
+                       $fields = array_merge(
+                               LinkCache::getSelectFields(),
+                               [ 'page_namespace', 'page_title' ]
+                       );
 
                        $varRes = $dbr->select( 'page',
                                $fields,