Extension talk:MagicNoNumberedHeadings

From MediaWiki.org
Jump to navigation Jump to search


Install Problems[edit]

On our Wiki the extension does not work.

The following message is emmitted if

ini_set('display_errors', 1);

will be added to LocalSettings.php:

Zeichen 206.svg
Notice: Use of undefined constant MAG_NONUMBEREDHEADINGS - assumed 'MAG_NONUMBEREDHEADINGS'
in /srv/www/wiki/extensions/MagicNoNumberedHeadings/MagicNoNumberedHeadings.php on line 71
Warning: preg_replace_callback(): Compilation failed: invalid UTF-8 string at offset 8 in /srv/www/wiki/includes/MagicWord.php on line 279
Notice: Undefined index: nonumberedheadings in /srv/www/wiki/languages/Language.php on line 1097
Warning: array_slice(): The first argument should be an array in /srv/www/wiki/languages/Language.php on line 1105
Warning: preg_replace_callback(): Compilation failed: invalid UTF-8 string at offset 8 in /srv/www/wiki/includes/MagicWord.php on line 279
.

We use:

Version:

  • MediaWiki: 1.9.2
  • PHP: 5.2.0 (apache2handler)
  • MySQL: 5.0.26

Extensions

Special Pages
Pdf prints a page as pdf Thomas Hempel


Parser Hooks
CharInsert Allows creation of JavaScript box for inserting non-standard characters Brion Vibber
DynamicPageList2 (version 1.0.4) based on DynamicPageList, featuring many improvements IlyaHaykinson, Amgine,Unendlich, Cyril Dangerville,Algorithmix
PageSecurity (version 1.1.4) Restricts access to pages according to security definitions Fernando Correia


Other
LDAP Authentication Plugin (version 1.1d) LDAP Authentication plugin with support for numerous LDAP authentication methods Ryan Lane
RevManager (version 1.0.0) Allows to set revisions as "approved" and hide newer edits to users not having the "approve" right. (Internal development)
talkright (version 1.0.1) adds a talk permission independant from article edition Marc Noirot


Extension functions
wfNamespacePermissions, fnPageSecurityExtension, wfSpecialPdf, rmSetup, wfDynamicPageList3, wfDynamicPageList2 and setupSpecialChars


Parser extension tags
<security-definition>, <dpl>, <section>, <charinsert> and <pre>


Parser function hooks
approvedver, dpl, int, ns, urlencode, lcfirst, ucfirst, lc, uc, localurl, localurle, fullurl, fullurle, formatnum, grammar, plural, numberofpages, numberofusers, numberofarticles, numberoffiles, numberofadmins, language, padleft, padright, anchorencode, special and defaultsort


Hook name Subscribed by
AlternateEdit alternateEdit
ArticleSave fnPageSecuritySaveHook
ArticleViewHeader rmArticleViewHeader
BeforePageDisplay fnPageSecurityBeforePageDisplayHook
LanguageGetMagic rmAppVer_Magic and wfDynamicPageList3_Magic
MonoBookTemplateToolboxEnd wfSpecialPdfToolbox
PermissionRequired fnPageSecurityPermissionRequiredHook
RevisionDataBefore rmRevisionDataBefore
SkinFooterLinks fnPageSecuritySkinFooterLinksHook
SkinTemplateBuildNavUrlsNav_urlsAfterPermalink wfSpecialPdfNav
userCan fnPageSecurityUserCanHook, userCanTalk and namespacePermissionsCheckNamespace



Solution (works for me): Replace MAG_NONUMBEREDHEADINGS by 'MAG_NONUMBEREDHEADINGS' in the MagicNoNumberedHeadings.php file where the word is not between single quotes.

NONUMBEREDHEADINGS ignores the <nowiki> and the <pre> tags. If written in one of these, the headings aren't numbered.

-I made the change above (added quotes around MAG_NONUMBEREDHEADINGS) and didnt' receive any errors, but the extension didn't work--the TOC heading numbers were still there. I am using MediaWiki version 1.16.4. Did anybody else get this to work with the latest MediaWiki version? Lost Student

Variant that worked for me:

<?php
/**
 * @copyright Copyright © 2007, Purodha Blissenabch.
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 *
 * 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 __NONUMBEREDHEADINGS__.
 * If an article contains this MagicWord, numbering of the
 * headings is disabled regardless of the user preference setting.
 *
 * How to use:
 * * include this extension in LocalSettings.php:
 *   require_once($IP.'/extensions/MagicNoNumberedHeadings/MagicNoNumberedHeadings.php');
 * * Add "__NONUMBEREDHEADINGS__" to any article of your choice.
 *
 * @author Purodha Blissenbach
 */

if (!defined('MEDIAWIKI')) {
	die("This requires the MediaWiki enviroment.");
}

$wgExtensionCredits['parserhook'][] = array(
	'path' => __FILE__,
	'name' => 'MagicNoNumberedHeadings',
	'version' => '1.12',
	'author' => 'Purodha Blissenbach',
	'url' => 'https://www.mediawiki.org/wiki/Extension:MagicNoNumberedHeadings',
	'descriptionmsg' => 'magicnonumberedheadings-desc',
);

$dir = dirname(__FILE__) . '/';
$wgExtensionMessagesFiles['MagicNoNumberedHeadings'] = $dir . 'MagicNoNumberedHeadings.i18n.php';
$wgExtensionMessagesFiles['MagicNoNumberedHeadingsMagic'] = $dir . 'MagicNoNumberedHeadings.i18n.magic.php';

$wgHooks['ParserBeforeInternalParse'][] = 'MagicNoNumberedHeadingsParserBeforeInternalParse';
$wgHooks['BeforePageDisplay'][] = 'MagicNoNumberedTOC';

function MagicNoNumberedHeadingsParserBeforeInternalParse($parser, $text, $stripState)
{
	if (MagicWord::get( 'MAG_NONUMBEREDHEADINGS' )->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 (!isset($out->mNumberHeadings) || !$out->mNumberHeadings) $out->addScript('<style type="text/css"><!-- .tocnumber {display:none;} --></style>');
 
        return true;
}

Magic Word is Displayed[edit]

Installed and running, no problems, headings are removed. However the magic word is visible in the article.

Product Version

  • MediaWiki 1.21.1
  • PHP 5.5.0 (cgi-fcgi)
  • MySQL 5.0.24-community-nt-log

The matchandremove function appears to be failing to spot it. --Hoggle42 (talk) 09:39, 26 February 2014 (UTC)

You have to add & to the parameters of the function MagicNoNumberedHeadingsParserBeforeInternalParse

function MagicNoNumberedHeadingsParserBeforeInternalParse(&$parser, &$text, &$stripState)
that did it, thanks, mysterious stranger :) --Hoggle42 (talk) 15:12, 23 October 2014 (UTC)

Solution for this extension to work with MW1.30[edit]

In MagicNoNumberedHeadings.php, you must replace the MagicNoNumberedHeadingsInternalParseBeforeLinks function with this code :

function MagicNoNumberedHeadingsInternalParseBeforeLinks(&$parser, &$text, &$stripState)
{
	if (MagicWord::get( 'MAG_NONUMBEREDHEADINGS' )->matchAndRemove( $text ) ) {
		$parser->mOptions->setNumberHeadings(FALSE);
	}	
	return true;
}

--Megajoule (talk) 16:39, 29 April 2018 (UTC)