Extension:NiceCategoryList2

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
NiceCategoryList2

Release status: stable

px
Implementation Tag
Description Displays a nicely-formatted category list, with versatile sub-category listing.
Author(s) Kichik, JohanTheGhost, *Surak* (*Surak*talk)
Latest version 2.2.3 (2011-05-01)
MediaWiki 1.16
PHP 5.2, 5.3
License GPL
Download Version 2.2.3 (find other versions)
Example see below
Parameters

$egNiceCategoryListDisableCache, $egNiceCategoryListHeadStart, $egNiceCategoryListInstallDir, $egNiceCategoryListShowFirst

Tags
<ncl>

Translate the NiceCategoryList2 extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

What can this extension do?[edit | edit source]

This extension displays a category listing, including sub-categories, in a number of useful formats. This is intended to allow easier navigation of a wiki's category tree. It implements a new tag, <ncl>, which generates a list of all pages and sub-categories in a given category. The list can display multiple levels of sub-categories, and has several options for the display style.

This extension was originally created by Kichik as Extension:NiceCategoryList, and has been enhanced by JohanTheGhost and *Surak*.

Usage[edit | edit source]

Parameters[edit | edit source]

The <ncl> tag displays a category list:

<ncl [options]>Category:Some Category</ncl>

The tag takes the following parameters, all of which are optional:

maxdepth=<number>
maximum category depth to display; default 32
headings=<style>
'head' to display category headings as Wiki headings (default); 'bullet' to display category headings as bullet lists
showfirst=<bool>
'0' to skip top heading (default), else display it
headstart=<number>
with 'headings=head', headstart is the heading level to list top-level categories with; default 2
style=<style>
'bullet' to show category contents as bullet lists (default); 'compact' for a more compact listing
showcats=<bool>
not '0' to display sub-category links in "bottom" (i.e. maxdepth) categories; default 0
showarts=<bool>
not '0' to display articles in categories; default 1
sort=<bool>
not '0' to sort the list alphabetically; else sort the list according to the index key; default 0
number=<number>
not '0' to display only up to <number> of articles, else display all articles; default 0
random=<bool>
with number not '0': display random choice of articles if random not '0', else display the first <number> of articles; default 0

CSS Styles[edit | edit source]

The original wiki syntax created with version 2.2 was basically left, but all direct formatting was taken out. Instead the discrete elements are enclosed in DIV and SPAN tags with class names. The benefit is that you can apply styles to the items, either in Common.css, in the current skin's CSS or in your user CSS.

<!-- Sample output for
     <ncl headings=head headstart=2 style=bullet>category</ncl>
-->
<div class="ncl-nicecategorylist>
  <div class="ncl-block ncl-block-head ncl-block-head-0">
    <h2 class="ncl-heading ncl-heading-0">
      Category Name
    </h2>
    <div class="ncl-content ncl-content-bullet ncl-content-bullet-0">
      <ul>
        <li><span class="ncl-subcategory">Subcategory Link</span></li>
        <li><span class="ncl-subcategory">Subcategory Link</span></li>
        <li></li>
        <li><span class="ncl-article">Article Link</span></li>
        <li><span class="ncl-article">Article Link</span></li>
        <li></li>
      </ul>
    </div>
  </div></div>


<!-- Sample output for
     <ncl headings=bullet style=compact>category</ncl>
-->
<div class="ncl-nicecategorylist>
  <div class="ncl-block ncl-block-bullet ncl-block-bullet-0">
    <div class="ncl-heading ncl-heading-0">
      <ul><li>Category Link</li></ul>
    </div>
    <div class="ncl-content ncl-content-compact ncl-content-compact-0">
      <p>
        <span class="ncl-subcategory">Subcategory Link</span><span class="ncl-subcategory">Subcategory Link</span> •  
        ‴  •
        <span class="ncl-article">Article Link</span><span class="ncl-article">Article Link</span> •
        ‴  •
        …
      </p>
    </div>
  </div></div>

The whole category tree is now encapsulated into a DIV container with a classname of ncl-nicecategorylist.

Each level of the category tree is encapsulated in a div container with a classname of ncl-block-{headings}-{x}. {headings} means one of the headings options, either bullet or head. {x} means a numeric value that starts at zero and is increased on each subordinate level of the category list, until maxdepth is reached.

Inside of this top DIV container, two subordinate blocks exist for the heading and the content:

  • The heading is covered by a block with a classname of ncl-heading-{x}. {x} means a numeric value that starts at zero and is increased on each subordinate level of the category list, until maxdepth is reached. If the option showfirst=0, then the first header is not displayed. This is the default setting, since previous versions of the extension did not display it. The default can be overwritten by using $egNiceCategoryListShowFirst = 1; in LocalSettings.php.
    • If the option heading=bullet, the block is a DIV block displaying the category as link to the category page as bullet list item.
    • If the option heading=head, the block is a usual headings block, starting at <h{n}>. {n} means a numeric value that starts at {headstart} and is increased on each subordinate level of the category list. The default setting is headstart=2. It can be set back to the default of previous versions by using $egNiceCategoryListHeadStart = 1; in LocalSettings.php. If you want to activate the first heading for a certain category list, you can use the option showfirst=1 (or inactivate it with showfirst=0 otherwise).
  • The content is covered by a block with a classname of ncl-content-{style}-{x}. {style} means one of the style options, either bullet or compact. {x} means a numeric value that starts at zero and is increased on each subordinate level of the category list, until maxdepth is reached. It contains SPAN containers with the subcategories (if showcats=1) and articles (if showarts=1) of the regarding category.
    • Each subcategory is enclosed in a SPAN container with a classname of ncl-subcategory.
    • Each article is enclosed in a SPAN container with a classname of ncl-article.

Additionally to the above mentioned classes, some generic classes are defined to apply styles on groups of items:

  • ncl-block to apply styles to all items with classnames of ncl-block-bullet-{x} and ncl-block-head-{x}.
  • ncl-block-bullet to apply styles to all items with classnames of ncl-block-bullet-{x}.
  • ncl-block-head to apply styles to all items with classnames of ncl-block-head-{x}.
  • ncl-heading to apply styles to all items with classnames of ncl-heading-{x}.
  • ncl-content-compact to apply styles to all items with classnames of ncl-content-bullet-{x} and ncl-content-compact-{x}.
  • ncl-content-bullet to apply styles to all items with classnames of ncl-content-bullet-{x}.
  • ncl-content-compact to apply styles to all items with classnames of ncl-content-compact-{x}.


Examples[edit | edit source]

For a full, recursive listing of all categories under a specified category, use this:

<ncl>Category:Some Category</ncl>

NiceCategoryList2 extension default.jpg

For a nice "high-level" category index, use this in a template:

<ncl style=compact maxdepth=2 headings=bullet headstart=2
     showcats=1 showarts=1>Category:{{PAGENAME}}</ncl>

and include it in major category pages to provide a nice 2-level (or however many you like) index of the category.

NiceCategoryList2 extension example.jpg

This:

<ncl style=compact headings=bullet headstart=2 showcats=1
      showarts=0>Category:Categories</ncl>

generates a full category listing, with indentation indicating category containment.

NiceCategoryList2 extension full.jpg

Caveat: When used in a template, the category list will not refresh immediately when reloaded; edit and save the article to see updates.

Performance[edit | edit source]

Installation & Configuration[edit | edit source]

Versions[edit | edit source]

Version 2.2.3 added CSS formatting and improved several minor issues; tested with MW 1.16.2 and PHP 5.2.17; includes the fix from version 2.2a to work with PHP 5.3 (not tested)
Version 2.2.2a works for PHP 5.3
Version 2.2.2 solved problem with MW 1.12; seems to not work with PHP 5.3
Version 2.2.1 fixes rendering bugs for sibling categories and articles
Version 2.2.0 known to work with PHP 5 and MW 1.9; will not work on PHP 4 / MW 1.6; this version has much better encapsulation and is better structured
Version 2.1.0 known to work with PHP 4 and MW 1.6
Version 1.1.5
Version 1.1.4

Installation[edit | edit source]

Save all files of the latest version from above into the directory {your wiki}/extensions/NiceCategoryList, and add the following near the end of {your wiki}/LocalSettings.php:

include_once("$IP/extensions/NiceCategoryList/NiceCategoryList.php");

If you need to install the extension into a different extensions subdirectory, use:

include_once("$IP/extensions/{your directory}/NiceCategoryList.php");
              $egNiceCategoryListInstallDir = "{your directory}";

Configuration[edit | edit source]

If you want to inactivate the cache for pages using the extension, use:

              $egNiceCategoryListDisableCache = true; // disables page caching

If you want to default the headstart option to something different than '2', use:

              $egNiceCategoryListHeadstart = 1; // defaults headstart to 1

If you want to default the display of the first heading, use:

              $egNiceCategoryListShowFirst = 1; // displays first heading