Extension talk:MagicNumberedHeadings/Archive 1

Latest comment: 8 years ago by Пика Пика in topic Error in MW 1.26.2

Mediawiki 1.12 " PHP Notice: Use of undefined constant MAG_NUMBEREDHEADINGS"

edit

although it works just fine, this PHP notice was showing up in the httpd error_log:

PHP Notice:  Use of undefined constant MAG_NUMBEREDHEADINGS 
assumed 'MAG_NUMBEREDHEADINGS' in /var/www/html/wiki/extensions/MagicNumberedHeadings/MagicNumberedHeadings.php 
on line 77 

resolved by editing MagicNumberedHeadings.php line 77 from:

$magicWords[MAG_NUMBEREDHEADINGS]

to

$magicWords['MAG_NUMBEREDHEADINGS']
Product Version
MediaWiki 1.12.0
PHP 5.1.6 (apache2handler)
MySQL 5.0.58

--62.56.165.173 11:21, 1 July 2008 (UTC)Reply

I had this same issue and used the same fix with versions:
Product Version
MediaWiki 1.13.3
PHP 5.2.8 (apache2handler)
MySQL 5.1.30
-- Highland 13:14, 24 December 2008 (UTC)Reply

Seems not to work with v1.13

edit

I just added the extension to my wikis. They all run on v1.13. I recieve the error message:

Use of undefined constant MAG_NUMBEREDHEADINGS - assumed 'MAG_NUMBEREDHEADINGS' in <b>C:\Programme\Wamp\www\w\extensions\MagicNumberedHeadings\MagicNumberedHeadings.php
 Compilation failed: invalid UTF-8 string at offset 3 in <b>C:\Programme\Wamp\www\w\includes\MagicWord.php

Does anyone have an idea?

thanks in advance
best regards
--TurboKanne 11:02, 23 September 2008 (UTC)Reply

Probably those Ü and Ö letters at lines 71 and 74 (cases de and ksh). Delete those lines (just leave the default line), take them in those /** */ brackets for PHP comments (of course NOT the default lines), or replace the respecting magic words for those languages with ones without umlauts. (I chose the second option, and now it works.) -- JörgM 84.156.139.3 20:54, 29 March 2009 (UTC)Reply
And for the first line of the error message try what the users in the thread above have done. -- JörgM 84.156.139.3 20:56, 29 March 2009 (UTC)Reply

Problems with templates

edit

I tried to use __NUMBEREDHEADINGS__ inside a template that is used in several articles. Instead of the headings numbered, i get the text "__NUMBEREDHEADINGS__" . It seems, that the magic word is not "replaced".

If i use __NUMBEREDHEADINGS__ on a standard page it works perfect.

--Planetenxin 14:00, 16 October 2008 (UTC)Reply

The problem is that when the ParserAfterStrip() hook gets called, only the text of the page is available, the template hasn't been expanded yet. Only one hook is available (at least in MW 1.16) that allows a change to the header option before it's too late after all templates have been processed, and that's InternalParseBeforeLinks(). To get MagicNumberedHeadings to work, edit MagicNumberedHeadings.php and make these changes (don't get on me about the remedial patch syntax, I'm doing it for the kids):

... around line 52
REMOVE: $wgHooks['ParserBeforeInternalParse'][] = 'MagicNumberedHeadingsParserBeforeInternalParse';
   ADD: $wgHooks['InternalParseBeforeLinks'][] = 'MagicNumberedHeadingsInternalParseBeforeLinks';

... around line 90
REMOVE: function MagicNumberedHeadingsParserBeforeInternalParse(&$parser, &$text, &$stripState)
   ADD: function MagicNumberedHeadingsInternalParseBeforeLinks(&$parser, &$text, &$stripState)

This applies to a few other extensions I saw, so if you're searching for "why doesn't it work in a template" problems, take a look here too. --Skew 20:30, 21 April 2011 (UTC)

That's terrific! Thanks for the hint. --Nakohdo 18:26, 25 May 2011 (UTC)Reply

NoWiki trick for Special:Version

edit

Putting the whole magic word in MagicNumberedHeadings.php between <nowi>tags like so doesn't seem to work on Special:Version:

<nowiki>__NUMBEREDHEADINGS__</nowiki>

However, putting the tags around only part of the magic word does the trick:

<nowiki>__</nowiki>NUMBEREDHEADINGS__

--Nakohdo 18:12, 25 May 2011 (UTC)Reply

Doesn't seem to work in 1.19

edit

I tried to use this for the first time with 1.19 but it doesn't seem to recognize and replace the magic word. Is anyone using this with a more modern version of Mediawiki?

I made the suggested changes to the script but still no luck.

Thanks!

Konjurer (talk)

Does work as promised on MediaWiki 1.20.2, PHP 5.3.21 (apache2handler) --Nakohdo (talk) 12:28, 8 April 2013 (UTC)Reply

Running in MW 1.21 - changed code

edit

The extension works in MW 1.21. Since I had to change different parts of the code and the code is short, I post the complete file rather than describing the changes individually:

MagicNumberedHeadings.php
<?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 __NUMBEREDHEADINGS__.
 * If an article contains this MagicWord, numbering of the
 * headings is performed regardless of the user preference setting.
 * 
 * How to use:
 * * include this extension in LocalSettings.php: 
 *   require_once($IP.'/extensions/MagicNoNumberedHeadings.php');
 * * Add "__NUMBEREDHEADINGS__" to any article of your choice.
 * 
 * @author Purodha Blissenbach
 * @version $Revision: 1.12
 */
 
if (!defined('MEDIAWIKI')) {
        die("This requires the MediaWiki enviroment.");
}
 
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'MagicNumberedHeadings',
        'version' => '1.12',
        'author' => 'Purodha Blissenbach',
        'url' => 'https://www.mediawiki.org/wiki/Extension:MagicNumberedHeadings',
        'description' => 'Adds MagicWord "<nowiki>__NUMBEREDHEADINGS__</nowiki>"',
);
$dir = dirname(__FILE__) . '/';

$wgExtensionMessagesFiles['MagicNumberedHeadings'] = $dir . 'MagicNumberedHeadings.i18n.php';

$wgHooks['MagicWordMagicWords'][] = 'MagicNumberedHeadingsMagicWordMagicWords';
$wgHooks['MagicWordwgVariableIDs'][] = 'MagicNumberedHeadingsMagicWordwgVariableIDs';
#$wgHooks['ParserBeforeInternalParse'][] = 'MagicNumberedHeadingsParserBeforeInternalParse';
$wgHooks['InternalParseBeforeLinks'][] = 'MagicNumberedHeadingsInternalParseBeforeLinks';
 
function MagicNumberedHeadingsMagicWordMagicWords(&$magicWords)
{
        $magicWords[] = 'MAG_NUMBEREDHEADINGS';
        return true;
}
 
function MagicNumberedHeadingsMagicWordwgVariableIDs(&$wgVariableIDs)
{
        $wgVariableIDs[] = 'MAG_NUMBEREDHEADINGS';
        return true;
}
 
#function MagicNumberedHeadingsParserBeforeInternalParse($parser, $text, $stripState)
function MagicNumberedHeadingsInternalParseBeforeLinks(&$parser, &$text, &$stripState)
{
        if (MagicWord::get( 'MAG_NUMBEREDHEADINGS' )->matchAndRemove( $text ) )
        {
                $parser->mOptions->mNumberHeadings = (TRUE);
        }
        return true;
}
MagicNumberedHeadings.i18n.php
<?php
 
$messages = array();
 
$magicWords = array();
 
$magicWords['en'] = array(
        'MAG_NUMBEREDHEADINGS' => array( 0, '__NUMBEREDHEADINGS__' ),
);
 
$magicWords['de'] = array(
        'MAG_NUMBEREDHEADINGS' => array( 0, '__UEBERSCHRIFTENNUMMERIERUNG__' ), /* not working with Umlaut */
);
 
$magicWords['ksh'] = array(
        'MAG_NUMBEREDHEADINGS' => array( 0, '__OEVVERSCHRIFTENUMMERIERE__' ), /* not working with Umlaut */

);

Kappa (talk) 10:16, 31 March 2014 (UTC)Reply


This changes are working for me thank you! (MediaWiki Version 1.22.4)
Is it planned to add this changes into the regular source?

Peter.scheidegger (talk) 14:53, 3 April 2014 (UTC)Reply


MediaWiki 1.23 -- __NUMBEREDHEADINGS__ won't disappear from the wikipage

edit

I use MagicNumberedHeadings with my MediaWiki 1.23. It works as intended (forces headings numbering on a page), but the magic word __NUMBEREDHEADINGS__ won't disappear from the page, as it used to in 1.21. I've examined the code, but it seems I don't understand all those hooks and stuff good enough. Any help? Another clue (I don't know whether this is important): The problem has appeared after a semi-successful upgrade of Apache 2 (there has been issues with a new format of Apache's config files in Ubuntu 12.04.5 LTS). I upgraded the MediaWiki to 1.23 straight away after I solved the problems with the Apache. I have not noticed exactly when the problem with the magic word appeared. --Пика Пика (talk) 12:06, 4 September 2014 (UTC)Reply

I had the same problem, but I figured out what's wrong. The arguments for the main function are not properly assigned by reference. What's happening is that the function is duplicated the data instead of referring to the main data. Instead, the arguments need to be &$. In other words, the function line should read: function MagicNumberedHeadingsInternalParseBeforeLinks(&$parser, &$text, &$stripState). --Nick2253 (talk) 21:58, 18 September 2014 (UTC)Reply

Does not work in MW 1.26

edit

I keep getting following:

Fatal error: Cannot access private property ParserOptions::$mNumberHeadings in /var/www/w/extensions/MagicNumberedHeadings/MagicNumberedHeadings.php on line 75

This must be because the property mNumberHeadings in ParserOptions.php is private in MW 1.26 instead of public as it was in MW 1.25. Any hacks to make the extension work in MW 1.26?

--Пика Пика (talk) 14:27, 4 February 2016 (UTC)Reply

See the resolution in the next post, which I just made.
Chiefgeek157 (talk) 15:12, 8 February 2016 (UTC)Reply

Error in MW 1.26.2

edit

The code cannot directly access ParserOptions any longer.

$parser->mOptions->mNumberHeadings = (TRUE);

should become

$parser->mOptions->setNumberHeadings(true);

I'd make this change on the main page, but I am unsure of the effect in earlier versions of MW.

Chiefgeek157 (talk) 15:11, 8 February 2016 (UTC)Reply

It seems to work in MW 1.25.2. I'll check it out in MW 1.26. Пика Пика (talk) 08:40, 25 February 2016 (UTC)Reply
Return to "MagicNumberedHeadings/Archive 1" page.