Go to file
Thiemo Kreuz 670f0bb8f9 Don't expect objects by reference in hook handlers
The motivation for this patch is to make the code less complex, better
readable, and less brittle.

Example:

public function onExampleHook( Parser &$parser, array &$result ) {
    /* This is the hook handler */
}

In this example the $result array is meant to be manipulated by the
hook handler. Changes should become visible to the caller. Since PHP
passes arrays by value, the & is needed to make this possible.

But the & is misplaced in pretty much all cases where the parameter is
an object. The only reason we still see these & in many hook handlers
is historical: PHP 4 passed objects by value, which potentially caused
expensive cloning. This was prevented with the &.

Since PHP 5 objects are passed by reference. However, this did not
made the & entirely meaningless. Keeping the & means callees are
allowed to replace passed objects with new ones. The & makes it look
like a function might intentionally replace a passed object, which is
unintended and actually scary in cases like the Parser. Luckily all
Hooks::run I have seen so far ignore unintended out-values. So even if
a hook handler tries to do something bad like replacing the Parser
with a different one, this would not have an effect.

Removing the & does not remove the possibility to manipulate the
object. Changes done to public properties are still visible to the
caller.

Unfortunately these & cannot be removed from the callers as long as
there is a single callee expecting a reference. This patch reduces the
number of such problematic callees.

Change-Id: I21d53c989ea487607dc69e6b3365c023ef6729f5
2018-05-15 17:50:08 +02:00
db Mathoid CLI interface 2018-02-21 20:29:20 +01:00
i18n Localisation updates from https://translatewiki.net. 2018-05-14 22:44:23 +02:00
images Update reference images 2016-10-10 18:26:22 +02:00
maintenance build: Updating mediawiki/mediawiki-codesniffer to 0.9.0 2017-06-21 00:59:25 +00:00
math Do not ignore all .mli files in texvccheck 2016-12-25 13:39:20 +00:00
mathoid Separate Mathoid from the Math extension 2014-02-10 18:28:08 +00:00
modules Autocomplete LaTeX commands with backslash 2018-04-24 20:17:21 +02:00
src Don't expect objects by reference in hook handlers 2018-05-15 17:50:08 +02:00
tests Disable PHPCS more narrowly 2018-05-03 19:00:55 -07:00
texvccheck Merge "Remove broken test script texvccheck/test.pl" 2016-12-26 00:05:16 +00:00
.eslintrc.json eslint: Re-enable wrap-iife and partially enable dot-notation 2016-11-15 13:13:05 +00:00
.gitattributes Update to MathJax 2.3 2014-01-27 21:36:02 +00:00
.gitignore Expand .gitignore for more editors 2016-11-13 13:22:03 +01:00
.gitreview Whoops, track not trace 2016-10-24 17:02:56 -07:00
.phpcs.xml build: Updating mediawiki/mediawiki-codesniffer to 18.0.0 2018-04-14 22:39:05 +00:00
.rubocop.yml Fixed Style/StringLiterals RuboCop offense 2015-09-22 10:18:13 -07:00
.stylelintrc.json Use json extension for .stylelintrc 2017-08-19 09:58:39 +02:00
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT.md 2017-06-07 14:32:26 +04:30
composer.json build: Updating mediawiki/mediawiki-codesniffer to 18.0.0 2018-04-14 22:39:05 +00:00
COPYING Add COPYING 2014-03-01 16:15:39 +00:00
extension.json Move php source files 2018-04-23 15:09:23 +02:00
Gemfile Update RuboCop Ruby gem 2017-12-04 16:49:44 +01:00
Gemfile.lock Update RuboCop Ruby gem 2017-12-04 16:49:44 +01:00
Gruntfile.js Use json extension for .stylelintrc 2017-08-19 09:58:39 +02:00
HISTORY Use extension.json, empty PHP entry point 2015-07-30 22:01:20 +00:00
Makefile Remove unused Makefile variable "DIRS" 2016-12-25 13:35:16 +00:00
Math.alias.noTranslate.php Convert all array() syntax to [] 2016-04-13 10:18:23 -04:00
Math.alias.php Setting alias of Special:MathStatus for Urdu language 2017-10-05 08:31:18 +00:00
Math.php Add php code sniffer to composer 2015-09-23 10:46:14 +01:00
MathInputCheckTexvc.php Update @license tags from GPLv2 to GPL-2.0-or-later 2018-04-14 09:36:27 +00:00
MathLaTeXML.php Update @license tags from GPLv2 to GPL-2.0-or-later 2018-04-14 09:36:27 +00:00
MathTexvc.php Update @license tags from GPLv2 to GPL-2.0-or-later 2018-04-14 09:36:27 +00:00
package.json build: Update linters 2018-02-04 22:08:31 +00:00
Rakefile Migration of browsertests* Jenkins jobs to selenium* jobs 2016-04-25 18:31:00 +02:00
README Update default configuration 2018-02-21 22:09:22 +01:00
RELEASE-NOTES-3.0.0 Add release notes for version 3.0.0 2015-07-25 22:01:48 +01:00

This version (for MediaWiki 1.31) has some changes since previous versions:

By default the math rendering service from the Wikimedia Foundation located at
https://wikimedia.org/api/rest_v1/
will be used for math rendering.
Therefore php-curl is required.
cf. https://www.mediawiki.org/wiki/Manual:CURL

Consult https://www.mediawiki.org/wiki/Extension:Math for further information and advanced settings.


Attributes of the <math /> element:
attribute "display":
possible values: "inline", "block" or "inline-displaystyle" (default)

"display" reproduces the old texvc behavior:
The equation is rendered with large height operands (texvc used $$ $tex $$ to render)
but the equation printed to the current line of the output and not centered in a new line.
In Wikipedia users use :<math>$tex</math> to move the math element closer to the center.

"inline" renders the equation in with small height operands by adding {\textstyle $tex } to the
users input ($tex). The equation is displayed in the current text line.

"inline-displaystyle" renders the equation in with large height operands centered in a new line by adding
{\displaystyle $tex } to the user input ($tex).


For testing your installation run
php tests/phpunit/phpunit.php extensions/Math/tests/
from your MediWiki home path.

== Logging ==
The math extension supports PSR-3 logging:
Configuration can be dona via
$wgDebugLogGroups['Math'] = [ 'level' => 'info', 'destination' => '/path/to/file.log' ];