From de86115ff0383969b81596d382d90f53f0f46d6d Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sat, 26 May 2007 16:23:34 +0000 Subject: [PATCH] * Fix #908: links to Special: pages should check for existence, and display appropriately * Add SpecialPage::exists() method. --- RELEASE-NOTES | 1 + includes/Parser.php | 8 +++++++- includes/SpecialPage.php | 23 +++++++++++++++++++++++ includes/Title.php | 5 ++--- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1e6fb2e778..460b0b6775 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 == diff --git a/includes/Parser.php b/includes/Parser.php index 0a7e86260e..9567d335c0 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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 ) ) { diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index cf88250993..c6133aa26e 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -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 diff --git a/includes/Title.php b/includes/Title.php index 63b0485442..4a5f35b5bd 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 ) ) ); } -- 2.20.1