Go to file
Thiemo Kreuz 0fe9dbb366 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: Ib3a9da257b50326d569ab1973b523c952963c16b
2018-05-17 17:09:55 +00:00
i18n Localisation updates from https://translatewiki.net. 2018-05-16 23:07:37 +02:00
includes Don't expect objects by reference in hook handlers 2018-05-17 17:09:55 +00:00
modules Localisation updates from https://translatewiki.net. 2018-05-15 22:24:26 +02:00
tests Support directionality for reference 2018-05-02 17:27:32 +02:00
.eslintrc.json eslint: Re-enable wrap-iife and partially enable dot-notation 2016-11-15 12:59:21 +00:00
.gitignore Add phan configuration for static analysis 2017-12-29 11:50:01 -08:00
.gitreview Whoops, track not trace 2016-10-24 17:02:15 -07:00
.phpcs.xml build: Updating mediawiki/mediawiki-codesniffer to 17.0.0 2018-03-29 00:35:52 +00:00
.stylelintrc.json Use json extension for .stylelintrc 2017-08-19 09:39:19 +02:00
AUTHORS.txt Fix expected remove data to match actual remove data exactly 2017-08-13 11:41:30 -04:00
Cite.php Add extension.json, empty PHP entry point 2015-05-03 06:36:25 +00:00
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT.md 2017-06-07 12:58:44 +04:30
composer.json build: Updating mediawiki/mediawiki-codesniffer to 18.0.0 2018-04-13 22:53:31 +00:00
COPYING.txt Add license details and give credit to more authors (based on git shortlog) 2014-07-26 16:16:47 -07:00
extension.json Give Cite a version number 2018-05-12 13:28:50 +01:00
Gruntfile.js build: Bring SVGO optimization to build step 2018-02-12 10:05:27 -08:00
MIT-LICENSE.txt doc: Bump copyright year 2018-01-02 17:05:50 -08:00
package.json build: Bring SVGO optimization to build step 2018-02-12 10:05:27 -08:00
README.md Store references in page_props and cache 2016-02-10 14:47:02 +01:00

Cite

The Cite extension provides a way for users to create references as footnotes to articles.

See https://www.mediawiki.org/wiki/Extension:Cite for detailed documentation.

Configuration

  • $wgCiteStoreReferencesData: If set to true, references are saved in the database so that other extensions can retrieve them independently of the main article content.
  • $wgCiteCacheReferencesDataOnParse: ($wgCiteStoreReferencesData required) By default, references are cached only on database access. If set to true, references are also cached whenever pages are parsed.