Jump to content

Topic on Project:Support desk

[RESOLVED] How to find Displaytitle from $Title via PHP

7
Dries (talkcontribs)

Can somebody help me or direct me into the right place/direction? I have the $title of a page. How can I get to the DisplayTitle via php. I get lost in all the documentation. (Not a very experienced programmer)

Any help is greatly appreciated! Thanks, greetings Dries

Euloiix (talkcontribs)

I am not very sure what you call the DisplayTitle, but I am willing to help.

I will assume that you mean by DisplayTitle the part of the page title eventually displayed as the page heading. Also I am assuming that the $title of the page you are talking about is an instance of the Title class from the Title.php file. Please say so if I am wrong.

Then, to achieve your goal, something like $title->mTextform should work. If the result is not what you want, take a look at the class properties of the Title class(includes/Title.php file), you might be able to solve your problem.

I hope this helps.

Dries (talkcontribs)

Hello!

Thanks for your reply. By displaytitle I mean the alternative title you can set with {{DISPLAYTITLE:This is an alternative title}}. We use that a lot on our wiki so we can keep every page with the corresponding filename of our framework. With {{DISPLAYTITLE...}} we use a more readable title.

I can get it via the /wiki/api.php but I get very bad reaction times, it really slows down my extension. I was wondering there was a faster way of getting it, by a query on the database or some function but I'm kind of losing my way in all the code docs...

Euloiix (talkcontribs)

Sorry for the late reply. And... I have no idea. I did not even knew about this feature. But from what this page says, the display title must be the same that the actual title. Sorry I cannot be more useful.

Bawolff (talkcontribs)

It's stored in the page_props table. Assuming $title is an instance Title class you can do something like follows:

$dbr = wfGetDB( DB_SLAVE );
$displayTitle = $dbr->selectField(
  'page_props',
  'pp_value',
  array( 'pp_propname' => 'displaytitle', 'pp_page' => $title->getArticleId() ),
  __METHOD__
);
// displayTitle will be the html (aka all wikitext is converted to html) of the field or false if no display title is set for the page
Dries (talkcontribs)

Thanks, finally had the time to check it out. It works!

Euloiix (talkcontribs)
Reply to "[RESOLVED] How to find Displaytitle from $Title via PHP"