Created
March 31, 2014 20:19
-
-
Save adeel/9901313 to your computer and use it in GitHub Desktop.
A MediaWiki extension which adds support for itex2mml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# itex2mml.php | |
# A MediaWiki extension which adds support for itex2mml. | |
if (!defined('MEDIAWIKI')) die(); | |
$wgExtensionCredits['other'][] = array( | |
'name' => 'itex2mml', | |
'description' => 'Adds support for math via itex2mml.', | |
'version' => '0.1' | |
); | |
$wgHooks['ParserAfterTidy'][] = 'itex2mml_hook'; | |
function itex2mml_hook(&$parser, &$text) { | |
$text = itex2mml($text); | |
return true; | |
} | |
function itex2mml($src) { | |
$file = get_random_filename(); | |
file_put_contents($file, $src); | |
exec("itex2MML < \"" . $file . "\"", $output); | |
$result = join("\n", $output); | |
return $result; | |
} | |
function get_random_filename() { | |
while (true) { | |
$filename = uniqid("itex2mml", true); | |
$filepath = sys_get_temp_dir() . "/" . $filename; | |
if (!file_exists($filepath)) | |
return $filepath; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment