Page MenuHomePhabricator

User-defined variables packed into one array
Closed, ResolvedPublic

Description

Author: ReneeMattie

Description:
User-defined variables are useful while an article is being written.
I could write the code, but have nowhere to test my work...

BENEFIT OF EXTENSION:
Example 1: Keep a group of images the same size
Editor has several images on page, needs them all the same size.
Editor decides to change the size of all the images. The ability
to create and use a variable would make this a lot easier
<VarSet>imagesize=250px</VarSet>
[[Image:imageA.jpg|<VarGet>imagesize</VarGet>]]
[[Image:imageB.jpg|<VarGet>imagesize</VarGet>]]
... a lot of text ...
[[Image:imageC.jpg|<VarGet>imagesize</VarGet>]]

Example 2: Print or Supress all footnotes
A set of children's books is being developed at WikiJunior.
During development, we want to display citations so we can see which
facts have been checked and which have not. After development, we
would like to supress display of citations, because they are not
used in children's books. But we would not like to have to delete
all of the citations.

We could create a set of templates that would depend on the value of
a single variable -- showrefs. At the top of the document,
<!-- Today, no refs --><VarSet>showrefs=0</VarSet>
In Template:WJFootnote we have {{WJCite<VarGet>showrefs</VarGet>}}
Which would select template WJCite0 (which does nothing) or WJCite1
(which generates the citation reference) depending on how showrefs
was set at the top of the document

IMPLEMENTATION:
$uservar['myvar']='string'
The variables would only exist during the display of a page.
The variables MUST BE GLOBAL --accessible even within nested
templates
The variables SHOULD BE passable as parameters to templates.
The variables COULD BE made available when an editor was
editing/previewing only one section of the page if, for example,
they were stuffed into a new magic word.

USER INTERFACE:
Variables would be manipulated by a set of wiki extensions:
VarSet

<VarSet>myvar</VarSet>
<VarSet>myvar="string"</VarSet> 
<VarSet>myvar=6.02E23</VarSet>
sets the variable, produces no output.
if no value is given for myvar, default value is 1

VarIsSet

<VarIsSet>myvar</VarIsSet>
returns 1 or 0, which could be incorporated into a templatename

VarGet

<VarGet>myvar</VarGet> 
returns the value of myvar
if the var is not set, produces no output

VarUnSet

<VarUnSet>myvar</VarUnSet>
unsets the variable, produces no output.

Version: unspecified
Severity: enhancement

Details

Reference
bz3264

Revisions and Commits

Event Timeline

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

ReneeMattie wrote:

Someone suggested this bug depends on 1911. I don't think it does.

  • 1911 requests the creation of properties for articles. These

properties would probably have to be stored in a separate field on the
database so they could be efficiently retrieved for Special pages.

  • This request is simpler. It does not involve saving anything new on

the database. The values would be set and used within the php scripts
that do the rendering. It would only be available to another page if
that page transcluded the page in which the variable is set.

  • This request can be done with some simple php. And if I had a place to

test it, I could write it myself. But I don't have a test wiki to
practice on...

Taking your first example, you can load the text in an external editor
and use the search&replace function

[[Image:imageA.jpg|300px]]
[[Image:imageB.jpg|300px]]
... a lot of text ...
[[Image:imageC.jpg|300px]]

In vi it would be something like:

%s/300px/250px/g

(to change the size of images to 250px.

ReneeMattie wrote:

That is one possible workaround for examples #1 and #2 both
%s/{{ab/{{ab0/g
%s/{{abn/{{abn0/g
to change the citations from ab and abn which render to ab0 and abn0
which do not.

Hmmm... I've just posted bug 16337 describing a more general ParserFunction extension to handle what I call "Context Variables" (at first only "Global Context Variables") for a similar task.

There's a page on Meta discussing it and why we need something like that for existing problems on Wiktionary and similar multilingual projects on Commons (where the same page needs specialization of templates according to a "language context", without depending only on explicit template parameters.

Basically, it defined first the following two syntaxes {{#v:get:x}} and {{#v:set:x|value}}, part of a proposal for a parserfunction identified by {{#v: }} ("v" for "variable") and with general form {{#v:action:variableName|optional parameters...}} and a default "action" which would be "get".

The syntax adopted here is very near from the syntax already used for template parameters, and its use would be similar. No more embedded braces, no difficult syntax with XML-like open/close tags, and more versatile, using an approach that would be easy to adopt by existing MW template designers.

See [[Meta:GlobalContextVariables_Extension]] for the discussion started there, and Bug 16337 where I have posted this reference and an introduction.

ReneeMattie wrote:

(In reply to comment #4)

Hmmm... I've just posted bug 16337 describing a more general ParserFunction
...
Basically, it defined first the following two syntaxes {{#v:get:x}} and
{{#v:set:x|value}}, part of a proposal for a parserfunction identified by {{#v:
}} ("v" for "variable") and with general form {{#v:action:variableName|optional
parameters...}} and a default "action" which would be "get".

I think your number 16337 does encompass the functionality I've requested, although it has the potential to do quite a lot more in subtle ways, I think.

If you have a test wiki, why not implement just part of this functionality and demo it. I think the discussions that follow a concrete demo will be very useful.

Functionality seems to be provided in http://www.mediawiki.org/wiki/Extension:VariablesExtension (and probably a few other ones by now), so I'm marking this FIXED.

Getting it enabled on Wikimedia sites requires consensus, and approval/review by a senior developer.

epriestley added a commit: Unknown Object (Diffusion Commit).Mar 4 2015, 8:15 AM