Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Current Page URL in MediaWiki

Tags:

php

mediawiki

I am trying to get the current page's url and store it to a variable in my custom skin template. I am trying to do this so I can use this url for other purposes. I am trying to do something like this

function currentpageurl() //Some Custom function
{
    $url= [something that can get current page's url in mediawiki and store it to this variable]
    .....use the $url variable for other purposes....
    ......
    .....
}

Does Mediawiki has a way that can identify the current page's url or is my only option to find the current page is by using this method?

$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
like image 879
Neel Avatar asked Mar 23 '23 15:03

Neel


2 Answers

If you're writing a QuickTemplate subclass for a skin, you can get a Title object for the current page using $this->getSkin()->getTitle().

Once you have the Title object, you can call getLinkURL() on it to get the URL of the page. (You probably don't want to use getPrefixedURL() as Ilya suggests, as that just gives you an URL-encoded version of the page name.) Or you can pass the Title object to Linker::link() if you want to generate a standard wikilink-style link without having to mess with URLs yourself.

In fact, $this-getSkin() is the general way to gain access to "request-global" MediaWiki objects like the current Title, WebRequest, User, Language, OutputPage, etc. from a skin template. Specifically, the Skin class implements the IContextSource interface, which provides access to all those objects.

like image 51
Ilmari Karonen Avatar answered Mar 25 '23 04:03

Ilmari Karonen


Since your know current page name ($name), you can use MediaWiki Title (see http://www.mediawiki.org/wiki/Manual:Title.php ). As I understand, it must looks like this:

$title = Title::newFromText($name);
$url = $title->getPrefixedUrl();
like image 39
Ilya Avatar answered Mar 25 '23 05:03

Ilya