14 Oct, 2018

Move MediaWiki table of contents (TOC) to the right in Vector skin

MediaWiki is growing on me more and more as far as organising information to share between the members of a team. Sure, it has downsides which are rather obvious (e.g. maybe complicated to update), but all in all it is worth being taken into consideration as your own Wiki.

So, having the Table of contents to the right is something some people might want. So here is a solution:

MediaWiki:Common.css

Access your Common.css file with this URL: https://example.com/index.php?title=MediaWiki:Common.css and add:

MediaWiki:Common.js

Access your Common.js file with this URL: https://example.com/index.php?title=MediaWiki:Common.js

Last notes

As the comments in each set of mods say, this changes apply to all the skins available. Therefore, if not using the Vector skin, it might make the wiki look bad. As far as what the code does:

  1. In the URLs, replace example.com with the address of your wiki, obviously;
  2. The CSS file is loaded first and faster, so it contains the default rules;
  3. If the width of the whole content is big enough (the choice was for 800px, but you can change this to whichever value you want) then the TOC is moved to the right and some padding to the right is added to the content;
  4. As we all know, there are no IFs in CSS. Therefore, this is where Javascript and jQuery (which is loaded by default in MediaWiki) come in. The JS part checks if the TOC is there and if it is not, it changes the CSS for the content to the default.