Drop some useless parameters to silly methods on the pretty much broken MediaWiki...
[lhc/web/wiklou.git] / includes / LinkBatch.php
index 249a8ec..c5c5721 100644 (file)
@@ -34,7 +34,7 @@ class LinkBatch {
                        $this->data[$ns] = array();
                }
 
-               $this->data[$ns][$dbkey] = 1;
+               $this->data[$ns][str_replace( ' ', '_', $dbkey )] = 1;
        }
 
        /**
@@ -73,12 +73,18 @@ class LinkBatch {
         * Return an array mapping PDBK to ID
         */
        function executeInto( &$cache ) {
-               $fname = 'LinkBatch::executeInto';
-               wfProfileIn( $fname );
-               // Do query
+               wfProfileIn( __METHOD__ );
                $res = $this->doQuery();
+               $ids = $this->addResultToCache( $cache, $res );
+               wfProfileOut( __METHOD__ );
+               return $ids;
+       }
+
+       /**
+        * Add a ResultWrapper containing IDs and titles to a LinkCache object
+        */
+       function addResultToCache( $cache, $res ) {
                if ( !$res ) {
-                       wfProfileOut( $fname );
                        return array();
                }
 
@@ -92,7 +98,6 @@ class LinkBatch {
                        $ids[$title->getPrefixedDBkey()] = $row->page_id;
                        unset( $remaining[$row->page_namespace][$row->page_title] );
                }
-               $res->free();
 
                // The remaining links in $data are bad links, register them as such
                foreach ( $remaining as $ns => $dbkeys ) {
@@ -102,7 +107,6 @@ class LinkBatch {
                                $ids[$title->getPrefixedDBkey()] = 0;
                        }
                }
-               wfProfileOut( $fname );
                return $ids;
        }
 
@@ -110,12 +114,10 @@ class LinkBatch {
         * Perform the existence test query, return a ResultWrapper with page_id fields
         */
        function doQuery() {
-               $fname = 'LinkBatch::doQuery';
-
                if ( $this->isEmpty() ) {
                        return false;
                }
-               wfProfileIn( $fname );
+               wfProfileIn( __METHOD__ );
 
                // Construct query
                // This is very similar to Parser::replaceLinkHolders
@@ -123,22 +125,21 @@ class LinkBatch {
                $page = $dbr->tableName( 'page' );
                $set = $this->constructSet( 'page', $dbr );
                if ( $set === false ) {
-                       wfProfileOut( $fname );
+                       wfProfileOut( __METHOD__ );
                        return false;
                }
                $sql = "SELECT page_id, page_namespace, page_title FROM $page WHERE $set";
 
                // Do query
-               $res = new ResultWrapper( $dbr,  $dbr->query( $sql, $fname ) );
-               wfProfileOut( $fname );
+               $res = new ResultWrapper( $dbr,  $dbr->query( $sql, __METHOD__ ) );
+               wfProfileOut( __METHOD__ );
                return $res;
        }
 
        /**
         * Construct a WHERE clause which will match all the given titles.
-        * Give the appropriate table's field name prefix ('page', 'pl', etc).
         *
-        * @param $prefix String: ??
+        * @param string $prefix the appropriate table's field name prefix ('page', 'pl', etc)
         * @return string
         * @public
         */
@@ -158,9 +159,9 @@ class LinkBatch {
                        }
                        
                        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=".
-                                       $db->addQuotes(current(array_keys($dbkeys))).
+                                       $db->addQuotes($singleKey[0]).
                                        ")";
                        } else {
                                $sql .= "({$prefix}_namespace=$ns AND {$prefix}_title IN (";
@@ -186,4 +187,4 @@ class LinkBatch {
        }
 }
 
-?>
+