This is a minimal change to add a new magic token that prevents numbering of the TOC and to do the same when the user option "Auto-number headings" under "Misc" in "Preferences" is set. This option is already retrieved through $this->mOptions->getNumberHeadings(); but currently not used effectively.
The token directive is useful because some sections in a wiki may already include numbering as part of the heading and suppressing auto-numbering is useful in those cases.
Index: includes/Parser.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/Parser.php,v retrieving revision 1.509 diff -u -r1.509 Parser.php --- includes/Parser.php 23 Sep 2005 12:10:39 -0000 1.509 +++ includes/Parser.php 24 Sep 2005 12:57:48 -0000 @@ -2461,8 +2461,15 @@ */ function formatHeadings( $text, $isMain=true ) { global $wgMaxTocLevel, $wgContLang, $wgLinkHolders, $wgInterwikiLinkHolders; - - $doNumberHeadings = $this->mOptions->getNumberHeadings(); + + # if the string __NOTOCNUM__ (not case-sensitive) occurs in the HTML, + # or if the user prefers not to, do not add TOC Numbering + $mw =& MagicWord::get( MAG_NOTOCNUM ); + if( $mw->matchAndRemove( $text ) ) { + $doNumberHeadings = false; + } else { + $doNumberHeadings = $this->mOptions->getNumberHeadings(); + } $doShowToc = true; $forceTocHere = false; if( !$this->mTitle->userCanEdit() ) { @@ -2647,7 +2654,7 @@ $anchor .= '_' . $refcount[$headlineCount]; } if( $doShowToc && ( !isset($wgMaxTocLevel) || $toclevel<$wgMaxTocLevel ) ) { - $toc .= $sk->tocLine($anchor, $tocline, $numbering, $toclevel); + $toc .= $sk->tocLine($anchor, $tocline, $doNumberHeadings?$numbering:'', $toclevel); } if( $showEditLink && ( !$istemplate || $templatetitle !== "" ) ) { if ( empty( $head[$headlineCount] ) ) { Index: languages/Language.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/languages/Language.php,v retrieving revision 1.684 diff -u -r1.684 Language.php --- languages/Language.php 23 Sep 2005 12:10:39 -0000 1.684 +++ languages/Language.php 24 Sep 2005 12:58:06 -0000 @@ -190,6 +190,7 @@ # ID CASE SYNONYMS MAG_REDIRECT => array( 0, '#redirect' ), MAG_NOTOC => array( 0, '__NOTOC__' ), + MAG_NOTOCNUM => array( 0, '__NOTOCNUM__' ), MAG_FORCETOC => array( 0, '__FORCETOC__' ), MAG_TOC => array( 0, '__TOC__' ), MAG_NOEDITSECTION => array( 0, '__NOEDITSECTION__' ),
On Sat, 24 Sep 2005 23:07:07 +1000, Netocrat wrote:
This is a minimal change to add a new magic token that prevents numbering of the TOC and to do the same when the user option "Auto-number headings" under "Misc" in "Preferences" is set.
^^^ Should have been "not set", but since I misinterpreted the purpose of that preference, I'm not surprised the patch received no attention.
Here's a new patch that deals solely with suppressing TOC/heading auto-numbering when a __NOTOCNUM__ directive is included in the page. Same reasoning as originally (e.g. for FAQ pages where deprecated answers are removed but new content should not reuse that answer's number):
The token directive is useful because some sections in a wiki may already include numbering as part of the heading and suppressing auto-numbering is useful in those cases.
Let me know if there's a more appropriate place to submit this.
Index: includes/Parser.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/Parser.php,v retrieving revision 1.533 diff -u -r1.533 Parser.php --- includes/Parser.php 27 Nov 2005 06:04:41 -0000 1.533 +++ includes/Parser.php 29 Nov 2005 14:09:35 -0000 @@ -2708,6 +2708,11 @@ function formatHeadings( $text, $isMain=true ) { global $wgMaxTocLevel, $wgContLang, $wgLinkHolders, $wgInterwikiLinkHolders;
+ # do not number TOC entries or corresponding headings if the string + # __NOTOCNUM__ (not case-sensitive) occurs in the HTML + $mw =& MagicWord::get( MAG_NOTOCNUM ); + $noTocNum = $mw->matchAndRemove( $text ); + $doNumberHeadings = $this->mOptions->getNumberHeadings(); $doShowToc = true; $forceTocHere = false; @@ -2836,16 +2841,18 @@
$levelCount[$toclevel] = $level;
- # count number of headlines for each level - @$sublevelCount[$toclevel]++; - $dot = 0; - for( $i = 1; $i <= $toclevel; $i++ ) { - if( !empty( $sublevelCount[$i] ) ) { - if( $dot ) { - $numbering .= '.'; + if (! $noTocNum ) { + # count number of headlines for each level + @$sublevelCount[$toclevel]++; + $dot = 0; + for( $i = 1; $i <= $toclevel; $i++ ) { + if( !empty( $sublevelCount[$i] ) ) { + if( $dot ) { + $numbering .= '.'; + } + $numbering .= $wgContLang->formatNum( $sublevelCount[$i] ); + $dot = 1; } - $numbering .= $wgContLang->formatNum( $sublevelCount[$i] ); - $dot = 1; } } } Index: languages/Language.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/languages/Language.php,v retrieving revision 1.741 diff -u -r1.741 Language.php --- languages/Language.php 28 Nov 2005 23:56:35 -0000 1.741 +++ languages/Language.php 29 Nov 2005 14:09:56 -0000 @@ -203,6 +203,7 @@ # ID CASE SYNONYMS MAG_REDIRECT => array( 0, '#REDIRECT' ), MAG_NOTOC => array( 0, '__NOTOC__' ), + MAG_NOTOCNUM => array( 0, '__NOTOCNUM__' ), MAG_FORCETOC => array( 0, '__FORCETOC__' ), MAG_TOC => array( 0, '__TOC__' ), MAG_NOEDITSECTION => array( 0, '__NOEDITSECTION__' ),
On 29/11/05, Netocrat netocrat@dodo.com.au wrote:
Here's a new patch that deals solely with suppressing TOC/heading auto-numbering when a __NOTOCNUM__ directive is included in the page. Same reasoning as originally (e.g. for FAQ pages where deprecated answers are removed but new content should not reuse that answer's number):
Let me know if there's a more appropriate place to submit this.
Well, I think the officially preferred way is to attach to a [new] bug on http://bugzilla.wikimedia.org and add the "patch" and "need-review" keywords. I don't know for certain that that's any less likely to disappear into the ether than here, though...
-- Rowan Collins BSc [IMSoP]
Presuming the full patch got through then this is not sufficient, you also have to define that constant in MagicWord.php, it might work on your server due to the lazyness of PHP but it'll spew errors on E_ALL.
Also, submit it to bugzilla, not the list.
On Wed, 30 Nov 2005 17:13:39 +0000, Rowan Collins wrote: [attribution truncated]
On 29/11/05, Netocrat wrote:
Let me know if there's a more appropriate place to submit this.
Well, I think the officially preferred way is to attach to a [new] bug on http://bugzilla.wikimedia.org and add the "patch" and "need-review" keywords.
After defining the constant in MagicWord.php as Ævar Arnfjörð Bjarmason suggested I've done that.
http://bugzilla.wikimedia.org/show_bug.cgi?id=4127
[...]
wikitech-l@lists.wikimedia.org