forked from wikimedia/mediawiki-extensions-Math
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Math.php
195 lines (170 loc) · 6.56 KB
/
Math.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* MediaWiki math extension
*
* @file
* @ingroup Extensions
* @version 1.0
* @author Tomasz Wegrzanowski
* @author Brion Vibber
* @author Moritz Schubotz
* @copyright © 2002-2012 various MediaWiki contributors
* @license GPLv2 license; info in main package.
* @link http://www.mediawiki.org/wiki/Extension:Math Documentation
* @see https://bugzilla.wikimedia.org/show_bug.cgi?id=14202
*/
if ( !defined( 'MEDIAWIKI' ) ) {
die( "This is not a valid entry point to MediaWiki.\n" );
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Math',
'version' => '1.1',
'author' => array( 'Tomasz Wegrzanowski', 'Brion Vibber', '...' ),
'descriptionmsg' => 'math-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:Math',
);
/**@{
* Maths constants
*/
define( 'MW_MATH_PNG', 0 );
define( 'MW_MATH_SIMPLE', 1 ); /// @deprecated
define( 'MW_MATH_HTML', 2 ); /// @deprecated
define( 'MW_MATH_SOURCE', 3 );
define( 'MW_MATH_MODERN', 4 ); /// @deprecated
define( 'MW_MATH_MATHML', 5 ); /// @deprecated
define( 'MW_MATH_MATHJAX', 6 ); /// new in 1.19/1.20
define( 'MW_MATH_LATEXML', 7 ); /// new in 1.22
/**@}*/
/** For back-compat */
$wgUseTeX = true;
/** Location of the texvc binary */
$wgTexvc = dirname( __FILE__ ) . '/math/texvc';
/**
* Texvc background color
* use LaTeX color format as used in \special function
* for transparent background use value 'Transparent' for alpha transparency or
* 'transparent' for binary transparency.
*/
$wgTexvcBackgroundColor = 'transparent';
/**
* Normally when generating math images, we double-check that the
* directories we want to write to exist, and that files that have
* been generated still exist when we need to bring them up again.
*
* This lets us give useful error messages in case of permission
* problems, and automatically rebuild images that have been lost.
*
* On a big site with heavy NFS traffic this can be slow and flaky,
* so sometimes we want to short-circuit it by setting this to false.
*/
$wgMathCheckFiles = true;
/**
* The URL path of the math directory. Defaults to "{$wgUploadPath}/math".
*
* See http://www.mediawiki.org/wiki/Manual:Enable_TeX for details about how to
* set up mathematical formula display.
*/
$wgMathPath = false;
/**
* The name of a file backend ($wgFileBackends) to use for storing math renderings.
* Defaults to FSFileBackend using $wgMathDirectory as a base path.
*
* See http://www.mediawiki.org/wiki/Manual:Enable_TeX for details about how to
* set up mathematical formula display.
*/
$wgMathFileBackend = false;
/**
* The filesystem path of the math directory.
* Defaults to "{$wgUploadDirectory}/math".
*
* See http://www.mediawiki.org/wiki/Manual:Enable_TeX for details about how to
* set up mathematical formula display.
*/
$wgMathDirectory = false;
/**
* Experimental option to use MathJax library to do client-side math rendering
* when JavaScript is available. In supporting browsers this makes nice output
* that's scalable for zooming, printing, and high-resolution displays.
*
* Not guaranteed to be stable at this time.
*/
$wgUseMathJax = false;
/**
* Use of LaTeXML for details see
* <http://latexml.mathweb.org/help>
*
* If you want or need to run your own server, follow these installation
* instructions and override $wgLaTeXMLUrl:
* <https://svn.mathweb.org/repos/LaTeXML/branches/arXMLiv/INSTALL>
*
* If you expect heavy load you can specify multiple servers. In that case one
* server is randomly chosen for each rendering process. Specify the list of
* servers in an array e.g $wgLaTeXMLUrl = array ( 'http://latexml.example.com/convert',
* 'http://latexml2.example.com/convert');
*/
$wgLaTeXMLUrl = 'http://latexml.mathweb.org/convert';
/**
* Allows to use LaTeXML as renderer for mathematical equation.
*/
$wgUseLaTeXML = false;
/**
* The timeout for the HTTP-Request sent to the LaTeXML to render an equation,
* in seconds.
*/
$wgLaTeXMLTimeout = 240;
/**
* Setting for the LaTeXML renderer.
* See http://dlmf.nist.gov/LaTeXML/manual/commands/latexmlpost.xhtml for details.
*/
$wgDefaultLaTeXMLSetting = 'format=xhtml&whatsin=math&whatsout=math&pmml&cmml&nodefaultresources&preload=LaTeX.pool&preload=article.cls&preload=amsmath.sty&preload=amsthm.sty&preload=amstext.sty&preload=amssymb.sty&preload=eucal.sty&preload=[dvipsnames]xcolor.sty&preload=url.sty&preload=hyperref.sty&preload=[ids]latexml.sty&preload=texvc';
////////// end of config settings.
$wgDefaultUserOptions['math'] = MW_MATH_PNG;
$wgExtensionFunctions[] = 'MathHooks::setup';
$wgHooks['ParserFirstCallInit'][] = 'MathHooks::onParserFirstCallInit';
$wgHooks['GetPreferences'][] = 'MathHooks::onGetPreferences';
$wgHooks['LoadExtensionSchemaUpdates'][] = 'MathHooks::onLoadExtensionSchemaUpdates';
$wgHooks['ParserTestTables'][] = 'MathHooks::onParserTestTables';
$wgHooks['ParserTestParser'][] = 'MathHooks::onParserTestParser';
$wgHooks['UnitTestsList'][] = 'MathHooks::onRegisterUnitTests';
$dir = dirname( __FILE__ ) . '/';
$wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';
$wgAutoloadClasses['MathRenderer'] = $dir . 'MathRenderer.php';
$wgAutoloadClasses['MathTexvc'] = $dir . 'MathTexvc.php';
$wgAutoloadClasses['MathSource'] = $dir . 'MathSource.php';
$wgAutoloadClasses['MathLaTeXML'] = $dir . 'MathLaTeXML.php';
$wgExtensionMessagesFiles['Math'] = $dir . 'Math.i18n.php';
// Hook into EditPage::showEditForm:initial to modify the edit page.
$wgHooks[ 'EditPage::showEditForm:initial' ][] = 'formulaTemplate';
function formulaTemplate($editPage) {
global $wgTitle,$wgOut;
# Only for new pages
if ($wgTitle->exists( $wgTitle->getArticleID() ) ) { return true; }
# Only for formula pages
if (! preg_match("/^Formula\:(.+)$/", $wgTitle,$label)) { return true; }
$dbr = wfGetDB( DB_SLAVE );
$rpage = $dbr->selectRow( 'math', array('math_tex'),
array( 'math_label' => $label[1] ), __METHOD__ );
$content = "== Formula ==\n\n\n<math>".$rpage->math_tex."</math>\n\n";
$content .= "== Proof ==\n\n\n";
$content .= "== Properties ==\n\n\n";
$editPage->textbox1 .= $content;
return true;
}
$wgParserTestFiles[] = $dir . 'mathParserTests.txt';
$moduleTemplate = array(
'localBasePath' => dirname( __FILE__ ) . '/modules',
'remoteExtPath' => 'Math/modules',
);
$wgResourceModules['ext.math.mathjax'] = array(
'scripts' => array(
'MathJax/MathJax.js',
// We'll let the other parts be loaded by MathJax's
// own module/config loader.
),
'group' => 'ext.math.mathjax',
) + $moduleTemplate;
$wgResourceModules['ext.math.mathjax.enabler'] = array(
'scripts' => 'ext.math.mathjax.enabler.js',
) + $moduleTemplate;