-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiki_plugin.php
27 lines (26 loc) · 1.13 KB
/
wiki_plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
use MediaWiki\Shell\Shell;
use MediaWiki\MediaWikiServices;
class Argdown {
public static function onParserFirstCallInit( Parser $parser ) {
$parser->setHook( 'Argdown', array( __CLASS__, 'argdownRender' ) );
return true;
}
public static function onBeforePageDisplay( OutputPage $out ) {
$out->addModules( [ 'ext.Argdown' ]);
}
static function argdownRender( $input, array $args, Parser $parser, PPFrame $frame )
{
global $IP, $wgExtensionAssetsPath;
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'Argdown' );
$nodePath = $config->get( 'NodeJsPath' );
if (!file_exists($nodePath)) return "<h1 style='color: maroon'>Can't find Node.js path. Please see README.md for your Argdown plugin.</h1>";
$result = Shell::command( $nodePath, "$IP/extensions/Argdown/wiki-plugin.js", $input, $wgExtensionAssetsPath )->execute();
$stdout = $result->getStdout();
$stderr = $result->getStderr();
if (!empty($stderr)) {
wfDebugLog( 'argdown', "Argdown error: $stderr\n");
}
return $stdout;
}
}