Page MenuHomePhabricator

Allow Variable Extensions
Closed, ResolvedPublic

Description

Author: Astronouth7303

Description:
You should allow for extensions to define new variables (eg, {{FOO}}).


Version: 1.6.x
Severity: enhancement

Details

Reference
bz3420

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 8:47 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz3420.
bzimport added a subscriber: Unknown Object (MLST).

Astronouth7303 wrote:

Proposed implementation (1.5)

This is my implementation of this bug. It modifies MagicWord.php, Parser.php,
and SpecialVersion.php.

attachment VariableExtensions.patch ignored as obsolete

Astronouth7303 wrote:

Example Extension using the previous implementation

This is an example extension that creates the variable RANDOM. It should be
fairly self-explainatory.

attachment random.php ignored as obsolete

Astronouth7303 wrote:

Proposed implementation (1.5)

Added a few more comments in MagicWord.php

attachment VariableExtensions.patch ignored as obsolete

Astronouth7303 wrote:

Proposed implementation (1.5)

Some phpdoc corrections, other comment changes.

attachment VariableExtensions.patch ignored as obsolete

Astronouth7303 wrote:

I just realized that in Parser.php, it does not cache the result of it in the
static $varCache. (Parser::getVariableValue().)

I'm not sure this would be a bug or a feature.

avarab wrote:

Implementation using the existing hook system

Your implementation of this was overly complex and redundant, we already have
an all purpose hook system in place and there's no need to write a custom one
for this occation when that one will do perfectly. I've commited my own
implementation of this (attached) using the existing system. You can find an
example extension that implements it called Variable_hook.php in the examples
directory in the extensions module in CVS HEAD.

Attached:

avarab wrote:

Marking this as FIXED in CVS HEAD.

Astronouth7303 wrote:

(In reply to comment #6)

Created an attachment (id=1099) [edit]
Implementation using the existing hook system

Your implementation of this was overly complex and redundant, we already have
an all purpose hook system in place and there's no need to write a custom one
for this occation when that one will do perfectly. I've commited my own
implementation of this (attached) using the existing system. You can find an
example extension that implements it called Variable_hook.php in the examples
directory in the extensions module in CVS HEAD.

I was aiming for implementation similar to the parser extensions. (ie, you
register your variable, and the parser calls your function.)

But in hindsight, your version is more flexible in that you could use it to do
simple {{foo:...}} extensions (but no params).