* Second try at normalising special page titles, now at the linker
authorNiklas Laxström <nikerabbit@users.mediawiki.org>
Tue, 17 Jun 2008 08:08:59 +0000 (08:08 +0000)
committerNiklas Laxström <nikerabbit@users.mediawiki.org>
Tue, 17 Jun 2008 08:08:59 +0000 (08:08 +0000)
* Normalises namespace and name to the content language of the wiki

includes/Linker.php

index 9cf8790..142cc5d 100644 (file)
@@ -277,15 +277,17 @@ class Linker {
         * @param $style  String: style to apply - if empty, use getInternalLinkAttributesObj instead
         * @return the a-element
         */
-       function makeKnownLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
+       function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
                wfProfileIn( __METHOD__ );
 
-               if ( !$nt instanceof Title ) {
+               if ( !$title instanceof Title ) {
                        # Fail gracefully
                        wfProfileOut( __METHOD__ );
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
 
+               $nt = $this->normaliseSpecialPage( $title );
+
                $u = $nt->escapeLocalURL( $query );
                if ( $nt->getFragment() != '' ) {
                        if( $nt->getPrefixedDbkey() == '' ) {
@@ -321,15 +323,17 @@ class Linker {
         *                      be included in the link text. Other characters will be appended after
         *                      the end of the link.
         */
-       function makeBrokenLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
+       function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
                wfProfileIn( __METHOD__ );
 
-               if ( !$nt instanceof Title ) {
+               if ( !$title instanceof Title ) {
                        # Fail gracefully
                        wfProfileOut( __METHOD__ );
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
 
+               $nt = $this->normaliseSpecialPage( $title );
+
                if( $nt->getNamespace() == NS_SPECIAL ) {
                        $q = $query;
                } else if ( '' == $query ) {
@@ -421,6 +425,16 @@ class Linker {
                return "<strong class=\"selflink\">{$prefix}{$text}{$inside}</strong>{$trail}";
        }
 
+       function normaliseSpecialPage( Title $title ) {
+               if ( $title->getNamespace() == NS_SPECIAL ) {
+                       list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $title->getDBkey() );
+                       if ( !$name ) return $title;
+                       return SpecialPage::getTitleFor( $name, $subpage );
+               } else {
+                       return $title;
+               }
+       }
+
        /** @todo document */
        function fnamePart( $url ) {
                $basename = strrchr( $url, '/' );