Mailing List Archive

Programmatically getting the current page's title?
I am writing a custom extension. What is the best way in PHP to get the
current page's/article title in PHP? I've seen that Title::getText()
will work but I've also seen something called MagicWord with a PAGENAME
attribute ...

Something that will work even when doing a 'preview'.

Thanks,

Jc
Re: Programmatically getting the current page's title? [ In reply to ]
On Nov 29, 2004, at 4:00 AM, Jean-Christian Imbeault wrote:
> I am writing a custom extension. What is the best way in PHP to get
> the current page's/article title in PHP? I've seen that
> Title::getText() will work but I've also seen something called
> MagicWord with a PAGENAME attribute ...
>
> Something that will work even when doing a 'preview'.

The current page title is provided (as a Title object) in the global
variable $wgTitle. You can get its full text name including namespace
as $wgTitle->getPrefixedText().

(The 'text' forms use spaces, while the 'dbkey' forms use underscores.
The dbkey form is used internally in the database and for URLs.)

Note that since titles can contain ampersand and quote characters, you
should always escape any titles that you output in HTML using the
htmlspecialchars() function or equivalent.

-- brion vibber (brion @ pobox.com)