Extension:PSINoTocNum
From MediaWiki.org
|
Release status: stable |
|||
|---|---|---|---|
![]() |
|||
| Implementation | Extended syntax | ||
| Description | New MagicWord __NOTOCNUM__ to disable TOC numbering. | ||
| Author(s) | Benedikt Meuthrath | ||
| Last Version | 1 (17.04.07) | ||
| MediaWiki | 1.9.x | ||
| License | GPLv2 or later | ||
| Download | PSINoTocNum.php | ||
| Example | KrefeldWiki | ||
|
|||
|
check usage (experimental) |
|||
Contents |
[edit] What can this extension do?
This extension realizes a new MagicWord __NOTOCNUM__. If an article contains this MagicWord numbering in the table of contents (TOC) is disabled by extra CSS.
[edit] Usage
- Add "__NOTOCNUM__" to any article.
[edit] Installation
- include this extension in LocalSettings.php: require_once("extensions/PSINoTocNum.php");
[edit] Changes to LocalSettings.php
require_once("$IP/extensions/PSINoTocNum.php");
[edit] Code
<?php /** * @copyright Copyright © 2007, Benedikt Meuthrath, PSI AG * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later * * This MediaWiki extension is funded by PSI AG. http://www.psi.de * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, version 2 * of the License. * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * See the GNU General Public License for more details. */ /** * This extension realizes a new MagicWord __NOTOCNUM__. * If an article contains this MagicWord numbering in the * table of contents (TOC) is disabled by extra CSS. * * How to use: * * include this extension in LocalSettings.php: * require_once("extensions/PSINoTocNum.php"); * * Add "__NOTOCNUM__" to any article. * * @author Benedikt Meuthrath * @author Dieter Wunderer * @version $Revision: 1.4 $ */ if (!defined('MEDIAWIKI')) { die("This can not be run from command line"); } $wgExtensionCredits['parserhook'][] = array( 'name' => 'PSINoTocNum', 'version' => '$Revision: 1.4 $', 'author' => 'Benedikt Meuthrath', 'url' => 'http://www.mediawiki.org/wiki/Extension:PSINoTocNum', 'description' => 'New MagicWord "<nowiki>__NOTOCNUM__</nowiki>".', ); $wgHooks['MagicWordMagicWords'][] = 'PSINoTocNumMagicWordMagicWords'; $wgHooks['MagicWordwgVariableIDs'][] = 'PSINoTocNumMagicWordwgVariableIDs'; $wgHooks['LanguageGetMagic'][] = 'PSINoTocNumLanguageGetMagic'; //Originally 'ParserBeforeInternalParse' was used. Since it is not recommended according to [[Manual:Hooks/ParserBeforeInternalParse]] //it was replaced by hook 'ParserAfterStrip', working perfectly for me. $wgHooks['ParserAfterStrip'][] = 'MagicNoNumberedHeadings_AfterStrip'; //This is actually the most important part. We add the style to hide the TOC numbers right before the page is displayed. So nothing can //get between our code and the result... ;-) $wgHooks['BeforePageDisplay'][] = 'MagicNoNumberedTOC'; function PSINoTocNumMagicWordMagicWords(&$magicWords) { $magicWords[] = 'MAG_NOTOCNUM'; return true; } function PSINoTocNumMagicWordwgVariableIDs(&$wgVariableIDs) { $wgVariableIDs[] = MAG_NOTOCNUM; return true; } function PSINoTocNumLanguageGetMagic(&$magicWords, $langCode) { $magicWords[MAG_NOTOCNUM] = array( 0, "__NOTOCNUM__" ); return true; } function MagicNoNumberedHeadings_AfterStrip(&$parser, &$text, &$stripState) { //Here we set the option to number the headings to false. During parsing the headings in the text are not numbered if false. //Unfortunately this does not prevent the TOC to get numbered. Therefore we need another hood (see below). if (MagicWord::get( MAG_NOTOCNUM )->matchAndRemove( $text ) ) { $parser->mOptions->mNumberHeadings = (FALSE); } return true; } function MagicNoNumberedTOC (&$out) { //Here we check if the option for numbering the headings is true. If not (no numbering) we hide the TOC numbers. //Why numbers disappear: the numbers of the TOC are luckily formatted with a special class '.tocnumber', that's why this works. //Why adding as script: because there is only a method to add CSS files, not just a CSS style directly. But you can add a script directly... ;-) if (!$out->mNumberHeadings) $out->addScript('<style type="text/css"><!-- .tocnumber {display:none;} --></style>'); return true; }
[edit] See also
Related extensions:
[edit] Bugs
For some (or all) people this extension does not work correctly. Please see discussion page for a solution.
