Merge "Followup I888c616e: Keep IRC line format unchanged."
[lhc/web/wiklou.git] / includes / parser / LinkHolderArray.php
index 9f1fff2..0c05a51 100644 (file)
@@ -254,12 +254,12 @@ class LinkHolderArray {
         * @todo FIXME: Update documentation. makeLinkObj() is deprecated.
         * Replace <!--LINK--> link placeholders with actual links, in the buffer
         * Placeholders created in Skin::makeLinkObj()
-        * Returns an array of link CSS classes, indexed by PDBK.
+        * @return array of link CSS classes, indexed by PDBK.
         */
        function replace( &$text ) {
                wfProfileIn( __METHOD__ );
 
-               $colours = $this->replaceInternal( $text );
+               $colours = $this->replaceInternal( $text ); // FIXME: replaceInternal doesn't return a value
                $this->replaceInterwiki( $text );
 
                wfProfileOut( __METHOD__ );
@@ -322,7 +322,7 @@ class LinkHolderArray {
                }
                if ( $queries ) {
                        $where = array();
-                       foreach( $queries as $ns => $pages ){
+                       foreach( $queries as $ns => $pages ) {
                                $where[] = $dbr->makeList(
                                        array(
                                                'page_namespace' => $ns,
@@ -497,20 +497,24 @@ class LinkHolderArray {
                // process categories, check if a category exists in some variant
                $categoryMap = array(); // maps $category_variant => $category (dbkeys)
                $varCategories = array(); // category replacements oldDBkey => newDBkey
-               foreach( $output->getCategoryLinks() as $category ){
+               foreach ( $output->getCategoryLinks() as $category ) {
+                       $categoryTitle = Title::makeTitleSafe( NS_CATEGORY, $category );
+                       $linkBatch->addObj( $categoryTitle );
                        $variants = $wgContLang->autoConvertToAllVariants( $category );
-                       foreach($variants as $variant){
-                               if($variant != $category){
-                                       $variantTitle = Title::newFromDBkey( Title::makeName(NS_CATEGORY,$variant) );
-                                       if(is_null($variantTitle)) continue;
+                       foreach ( $variants as $variant ) {
+                               if ( $variant !== $category ) {
+                                       $variantTitle = Title::makeTitleSafe( NS_CATEGORY, $variant );
+                                       if ( is_null( $variantTitle ) ) {
+                                               continue;
+                                       }
                                        $linkBatch->addObj( $variantTitle );
-                                       $categoryMap[$variant] = $category;
+                                       $categoryMap[$variant] = array( $category, $categoryTitle );
                                }
                        }
                }
 
 
-               if(!$linkBatch->isEmpty()){
+               if( !$linkBatch->isEmpty() ) {
                        // construct query
                        $dbr = wfGetDB( DB_SLAVE );
                        $varRes = $dbr->select( 'page',
@@ -556,25 +560,28 @@ class LinkHolderArray {
                                }
 
                                // check if the object is a variant of a category
-                               if(isset($categoryMap[$vardbk])){
-                                       $oldkey = $categoryMap[$vardbk];
-                                       if($oldkey != $vardbk)
-                                               $varCategories[$oldkey]=$vardbk;
+                               if ( isset( $categoryMap[$vardbk] ) ) {
+                                       list( $oldkey, $oldtitle ) = $categoryMap[$vardbk];
+                                       if ( !isset( $varCategories[$oldkey] ) && !$oldtitle->exists() ) {
+                                               $varCategories[$oldkey] = $vardbk;
+                                       }
                                }
                        }
                        wfRunHooks( 'GetLinkColours', array( $linkcolour_ids, &$colours ) );
 
                        // rebuild the categories in original order (if there are replacements)
-                       if(count($varCategories)>0){
+                       if( count( $varCategories ) > 0 ) {
                                $newCats = array();
                                $originalCats = $output->getCategories();
-                               foreach($originalCats as $cat => $sortkey){
+                               foreach( $originalCats as $cat => $sortkey ) {
                                        // make the replacement
-                                       if( array_key_exists($cat,$varCategories) )
+                                       if( array_key_exists( $cat, $varCategories ) ) {
                                                $newCats[$varCategories[$cat]] = $sortkey;
-                                       else $newCats[$cat] = $sortkey;
+                                       } else {
+                                               $newCats[$cat] = $sortkey;
+                                       }
                                }
-                               $output->setCategoryLinks($newCats);
+                               $output->setCategoryLinks( $newCats );
                        }
                }
        }