* addressed r53282#c3209 moved conditional inclusion of $wgExtensionMessages in mwScr...
[lhc/web/wiklou.git] / includes / LinkBatch.php
index c5c5721..d9a9666 100644 (file)
@@ -4,7 +4,7 @@
  * Class representing a list of titles
  * The execute() method checks them all for existence and adds them to a LinkCache object
  *
- * @addtogroup Cache
+ * @ingroup Cache
  */
 class LinkBatch {
        /**
@@ -18,7 +18,7 @@ class LinkBatch {
                }
        }
 
-       function addObj( $title ) {
+       public function addObj( $title ) {
                if ( is_object( $title ) ) {
                        $this->add( $title->getNamespace(), $title->getDBkey() );
                } else {
@@ -26,7 +26,7 @@ class LinkBatch {
                }
        }
 
-       function add( $ns, $dbkey ) {
+       public function add( $ns, $dbkey ) {
                if ( $ns < 0 ) {
                        return;
                }
@@ -41,21 +41,21 @@ class LinkBatch {
         * Set the link list to a given 2-d array
         * First key is the namespace, second is the DB key, value arbitrary
         */
-       function setArray( $array ) {
+       public function setArray( $array ) {
                $this->data = $array;
        }
 
        /**
         * Returns true if no pages have been added, false otherwise.
         */
-       function isEmpty() {
+       public function isEmpty() {
                return ($this->getSize() == 0);
        }
 
        /**
         * Returns the size of the batch.
         */
-       function getSize() {
+       public function getSize() {
                return count( $this->data );
        }
 
@@ -63,8 +63,8 @@ class LinkBatch {
         * Do the query and add the results to the LinkCache object
         * Return an array mapping PDBK to ID
         */
-        function execute() {
-               $linkCache =& LinkCache::singleton();
+        public function execute() {
+               $linkCache = LinkCache::singleton();
                return $this->executeInto( $linkCache );
         }
 
@@ -72,7 +72,7 @@ class LinkBatch {
         * Do the query and add the results to a given LinkCache object
         * Return an array mapping PDBK to ID
         */
-       function executeInto( &$cache ) {
+       protected function executeInto( &$cache ) {
                wfProfileIn( __METHOD__ );
                $res = $this->doQuery();
                $ids = $this->addResultToCache( $cache, $res );
@@ -81,9 +81,12 @@ class LinkBatch {
        }
 
        /**
-        * Add a ResultWrapper containing IDs and titles to a LinkCache object
+        * Add a ResultWrapper containing IDs and titles to a LinkCache object.
+        * As normal, titles will go into the static Title cache field.
+        * This function *also* stores extra fields of the title used for link
+        * parsing to avoid extra DB queries.
         */
-       function addResultToCache( $cache, $res ) {
+       public function addResultToCache( $cache, $res ) {
                if ( !$res ) {
                        return array();
                }
@@ -94,7 +97,7 @@ class LinkBatch {
                $remaining = $this->data;
                while ( $row = $res->fetchObject() ) {
                        $title = Title::makeTitle( $row->page_namespace, $row->page_title );
-                       $cache->addGoodLinkObj( $row->page_id, $title );
+                       $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect );
                        $ids[$title->getPrefixedDBkey()] = $row->page_id;
                        unset( $remaining[$row->page_namespace][$row->page_title] );
                }
@@ -113,7 +116,7 @@ class LinkBatch {
        /**
         * Perform the existence test query, return a ResultWrapper with page_id fields
         */
-       function doQuery() {
+       public function doQuery() {
                if ( $this->isEmpty() ) {
                        return false;
                }
@@ -128,10 +131,10 @@ class LinkBatch {
                        wfProfileOut( __METHOD__ );
                        return false;
                }
-               $sql = "SELECT page_id, page_namespace, page_title FROM $page WHERE $set";
+               $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect FROM $page WHERE $set";
 
                // Do query
-               $res = new ResultWrapper( $dbr,  $dbr->query( $sql, __METHOD__ ) );
+               $res = $dbr->query( $sql, __METHOD__ );
                wfProfileOut( __METHOD__ );
                return $res;
        }
@@ -143,7 +146,7 @@ class LinkBatch {
         * @return string
         * @public
         */
-       function constructSet( $prefix, &$db ) {
+       public function constructSet( $prefix, &$db ) {
                $first = true;
                $firstTitle = true;
                $sql = '';
@@ -157,7 +160,7 @@ class LinkBatch {
                        } else {
                                $sql .= ' OR ';
                        }
-                       
+
                        if (count($dbkeys)==1) { // avoid multiple-reference syntax if simple equality can be used
                                $singleKey = array_keys($dbkeys);
                                $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title=".
@@ -165,7 +168,7 @@ class LinkBatch {
                                        ")";
                        } else {
                                $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title IN (";
-                               
+
                                $firstTitle = true;
                                foreach( $dbkeys as $dbkey => $unused ) {
                                        if ( $firstTitle ) {
@@ -186,5 +189,3 @@ class LinkBatch {
                }
        }
 }
-
-