-
Notifications
You must be signed in to change notification settings - Fork 1
/
math_editor.php
70 lines (61 loc) · 2.31 KB
/
math_editor.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
if (!defined('MEDIAWIKI')) {
die("This file is part of MediaWiki and is not a valid entry point\n");
}
$myRedirectPng = "/extensions/mathEditor/myRedirect.png";
$wgHooks['EditPage::showEditForm:initial'][] = 'mathEditor';
$wgHooks['EditPageBeforeEditToolbar'][] = 'addMathButton';
$wgExtensionCredits['mathEditor'][] = array(
'name' => 'my Redirect Button Extension',
'version' => '1.0.0',
'author' => 'Muhammad Al-Syrwan',
'url' => 'https://github.com/wikitechie/mediawikiMathEditor',
'description' => 'This extension adds a Latex editor using codecogs');
function getEditorHTML() {
$html = <<< EDITOR
<script type='text/javascript' src='http://latex.codecogs.com/js/eq_editor-lite-11.js' ></script>
<div style='border:1px solid gray; clear:both;'>
<div id="editor" style=""></div>
<table style='width:100%'>
<tr><td>
<textarea id="mathtestbox" style = "resize:none;"></textarea>
</td><td>
==>
<img style='padding-left:10px' id="equation" />
</td></tr>
</table>
<script type="text/javascript">
EqEditor.embed('editor','things','mini','en-us')
var a=new EqTextArea('equation', 'mathtestbox');
EqEditor.add(a,false);
</script>
</div>
EDITOR;
return $html;
}
function addMathButton(&$toolbar) {
//global $myRedirectPng;
$toolbar = str_replace('</div>', "<a onclick='writeMath()'>Insert Latex</a></div>", $toolbar);
return true;
}
// Add a button to the internal editor
function mathEditor($editPage) {
global $wgOut, $wgScriptPath, $myRedirectPng;
$wgOut->addLink(array(
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => 'http://latex.codecogs.com/css/equation-embed.css'
));
$editorHTML = getEditorHTML();
$editPage->editFormTextTop .= $editorHTML;
// Insert javascript script that hooks up to create button.
$wgOut->addScript("<script type='text/javascript' src='http://latex.codecogs.com/js/eq_config.js' ></script>");
$wgOut->addScript("<script type='text/javascript' >function getMathText() { var box = document.getElementById('mathtestbox'); return box.value;}</script>");
$wgOut->addScript("<script type=\"text/javascript\">\n" .
"function writeMath(){\n" .
" insertTags('<math>','</math>',getMathText());" .
" }\n" .
"</script>");
return true;
}
?>