Page MenuHomePhabricator

Magic word variable for content model {{CONTENTMODEL}}
Open, LowPublicFeature

Assigned To
None
Authored By
Bugreporter2
Jan 30 2023, 8:11 AM
Referenced Files
None
Tokens
"Like" token, awarded by Pppery."Like" token, awarded by Bugreporter2.

Description

Feature summary

There should be a Extension:ParserFunctions variable for the content model of a page.
Suggest` {{CONTENTMODEL}} and {{CONTENTMODELE}}`.

A standard Wikitext page would return Wikitext. Other content types could not return the variable within the page itself, but this variable could be used in wikitext-based system messages; so a JavaScript page returns JavaScript, a CSS page returns CSS, etc. This info can be used to trigger switches.

This would not affect caching, given that content model changes are rare.

Event Timeline

@Bugreporter2 Could you please give a example on how this could be used?

Examples of the system messages I mentioned earlier would include, for example:

[[Mediawiki:editinginterface]] which could be changed depending on content model. For example 'you are editing a CSS page, etc'

Another one: [[Mediawiki:ns-tab]] could say something different for different content models, like 'user CSS page'.

Or [[Mediawiki: sitenotice]] could display something based on content model. [[Mediawiki:copyrights]] can also be used as a page-bottom general element, with switches (I know it's not intended as such, but it can be used that way).

There is also the potential for its use in things like custom toolbars, if and when that happens, and they are wikitext-based. Just one extra building block towards that.

Some notes:

"Magic Variables" are defined in <code>\includes\parser\CoreMagicVariables.php</code>

The following lines of code need to be added to an appropriate place. The second one with the e on the end is to return <code>plain_text</code> (with an underscore) rather than <code>plain text</code> (with a space character):

<pre>

			case 'contentmodel':
			case 'contentmodele':

</pre>

There is an array called <code>$wgContentHandlers</code> which should contain these four values:

<pre>
CONTENT_MODEL_CSS
CONTENT_MODEL_JSON
CONTENT_MODEL_UNKNOWN
CONTENT_MODEL_WIKITEXT
</pre>

And may have others added to it; in particular there's one for "Sanitized CSS" and possibly another one called JavaScript (though JSON=JavaScript, potentially. It's confusing.)

Now then, if matches, then output...

Does this help anyone?

Bugreporter2 renamed this task from ParserFunctions variable for content model to Magic word variable for content model {{CONTENTMODEL}}.Nov 7 2023, 7:07 AM
Aklapper lowered the priority of this task from Medium to Low.Nov 14 2023, 8:59 AM

@Bugreporter2: A good first task is a self-contained, non-controversial task with a clear approach. It should be well-described with pointers to help a completely new contributor. Given the current short task description I'm removing the good first task tag. Please add details what exactly has to happen where and how for a new contributor, and then add back the good first task project tag. Thanks a lot in advance!