Page MenuHomePhabricator

Add a magic word that returns the page title, which may be set by {{DISPLAYTITLE}} or default to page name
Open, LowPublicFeature

Description

Output the page's DISPLAYTITLE as a magic word. I suggest using {{PAGETITLE}}

It's possible to set the page title with {{DISPLAYTITLE}} to be a modified form of the page title. Or, with less paranoid wikis with $wgRestrictDisplayTitle=false; this could be any permitted string (there are still some restrictions).

So, for example, using {{PAGETITLE}} on the English Wikipedia page https://en.wikipedia.org/wiki/A_Day_in_the_Life_of_Lakshmi_Manchu%27s_Feet would output <i>A Day in the Life of Lakshmi Manchu's Feet</i> because that has a {{DISPLAYTITLE}} code to make it italic.

The code {{PAGETITLE:A_Day_in_the_Life_of_Lakshmi_Manchu's_Feet}} would output the same.

However, if the page has no {{DISPLAYTITLE}}, it should default back to the default, i.e. {{FULLPAGENAME}}.

Benefits:

This may have some uses with footnotes, system messages, being able to call it.

Notes:

  • First, {{PAGETITLE}} needs to be defined in includes/parser/CoreMagicVariables.php add pagetitle (lowercase) to array $noHashFunctions = [].
  • Next, the function needs to be defined in includes/parser/CoreParserFunctions.php.
  • The page title can be pulled with getDisplayTitle() which would look something like (needs checking):
public static function pagetitle( $parser, $title = null ) {
    $t = self::makeTitle( $parser, $title );
    if ( $t === null ) {
        return '';
    }
    return wfEscapeWikiText( $t->getDisplayTitle() );
}

References

Details

Due Date
Jun 18 2025, 3:30 AM
Related Changes in Gerrit:

Event Timeline

@SomeRandomDeveloper I think I've worked out all the details for this one, but would you mind checking:

  1. Do you agree with the above code?
  2. If so, would you mind submitting the above code to review for me? I have issues with MediaWiki accounts.

(Comments from anyone else welcome if you're feeling helpful today).

Thank you for tagging this task with good first task for Wikimedia newcomers!

Newcomers often may not be aware of things that may seem obvious to seasoned contributors, so please take a moment to reflect on how this task might look to somebody who has never contributed to Wikimedia projects.

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, for example it should clearly pointed to the codebase URL and provide clear steps to help a contributor get setup for success. We've included some guidelines at https://phabricator.wikimedia.org/tag/good_first_task/ !

Thank you for helping us drive new contributions to our projects <3

I want to work on this task. Can you assign me this task

I’m worried that it’s not immediately clear from the name of the proposed magic word (PAGETITLE) that - in addition to the name/title of the page - its output would also include any formatting that’s been set using DISPLAYTITLE.
I’m also worried that the proposed name would cause ambiguity/confusion between itself and the current magic word PAGENAME - obviously I’m speaking anecdotally here, but - to me - ‘page name’ and ‘page title’ seem like synonyms of one another.

On a more general note — @Bugreporter2, if you don’t mind me asking - as the original filer of this task, do you have a specific/example use case for the proposed functionality in mind? I’m asking as it may help me to understand better what the benefits of adding this magic word may be.

What is the behaviour that is excepted after making the changes?

I'm not sure the criticism that "this is too complicated" holds any water.

Call it something else if you like, but the page name is the page name, and the page title is the page title. Perhaps it doesn't help that #titleparts parses the page name, but that's the problem for #titleparts, not this. Rename that if you want.

Next, if you're somehow confused, there is documentation: https://en.wikipedia.org/wiki/Help:Magic_words

And there are Wikipedians who can deal with hideously complex templates.

There may be specific use cases of retrieving the page title, in the case of reports, or in templates, but also in system messages. It's clearly an important page property, but there's currently no way to output it.

Finally, one of the things that I also think we should be doing is giving people tools. Give artists people paint and canvas and they will paint. I'm not sure what they will paint, but they'll paint something. Maybe it will be profoundly life-changing, maybe it won't, but you won't find out unless you give them the chance.

And also, conversely, I'm not sure the general negativity is particularly helpful.

ZhaoFJx changed the task status from Open to In Progress.Jun 14 2025, 1:37 AM
ZhaoFJx set Due Date to Jun 18 2025, 3:30 AM.

There happens to be a hackathon on the 6/17, and I will submit the patch for code review on that day.

I'm not sure the criticism that "this is too complicated" holds any water.

Call it something else if you like, but the page name is the page name, and the page title is the page title. Perhaps it doesn't help that #titleparts parses the page name, but that's the problem for #titleparts, not this. Rename that if you want.

Next, if you're somehow confused, there is documentation: https://en.wikipedia.org/wiki/Help:Magic_words

And there are Wikipedians who can deal with hideously complex templates.

There may be specific use cases of retrieving the page title, in the case of reports, or in templates, but also in system messages. It's clearly an important page property, but there's currently no way to output it.

Finally, one of the things that I also think we should be doing is giving people tools. Give artists people paint and canvas and they will paint. I'm not sure what they will paint, but they'll paint something. Maybe it will be profoundly life-changing, maybe it won't, but you won't find out unless you give them the chance.

And also, conversely, I'm not sure the general negativity is particularly helpful.

Firstly, I apologize if what I’m saying is coming across as me just generally being negative, as that is absolutely not my intention.

I appreciate that there is documentation for the existing magic words, and that some existing magic words could probably have clearer names; however, IMO we should be cautious about the idea of adding any more potentially ambiguous/unclearly named magic words to MediaWiki. There might not be much that can be done about some of the magic words that already exist, but IMO the pre-existence of magic words with ambiguous names shouldn't be a reason/justification in and of itself for newly-added magic words to also have potentially ambiguous names. To be completely honest, "page name" and "page title" really do just appear as synonyms to me (& IMO, this is reinforced by the fact that the documentation for the existing 'page name' magic words uses the phrase "page title" in describing what many of those magic words return).

One reason I asked whether there was a specific use case was because I guess I’m instinctively wary of the software potentially being made more complex, without there being a known potential use case for the result of the added complexity; and because I'm having trouble thinking of a potential use case for this feature myself. While I appreciate that people need tools in order to build things, I guess I'm just a little cautious about the idea of adding features without knowing that they would likely be useful in some way — otherwise, I guess my thinking is that there's a risk that we (as developers) could add a number of extra features that seem like they might be good, but which might then have little-to-no usage in practice.

I'll add my name to say that I would find this feature extremely useful at {{Wikisource}}, to default the link display text to the page's DISPLAYTITLE. (In fact, I was going to file a feature request!) I'm sure there are other templates which could make use of the functionality to correctly format a link to a page.

Would {{PAGEDISPLAYTITLE}} or {{PAGEDISPLAY}} be a better name?

@HouseBlaster thank you for the comment! It's good to hear that there would be use cases for this functionality - thank you for the examples :)
Looking at the {{wikisource}} template specifically though, would that require fetching the DISPLAYTITLE for a page on a different project? If so, I may be completely wrong here — & happy to be corrected if so! — but my instinct is that this might not be possible with this magic word on its own (at least, as currently proposed) / that this might require more (software) connections between individual wikis than currently exists.

On the subject of the name, I might have slight concerns that something like {{PAGEDISPLAYTITLE:}} could be potentially ambiguous with {{DISPLAYTITLE:}} itself… but, to be honest, that sort of name for the magic word would probably resolve my worries around ambiguity with the page's canonical title!
(As another idea to throw into the mix, maybe something like {{GETDISPLAYTITLE:}} might work, in order to distinguish it as the magic word that fetches a page's DISPLAYTITLE? I don't know whether/how that would fit in to existing magic word naming conventions, though.)

A_smart_kitten renamed this task from output page title as magic word `{{PAGETITLE}}` to Add a magic word that returns a page's DISPLAYTITLE.Jun 15 2025, 2:15 PM
A_smart_kitten updated the task description. (Show Details)

My plan would be to change the current line 42 of the Lua module, which currently sets the displayText to the canonical page name. (I know this is a magic word, not a Lua function—the plan would be to use frame:callParserFunction.)

I guess I could make use of a magic word which fetches the DISPLAYTITLE from a different project, but that is outside the scope of this task.

Ah! My apologies, I misunderstood you previously :)

Change #1162091 had a related patch set uploaded (by ZhaoFJx; author: ZhaoFJx):

[mediawiki/core@master] parser: Add PAGETITLE magic variable (TEST)

https://gerrit.wikimedia.org/r/1162091

for the name of {{PAGETITLE}}, it may conflicts with

	"pagetitle": "$1 - {{SITENAME}}",

in i18n/en.json at line 151.


I will use TITLENAME for now until a new name is chosen.

@Bugreporter2 the doc meantioned

...MediaWiki checks to see if the magic word ID has been declared as a variable ID. To check this, it retrieves the list of magic words serving by calling MagicWord::getVariableIDs(). This method gets its list of variable IDs from a hard coded list of variable IDs (see Help:Variables) and from a list of custom variable IDs provided by all functions attached to the hook MagicWordwgVariableIDs.

somehow I have to declare these in the LocalSettings.php to make it works:

$wgHooks['MagicWordwgVariableIDs'][] = function ( &$variableIDs ) {
    $variableIDs[] = 'titlename';
    $variableIDs[] = 'titlenamee';
    return true;
};

I'm sure there is a more elegant and proper way to do this, would you clarify where can I save this block?

If {{PAGETITLE}} is a problem, then {{WIKIPAGETITLE}} might be better.

If {{PAGETITLE}} is a problem, then {{WIKIPAGETITLE}} might be better.

Noted

I'm sure there is a more elegant and proper way to do this, would you clarify where can I save this block?

Found it, includes/parser/MagicWordFactory.php.

Change #1163442 had a related patch set uploaded (by ZhaoFJx; author: ZhaoFJx):

[mediawiki/core@master] parser: Add WIKIPAGETITLE magic variable

https://gerrit.wikimedia.org/r/1163442

Change #1162091 abandoned by ZhaoFJx:

[mediawiki/core@master] parser: Add PAGETITLE magic variable (TEST)

Reason:

Proper patch submitted at I529aa94e6ea46c3b81de1ee0ff989c6a15287fdd

https://gerrit.wikimedia.org/r/1162091

New parser features should use {{#...}} syntax and be case sensitive. See T204370 and T389029.

The biggest issue here is the order-dependence between {{DISPLAYTITLE}} and {{PAGETITLE}}. I don't have a great solution for that, but we're unlikely to add new order-dependence constructs to wikitext as they interfere with selective update.

One option would be to make displaytitle a separate metadata property independent of the page wikitext, like language links are now. Then the parser function could echo the metadata without causing circularity issues with wikitext parsing.

New parser features should use {{#...}} syntax and be case sensitive. See T204370 and T389029.

That's fine. Suggest something like {{#pagetitle}} instead:

One option would be to make displaytitle a separate metadata property independent of the page wikitext, like language links are now. Then the parser function could echo the metadata without causing circularity issues with wikitext parsing.

That sounds like a promising approach.

Now that T328254: Parser function for content model {{#contentmodel:}} is fixed, I think this is the last major page variable that can't be output as a magic word.

Now that T328254: Parser function for content model {{#contentmodel:}} is fixed, I think this is the last major page variable that can't be output as a magic word.

No, I was wrong. There are two now; this and T386673: magic word {{#isredirect}}.

Also, it's worth noting that the DISPLAY in DISPLAYTITLE is an imperative mood verb. It's saying "[The wiki will] DISPLAY [as the] TITLE [the following]:". {{SETTITLE}} might have been a good alternative.

DISPLAY in DISPLAYTITLE is not an adjective -- that would require a past participial adjective DISPLAYed. Finally, the default page title is equal to the page name, so most pages do not have a displayed title set by the magic word, they use the default page name value. But this feature request requests that the page title is output, regardless of whether that's set by {{DISPLAYTITLE}} or the default.

Bugreporter2 renamed this task from Add a magic word that returns a page's DISPLAYTITLE to Add a magic word that returns the page title, which may be set by {{DISPLAYTITLE}} or default to page name.Sep 16 2025, 2:27 AM

Also, it's worth noting that the DISPLAY in DISPLAYTITLE is an imperative mood verb. It's saying "[The wiki will] DISPLAY [as the] TITLE [the following]:". […]

I read it as noun, not a verb.

DISPLAYTITLE is the title shown on the display. It is what the software renders on the web page, on the display. This goes well alongside other title variants, such as database title or URL title. See also "display name" (wiki, BBC) as a way to describe your preferred name shown in an interface (as distinct from your login username).

In context of magic wrods, we have only one other setter, I think, {{DEFAULTSORT:}}. It is implied that declaring it wikitext, sets it.

ZhaoFJx changed the task status from In Progress to Open.Sep 28 2025, 4:54 PM

Under analysis

ZhaoFJx subscribed.

I'm not quite too sure how to meet the QAs, so I will unassign me for now, and please feel free to claim it.