* Fix #908: links to Special: pages should check for existence,
authorAntoine Musso <hashar@users.mediawiki.org>
Sat, 26 May 2007 16:23:34 +0000 (16:23 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Sat, 26 May 2007 16:23:34 +0000 (16:23 +0000)
  and display appropriately
* Add SpecialPage::exists() method.

RELEASE-NOTES
includes/Parser.php
includes/SpecialPage.php
includes/Title.php

index 1e6fb2e..460b0b6 100644 (file)
@@ -86,6 +86,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 5850) Added hexadecimal html entities comments for $digitTransformTable
   entries.
 * (bug 7432) Change language name for Aromanian (roa-rup)
+* (bug 908) Unexistent special pages now generate a red link.
 
 == MediaWiki API changes since 1.10 ==
 
index 0a7e862..9567d33 100644 (file)
@@ -1799,7 +1799,11 @@ class Parser
                                $this->mOutput->addImage( $nt->getDBkey() );
                                continue;
                        } elseif( $ns == NS_SPECIAL ) {
-                               $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
+                               if( SpecialPage::exists( $nt->getDBkey() ) ) {
+                                       $s .= $this->makeKnownLinkHolder( $nt, $text, '', $trail, $prefix );
+                               } else {
+                                       $s .= $this->makeLinkHolder( $nt, $text, '', $trail, $prefix );
+                               }
                                continue;
                        } elseif( $ns == NS_IMAGE ) {
                                $img = new Image( $nt );
@@ -4037,6 +4041,8 @@ class Parser
                                        $this->mOutput->addLink( $title, $id );
                                } elseif ( $linkCache->isBadLink( $pdbk ) ) {
                                        $colours[$pdbk] = 0;
+                               } elseif ( $title->getNamespace() == NS_SPECIAL && !SpecialPage::exists( $pdbk ) ) {
+                                       $colours[$pdbk] = 0;
                                } else {
                                        # Not in the link cache, add it to the query
                                        if ( !isset( $current ) ) {
index cf88250..c6133aa 100644 (file)
@@ -274,6 +274,29 @@ class SpecialPage
                unset( self::$mList[$name] );
        }
 
+       /**
+        * Check if a given name exist as a special page or as a special page alias
+        * @param $name string: name of a special page
+        * @return boolean: true if a special page exists with this name
+        */
+       static function exists( $name ) {
+               if ( !self::$mListInitialised ) {
+                       self::initList();
+               }
+               if( !self::$mAliases ) {
+                       self::initAliasList();
+               }
+
+               # Remove special pages inline parameters:
+               $bits = explode( '/', $name );
+               $name = $bits[0];
+
+               return
+                       array_key_exists( $name, self::$mList )
+                       or array_key_exists( $name, self::$mAliases )
+               ;
+       }
+
        /**
         * Find the object with a given name and return it (or NULL)
         * @static
index 63b0485..4a5f35b 100644 (file)
@@ -2407,13 +2407,12 @@ class Title {
         * Should a link should be displayed as a known link, just based on its title?
         *
         * Currently, a self-link with a fragment and special pages are in
-        * this category. Special pages never exist in the database. System
-        * messages that have defined default values are also always known.
+        * this category. System messages that have defined default values are also
+        * always known.
         */
        public function isAlwaysKnown() {
                return ( $this->isExternal() ||
                         ( 0 == $this->mNamespace && "" == $this->mDbkeyform ) ||
-                        ( NS_SPECIAL == $this->mNamespace ) ||
                         ( NS_MEDIAWIKI == $this->mNamespace && wfMsgWeirdKey( $this->mDbkeyform ) ) );
        }