Search code examples
phpmediawikisemantic-mediawiki

How to programmatically generate a link in MediaWiki to a page via php?


I just want to generate a Link to a page of a MediaWiki in CODE via PHP, specifically in the skin template.

The background is that the skin has a set of links in a sidebar that don't change but refer to a page in the Wiki.

I don't want to use hard coded links as Host-URLs might change and I don't want to deal with GET-parameters in the URL that might already be there.

Any ideas?

I can't find a solution in the MediaWiki Docs, API etc.


Solution

  • $title = Title::newFromText( 'Pagename' );
    echo $title->getLocalUrl();
    

    /wiki/Pagename

    echo $title->getFullURL();
    

    http://example.com/wiki/Pagename

    echo $title->getFullURL( array( 'foo' => 'bar' ) );
    

    http://example.com/w/index.php?title=Pagename&foo=bar