Page MenuHomePhabricator

Fix the way namespaces are treated in the headings of Special:Drilldown
Closed, ResolvedPublic

Description

Cargo's Special:Drilldown works differently to a normal category page:

  • A category page sorts according to page name minus namespace (see [[Help:Categories#Sort_key]]).
  • Special:Drilldown sorts according to page name WITH namespace.

This can be a problem, e.g. if all result pages are in a "Books" namespace:

  • A category page will display headings from "A" to "Z" as appropriate.
  • Special:Drilldown will only have "B", "B cont.", and "B cont."

Here is a patch which I hope fixes this:

index 8ed5d8a..471353c 100644
--- a/drilldown/CargoSpecialDrilldown.php
+++ b/drilldown/CargoSpecialDrilldown.php
@@ -1306,7 +1306,8 @@ END;
                $matchingPages = array();
                while ( $row = $cdb->fetchRow( $res ) ) {
                        $pageName = $row['title'];
-                       $curValue = array( 'title' => $pageName );
+                       $pageNamespace = MWNamespace::getCanonicalName( $row['namespace'] ); #xxx added
+                       $curValue = array( 'title' => $pageName, 'namespace' =>  $pageNamespace); #xxx changed
                        if ( array_key_exists( 'foundFileMatch', $row ) && $row['foundFileMatch'] ) {
                                if ( array_key_exists( 'fileName', $row ) ) {
                                        // Not used for _fileData drilldown.
diff --git a/formats/CargoCategoryFormat.php b/formats/CargoCategoryFormat.php
index 2b5f7d0..edea47d 100644
--- a/formats/CargoCategoryFormat.php
+++ b/formats/CargoCategoryFormat.php
@@ -54,7 +54,7 @@ class CargoCategoryFormat extends CargoListFormat {
                        } else {
                                $curValue = $valuesTable[$i][$headerField];
                        }
-                       $cur_first_char = $wgContLang->firstChar( $curValue );
+                       $cur_first_char = $wgContLang->firstChar( str_replace ($row['namespace'].':', '', $curValue) ); #xxx changed

                        if ( $rowindex % $rows_per_column == 0 ) {
                                $result .= "\n\t\t\t<div style=\"float: left; width: $column_width%;\">\n";

Event Timeline

Very clever! Thanks. I made some modifications to your patch, and just checked it in.