Hi,
I don't create a parser extension, but on special pages you output a text with $wgOut->addWiki( '<wikitext>' ); or $wgOut->addHtml( '<html text>' );
Viele Grüße Jan
-----Ursprüngliche Nachricht----- Von: mediawiki-l-bounces@lists.wikimedia.org [mailto:mediawiki-l-bounces@lists.wikimedia.org] Im Auftrag von Ross McKay Gesendet: Samstag, 31. Juli 2010 09:20 An: alok.watve@gmail.com Cc: MediaWiki announcements and site admin list Betreff: Re: [Mediawiki-l] Help with "Hello World" extension
G'day Alok,
Thanks for the reply. I did correct that but that does not solve the problem. I created a small page which has only one line
{{#SayHello:John}}
I was expecting the page to display "Hello John" But instead it displayed the same line. I am not sure why is this happening.
Firstly, when testing extensions don't forget to append ?action=purge to URLs to make sure that MediaWiki executes your code again. If you've already worked out the way to fix your code and it's not having any effect, maybe this is your problem!
Now, I actually looked above the last two lines of code this time and saw that you're trying to directly access the parser global object. I don't know if that will even work, but the correct way to approach this is to use event hooks to install your parser function, as per the example you linked to.
Try this code, which is a slight reworking of your code to use event hooks to install the parser function:
<?php
if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' );
$wgExtensionCredits['SayHello'][] = array( 'name' => 'SayHello', 'author' => 'Alok', 'url' => '', 'description' => 'Extension that greets user', 'descriptionmsg' => 'This is a test extension', 'version' => '1.0.0', );
// create hooks for initialising your parser function $wgHooks['ParserFirstCallInit'][] = "SayHello_init"; $wgHooks['LanguageGetMagic'][] = "SayHello_magic";
// hook your parser function on the parser init event function SayHello_init( &$parser ) { $parser->setFunctionHook('SayHello', 'SayHello'); return TRUE; }
// add your magic word(s) function SayHello_magic( &$magicWords, $langCode ) { $magicWords['SayHello'] = array(0, 'SayHello'); return TRUE; }
// your parser function function SayHello($parser, $userNameInput = '') { return "Hello " . $userNameInput; }