Snippets/Multi-column sorted categories

From MediaWiki.org
Jump to navigation Jump to search
How to use Snippets
List of Snippets
Crystal Clear action run.png
Multi-column sorted categories
Language(s): PHP
Compatible with: MediaWiki 1.27 (or earlier)+ (all)

Instead of an unreadable old-style, concatenated, unsorted, long list of categories you can now choose to display your page categories as a modern, multi-column, sorted table.

A really nice and readable layout for MediaWiki page categories. Very easy to implement.

Simple PHP patch[edit]

Patch valid for MediaWiki 1.27, or earlier. You only have to change 5 lines of code.

rcsdiff -u includes/skins/Skin.php
 1 RCS file: includes/skins/RCS/Skin.php,v
 2 retrieving revision 1.1
 3 diff -u -r1.1 includes/skins/Skin.php
 4 --- includes/skins/Skin.php 2017/09/30 18:41:49 1.1
 5 +++ includes/skins/Skin.php 2017/09/30 19:27:04
 6 @@ -442,14 +442,16 @@
 7 $colon = $this->msg( 'colon-separator' )->escaped();
 8 
 9 if ( !empty( $allCats['normal'] ) ) {
10 - $t = $embed . implode( "{$pop}{$embed}", $allCats['normal'] ) . $pop;
11 +$gvpCat =$allCats['normal'];
12 +asort($gvpCat);
13 + $t = implode( '<br>', $gvpCat ) ;
14 
15 $msg = $this->msg( 'pagecategories' )->numParams( count( $allCats['normal'] ) )->escaped();
16 $linkPage = wfMessage( 'pagecategorieslink' )->inContentLanguage()->text();
17 $title = Title::newFromText( $linkPage );
18 $link = $title ? Linker::link( $title, $msg ) : $msg;
19 - $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
20 - $link . $colon . '<ul>' . $t . '</ul>' . '</div>';
21 + $s .= $link . ':<br><div id="mw-normal-catlinks" class="mw-normal-catlinks" >' .
22 + $t . '</div>';
23 }

Small change in CSS[edit]

Edit MediaWiki:Common.css

.mw-normal-catlinks {
	column-count:6; -moz-column-count:6; -webkit-column-count:6
}