Mastergalen
Mastergalen

Reputation: 4389

Show different Main Pages based on host name in MediaWiki

I have two domains pointing to the same wiki sharing the same database.

I would like it so that with domainA.com the main page is MainPageA and with domainB.com it is MainPageB.

The only way to change the the main page of MediaWiki that I know of is to edit MediaWiki:Mainpage, but that is stored in the MySQL database. Since both wikis are sharing the same database, both main pages get changed too.

The reason that the databases are shared is because all articles apply to both wikis, just that the logo of the wiki etc. is different.

Is there some kind of PHP conditional variable I can set to set the Main Page?

Upvotes: 2

Views: 321

Answers (1)

Ilmari Karonen
Ilmari Karonen

Reputation: 50328

You could do this in wikicode, by making your Main Page source look something like this:

{{#switch:{{SERVERNAME}}
  |domainA.com={{:Main Page for domainA.com}}
  |domainB.com={{:Main Page for domainB.com}}
  |#default=<span class=error>Unrecognized domain {{SERVERNAME}}.</span>
}}

or even just:

{{:Main Page for {{SERVERNAME}}}}

For more information, see Help:Magic words at mediawiki.org. (Note that the first version also requires the ParserFunctions extension.)

Ps. There might be some issues with MediaWiki's parser caching that could cause the wrong Main Page to appear. If so, a quick and dirty workaround would be to install the MagicNoCache extension and add __NOCACHE__ to the Main Page.

Pps. A better solution for cache issues might be to make sure that the different sites have separate cache keys, by adding the following line to your LocalSettings.php:

$wgRenderHashAppend .= "!$wgServer";

Upvotes: 5

Related Questions