re bug #25523: add mime.info and mime.types for *.dwg files so that when people add...
[lhc/web/wiklou.git] / includes / LinkBatch.php
index 7df39e2..9486815 100644 (file)
@@ -12,12 +12,30 @@ class LinkBatch {
         */
        var $data = array();
 
+       /**
+        * For debugging which method is using this class.
+        */
+       protected $caller;
+
        function __construct( $arr = array() ) {
                foreach( $arr as $item ) {
                        $this->addObj( $item );
                }
        }
 
+       /**
+        * Use ->setCaller( __METHOD__ ) to indicate which code is using this
+        * class. Only used in debugging output.
+        * @since 1.17
+        */
+       public function setCaller( $caller ) {
+               $this->caller = $caller;
+       }
+
+       /**
+        * @param  $title Title
+        * @return void
+        */
        public function addObj( $title ) {
                if ( is_object( $title ) ) {
                        $this->add( $title->getNamespace(), $title->getDBkey() );
@@ -76,6 +94,7 @@ class LinkBatch {
                wfProfileIn( __METHOD__ );
                $res = $this->doQuery();
                $ids = $this->addResultToCache( $cache, $res );
+               $this->doGenderQuery();
                wfProfileOut( __METHOD__ );
                return $ids;
        }
@@ -95,7 +114,7 @@ class LinkBatch {
 
                $ids = array();
                $remaining = $this->data;
-               while ( $row = $res->fetchObject() ) {
+               foreach ( $res as $row ) {
                        $title = Title::makeTitle( $row->page_namespace, $row->page_title );
                        $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest );
                        $ids[$title->getPrefixedDBkey()] = $row->page_id;
@@ -122,23 +141,37 @@ class LinkBatch {
                }
                wfProfileIn( __METHOD__ );
 
-               // Construct query
-               // This is very similar to Parser::replaceLinkHolders
+               // This is similar to LinkHolderArray::replaceInternal
                $dbr = wfGetDB( DB_SLAVE );
-               $page = $dbr->tableName( 'page' );
-               $set = $this->constructSet( 'page', $dbr );
-               if ( $set === false ) {
-                       wfProfileOut( __METHOD__ );
-                       return false;
-               }
-               $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect, page_latest FROM $page WHERE $set";
+               $table = 'page';
+               $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len',
+                       'page_is_redirect', 'page_latest' );
+               $conds = $this->constructSet( 'page', $dbr );
 
                // Do query
-               $res = $dbr->query( $sql, __METHOD__ );
+               $caller = __METHOD__;
+               if ( strval( $this->caller ) !== '' ) {
+                       $caller .= " (for {$this->caller})";
+               }
+               $res = $dbr->select( $table, $fields, $conds, $caller );
                wfProfileOut( __METHOD__ );
                return $res;
        }
 
+       public function doGenderQuery() {
+               if ( $this->isEmpty() ) {
+                       return false;
+               }
+
+               global $wgContLang;
+               if ( !$wgContLang->needsGenderDistinction() ) {
+                       return false;
+               }
+
+               $genderCache = GenderCache::singleton();
+               $genderCache->dolinkBatch( $this->data, $this->caller );
+       }
+
        /**
         * Construct a WHERE clause which will match all the given titles.
         *
@@ -147,6 +180,6 @@ class LinkBatch {
         * @return mixed string with SQL where clause fragment, or false if no items.
         */
        public function constructSet( $prefix, $db ) {
-           return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
+               return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
        }
 }