From f5021e22749229808cc6cbd8bd1bb49ca656fe11 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sun, 9 Nov 2008 18:21:42 +0000 Subject: [PATCH] * Add class "disambiguationpage" to body tag * Split off MediaWiki:Disambiguationspage parsing to wfGetDisambiguationTemplates() --- RELEASE-NOTES | 1 + includes/Article.php | 14 ++++++++ includes/GlobalFunctions.php | 35 ++++++++++++++++++++ includes/specials/SpecialDisambiguations.php | 31 ++--------------- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 6e33328455..b45c9c8a5d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -200,6 +200,7 @@ The following extensions are migrated into MediaWiki 1.14: $wgMediaHandlers configuration variable. * New 'AbortDiffCache' hook can be used to cancel the caching of a diff * (bug 15835) Added Content-Style-Type meta tag +* Add class="disambiguationpage" to tag for disambiguations === Bug fixes in 1.14 === diff --git a/includes/Article.php b/includes/Article.php index f64e9f413c..c629c42a58 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -574,6 +574,20 @@ class Article { return $titleObj !== NULL; } + function isDisambig() { + global $wgParser; + $this->loadContent(); + $output = $wgParser->parse( $this->fetchContent(), $this->mTitle, new ParserOptions() ); + $templates = $output->getTemplates(); + $disambigs = wfGetDisambiguationTemplates(); + if( isset( $templates[NS_TEMPLATE] ) ) + foreach( $templates[NS_TEMPLATE] as $dbk => $id ) + foreach( $disambigs as $disambig ) + if( $disambig->getDBkey() == $dbk ) + return true; + return false; + } + /** * Returns true if the currently-referenced revision is the current edit * to this page (and it exists). diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 67c64c9004..eaa806c935 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2965,3 +2965,38 @@ function wfStripIllegalFilenameChars( $name ) { $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name ); return $name; } + +/** + * Fetches all disambiguation templates from MediaWiki:Disambiguationspage + */ +function wfGetDisambiguationTemplates() { + static $templates = null; + if( $templates ) + return $templates; + $msgText = wfMsgForContent('disambiguationspage'); + $templates = array(); + + # If the text can be treated as a title, use it verbatim. + # Otherwise, pull the titles from the links table + $dp = Title::newFromText($msgText); + if( $dp ) { + if($dp->getNamespace() != NS_TEMPLATE) { + # FIXME we assume the disambiguation message is a template but + # the page can potentially be from another namespace :/ + wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n"); + } + $templates [] = $dp; + } else { + # Get all the templates linked from the Mediawiki:Disambiguationspage + # Originally used database, now uses parser + global $wgParser; + $output = $wgParser->parse( $msgText, + Title::makeTitle( NS_MEDIAWIKI, 'Disambiguationspage' ), new ParserOptions() ); + $links = $output->getLinks(); + if( isset( $links[NS_TEMPLATE] ) ) + foreach( $links[NS_TEMPLATE] as $dbk => $id ) + if( $id ) + $templates[] = Title::makeTitle( NS_TEMPLATE, $dbk ); + } + return $templates; +} diff --git a/includes/specials/SpecialDisambiguations.php b/includes/specials/SpecialDisambiguations.php index 0a728b6860..dbf27d07a8 100644 --- a/includes/specials/SpecialDisambiguations.php +++ b/includes/specials/SpecialDisambiguations.php @@ -24,36 +24,9 @@ class DisambiguationsPage extends PageQueryPage { function getSQL() { $dbr = wfGetDB( DB_SLAVE ); - $dMsgText = wfMsgForContent('disambiguationspage'); - $linkBatch = new LinkBatch; - - # If the text can be treated as a title, use it verbatim. - # Otherwise, pull the titles from the links table - $dp = Title::newFromText($dMsgText); - if( $dp ) { - if($dp->getNamespace() != NS_TEMPLATE) { - # FIXME we assume the disambiguation message is a template but - # the page can potentially be from another namespace :/ - wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n"); - } - $linkBatch->addObj( $dp ); - } else { - # Get all the templates linked from the Mediawiki:Disambiguationspage - $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' ); - $res = $dbr->select( - array('pagelinks', 'page'), - 'pl_title', - array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, - 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), - __METHOD__ ); - - while ( $row = $dbr->fetchObject( $res ) ) { - $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title )); - } - - $dbr->freeResult( $res ); - } + foreach( wfGetDisambiguationTemplates() as $tl ) + $linkBatch->addObj( $tl ); $set = $linkBatch->constructSet( 'lb.tl', $dbr ); if( $set === false ) { -- 2.20.1