r52213 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52212‎ | r52213 | r52214 >
Date:21:47, 20 June 2009
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
Core changes for NavigableTOC extension:
* Add TOC HTML to ParserOutput
* Add class tocsection-$section to <li> elements in the TOC representing sections in the current page (as opposed to transcluded sections)
Modified paths:
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOutput.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -3647,7 +3647,8 @@
36483648 $legacyAnchor .= '_' . $refers[$legacyArrayKey];
36493649 }
36503650 if( $enoughToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) {
3651 - $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel);
 3651+ $toc .= $sk->tocLine($anchor, $tocline,
 3652+ $numbering, $toclevel, ($isTemplate ? false : $sectionIndex));
36523653
36533654 # Find the DOM node for this header
36543655 while ( $node && !$isTemplate ) {
@@ -3703,6 +3704,8 @@
37043705 }
37053706 $toc = $sk->tocList( $toc );
37063707 }
 3708+
 3709+ $this->mOutput->setTOCHTML( $toc );
37073710
37083711 # split up and insert constructed headlines
37093712
Index: trunk/phase3/includes/parser/ParserOutput.php
@@ -24,7 +24,8 @@
2525 $mOutputHooks = array(), # Hook tags as per $wgParserOutputHooks
2626 $mWarnings = array(), # Warning text to be returned to the user. Wikitext formatted, in the key only
2727 $mSections = array(), # Table of contents
28 - $mProperties = array(); # Name/value pairs to be cached in the DB
 28+ $mProperties = array(), # Name/value pairs to be cached in the DB
 29+ $mTOCHTML = ''; # HTML of the TOC
2930 private $mIndexPolicy = ''; # 'index' or 'noindex'? Any other value will result in no change.
3031
3132 /**
@@ -58,6 +59,7 @@
5960 function getOutputHooks() { return (array)$this->mOutputHooks; }
6061 function getWarnings() { return array_keys( $this->mWarnings ); }
6162 function getIndexPolicy() { return $this->mIndexPolicy; }
 63+ function getTOCHTML() { return $this->mTOCHTML; }
6264
6365 function containsOldMagic() { return $this->mContainsOldMagic; }
6466 function setText( $text ) { return wfSetVar( $this->mText, $text ); }
@@ -68,6 +70,7 @@
6971 function setTitleText( $t ) { return wfSetVar( $this->mTitleText, $t ); }
7072 function setSections( $toc ) { return wfSetVar( $this->mSections, $toc ); }
7173 function setIndexPolicy( $policy ) { return wfSetVar( $this->mIndexPolicy, $policy ); }
 74+ function setTOCHTML( $tochtml ) { return wfSetVar( $this->mTOCHTML, $tochtml ); }
7275
7376 function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
7477 function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
Index: trunk/phase3/includes/Linker.php
@@ -1142,8 +1142,11 @@
11431143 /**
11441144 * parameter level defines if we are on an indentation level
11451145 */
1146 - function tocLine( $anchor, $tocline, $tocnumber, $level ) {
1147 - return "\n<li class=\"toclevel-$level\"><a href=\"#" .
 1146+ function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
 1147+ $classes = "toclevel-$level";
 1148+ if ( $sectionIndex !== false )
 1149+ $classes .= " tocsection-$sectionIndex";
 1150+ return "\n<li class=\"$classes\"><a href=\"#" .
11481151 $anchor . '"><span class="tocnumber">' .
11491152 $tocnumber . '</span> <span class="toctext">' .
11501153 $tocline . '</span></a>';

Follow-up revisions

RevisionCommit summaryAuthorDate
r53308Fix parser tests for r52213....catrope11:29, 15 July 2009

Comments

#Comment by Simetrical (talk | contribs)   22:30, 14 July 2009

This broke a load of parser tests.

#Comment by Catrope (talk | contribs)   22:43, 14 July 2009

Ah, of course, my apologies. I'll dive into them tomorrow.

#Comment by Catrope (talk | contribs)   11:30, 15 July 2009

Parser tests fixed in r53308

#Comment by Simetrical (talk | contribs)   22:19, 15 July 2009

I'm still seeing one failing: "Running test TOC with wgMaxTocLevel=3 (bug 6204)"

#Comment by Catrope (talk | contribs)   22:34, 15 July 2009

Fixed in r53336

Status & tagging log