r43329 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43328‎ | r43329 | r43330 >
Date:18:21, 9 November 2008
Author:vasilievvv
Status:old (Comments)
Tags:
Comment:
* Add class "disambiguationpage" to body tag
* Split off MediaWiki:Disambiguationspage parsing to
wfGetDisambiguationTemplates()
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialDisambiguations.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -574,6 +574,20 @@
575575 return $titleObj !== NULL;
576576 }
577577
 578+ function isDisambig() {
 579+ global $wgParser;
 580+ $this->loadContent();
 581+ $output = $wgParser->parse( $this->fetchContent(), $this->mTitle, new ParserOptions() );
 582+ $templates = $output->getTemplates();
 583+ $disambigs = wfGetDisambiguationTemplates();
 584+ if( isset( $templates[NS_TEMPLATE] ) )
 585+ foreach( $templates[NS_TEMPLATE] as $dbk => $id )
 586+ foreach( $disambigs as $disambig )
 587+ if( $disambig->getDBkey() == $dbk )
 588+ return true;
 589+ return false;
 590+ }
 591+
578592 /**
579593 * Returns true if the currently-referenced revision is the current edit
580594 * to this page (and it exists).
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2965,3 +2965,38 @@
29662966 $name = preg_replace ( "/[^".Title::legalChars()."]|:/", '-', $name );
29672967 return $name;
29682968 }
 2969+
 2970+/**
 2971+ * Fetches all disambiguation templates from MediaWiki:Disambiguationspage
 2972+ */
 2973+function wfGetDisambiguationTemplates() {
 2974+ static $templates = null;
 2975+ if( $templates )
 2976+ return $templates;
 2977+ $msgText = wfMsgForContent('disambiguationspage');
 2978+ $templates = array();
 2979+
 2980+ # If the text can be treated as a title, use it verbatim.
 2981+ # Otherwise, pull the titles from the links table
 2982+ $dp = Title::newFromText($msgText);
 2983+ if( $dp ) {
 2984+ if($dp->getNamespace() != NS_TEMPLATE) {
 2985+ # FIXME we assume the disambiguation message is a template but
 2986+ # the page can potentially be from another namespace :/
 2987+ wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
 2988+ }
 2989+ $templates [] = $dp;
 2990+ } else {
 2991+ # Get all the templates linked from the Mediawiki:Disambiguationspage
 2992+ # Originally used database, now uses parser
 2993+ global $wgParser;
 2994+ $output = $wgParser->parse( $msgText,
 2995+ Title::makeTitle( NS_MEDIAWIKI, 'Disambiguationspage' ), new ParserOptions() );
 2996+ $links = $output->getLinks();
 2997+ if( isset( $links[NS_TEMPLATE] ) )
 2998+ foreach( $links[NS_TEMPLATE] as $dbk => $id )
 2999+ if( $id )
 3000+ $templates[] = Title::makeTitle( NS_TEMPLATE, $dbk );
 3001+ }
 3002+ return $templates;
 3003+}
Index: trunk/phase3/includes/specials/SpecialDisambiguations.php
@@ -24,37 +24,10 @@
2525 function getSQL() {
2626 $dbr = wfGetDB( DB_SLAVE );
2727
28 - $dMsgText = wfMsgForContent('disambiguationspage');
29 -
3028 $linkBatch = new LinkBatch;
 29+ foreach( wfGetDisambiguationTemplates() as $tl )
 30+ $linkBatch->addObj( $tl );
3131
32 - # If the text can be treated as a title, use it verbatim.
33 - # Otherwise, pull the titles from the links table
34 - $dp = Title::newFromText($dMsgText);
35 - if( $dp ) {
36 - if($dp->getNamespace() != NS_TEMPLATE) {
37 - # FIXME we assume the disambiguation message is a template but
38 - # the page can potentially be from another namespace :/
39 - wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
40 - }
41 - $linkBatch->addObj( $dp );
42 - } else {
43 - # Get all the templates linked from the Mediawiki:Disambiguationspage
44 - $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
45 - $res = $dbr->select(
46 - array('pagelinks', 'page'),
47 - 'pl_title',
48 - array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
49 - 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
50 - __METHOD__ );
51 -
52 - while ( $row = $dbr->fetchObject( $res ) ) {
53 - $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
54 - }
55 -
56 - $dbr->freeResult( $res );
57 - }
58 -
5932 $set = $linkBatch->constructSet( 'lb.tl', $dbr );
6033 if( $set === false ) {
6134 # We must always return a valid sql query, but this way DB will always quicly return an empty result
Index: trunk/phase3/RELEASE-NOTES
@@ -200,6 +200,7 @@
201201 $wgMediaHandlers configuration variable.
202202 * New 'AbortDiffCache' hook can be used to cancel the caching of a diff
203203 * (bug 15835) Added Content-Style-Type meta tag
 204+* Add class="disambiguationpage" to <body> tag for disambiguations
204205
205206 === Bug fixes in 1.14 ===
206207

Follow-up revisions

RevisionCommit summaryAuthorDate
r43438Revert r43329, r43330 due to said performance issuesaaron08:15, 13 November 2008

Comments

#Comment by Werdna (talk | contribs)   22:58, 9 November 2008

Adds a reparse every page view. Please use the parser cache.

#Comment by Aaron Schulz (talk | contribs)   08:16, 13 November 2008

Reverted in r43438

Status & tagging log