mediawiki - make link evaluation case insensitive

Viewed 167

i'm running a small wiki and our users would like an interface they find less confusing. the complaint is that a page titled something like 'Big_news' displays as a redlink if the link is 'Big News' or 'big news' or some other upper/lower case permutation, and they'd like these to appear as normal-coloured links if the page exists. when a user clicks on the link, the appropriate page is displayed correctly, but it would be better to see that the page already exists beforehand.

i've tried to implement solutions such as those presented here, here, and here, but they don't work -- links still display as redlinks on the page. [indeed, i think some of the articles are out of date ; mediawiki 1.27 doesn't seem to have the tables mentioned in them.]

any ideas how i might go about doing this ?

3 Answers

You could look at how $wgCapitalLinks is being used. Chances are, all-lowercase titles will need special casing in the same places where code needs to be branched based on that setting.

You could hook on HtmlPageLinkRendererBegin and use the link target to run a database query to find any case-insensitive matches for the page name (on page title, and it'd have to do this only for internal links), and then replace the target if there's a match.

thanks for the tip, @Sam Wilson. that looks like an interesting function, but unless i miss my guess, i'd have to query the database for every single link in a page -- correct ? if so, i think performance would suffer. anyway, that hook didn't seem to work for me [mostly because my unfamiliarity with mediawiki left me scratching my head...]. the solution i came up with is as follows :

1- add the variable $wgLinksIgnoreCase to your LocalSettings.php file. set this to true if you want link displays to be mapped case-insensitively.

2- modify the file includes/parser/LinkHolderArray.php as follows [diff accurate for wikimedia version 1.29] -

283a284
>               global $wgLinksIgnoreCase;
370a373,376
>               if (!empty($wgLinksIgnoreCase)) {
>                   $mapper = array_combine(array_keys($colours), array_keys($colours));
>                   $mapper = array_change_key_case($mapper);
>               }
373a380,381
>               if (!empty($wgLinksIgnoreCase) && isset($mapper[strtolower($pdbk)]))
>                   $pdbk = $mapper[strtolower($pdbk)];

as i say, i'm not very familiar with the software, so if anyone who is familiar with it finds a more elegant solution, feel free to chime in.

Related