wfLoadExtension

这个提交包含在:
jmnote 2017-06-12 02:11:02 +09:00
父节点 3213757a63
当前提交 788734105c
共有 5 个文件被更改,包括 91 次插入77 次删除

查看文件

@ -1,46 +0,0 @@
<?php
class SimpleMathJax {
static function init() {
global $wgParser, $wgSimpleMathJaxChem;
$wgParser->setHook( 'math', 'SimpleMathJax::renderMath' );
if( $wgSimpleMathJaxChem )
$wgParser->setHook( 'chem', 'SimpleMathJax::renderChem' );
}
static function renderMath($tex) {
$tex = str_replace('\>', '\;', $tex);
$tex = str_replace('<', '\lt ', $tex);
$tex = str_replace('>', '\gt ', $tex);
return self::renderTex($tex);
}
static function renderChem($tex) {
$tex = '\ce{'.$tex.'}';
return self::renderTex($tex);
}
static function renderTex($tex) {
return ["<span class='mathjax-wrapper'>[math]${tex}[/math]</span>", 'markerType'=>'nowiki'];
}
static function addScripts( $out ) {
global $wgSimpleMathJaxSize, $wgSimpleMathJaxChem, $wgSimpleMathJaxJs, $wgSimpleMathJaxChemJs;
if( !$wgSimpleMathJaxJs )
$wgSimpleMathJaxJs = '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
if( !$wgSimpleMathJaxChemJs )
$wgSimpleMathJaxChemJs = '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/extensions/TeX/mhchem.js';
$out->addScript( <<<HEREDOC
<style>.mathjax-wrapper{display:none;font-size:${wgSimpleMathJaxSize}%;}.MathJax_Display{display:inline !important;}</style>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({"messageStyle":"none","tex2jax":{"preview":"none","displayMath":[["[math]","[/math]"]]}});
MathJax.Hub.Queue(function(){\$(".mathjax-wrapper").show();});</script>
<script src="${wgSimpleMathJaxJs}"></script>
HEREDOC
);
if( $wgSimpleMathJaxChem )
$out->addScript( "<script src='${wgSimpleMathJaxChemJs}'></script>" );
return true;
}
}

查看文件

@ -1,32 +1,11 @@
<?php
/**
* MediaWiki extension to render TeX
* Installation instructions can be found on
* http://www.mediawiki.org/wiki/Extension:SimpleMathJax
*
* @ingroup Extensions
* @author Jmkim dot com
* @license GNU Public License
*/
// Exit if called outside of MediaWiki
if( !defined( 'MEDIAWIKI' ) ) exit;
// Global Settings
$wgSimpleMathJaxSize = 100;
$wgSimpleMathJaxChem = false;
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'SimpleMathJax',
'version' => '0.5',
'author' => 'jmnote, vedmaka, jamesmontalvo3, badshah400',
'description' => 'render TeX between <nowiki><math></nowiki> and <nowiki></math></nowiki>',
'url' => '//www.mediawiki.org/wiki/Extension:SimpleMathJax'
);
// Register class
$dir = dirname(__FILE__) . '/';
$wgAutoloadClasses['SimpleMathJax'] = $dir.'SimpleMathJax.class.php';
$wgExtensionFunctions[] = 'SimpleMathJax::init';
$wgHooks['BeforePageDisplay'][] = 'SimpleMathJax::addScripts';
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'SimpleMathJax' );
wfWarn(
'Deprecated PHP entry point used for SimpleMathJax extension. Please use wfLoadExtension ' .
'instead, see https://www.mediawiki.org/wiki/Extension_registration for more details.'
);
return true;
} else {
die( 'This version of the SimpleMathJax extension requires MediaWiki 1.25+' );
}

37
SimpleMathJax_body.php 普通文件
查看文件

@ -0,0 +1,37 @@
<?php
class SimpleMathJax {
public static function onRegistration() {
global $wgExtensionFunctions;
$wgExtensionFunctions[] = __CLASS__ . '::loadModule';
Hooks::register( 'ParserFirstCallInit', __CLASS__ . '::onParserFirstCallInit' );
}
public static function loadModule() {
global $wgOut, $wgSimpleMathJaxSize;
$wgOut->addJsConfigVars( 'wgSimpleMathJaxSize', $wgSimpleMathJaxSize );
$wgOut->addModules( 'ext.SimpleMathJax' );
}
public static function onParserFirstCallInit( Parser $parser ) {
$parser->setHook( 'math', __CLASS__ . '::renderMath' );
$parser->setHook( 'chem', __CLASS__ . '::renderChem' );
}
public static function renderMath($tex) {
$tex = str_replace('\>', '\;', $tex);
$tex = str_replace('<', '\lt ', $tex);
$tex = str_replace('>', '\gt ', $tex);
return self::renderTex($tex);
}
public static function renderChem($tex) {
$tex = '\ce{'.$tex.'}';
return self::renderTex($tex);
}
public static function renderTex($tex) {
return ["<span style='display:none'>[math]${tex}[/math]</span>", 'markerType'=>'nowiki'];
}
}

12
ext.SimpleMathJax.js 普通文件
查看文件

@ -0,0 +1,12 @@
MathJax.Ajax.config.root = mw.config.get('wgExtensionAssetsPath') + '/SimpleMathJax/MathJax';
MathJax.Hub.Config({
"messageStyle": "none",
"HTML-CSS": { scale: mw.config.get('wgSimpleMathJaxSize') },
"tex2jax": {
"preview": "none",
"inlineMath": [["[math]","[/math]"]]
}
});
MathJax.Hub.Queue( function() {
$(".MathJax").parent().show();
});

32
extension.json 普通文件
查看文件

@ -0,0 +1,32 @@
{
"name": "SimpleMathJax",
"version": "0.6",
"author": [
"jmnote", "vedmaka", "jamesmontalvo3", "badshah400"
],
"url": "http://www.mediawiki.org/wiki/Extension:SimpleMathJax",
"description": "render TeX between <code>&lt;math&gt;</code> and <code>&lt;/math&gt;</nowiki></code>",
"license-name": "GPL-2.0+",
"type": "parserhook",
"AutoloadClasses": {
"SimpleMathJax": "SimpleMathJax_body.php"
},
"callback": "SimpleMathJax::onRegistration",
"config": {
"SimpleMathJaxSize": 125
},
"ResourceModules": {
"ext.SimpleMathJax": {
"scripts": [
"MathJax/MathJax.js",
"ext.SimpleMathJax.js",
"MathJax/config/TeX-AMS-MML_HTMLorMML.js",
"MathJax-mhchem/mhchem.js"
]
}
},
"ResourceFileModulePaths": {
"localBasePath": "",
"remoteExtPath": "SimpleMathJax"
}
}