RenéV
This page used the Structured Discussions extension to give structured discussions. It has since been converted to wikitext, so the content and history here are only an approximation of what was actually displayed at the time these comments were made. |
Output wikitext with my home-made extension
editI need some help creating a small extension. I would like to be able to use wikitext in the output of this extension.
Due to the limited experience that I have I am unable to understand the explanation on the help pages here on MediaWiki.
Below is the code as I now have for extension.json and TesT.php. The output that the script currently gives is literally the text as it appears in the script, including the square brackets: This is [[my]] text.
Can someone please provide a simple explanation how to use wikitext?
Thanks.
extension.json:<source> { "name": "TesT", "version": "0.0.0", "author": [ "RenéV" ], "description": "TesT Extension", "type": "parserhook", "requires": { "MediaWiki": ">= 1.32.0" }, "license-name": "GPL-2.0-or-later",
"AutoloadClasses": { "TesTHooks": "TesT.php"
},
"Hooks": { "ParserFirstCallInit": [ "TesTHooks::onParserFirstCallInit" ]
},
"manifest_version": 1 }
</syntaxhighlight>
Test.php:
<?php
use MediaWiki\MediaWikiServices;
class TesTHooks {
public static function onParserFirstCallInit( &$parser ) {
$parser->setHook( 'TesT', 'TesTHooks::renderTesT' );
return true;
}
public static function renderTesT( $input, $args, $mwParser ) {
if ( htmlspecialchars( $input ) == 'test') {
$output = "This is [[my]] text.";
}
return $output;
}
}
RenéV (talk) 20:18, 1 February 2020 (UTC)
- See Manual:Parser functions or Manual:Tag extensions for help with extensions. If you want to support wikitext, I think you will want to use a parser function (
setFunctionHook
) instead of parser tag (setHook
). Krinkle (talk) 18:42, 6 February 2020 (UTC)