Fix bug in prefixing scheme
[lhc/web/wiklou.git] / includes / LinksUpdate.php
index 4e31fcd..b7ad29c 100644 (file)
@@ -26,9 +26,9 @@ class LinksUpdate {
        /**
         * Constructor
         *
-        * @param Title $title Title of the page we're updating
-        * @param ParserOutput $parserOutput Output from a full parse of this page
-        * @param bool $recursive Queue jobs for recursive updates?
+        * @param $title Title of the page we're updating
+        * @param $parserOutput ParserOutput: output from a full parse of this page
+        * @param $recursive Boolean: queue jobs for recursive updates?
         */
        function LinksUpdate( $title, $parserOutput, $recursive = true ) {
                global $wgAntiLockFlags;
@@ -68,7 +68,6 @@ class LinksUpdate {
                }
 
                $this->mRecursive = $recursive;
-               $this->mTouchTmplLinks = false;
 
                wfRunHooks( 'LinksUpdateConstructed', array( &$this ) );
        }
@@ -226,8 +225,8 @@ class LinksUpdate {
        /**
         * Invalidate the cache of a list of pages from a single namespace
         *
-        * @param integer $namespace
-        * @param array $dbkeys
+        * @param $namespace Integer
+        * @param $dbkeys Array
         */
        function invalidatePages( $namespace, $dbkeys ) {
                if ( !count( $dbkeys ) ) {
@@ -421,30 +420,71 @@ class LinksUpdate {
 
        /**
         * Get an array of category insertions
-        * @param array $existing Array mapping existing category names to sort keys. If both
+        *
+        * @param $existing Array mapping existing category names to sort keys. If both
         * match a link in $this, the link will be omitted from the output
         * @private
         */
        function getCategoryInsertions( $existing = array() ) {
-               global $wgContLang;
+               global $wgContLang, $wgExperimentalCategorySort, $wgCollationVersion;
                $diffs = array_diff_assoc( $this->mCategories, $existing );
                $arr = array();
                foreach ( $diffs as $name => $sortkey ) {
                        $nt = Title::makeTitleSafe( NS_CATEGORY, $name );
                        $wgContLang->findVariantLink( $name, $nt, true );
-                       $arr[] = array(
-                               'cl_from'    => $this->mId,
-                               'cl_to'      => $name,
-                               'cl_sortkey' => $sortkey,
-                               'cl_timestamp' => $this->mDb->timestamp()
-                       );
+
+                       if ( $wgExperimentalCategorySort ) {
+                               if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
+                                       $type = 'subcat';
+                               } elseif ( $this->mTitle->getNamespace() == NS_FILE ) {
+                                       $type = 'file';
+                               } else {
+                                       $type = 'page';
+                               }
+
+                               # TODO: This is kind of wrong, because someone might set a sort
+                               # key prefix that's the same as the default sortkey for the
+                               # title.  This should be fixed by refactoring code to replace
+                               # $sortkey in this array by a prefix, but it's basically harmless
+                               # (Title::moveTo() has had the same issue for a long time).
+                               if ( $this->mTitle->getCategorySortkey() == $sortkey ) {
+                                       $prefix = '';
+                                       $sortkey = $wgContLang->convertToSortkey( $sortkey );
+                               } else {
+                                       # Treat custom sortkeys as a prefix, so that if multiple
+                                       # things are forced to sort as '*' or something, they'll
+                                       # sort properly in the category rather than in page_id
+                                       # order or such.
+                                       $prefix = $sortkey;
+                                       $sortkey = $wgContLang->convertToSortkey(
+                                               $this->mTitle->getCategorySortkey( $prefix ) );
+                               }
+
+                               $arr[] = array(
+                                       'cl_from'    => $this->mId,
+                                       'cl_to'      => $name,
+                                       'cl_sortkey' => $sortkey,
+                                       'cl_timestamp' => $this->mDb->timestamp(),
+                                       'cl_sortkey_prefix' => $prefix,
+                                       'cl_collation' => $wgCollationVersion,
+                                       'cl_type' => $type,
+                               );
+                       } else {
+                               $arr[] = array(
+                                       'cl_from'    => $this->mId,
+                                       'cl_to'      => $name,
+                                       'cl_sortkey' => $sortkey,
+                                       'cl_timestamp' => $this->mDb->timestamp()
+                               );
+                       }
                }
                return $arr;
        }
 
        /**
         * Get an array of interlanguage link insertions
-        * @param array $existing Array mapping existing language codes to titles
+        *
+        * @param $existing Array mapping existing language codes to titles
         * @private
         */
        function getInterlangInsertions( $existing = array() ) {