2011-04-09 00:39:40 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* MediaWiki math extension
|
|
|
|
*
|
2012-10-27 14:30:50 +00:00
|
|
|
* (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz, and other MediaWiki contributors
|
2011-04-09 00:39:40 +00:00
|
|
|
* GPLv2 license; info in main package.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-05-14 21:49:06 +00:00
|
|
|
* Abstract base class with static methods for rendering the <math> tags using
|
|
|
|
* different technologies. These static methods create a new instance of the
|
2013-04-24 08:21:35 +00:00
|
|
|
* extending classes and render the math tags based on the mode setting of the user.
|
|
|
|
* Furthermore this class handles the caching of the rendered output and provides
|
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
|
|
|
* debug information, if run in mathdebug mode.
|
2011-04-09 00:39:40 +00:00
|
|
|
*
|
2012-10-27 14:30:50 +00:00
|
|
|
* @author Tomasz Wegrzanowski
|
|
|
|
* @author Brion Vibber
|
|
|
|
* @author Moritz Schubotz
|
2011-04-09 00:39:40 +00:00
|
|
|
*/
|
2012-10-27 14:30:50 +00:00
|
|
|
abstract class MathRenderer {
|
2014-05-28 06:00:30 +00:00
|
|
|
|
|
|
|
// REPRESENTATIONS OF THE MATHEMATICAL CONTENT
|
|
|
|
/** @var string tex representation */
|
2013-05-14 21:49:06 +00:00
|
|
|
protected $tex = '';
|
2014-05-28 06:00:30 +00:00
|
|
|
/** @var string MathML content and presentation */
|
|
|
|
protected $mathml = '';
|
|
|
|
/** @var string SVG layout only (no semantics) */
|
|
|
|
protected $svg = '';
|
|
|
|
/** @var string the original user input string (which was used to calculate the inputhash) */
|
2014-01-03 14:29:03 +00:00
|
|
|
protected $userInputTex = '';
|
2014-05-28 06:00:30 +00:00
|
|
|
// FURTHER PROPERTIES OF THE MATHEMATICAL CONTENT
|
2014-03-17 06:14:02 +00:00
|
|
|
/** @var (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) the rendering style */
|
|
|
|
protected $mathStyle = MW_MATHSTYLE_INLINE_DISPLAYSTYLE;
|
2014-05-28 06:00:30 +00:00
|
|
|
/** @var array with userdefined parameters passed to the extension (not used) */
|
|
|
|
protected $params = array();
|
|
|
|
/** @var string a userdefined identifier to link to the equation. */
|
|
|
|
protected $id = '';
|
|
|
|
|
|
|
|
// DEBUG VARIABLES
|
|
|
|
// Available, if Math extension runs in debug mode ($wgMathDebug = true) only.
|
|
|
|
/** @var int LaTeXML return code (will be available in future Mathoid versions as well) */
|
|
|
|
protected $statusCode = 0;
|
|
|
|
/** @var timestamp of the last modification of the database entry */
|
|
|
|
protected $timestamp;
|
|
|
|
/** @var log messages generated during conversion of mathematical content */
|
|
|
|
protected $log = '';
|
2014-11-18 11:40:14 +00:00
|
|
|
/** @var time used for rendering in ms */
|
|
|
|
protected $renderingTime = 0;
|
|
|
|
/** @var post request sent to rendering server (if applicable) */
|
|
|
|
protected $postData = '';
|
2014-05-28 06:00:30 +00:00
|
|
|
|
|
|
|
// STATE OF THE CLASS INSTANCE
|
|
|
|
/** @var boolean has variable tex been security-checked */
|
|
|
|
protected $texSecure = false;
|
|
|
|
/** @var boolean has the mathematical content changed */
|
|
|
|
protected $changed = false;
|
|
|
|
/** @var boolean is there a database entry for the mathematical content */
|
|
|
|
protected $storedInDatabase = null;
|
|
|
|
/** @var boolean is there a request to purge the existing mathematical content */
|
|
|
|
protected $purge = false;
|
|
|
|
/** @var string with last occurred error */
|
|
|
|
protected $lastError = '';
|
|
|
|
/** @var string md5 value from userInputTex */
|
|
|
|
protected $md5 = '';
|
|
|
|
/** @var binary packed inputhash */
|
|
|
|
protected $inputHash = '';
|
|
|
|
/** @var int rendering mode MW_MATH_(PNG|MATHML|SOURCE...) */
|
|
|
|
protected $mode = MW_MATH_PNG;
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Constructs a base MathRenderer
|
|
|
|
*
|
2013-04-24 08:21:35 +00:00
|
|
|
* @param string $tex (optional) LaTeX markup
|
|
|
|
* @param array $params (optional) HTML attributes
|
2012-10-27 14:30:50 +00:00
|
|
|
*/
|
2013-05-14 21:49:06 +00:00
|
|
|
public function __construct( $tex = '', $params = array() ) {
|
2014-01-03 14:29:03 +00:00
|
|
|
$this->userInputTex = $tex;
|
2011-04-09 00:39:40 +00:00
|
|
|
$this->tex = $tex;
|
|
|
|
$this->params = $params;
|
2014-07-22 22:42:48 +00:00
|
|
|
if ( isset( $params['id'] ) ) {
|
|
|
|
$this->id = $params['id'];
|
|
|
|
}
|
2012-04-06 15:19:12 +00:00
|
|
|
}
|
2011-04-09 00:39:40 +00:00
|
|
|
|
2012-08-20 22:11:16 +00:00
|
|
|
/**
|
2012-10-27 14:30:50 +00:00
|
|
|
* Static method for rendering math tag
|
|
|
|
*
|
|
|
|
* @param string $tex LaTeX markup
|
|
|
|
* @param array $params HTML attributes
|
|
|
|
* @param int $mode constant indicating rendering mode
|
|
|
|
* @return string HTML for math tag
|
2012-08-20 22:11:16 +00:00
|
|
|
*/
|
2012-10-27 14:30:50 +00:00
|
|
|
public static function renderMath( $tex, $params = array(), $mode = MW_MATH_PNG ) {
|
2013-02-16 12:38:02 +00:00
|
|
|
$renderer = self::getRenderer( $tex, $params, $mode );
|
2014-06-05 21:06:43 +00:00
|
|
|
if ( $renderer->render() ) {
|
|
|
|
return $renderer->getHtmlOutput();
|
|
|
|
} else {
|
|
|
|
return $renderer->getLastError();
|
|
|
|
}
|
2012-08-20 22:11:16 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 11:14:56 +00:00
|
|
|
/**
|
|
|
|
*
|
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
|
|
|
* @param string $md5
|
2014-06-10 11:14:56 +00:00
|
|
|
* @return MathRenderer the MathRenderer generated from md5
|
|
|
|
*/
|
|
|
|
public static function newFromMd5( $md5 ) {
|
|
|
|
$class = get_called_class();
|
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
|
|
|
/** @var MathRenderer $instance */
|
2014-06-10 11:14:56 +00:00
|
|
|
$instance = new $class;
|
|
|
|
$instance->setMd5( $md5 );
|
|
|
|
$instance->readFromDatabase();
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Static factory method for getting a renderer based on mode
|
|
|
|
*
|
|
|
|
* @param string $tex LaTeX markup
|
|
|
|
* @param array $params HTML attributes
|
|
|
|
* @param int $mode constant indicating rendering mode
|
|
|
|
* @return MathRenderer appropriate renderer for mode
|
|
|
|
*/
|
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
|
|
|
public static function getRenderer( $tex, $params = array(), $mode = MW_MATH_PNG ) {
|
2014-06-10 11:18:26 +00:00
|
|
|
global $wgDefaultUserOptions, $wgMathValidModes, $wgMathEnableExperimentalInputFormats;
|
2014-03-17 06:14:02 +00:00
|
|
|
$mathStyle = null;
|
|
|
|
if ( isset( $params['display'] ) ) {
|
|
|
|
$layoutMode = $params['display'];
|
|
|
|
if ( $layoutMode == 'block' ) {
|
|
|
|
$mathStyle = MW_MATHSTYLE_DISPLAY ;
|
|
|
|
// TODO: Implement caching for attributes of the math tag
|
|
|
|
// Currently the key for the database entry relating to an equation
|
|
|
|
// is md5($tex) the new option to determine if the tex input
|
|
|
|
// is rendered in displaystyle or textstyle would require a database
|
|
|
|
// layout change to use a composite key e.g. (md5($tex),$mathStyle).
|
|
|
|
// As a workaround we use the prefix \displaystyle so that the key becomes
|
|
|
|
// md5((\{\\displaystyle|\{\\textstyle)?\s?$tex\}?)
|
|
|
|
// The new value of $tex string describes now how the rendering should look like.
|
|
|
|
// The variable MathRenderer::mathStyle determines if the rendered equation should
|
|
|
|
// be centered in a new line, or just in be displayed in the current line.
|
|
|
|
$tex = '{\displaystyle ' . $tex . '}';
|
|
|
|
} elseif ( $layoutMode == 'inline' ) {
|
|
|
|
$mathStyle = MW_MATHSTYLE_INLINE;
|
|
|
|
$tex = '{\textstyle ' . $tex . '}';
|
|
|
|
}
|
|
|
|
}
|
2014-07-22 22:42:48 +00:00
|
|
|
|
2014-06-10 11:18:26 +00:00
|
|
|
if ( isset( $params['forcemathmode'] ) ) {
|
|
|
|
$mode = $params['forcemathmode'];
|
|
|
|
}
|
2014-04-08 13:57:15 +00:00
|
|
|
if ( !in_array( $mode, $wgMathValidModes ) ) {
|
2012-10-27 14:30:50 +00:00
|
|
|
$mode = $wgDefaultUserOptions['math'];
|
2014-04-08 13:57:15 +00:00
|
|
|
}
|
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
|
|
|
if ( $wgMathEnableExperimentalInputFormats === true && $mode == MW_MATH_MATHML && isset( $params['type'] ) ) {
|
2014-06-10 11:18:26 +00:00
|
|
|
// Support of MathML input (experimental)
|
|
|
|
// Currently support for mode MW_MATH_MATHML only
|
|
|
|
if( !in_array( $params['type'], array( 'pmml', 'ascii' ) ) ) {
|
|
|
|
unset( $params['type'] );
|
|
|
|
}
|
|
|
|
}
|
2012-10-27 14:30:50 +00:00
|
|
|
switch ( $mode ) {
|
2013-09-09 10:07:18 +00:00
|
|
|
case MW_MATH_MATHJAX:
|
2012-10-27 14:30:50 +00:00
|
|
|
case MW_MATH_SOURCE:
|
|
|
|
$renderer = new MathSource( $tex, $params );
|
|
|
|
break;
|
2014-06-10 16:49:20 +00:00
|
|
|
case MW_MATH_PNG:
|
|
|
|
$renderer = new MathTexvc( $tex, $params );
|
|
|
|
break;
|
2013-05-14 21:49:06 +00:00
|
|
|
case MW_MATH_LATEXML:
|
|
|
|
$renderer = new MathLaTeXML( $tex, $params );
|
|
|
|
break;
|
2014-06-10 16:49:20 +00:00
|
|
|
case MW_MATH_MATHML:
|
2012-10-27 14:30:50 +00:00
|
|
|
default:
|
2014-06-10 16:49:20 +00:00
|
|
|
$renderer = new MathMathML( $tex, $params );
|
2011-11-28 22:30:33 +00:00
|
|
|
}
|
2013-05-14 21:49:06 +00:00
|
|
|
wfDebugLog ( "Math", 'start rendering $' . $renderer->tex . '$ in mode ' . $mode );
|
2014-03-17 06:14:02 +00:00
|
|
|
$renderer->setMathStyle( $mathStyle );
|
2012-10-27 14:30:50 +00:00
|
|
|
return $renderer;
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
2014-06-05 21:06:43 +00:00
|
|
|
* Performs the rendering
|
2012-10-27 14:30:50 +00:00
|
|
|
*
|
2014-06-05 21:06:43 +00:00
|
|
|
* @return boolean if rendering was successful.
|
2012-10-27 14:30:50 +00:00
|
|
|
*/
|
|
|
|
abstract public function render();
|
2011-04-09 00:39:40 +00:00
|
|
|
|
2014-06-05 21:06:43 +00:00
|
|
|
/**
|
|
|
|
* @return string Html output that is embedded in the page
|
|
|
|
*/
|
|
|
|
abstract public function getHtmlOutput();
|
2013-04-24 08:21:35 +00:00
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
2013-04-24 08:21:35 +00:00
|
|
|
* texvc error messages
|
|
|
|
* TODO: update to MathML
|
2012-10-27 14:30:50 +00:00
|
|
|
* Returns an internationalized HTML error string
|
|
|
|
*
|
|
|
|
* @param string $msg message key for specific error
|
2014-02-09 19:02:15 +00:00
|
|
|
* @internal param \Varargs $parameters (optional) zero or more message parameters for specific error
|
2012-10-27 14:30:50 +00:00
|
|
|
* @return string HTML error string
|
|
|
|
*/
|
2014-01-03 14:29:03 +00:00
|
|
|
public function getError( $msg /*, ... */ ) {
|
2012-09-07 17:43:09 +00:00
|
|
|
$mf = wfMessage( 'math_failure' )->inContentLanguage()->escaped();
|
2013-05-17 07:30:51 +00:00
|
|
|
$parameters = func_get_args();
|
|
|
|
array_shift( $parameters );
|
|
|
|
$errmsg = wfMessage( $msg, $parameters )->inContentLanguage()->escaped();
|
2011-04-09 00:39:40 +00:00
|
|
|
$source = htmlspecialchars( str_replace( "\n", ' ', $this->tex ) );
|
2014-02-19 18:04:07 +00:00
|
|
|
return "<strong class='error texerror'>$mf ($errmsg): $source</strong>\n";
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* Return hash of input
|
|
|
|
*
|
|
|
|
* @return string hash
|
|
|
|
*/
|
|
|
|
public function getMd5() {
|
|
|
|
if ( ! $this->md5 ) {
|
|
|
|
$this->md5 = md5( $this->userInputTex );
|
|
|
|
}
|
|
|
|
return $this->md5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the input hash (if user input tex is not available)
|
|
|
|
* @param $md5
|
|
|
|
* @return string hash
|
|
|
|
*/
|
|
|
|
public function setMd5( $md5 ) {
|
|
|
|
$this->md5 = $md5;
|
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Return hash of input
|
|
|
|
*
|
|
|
|
* @return string hash
|
|
|
|
*/
|
|
|
|
public function getInputHash() {
|
|
|
|
// TODO: What happens if $tex is empty?
|
2014-05-28 06:00:30 +00:00
|
|
|
if ( !$this->inputHash ) {
|
2014-05-28 19:31:41 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2014-05-28 06:00:30 +00:00
|
|
|
return $dbr->encodeBlob( pack( "H32", $this->getMd5() ) ); # Binary packed, not hex
|
2014-05-28 19:31:41 +00:00
|
|
|
}
|
2014-05-28 06:00:30 +00:00
|
|
|
return $this->inputHash;
|
|
|
|
}
|
|
|
|
|
2014-05-28 19:31:41 +00:00
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* Decode binary packed hash from the database to md5 of input_tex
|
|
|
|
* @param binary $hash
|
|
|
|
* @return string md5
|
|
|
|
*/
|
2014-11-20 17:15:40 +00:00
|
|
|
public static function dbHash2md5( $hash ) {
|
2014-05-28 06:00:30 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
|
|
|
$xhash = unpack( 'H32md5', $dbr->decodeBlob( $hash ) . " " );
|
|
|
|
return $xhash['md5'];
|
2012-10-27 14:30:50 +00:00
|
|
|
}
|
2011-04-09 00:39:40 +00:00
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Reads rendering data from database
|
|
|
|
*
|
|
|
|
* @return boolean true if read successfully, false otherwise
|
|
|
|
*/
|
2013-04-24 06:01:53 +00:00
|
|
|
public function readFromDatabase() {
|
2014-05-28 06:00:30 +00:00
|
|
|
/** @var DatabaseBase */
|
2011-04-09 00:39:40 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2014-09-06 01:59:13 +00:00
|
|
|
/** @var ResultWrapper */
|
2014-05-28 19:31:41 +00:00
|
|
|
$rpage = $dbr->selectRow( $this->getMathTableName(),
|
|
|
|
$this->dbInArray(),
|
|
|
|
array( 'math_inputhash' => $this->getInputHash() ),
|
|
|
|
__METHOD__ );
|
2012-10-27 14:30:50 +00:00
|
|
|
if ( $rpage !== false ) {
|
2013-09-19 00:37:35 +00:00
|
|
|
$this->initializeFromDatabaseRow( $rpage );
|
2014-05-28 19:31:41 +00:00
|
|
|
$this->storedInDatabase = true;
|
2013-05-14 21:49:06 +00:00
|
|
|
return true;
|
2014-05-28 19:31:41 +00:00
|
|
|
} else {
|
2014-05-27 04:46:53 +00:00
|
|
|
# Missing from the database and/or the render cache
|
2014-05-28 19:31:41 +00:00
|
|
|
$this->storedInDatabase = false;
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|
2013-09-19 00:37:35 +00:00
|
|
|
/**
|
2014-05-28 19:31:41 +00:00
|
|
|
* @return array with the database column names
|
2013-09-19 00:37:35 +00:00
|
|
|
*/
|
2014-05-28 19:31:41 +00:00
|
|
|
protected function dbInArray() {
|
|
|
|
$in = array( 'math_inputhash',
|
|
|
|
'math_mathml',
|
|
|
|
'math_inputtex',
|
|
|
|
'math_tex',
|
|
|
|
'math_svg'
|
|
|
|
);
|
|
|
|
return $in;
|
2013-09-19 00:37:35 +00:00
|
|
|
}
|
2011-04-09 00:39:40 +00:00
|
|
|
|
2013-09-19 00:37:35 +00:00
|
|
|
/**
|
2014-05-28 19:31:41 +00:00
|
|
|
* Reads the values from the database but does not overwrite set values with empty values
|
|
|
|
* @param database_row $rpage
|
2013-09-19 00:37:35 +00:00
|
|
|
*/
|
2014-05-28 19:31:41 +00:00
|
|
|
protected function initializeFromDatabaseRow( $rpage ) {
|
|
|
|
$this->inputHash = $rpage->math_inputhash; // MUST NOT BE NULL
|
|
|
|
$this->md5 = self::dbHash2md5( $this->inputHash );
|
|
|
|
if ( ! empty( $rpage->math_mathml ) ) {
|
|
|
|
$this->mathml = utf8_decode( $rpage->math_mathml );
|
|
|
|
}
|
|
|
|
if ( ! empty( $rpage->math_inputtex ) ) { // in the current database the field is probably not set.
|
|
|
|
$this->userInputTex = $rpage->math_inputtex;
|
|
|
|
}
|
|
|
|
if ( ! empty( $rpage->math_tex ) ) {
|
|
|
|
$this->tex = $rpage->math_tex;
|
|
|
|
}
|
|
|
|
if ( ! empty( $rpage->math_svg ) ) {
|
|
|
|
$this->svg = $rpage->math_svg;
|
|
|
|
}
|
|
|
|
$this->changed = false;
|
2013-09-19 00:37:35 +00:00
|
|
|
}
|
2014-05-28 19:31:41 +00:00
|
|
|
|
2011-04-09 00:39:40 +00:00
|
|
|
/**
|
2013-04-24 08:21:35 +00:00
|
|
|
* Writes rendering entry to database.
|
|
|
|
*
|
|
|
|
* WARNING: Use writeCache() instead of this method to be sure that all
|
|
|
|
* renderer specific (such as squid caching) are taken into account.
|
|
|
|
* This function stores the values that are currently present in the class to the database even if they are empty.
|
|
|
|
*
|
|
|
|
* This function can be seen as protected function.
|
2014-05-28 06:00:30 +00:00
|
|
|
* @param DatabaseBase $dbw
|
2011-04-09 00:39:40 +00:00
|
|
|
*/
|
2013-09-19 00:37:35 +00:00
|
|
|
public function writeToDatabase( $dbw = null ) {
|
2014-05-28 19:31:41 +00:00
|
|
|
global $wgMathDebug;
|
2012-10-27 14:30:50 +00:00
|
|
|
# Now save it back to the DB:
|
|
|
|
if ( !wfReadOnly() ) {
|
2014-02-09 19:02:15 +00:00
|
|
|
$dbw = $dbw ? : wfGetDB( DB_MASTER );
|
2014-05-28 06:00:30 +00:00
|
|
|
wfDebugLog( "Math", 'store entry for $' . $this->tex . '$ in database (hash:' . $this->getMd5() . ")\n" );
|
2013-09-19 00:37:35 +00:00
|
|
|
$outArray = $this->dbOutArray();
|
2014-05-28 19:31:41 +00:00
|
|
|
$method = __METHOD__;
|
|
|
|
$mathTableName = $this->getMathTableName();
|
|
|
|
if ( $this->isInDatabase() ) {
|
|
|
|
$inputHash = $this->getInputHash();
|
|
|
|
$dbw->onTransactionIdle(
|
|
|
|
function() use( $dbw, $outArray, $wgMathDebug, $inputHash, $method, $mathTableName ) {
|
|
|
|
$dbw->update( $mathTableName, $outArray , array( 'math_inputhash' => $inputHash ), $method );
|
|
|
|
if ( $wgMathDebug ) wfDebugLog( "Math", 'Row updated after db transaction was idle: ' . var_export( $outArray , true ) . " to database \n" );
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
$dbw->onTransactionIdle(
|
|
|
|
function() use( $dbw, $outArray, $wgMathDebug, $method, $mathTableName ) {
|
|
|
|
$dbw->insert( $mathTableName, $outArray, $method , array ( 'IGNORE' ) );
|
|
|
|
if ( $wgMathDebug ) {
|
|
|
|
wfDebugLog( "Math", 'Row inserted after db transaction was idle ' . var_export( $outArray , true ) . " to database \n" );
|
|
|
|
if ( $dbw->affectedRows() == 0 ) {
|
|
|
|
// That's the price for the delayed update.
|
|
|
|
wfDebugLog( "Math", 'Entry could not be written. Might be changed in between. ' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2013-09-19 00:37:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array that matches the variables of the class to the database columns
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-05-28 19:31:41 +00:00
|
|
|
protected function dbOutArray() {
|
|
|
|
$out = array( 'math_inputhash' => $this->getInputHash(),
|
|
|
|
'math_mathml' => utf8_encode( $this->mathml ),
|
|
|
|
'math_inputtex' => $this->userInputTex,
|
|
|
|
'math_tex' => $this->tex,
|
|
|
|
'math_svg' => $this->svg
|
|
|
|
);
|
2013-09-19 00:37:35 +00:00
|
|
|
return $out;
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Returns sanitized attributes
|
|
|
|
*
|
|
|
|
* @param string $tag element name
|
|
|
|
* @param array $defaults default attributes
|
|
|
|
* @param array $overrides attributes to override defaults
|
|
|
|
* @return array HTML attributes
|
|
|
|
*/
|
|
|
|
protected function getAttributes( $tag, $defaults = array(), $overrides = array() ) {
|
2011-04-09 00:39:40 +00:00
|
|
|
$attribs = Sanitizer::validateTagAttributes( $this->params, $tag );
|
|
|
|
$attribs = Sanitizer::mergeAttributes( $defaults, $attribs );
|
|
|
|
$attribs = Sanitizer::mergeAttributes( $attribs, $overrides );
|
|
|
|
return $attribs;
|
|
|
|
}
|
2013-05-14 21:49:06 +00:00
|
|
|
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
2013-09-19 00:37:35 +00:00
|
|
|
* Writes cache. Writes the database entry if values were changed
|
2012-10-27 14:30:50 +00:00
|
|
|
*/
|
|
|
|
public function writeCache() {
|
2014-05-28 19:31:41 +00:00
|
|
|
global $wgMathDebug;
|
|
|
|
if ( $wgMathDebug) wfDebugLog( "Math" , "writing of cache requested." );
|
2013-09-19 00:37:35 +00:00
|
|
|
if ( $this->isChanged() ) {
|
2014-05-28 19:31:41 +00:00
|
|
|
if ( $wgMathDebug) wfDebugLog( "Math" , "Change detected. Perform writing." );
|
2013-09-19 00:37:35 +00:00
|
|
|
$this->writeToDatabase();
|
2014-05-28 19:31:41 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if ( $wgMathDebug) wfDebugLog( "Math" , "Nothing was changed. Don't write to database." );
|
|
|
|
return false;
|
2013-09-19 00:37:35 +00:00
|
|
|
}
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 14:30:50 +00:00
|
|
|
/**
|
|
|
|
* Gets TeX markup
|
|
|
|
*
|
|
|
|
* @return string TeX markup
|
|
|
|
*/
|
|
|
|
public function getTex() {
|
|
|
|
return $this->tex;
|
2011-04-09 00:39:40 +00:00
|
|
|
}
|
2013-04-25 17:07:25 +00:00
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* gets the timestamp, of the last rendering of that equation
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getTimestamp() {
|
|
|
|
return $this->timestamp;
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:07:25 +00:00
|
|
|
/**
|
|
|
|
* gets the rendering mode MW_MATH_*
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getMode() {
|
|
|
|
return $this->mode;
|
|
|
|
}
|
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* Sets the rendering mode
|
|
|
|
* @param int $newMode element of the array $wgMathValidModes
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function setMode( $newMode ) {
|
2014-06-10 16:49:20 +00:00
|
|
|
global $wgMathValidModes;
|
|
|
|
if ( in_array( $newMode, $wgMathValidModes ) ) {
|
2014-05-28 06:00:30 +00:00
|
|
|
$this->mode = $newMode;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 19:31:41 +00:00
|
|
|
|
2013-04-25 17:07:25 +00:00
|
|
|
/**
|
|
|
|
* Sets the TeX code
|
|
|
|
*
|
|
|
|
* @param string $tex
|
|
|
|
*/
|
|
|
|
public function setTex( $tex ) {
|
2014-05-28 19:31:41 +00:00
|
|
|
if ( $this->tex != $tex ) {
|
|
|
|
$this->changed = true;
|
|
|
|
$this->tex = $tex;
|
|
|
|
}
|
2013-04-25 17:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the MathML XML element
|
|
|
|
* @return string in UTF-8 encoding
|
|
|
|
*/
|
|
|
|
public function getMathml() {
|
2015-02-25 19:32:56 +00:00
|
|
|
if ( !StringUtils::isUtf8( $this->mathml ) ) {
|
2014-05-28 19:31:41 +00:00
|
|
|
$this->setMathml( '' );
|
|
|
|
}
|
2013-04-25 17:07:25 +00:00
|
|
|
return $this->mathml;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $mathml use UTF-8 encoding
|
|
|
|
*/
|
|
|
|
public function setMathml( $mathml ) {
|
|
|
|
$this->changed = true;
|
|
|
|
$this->mathml = $mathml;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the attributes of the math tag
|
2013-05-14 21:49:06 +00:00
|
|
|
*
|
2013-04-25 17:07:25 +00:00
|
|
|
* @return array()
|
|
|
|
*/
|
|
|
|
public function getParams() {
|
|
|
|
return $this->params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array() $params
|
|
|
|
*/
|
|
|
|
public function setParams( $params ) {
|
2013-05-14 21:49:06 +00:00
|
|
|
// $changed is not set to true here, because the attributes do not affect
|
|
|
|
// the rendering in the current implementation.
|
|
|
|
// If this behavior will change in the future $this->tex is no longer a
|
|
|
|
// primary key and the input hash cannot be calculate form $this->tex
|
|
|
|
// only. See the discussion 'Tag extensions in Block mode' on wikitech-l.
|
2013-04-25 17:07:25 +00:00
|
|
|
$this->params = $params;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the instance was modified i.e., because math was rendered
|
|
|
|
*
|
|
|
|
* @return boolean true if something was changed false otherwise
|
|
|
|
*/
|
|
|
|
public function isChanged() {
|
|
|
|
return $this->changed;
|
|
|
|
}
|
|
|
|
|
2013-05-14 21:49:06 +00:00
|
|
|
/**
|
|
|
|
* Checks if there is an explicit user request to rerender the math-tag.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function isPurge( ) {
|
|
|
|
if ( $this->purge ) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-28 19:31:41 +00:00
|
|
|
$request = RequestContext::getMain()->getRequest();
|
2013-05-14 21:49:06 +00:00
|
|
|
// TODO: Figure out if ?action=purge
|
2014-05-28 19:31:41 +00:00
|
|
|
// $action = $request->getText('action'); //always returns ''
|
2013-05-14 21:49:06 +00:00
|
|
|
// until this issue is resolved we use ?mathpurge=true instead
|
2014-05-28 19:31:41 +00:00
|
|
|
$mathpurge = $request->getBool( 'mathpurge', false );
|
|
|
|
if ( $mathpurge ) {
|
|
|
|
wfDebugLog( 'Math', 'Re-Rendering on user request' );
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-14 21:49:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets purge. If set to true the render is forced to rerender and must not
|
|
|
|
* use a cached version.
|
2014-02-09 19:02:15 +00:00
|
|
|
* @param bool $purge
|
2013-05-14 21:49:06 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
function setPurge( $purge = true ) {
|
|
|
|
$this->changed = true;
|
|
|
|
$this->purge = $purge;
|
|
|
|
}
|
|
|
|
|
2013-09-19 00:37:35 +00:00
|
|
|
function getLastError() {
|
2013-05-14 21:49:06 +00:00
|
|
|
return $this->lastError;
|
|
|
|
}
|
2014-01-03 14:29:03 +00:00
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLog() {
|
|
|
|
return $this->log;
|
|
|
|
}
|
2014-03-17 06:14:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) $mathStyle
|
|
|
|
*/
|
|
|
|
public function setMathStyle( $displayStyle = MW_MATHSTYLE_DISPLAY ) {
|
|
|
|
if ( $this->mathStyle !== $displayStyle ){
|
|
|
|
$this->changed = true;
|
|
|
|
}
|
|
|
|
$this->mathStyle = $displayStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value of the DisplayStyle attribute
|
|
|
|
* @return (MW_MATHSTYLE_INLINE_DISPLAYSTYLE|MW_MATHSTYLE_DISPLAY|MW_MATHSTYLE_INLINE) the DisplayStyle
|
|
|
|
*/
|
|
|
|
public function getMathStyle() {
|
|
|
|
return $this->mathStyle;
|
|
|
|
}
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* @param string $log
|
|
|
|
*/
|
|
|
|
public function setLog( $log ) {
|
|
|
|
$this->changed = true;
|
|
|
|
$this->log = $log;
|
|
|
|
}
|
2014-03-17 06:14:02 +00:00
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getStatusCode() {
|
|
|
|
return $this->statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param unknown_type $statusCode
|
|
|
|
*/
|
|
|
|
public function setStatusCode( $statusCode ) {
|
|
|
|
$this->changed = true;
|
|
|
|
$this->statusCode = $statusCode;
|
|
|
|
}
|
2014-01-03 14:29:03 +00:00
|
|
|
/**
|
|
|
|
* Get if the input tex was marked as secure
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isTexSecure() {
|
|
|
|
return $this->texSecure;
|
|
|
|
}
|
|
|
|
|
2014-09-06 01:59:13 +00:00
|
|
|
/**
|
|
|
|
* @global $wgMathDisableTexFilter
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-01-03 14:29:03 +00:00
|
|
|
public function checkTex() {
|
2014-09-06 01:59:13 +00:00
|
|
|
global $wgMathDisableTexFilter;
|
|
|
|
if ( $this->texSecure || (int) $wgMathDisableTexFilter == MW_MATH_CHECK_NEVER ) {
|
|
|
|
// equation was already checked or checking is disabled
|
|
|
|
return true;
|
|
|
|
} else {
|
2014-10-11 14:04:18 +00:00
|
|
|
if( (int) $wgMathDisableTexFilter == MW_MATH_CHECK_NEW && $this->mode != MW_MATH_SOURCE ){
|
2014-09-06 01:59:13 +00:00
|
|
|
if( $this->readFromDatabase() ){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-01-03 14:29:03 +00:00
|
|
|
$checker = new MathInputCheckTexvc( $this->userInputTex );
|
2014-02-09 19:02:15 +00:00
|
|
|
if ( $checker->isValid() ) {
|
2014-01-03 14:29:03 +00:00
|
|
|
$this->setTex( $checker->getValidTex() );
|
|
|
|
$this->texSecure = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
$this->lastError = $checker->getError();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-07 08:32:23 +00:00
|
|
|
|
2014-05-28 19:31:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
public function isInDatabase() {
|
|
|
|
if ( $this->storedInDatabase === null ) {
|
|
|
|
$this->readFromDatabase();
|
|
|
|
}
|
|
|
|
return $this->storedInDatabase;
|
|
|
|
}
|
|
|
|
|
2014-02-07 08:32:23 +00:00
|
|
|
/**
|
2014-05-28 06:00:30 +00:00
|
|
|
*
|
|
|
|
* @return string TeX the original tex string specified by the user
|
2014-02-07 08:32:23 +00:00
|
|
|
*/
|
2014-02-09 19:02:15 +00:00
|
|
|
public function getUserInputTex() {
|
2014-02-07 08:32:23 +00:00
|
|
|
return $this->userInputTex;
|
|
|
|
}
|
2013-04-25 17:07:25 +00:00
|
|
|
|
2014-05-28 06:00:30 +00:00
|
|
|
/**
|
|
|
|
* @return string Userdefined ID
|
|
|
|
*/
|
|
|
|
public function getID() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
Merge changes from master to debug
combine commits to avoid potential problems
with gerrit and jenkins
This is a combination of 30 commits.
ve.ce.MWMathNode: Remove reference to defunct ve.bind
Bug: 73627
Change-Id: I3dd6b520a24e5cecb272de8f9a4aa0ba231bee58
Localisation updates from https://translatewiki.net.
Change-Id: I6074394864ee7c61b416ae146c94c75d48f509af
Localisation updates from https://translatewiki.net.
Change-Id: I2fa13da30e606e1dfb1e13ae64fb125bf4bfadf6
Fix Mathoid integration test
A recent change in mathoid, i.e.
I8d3cec0ee8a8c9368b7dca89e1d5e0c5683f946c
removed the margins. This causes breaking unit tests.
Change-Id: I312d6226c6f24c84254b99ee6292564a421133c3
Localisation updates from https://translatewiki.net.
Change-Id: I053b90b6a583c411270c950ab6bc0d4e94db583f
Localisation updates from https://translatewiki.net.
Change-Id: Icc6d5d961ad97e19de3c4fbdb86e5aa9315998bb
Localisation updates from https://translatewiki.net.
Change-Id: I7b8faf72ba814154896cf5039e14d23f07509440
Localisation updates from https://translatewiki.net.
Change-Id: I83ca4e6eb8eef02e98ddc6f556d113942fa436df
Localisation updates from https://translatewiki.net.
Change-Id: Icb25e8b51409754130ce22c47474f644c087124e
Localisation updates from https://translatewiki.net.
Change-Id: I6dae3f8fc6723265bf47b721148d261b11828f33
Fix for fatal caused by static call to MathRenderer::getError
MathRenderer::getError() uses $this, so it should not be called statically.
MathInputCheckTexvc should instead call its convertTexvcError method, which
constructs a MathRenderer object so it can call its getError method.
This code is pretty awful. But this way it won't throw fatal errors all the time.
Change-Id: Ic438b307a3b464651363b4cc16698c7d4320b253
Add support for display and ID attributes to VisualEditor
Change-Id: Ie65ff26c9e214f74b0217238a3def2242505d4c2
Localisation updates from https://translatewiki.net.
Change-Id: I5f978989a57affa823632061300f5de7028b2ec0
Localisation updates from https://translatewiki.net.
Change-Id: I366383149cb56c90800e06f94aaa6c8895d2381c
Localisation updates from https://translatewiki.net.
Change-Id: I204cb407cfb417961da361b4eaa84af432e2bd29
Localisation updates from https://translatewiki.net.
Change-Id: Ib3f357a76752ce2cba8642a02ec4f5373ddabe52
Localisation updates from https://translatewiki.net.
Change-Id: Iec289070ab64e2014b4c7f371926c03466258e3c
Localisation updates from https://translatewiki.net.
Change-Id: Id297a13ca02524d9db16990b6cdd282b0b52fd73
Localisation updates from https://translatewiki.net.
Change-Id: I1b86d72690b5907ef438d69cf067da6dcc1891b2
Localisation updates from https://translatewiki.net.
Change-Id: Ib4eb016b1602d94a73c5e355f0ae4a744083b0c3
Localisation updates from https://translatewiki.net.
Change-Id: I6b0398be5ec8ba5bfc71c987f80973bf2bb8afe3
Localisation updates from https://translatewiki.net.
Change-Id: Ie485a03f09f1534071d18abf64bbfa446cdee754
Localisation updates from https://translatewiki.net.
Change-Id: I2445b8fbf1b35f437d6dba99d9fe081833ab5089
Localisation updates from https://translatewiki.net.
Change-Id: If1f94c16fd20feef3403e326d58526eeb17c6a86
Localisation updates from https://translatewiki.net.
Change-Id: I74dcb97bbb16bfc6e0700ed90fcf9705f7bdecf8
Localisation updates from https://translatewiki.net.
Change-Id: I0ac3c68f796cde959629d63079d212473ad5a729
Localisation updates from https://translatewiki.net.
Change-Id: I35f1687b4f4e7030a91bdc8aba3c04bbf71f55a4
Localisation updates from https://translatewiki.net.
Change-Id: I64dfcdedea5ed345f730fe7080c8b511fe21dc49
Localisation updates from https://translatewiki.net.
Change-Id: Ib5c89c89ba2091f7784cc1c1237150ec55741fd7
MWException -> Exception
Change-Id: I18da1baeb70387b96e30811a049185a264dec26d
Update MathParser tests
In the most recent version of ubuntu14 the outputhash of the
png images for some math objects has changed.
However, the rendered images seem to look ok.
Bug: T86309
Change-Id: I52dbdefdcfa19c10f1d9d1a43369aabe8bfd92bf
Correct wrong variable name
Change-Id: Iecfa0bfa5861e077d98f7bf06af0e98cda56220b
Remove unused global
Change-Id: I8f5f77015de266f5a5b751fd7cfe424784eb3864
Update LaTeXML test
* The LaTeXML server was updated. In the new version unneccary id's
have been removed.
Change-Id: I25927912f1500ebfe6d61505c0e06ae2c24d6f6a
Update license headers
Change-Id: Ia38926b253e53a2cef5dfab623353e1dd79ad613
Make main code input area monospaced
A monospaced font is more suitable for writing LaTeX.
Change-Id: I1a6c7bbbe3618f43808be15eab1579de8b2ad59f
Whitespace fixes
Change-Id: Id22a4bfdc1b8c4074f6d7e6f21e8dbc2824d856e
Localisation updates from https://translatewiki.net.
Change-Id: I01c4bbe241c0842027b030ee912b8e481c90f625
Localisation updates from https://translatewiki.net.
Change-Id: Ie012febb53ee642520e71f18285d5b9e4133e224
Improve Math test generation
* Use the wikitext parser and not regexp to extract math
tags from the page.
* Extract the attributes from the math tags as well
In a follow up a pseudo attribute in the math tag could
be introduced to provide a bug description.
Change-Id: I0dec18d4e3f87e7b58b097b2a08c4897ceaf29ac
Remove unused XML namespace
Bug: T87142
Change-Id: I1c900584aeafbeb5848a3300904710ee312d6223
Add type hinting for newFromMd5 constructor
Bug: T87142
Change-Id: I2989ff42e48e802c1eed1877f0f2ac9316b5fd21
Remove duplicate entry from .gitignore
Change-Id: I78c7e9b630c6e96a2f125f20461ff9e720754ec4
MathRenderer, SpecialMathShowImage: Correct phpdoc
Change-Id: Ibce076dfb6bd3676e288cf2d762ebcb55606246d
MathMathML, MathTexvc: Improve PhpDoc
Change-Id: I84af65e15bdae81f69f0444afdd9ffa5fe9fc326
Minor clean up, optimisations and documentation corrections
* Handle-error-first approach for consistent function body
termination at the root with the main intend, and less indention.
* __DIR__ instead of dirname( __FILE__ )
* Single quotes.
* Correct pickHost documentation: wgMathMathMLUrl is not an array,
and is not used in this method, that's at a different level
of abstraction (via the constructor).
* White spacing.
* require_once is not a function.
Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Add dependency on mediawiki.toolbar
Follows-up Ibcda91bbb164b0.
ext.math.editbutton.enabler uses mw.toolbar. The toolbar interface
used to be part of mediawiki.action.edit but is now in its own module.
Bug: T86235
Change-Id: I37a0b8e84a9bd6a0de0386d5b9924bbbbbd7249c
Localisation updates from https://translatewiki.net.
Change-Id: I14cfdb2153121a9cbcd40345398dc84d3b17518f
Fix rendering issues in MathML mode
Force display:none on a hidden MathML rendering to avoid generating
focusable node highlights.
Move adding of class to setup to ensure it persists after render.
Bug: T87007
Change-Id: I5fc21afa61ccc07e9d2126846cf29ee898182a7c
Localisation updates from https://translatewiki.net.
Change-Id: I2cfa5bae2a6864548816934483cd2276e1071865
Localisation updates from https://translatewiki.net.
Change-Id: I7eb73bd36e5cd4461647bf05166fd2fd2fcbee07
Localisation updates from https://translatewiki.net.
Change-Id: I174400c5a3dad8f6bf8d03b7c738d5068682ceb3
2014-11-20 02:51:40 +00:00
|
|
|
* @param string user defined ID
|
2014-05-28 06:00:30 +00:00
|
|
|
*/
|
|
|
|
public function setID( $id ) {
|
|
|
|
// Changes in the ID affect the container for the math element on the current page
|
|
|
|
// only. Therefore an id change does not affect the $this->changed variable, which
|
|
|
|
// indicates if database relevant fields have been changed.
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param type $svg
|
|
|
|
*/
|
|
|
|
public function setSvg( $svg ) {
|
|
|
|
$this->changed = true;
|
|
|
|
$this->svg = trim( $svg );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-02-08 19:18:49 +00:00
|
|
|
* Gets the SVG image
|
2014-05-28 06:00:30 +00:00
|
|
|
*
|
2015-02-08 19:18:49 +00:00
|
|
|
* @param string $render if set to 'render' (default) and no SVG image exists, the function
|
|
|
|
* tries to generate it on the fly.
|
|
|
|
* Otherwise, if set to 'cached', and there is no SVG in the database
|
|
|
|
* cache, an empty string is returned.
|
|
|
|
*
|
|
|
|
* @return string XML-Document of the rendered SVG
|
2014-05-28 06:00:30 +00:00
|
|
|
*/
|
2015-02-08 19:18:49 +00:00
|
|
|
public function getSvg( $render = 'render' ) {
|
2014-05-28 06:00:30 +00:00
|
|
|
// Spaces will prevent the image from being displayed correctly in the browser
|
|
|
|
return trim( $this->svg );
|
|
|
|
}
|
2014-05-27 04:46:53 +00:00
|
|
|
|
|
|
|
protected abstract function getMathTableName();
|
|
|
|
|
|
|
|
public function getModeStr() {
|
|
|
|
$names = MathHooks::getMathNames();
|
|
|
|
return $names[ $this->getMode() ];
|
|
|
|
}
|
2014-11-18 11:40:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPostData() {
|
|
|
|
return $this->postData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $postData
|
|
|
|
*/
|
|
|
|
public function setPostData( $postData ) {
|
|
|
|
$this->postData = $postData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int time in ms
|
|
|
|
*/
|
|
|
|
public function getRenderingTime() {
|
|
|
|
return $this->renderingTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int|long $renderingTime either in ms or as in seconds as long
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
|
|
|
public function setRenderingTime( $renderingTime ) {
|
|
|
|
$type = gettype($renderingTime);
|
|
|
|
switch ( $type ) {
|
|
|
|
case "double":
|
|
|
|
case "float":
|
|
|
|
$this->renderingTime = (int) ( $renderingTime * 1000 );
|
|
|
|
break;
|
|
|
|
case "integer":
|
|
|
|
$this->renderingTime = $renderingTime;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new MWException( __METHOD__ . ": does not support type $type" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array that matches the variables of the class to the debug database columns
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function dbDebugOutArray() {
|
|
|
|
$out = array( 'math_inputhash' => $this->getInputHash(),
|
|
|
|
'math_log' => $this->getLog(),
|
|
|
|
'math_mode' => $this->getMode(),
|
|
|
|
'math_post' => $this->getPostData(),
|
|
|
|
'math_rederingtime' => $this->getRenderingTime()
|
|
|
|
);
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function writeDebugLog() {
|
|
|
|
global $wgMathDebug;
|
|
|
|
if ( $wgMathDebug ) {
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
$outArray = $this->dbDebugOutArray();
|
|
|
|
$method = __METHOD__;
|
|
|
|
$dbw->onTransactionIdle( function () use ( $dbw, $outArray, $method ) {
|
|
|
|
$dbw->insert( 'mathlog', $outArray, $method );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
2014-05-27 04:46:53 +00:00
|
|
|
}
|