Jump to content

Extension talk:NiceCategoryList2

Add topic
From mediawiki.org

mediawiki 1.25.3 and NiceCategoryList2 3.0

Doesn't work. Even simple:

<ncl>Category:Some Category</ncl>

doesn't show anything.

Just take this 2.2a Version, works fine for me.

Almost Nothing Displays at All

I'm running mw v1.6 with php v4.4.7 and NCL v1 with the include in localsettings.

With code like this: <ncl>Category:Books</ncl> then I get a list of the pages in the BOoks category. However, no matter what code I put in, I can't get the ncl to list all the categories. (I only have top level categories BTW).

Has anyone else had this or can anyone suggest anything here? Thanks!.

New option to sort regarding the key

I added a new option to avoid ncl to sort the list alphabetically, to have index key sorting like mediawiki does.

Thanks for your extension of the extension. Jej 10:46, 9 November 2006 (UTC)Reply

Cannot add more than one set of ncl tags

Why can't I add more than one set of <ncl> tags in a page?

Sarwar (sarwar@metafour.com)

It seems to be working for me... maybe try the new version? JohanTheGhost 00:42, 2 March 2007 (UTC)Reply

Broken with 1.9a

I'm running a recently-upgraded 1.9a, and I get this with any NCL listing:

UNIQa23a55a20531f14-ncl-00000002-QINU

Or something similar anyway. Different everytime I load the page. Not sure what's up, can you perhaps tell me what to fix? ℑilver§ℑide 18:39, 4 January 2007 (UTC)Reply

Yup, I've finally run into this myself. I've uploaded a new version which seems to fix it. Cheers, JohanTheGhost 00:36, 2 March 2007 (UTC)Reply
Do you have this fix in v1.0 also? I have MW 1.8.3 and recently run into same problem... Thanks! Khitrenovich 11:05, 25 July 2007 (UTC)Reply

Help (mediawiki 1.6,ncl 1.0)

I've installed the code[includes....] in my localsetting.php, and upload the version 1.0 in extensions. And when i put <ncl>category:...</ncl>, it display the category listing when I modified the page but when I saved, it isnt display anything.(sorry for my bad english) Idon't understand.--Add 02:23, 19 June 2007 (UTC)Reply

I don't know why that would be, but it sounds like a cache issue.... edit it again, and do "Show preview" -- does the list appear? And when you save again, what exactly is displayed? JohanTheGhost 15:23, 20 June 2007 (UTC)Reply
I have already test that, but when I do "Preview" it display correctly the category, but when i save it display "nothing", a blank. I have put
require_once("$IP/extensions/NiceCategoryList.php");
, maybe if I change it to
require_once($IP."/extensions/NiceCategoryList.php");
but I thing that it's no importante.I test and i post if it anything changed.--Add 02:26, 21 June 2007 (UTC)Reply
The only thing I can think of is that another extension may be interfering with it. Someone recently had a similar problem with the SelectCategory extension. Do you have other extensions installed? What happens if you disable them (comment out the "require_once" lines from LocalSettings)? JohanTheGhost 14:51, 21 June 2007 (UTC)Reply
MediaWiki: 1.6.10
PHP: 4.4.3-dev (cgi-fcgi)
MySQL: 5.0.37
Extensions:

    * Special pages:
          o Edit Count, Gets the edit count of a user, by Benjamin Peterson
          o MakeBot, Special page allows local bureaucrats to grant and revoke bot permissions, by Rob Church 
    * Parser hooks:
          o CharInsert, Allows creation of JavaScript box for inserting non-standard characters, by Brion Vibber
          o Edit Count, Gets the edit count of a user, by Benjamin Peterson
          o MultipleUpload, Allows users to upload several files at once., by Travis Derouin
          o NiceCategoryList, generate a category page showing all pages in a category, including subcategories, by Kichik
          o Sort, Simplify the creation of sorted lists., by Rob Church 
    * Other:
          o Newuserlog, adds a log of account creations to Special:Log, by Ævar Arnfjörð Bjarmason 

style=compact not working?

Hi,

Great extension! Im fairly new to MediaWiki but would really like to use your extension. I installed it but for some reason when I specify the style=compact option nothing shows up. If I used the style=bullet option it works, but I'm really after that nice compact look :(

Im running php5, MW 1.10. Tried NiceCategoryList version 1 but still no luck. Any idea?

Thanks again

Cheers

Weird. I just upgraded my test wiki to 1.10, and style=compact works fine for me; in fact, it's the style I use for my main index. Here's the exact code (it's in a template which I include in category pages):
<ncl style=compact maxdepth=2 headings=bullet headstart=2 showcats=1 showarts=1>Category:{{PAGENAME}}</ncl>
Try these exact parameters; if there's some parameter combination which doesn't work, let me know, and I'll try to fix it. Otherwise, all I can suggest is that you have some strange conflict with another extension you have installed. Try temporarily disabling them one by one to see if you can find which one is causing problems? JohanTheGhost 15:50, 5 July 2007 (UTC)Reply
I'm having the same problem.
These are my extensions :
  • CategoryTree
  • Contributors
  • Duplicator
  • NiceCategoryList
  • ParserFunctions
  • Google Maps Extension (version 0.7.7)
I've tried and switched them of, but no change.
MediaWiki: 1.10.1, PHP: 5.2.3 (cgi-fcgi), MySQL: 4.1.11-Debian_4sarge7-log
--Luc Verhelst 12:56, 10 August 2007 (UTC)
Yes, I am also having the same problem. All parameters work except for style=compact. --Magick 09:42, 4 September 2007 (UTC)Reply

style=compact and headings=bullet working together

JohanTheGhost: style=compact and headings=bullet don't quite work together if you have categories which have non-category siblings. For example, if you have a category 1, and you have 1.1 and 1.2 under 1, but you also have an articles X and Y under category 1, then NCL2 renders something like this:

<big>
* [[:Category:Category 1|'''Category 1''']]</big>
:[[:Article X|Article X]] • [[:Article Y|Article Y]]<br>
** [[:Category:Category 1.1|'''Category 1.1''']]
** [[:Category:Category 1.2|'''Category 1.2''']]

Notice that the articles introduce a newline before the subcategories. MediaWiki thinks this means that the subcategories are not part of the category list, and puts two bullets in front of Category 1.1. You can solve this by doing, e.g.,
<big>
* [[:Category:Category 1|'''Category 1''']]</big><br>:[[:Article X|Article X]] • [[:Article Y|Article Y]]
** [[:Category:Category 1.1|'''Category 1.1''']]
** [[:Category:Category 1.2|'''Category 1.2''']]

Doing this without breaking the other layout types looks a little annoying, though.
Follow-up: I think I fixed that bug, plus made "style=bullet headings=bullet" work properly in the situation where categories and articles are siblings. I posted my changes as version 2.1.

Allow for parser syntax

This is a great extension. However, I was trying to use it in a template and ran into an issue that the template arguements were not getting parsed by the extension. This is typical for non parser-style extensions. I have made the modifications to your code, v2.0. See below

<?php

/*
 * Nice Category List extension.
 *
 * This extension 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.
 *
 * Usage:
 *   <ncl [options]>Category:Some Category</ncl>
 *
 * The following options are available:
 *   maxdepth         Maximum category depth; default 32
 *   style            'bullet' to show category contents as bullet lists
 *                    'compact' for a more compact listing
 *   showcats         Non-0 to display sub-category links in "bottom" (ie.
 *                    maxdepth) categories (default 0).
 *   showarts         Non-0 to display articles in categories (default 1).
 *   headings         'head' to display category headings as Wiki headings;
 *                    'bullet' to display category headings as large bullets
 *                    ('bullet' works well with 'style=compact').
 *   headstart        With 'headings=head', the heading level to list
 *                    top-level categories with (level increases for sub-cats).
 *
 * Examples:
 * 1. This:
 *      <ncl>Category:Some Category</ncl>
 *    generates a full, recursive listing.
 *
 * 2. 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.
 *
 * 3. 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.
 *
 * Caveat: When used in a template, the category list will not refresh
 * immediately when reloaded; edit and save the article to see updates.
 */

if (!defined('MEDIAWIKI')) die();

$wgExtensionFunctions[] = 'wfNiceCategoryList';
$wgHooks['LanguageGetMagic'][] = 'wfNclParserFunction_Magic';
$wgExtensionCredits['parserhook'][] = array(
  'name' =>        'NiceCategoryList',
  'author' =>      'Kichik, Johan the Ghost',
  'url' =>         'http://meta.wikimedia.org/wiki/NiceCategoryList_extension',
  'description' => 'generate a category page showing all pages in a category, including subcategories',
);


function wfNclParserFunction_Magic( &$magicWords, $langCode ) {
        # Add the magic word
        # The first array element is case sensitive, in this case it is not case sensitive
        # All remaining elements are synonyms for our parser function
        $magicWords['ncl'] = array( 0, 'ncl' );
        # unless we return true, other parser functions extensions won't get loaded.
        return true;
}

/*
 * Setup Nice Category List extension.
 * Sets a parser hook for <ncl></ncl>.
 */
function wfNiceCategoryList() {
    new NiceCategoryList();
}


/*
 * Simple class to hold category's title, links list,
 * and categories list.
 */
class NiceCategoryList_Links {

    private $title;
    private $articles = array();
    private $categories = array();
    private $subcats = array();

    public function __construct($title) {
        $this->title = $title;
    }


    public function addCategory($title, $links) {
        $this->subcats[] = $title;
        if ($links)
        	$this->categories[] = $links;
    }


    public function addArticle($title) {
        $this->articles[] = $title;
    }


    /*
     * Get the title of this category.
     */
    public function getTitle() {
        return $this->title;
    }


    /*
     * Get the titles of the sub-categories of this category.
     */
    public function getCatTitles() {
        return $this->subcats;
    }


    /*
     * Get the titles of the articles in this category.
     */
    public function getArtTitles() {
        return $this->articles;
    }


    /*
     * Get the link records of the sub-categories of this category,
     * if we have them.
     * Returns an array of NiceCategoryList_Links objects.
     */
    public function getCategories() {
        return $this->categories;
    }


    /*
     * Return true iff we have link records for the sub-categories
     * of this category.
     */
    public function hasCatLinks() {
        return count($this->categories) > 0;
    }


    /*
     * Title comparison function
     */
    private function titleCmp($a, $b) {
        return $a->getText() > $b->getText();
    }

    /*
     * NiceCategoryList_Links comparison function
     */
    private function categoryCmp($a, $b) {
        return self::titleCmp($a->title, $b->title);
    }

    /*
     * Sort links and categories alphabetically.
     */
    public function sort() {
        usort($this->articles, array(&$this, "titleCmp"));
        usort($this->categories, array(&$this, "categoryCmp"));
    }

}


class NiceCategoryList {

    ////////////////////////////////////////////////////////////////////////
    // Configuration
    ////////////////////////////////////////////////////////////////////////

    /*
     * Default settings for the category list.
     */
    private $settings = array(
        'maxdepth'  => 32,           // Sanity stop level.
        'style'     => 'bullet',     // Default style for "leaf" level.
        'showcats'  => 0,            // Non-0 to display sub-cat links in a category.
        'showarts'  => 1,            // Non-0 to display article links in a category.
        'headings'  => 'head',       // Show category headings as headings.
        'headstart' => 1,            // Heading level to start at.
        'sort'      => 0,            // Non-0 to sort the list alphabetically;
                                     // else sort the list according to the
                                     // index key.
    );


    ////////////////////////////////////////////////////////////////////////
    // Constructor
    ////////////////////////////////////////////////////////////////////////

    /*
     * Setup Nice Category List extension.
     * Sets a parser hook for <ncl></ncl>.
     */
    public function __construct() {
            global $wgParser;
            $wgParser->setHook('ncl', array(&$this, 'hookNcl'));
            $wgParser->setFunctionHook('ncl', array(&$this, 'hookParserNcl'));
    }


    ////////////////////////////////////////////////////////////////////////
    // Hook
    ////////////////////////////////////////////////////////////////////////

    /*
     * The hook function.  Handles <ncl></ncl>.
     *     $category   The tag's text content (between <ncl> and </ncl>);
     *                 this is the name of the category we want to index.
     *     $argv       List of tag parameters; these can be any of the settings
     *                 in $this->settings.
     *     $parser     Parser handle.
     */
    public function hookNcl($category, $argv, &$parser) {
        // Get any user-specified parameters, and save them in $this->settings.
        foreach (array_keys($argv) as $key)
            $this->settings[$key] = $argv[$key];

        return NiceCategoryList::doNcl($category, &$parser, false);
    }

    public function hookParserNcl(&$parser, $params) {
        $options = preg_split('/\s?,\s?/', $params, -1, PREG_SPLIT_NO_EMPTY);
        $this->settings['category'] = '';
        foreach ($options as $option) {
            $nameval = preg_split('/\s*=\s*/', $option);
            $this->settings[$nameval[0]] = $nameval[1];
        }

        return NiceCategoryList::doNcl($this->settings['category'], &$parser, true);
    }

    public function doNcl($category, &$parser, $is_parser) {
        // Replace variables in $category by calling the parser on it.  This
        // allows it to use {{PAGENAME}}, etc.
        $localParser = new Parser();
        $category = $localParser->parse($category, $parser->mTitle, $parser->mOptions, false);
        $category = $category->getText();

        // Make a Title objhect for the requested category.
        $title = Title::newFromText($category);
        if (!$title)
        	return '<p>Failed to create title!</p>';

        // Get the database handle, and get all the category links for
        // this category.
        $dbr =& wfGetDB(DB_SLAVE);
        $catData = $this->searchCategory($dbr, $title, 0);

        // Generate the category listing.
        $output = $this->outputCategory($catData);

        // There's no need for a TOC, so suppress it.
        $output .= "__NOTOC__\n";

        if ($is_parser) {
            return $output;
        } else {
            // Convert the listing wikitext into HTML and return it.
            $localParser = new Parser();
            $output = $localParser->parse($output, $parser->mTitle, $parser->mOptions);
            return $output->getText();
        }
    }


    ////////////////////////////////////////////////////////////////////////
    // Database Access
    ////////////////////////////////////////////////////////////////////////

    /*
     * Get all of the direct and indirect members of a given category: ie.
     * all of the articles and categories which belong to that category
     * and its children.
     *     $dbr        The database handle
     *     $catTitle   The Title object for the category to search
     *     $depth      Our current recursion depth: starts at 0
     *     $processed  List of categories that have been searched to date
     *                 (to prevent looping)
     *
     * Returns null if this category has already been searched; otherwise,
     * a NiceCategoryList_Links object for the given category, containing all
     * the sub-categories and member articles.
     */
    private function searchCategory($dbr, $catTitle, $depth, $processed = array()) {
        // Avoid endless recursion by making sure we haven't been here before.
        if (in_array($catTitle->getText(), $processed))
            return null;
        $processed[] = $catTitle->getText();

        // Get all of the category links for this category.
        $links = $this->getCategoryLinks($dbr, $catTitle);

        // Build a list of items which belong to this category.
        $cl = new NiceCategoryList_Links($catTitle);
        foreach ($links as $l) {
	        // Make a Title for this item.
            $title = Title::makeTitle($l->page_namespace, $l->page_title);

            if ($title->getNamespace() == NS_CATEGORY) {
                // This item is itself a category: recurse to find all its
                // links, unless we've hit maxdepth.
                $subLinks = null;
                if ($depth + 1 < $this->settings['maxdepth'])
                    $subLinks = $this->searchCategory($dbr, $title,
                                                      $depth + 1, $processed);

                // Record the subcategory name, and its links if we got any.
                $cl->addCategory($title, $subLinks);
            } else {
                // This is a regular page; just add it to the list.
                $cl->addArticle($title);
            }
        }

        // Sort the item lists, if requested.  (Thanks, Jej.)
        if ($this->settings['sort'])
            $cl->sort();

        return $cl;
    }


    /*
     * Get all of the direct members of a given category.
     *     $dbr        The database handle
     *     $title      The Title object for the category to search
     *
     * Returns an array of objects, each representing one member of the named
     * caregory.  Each object contains the following fields from the database:
     *      page_title
     *      page_namespace
     *      cl_sortkey
     */
    private function getCategoryLinks($dbr, $title) {
	    // Query the database.
        $res = $dbr->select(
            array('page', 'categorylinks'),
            array('page_title', 'page_namespace', 'cl_sortkey'),
            array('cl_from = page_id', 'cl_to' => $title->getDBKey()),
            '',
            array('ORDER BY' => 'cl_sortkey')
        );
        if ($res === false)
        	return array();

        // Convert the results list into an array.
        $list = array();
        while ($x = $dbr->fetchObject($res))
        	$list[] = $x;

        // Free the results.
        $dbr->freeResult($res);

        return $list;
    }


    ////////////////////////////////////////////////////////////////////////
    // Output
    ////////////////////////////////////////////////////////////////////////

    /*
     * Generate output for the list.
     */
    function outputCategory($category, $level = 0) {
        global $wgContLang;

        $output = '';

        // The second level and onwards has a heading.
        // The heading gets smaller as the level grows.
        if ($level > 0) {
            $title = $category->getTitle();
            $ptitle = $title->getPrefixedText();
            $title = $wgContLang->convert($title->getText());
            $link = "[[:" . $ptitle . "|'''" . $title . "''']]";

            // Do the heading.  If settings['headings'] == 'head', then
            // the heading is a real Wiki heading; otherwise, it's a nested
            // bullet item.
            if ($this->settings['headings'] == 'head') {
                $heading = str_repeat('=', $level + $this->settings['headstart']);
                $output .= $heading . $title . $heading . "\n";
            } else {
                $stars = str_repeat('*', $level);
                if ($level <= 1)
                    $output .= "<big>\n" . $stars . " " . $link . "</big>\n";
                else
                    $output .= $stars . " " . $link . "\n";
            }
        }

        // Now generate the category output.  We put the various items in
        // $pieces at first.
        $pieces = array();

        // Output each subcategory's name, if we don't have a real
        // listing of its contents (because we hit maxdepth), and
        // if settings['showcats'].
        if ($this->settings['showcats'] && !$category->hasCatLinks()) {
        	$subCatTitles = $category->getCatTitles();
            foreach ($subCatTitles as $title) {
                $ptitle = $title->getPrefixedText();
                $title = $wgContLang->convert($title->getText());
                $disp = "[[:" . $ptitle . "|'''" . $title . "''']]";
                $pieces[] = $disp;
            }
        }

        // Output each article in the category, if settings['showarts'].
        if ($this->settings['showarts']) {
    		$articleTitles = $category->getArtTitles();
            foreach ($articleTitles as $link) {
                $ptitle = $link->getPrefixedText();
                $title = $link->getText();
                $disp = "[[:" . $ptitle . "|" . $title . "]]";
                $pieces[] = $disp;
            }
        }

        // If we got some items, then display them in the requested style.
        if (count($pieces) > 0) {
            if ($this->settings['style'] == 'bullet')
                $output .= "* " . implode("\n* ", $pieces) . "\n";
            else {
                $pre = $level == 0 ? "<big>" : str_repeat('*', $level - 1) . ':';
                $post = $level == 0 ? "</big>" : '';
                $output .= $pre . implode("&nbsp;&bull; ", $pieces) . $post . "<br>\n";
            }
        }

        // Recurse into each subcategory.
        $subCategories = $category->getCategories();
        foreach ($subCategories as $cat)
            $output .= $this->outputCategory($cat, $level + 1);

        return $output;
    }

}

?>

Broken with 1.10.1?

Sorry to bother you. I'm having a strange problem with NCL2 and mediawiki-1.10.1 that I'm hoping you can help me with. I've used the following code in a page:

     <ncl style=compact maxdepth=2 headings=bullet headstart=2
     showcats=1 showarts=1>Category:Universal Foundation</ncl>

However, it shows up like this:

UNIQ645602511ba5a312-ncl-00000002-QINU

Any ideas what I'm doing wrong? Perhaps it's the new version of mediawiki.

Thanks! Ben

Compact Style, Bullet Headings

When I used the combination of "compact" for style, and "bullet" for headings, I didn't like the way it put large "heading" type listings of the individual articles together on one line. Obviously, I wanted them on one line (that's why I chose compact for the stye), but didn't like the large headings.

To change that, I took the following code (beginning at my line 400):

        // If we got some items, then display them in the requested style.
        if (count($pieces) > 0) {
            if ($this->settings['style'] == 'bullet')
                $output .= "* " . implode("\n* ", $pieces) . "\n";
            else {
                $pre = $level == 0 ? "<big>" : str_repeat('*', $level - 1) . ':';
                $post = $level == 0 ? "</big>" : '';
                $output .= $pre . implode("&nbsp;&bull; ", $pieces) . $post . "<br>\n";
            }
        }

and added an elseif as shown below

        // If we got some items, then display them in the requested style.
        if (count($pieces) > 0) {
            if ($this->settings['style'] == 'bullet')
                $output .= "* " . implode("\n* ", $pieces) . "\n";
            elseif ($this->settings['headings'] == 'bullet') {
                $pre = $level == 0 ? "" : str_repeat('*', $level - 1) . ':';
                $output .= $pre . implode("&nbsp;&bull; ", $pieces) . $post . "<br>\n";
            }
            else {
                $pre = $level == 0 ? "<big>" : str_repeat('*', $level - 1) . ':';
                $post = $level == 0 ? "</big>" : '';
                $output .= $pre . implode("&nbsp;&bull; ", $pieces) . $post . "<br>\n";
            }
        }

I'm not a programmer, just a network guy. I don't know how well this will work with other combinations, but it did just what I wanted on my system. If someone with better programming skills wants to look at this and clean it up some so it works seamlessly for others, have at it.

--Herb Parsons 17:47, 7 December 2007 (UTC)Reply


Show All Categories

I have a relatively small site with < 100 categories and a maximum expected depth of 3 or 4. Is it possible to list all categories without first forcing the categories into a single category?

Tnabtaf 00:11, 29 January 2008 (UTC)Reply

Busted under mw 1.12 - Failed to create title!

the use of the parser (which afaik is pretty much for generating html from wiki markup) can cause a problem if the parser is appending NewPP limit info in a little html comment to the string passed in....which happens to be the category name you specified.

the resulting string of course doesn't match any categories, and you'll just get a message that says it 'Failed to create title!'

I'm sure there's a simple way to tell the parser not to add the NewPP info comment, but since my experience with mediawiki code and php is approaching about 1 hour now I just modified this extension to strip off the comment if it's there. Look in the code and find:

$category = $category->getText();

replace it with:

//hack to strip off NewPP limit report text that may be appended to string as html comment
$category = preg_replace('/<!--[^>]*>\s*/','',$category->getText());

I assume if/when someone fixes this "properly" this entire blurb can get whacked

Failed to create title!

NCL seems to be broken. I get "Failed to create title!" all the time. Even <ncl>Category:Scripts</ncl> does not work. NCL V1.0 works, but V2.0 should work as well w/ mediawiki 1.12.0rc1. Visus 13:12, 2 April 2008 (UTC)Reply

Stale Content / Extension Doesn't refresh

I ran into a nasty problem with this extension: every time you changed what category something was in, you had to re-edit the page with the tags in it, and even worse, sometimes the page itself would disappear for no good reason, with a re-edit necessary to see it again! The only suggestion I got was to change $wgParserCacheType to CACHE_NONE. However, this just made the whole page disappear, and not come back even after a re-edit. I scoured other extensions, and I think I found the solution. Just add this code to the extension:

in the hookNiceCategoryList function, add this near the top:

$DisableCache = true;

And later on in the same function, after fetchCategoryLinks is called add these line:

if ($DisableCache) {
       global $wgVersion;
       $dbr =& wfGetDB( DB_SLAVE );
       # Do not cache this wiki page.
       # for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions
       global $wgTitle, $wgDBprefix;
       $ts = mktime();
       $now = gmdate("YmdHis", $ts +120);
       $ns = $wgTitle->getNamespace();
       $ti = $dbr->addQuotes($wgTitle->getDBkey());
       $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion);
       $sql = "UPDATE $wgDBprefix" . "page SET page_touched='$now' WHERE page_namespace=$ns AND page_title=$ti";
       $dbr->query($sql, __METHOD__);
}


As you can see, I borrowed this fix from another extension, but as far as I can tell, it works great!

Language problems

Got a rather simple problem, I dont know what the top Category is in my language (Danish). For some reason, some tags are translated, while others are not.... how do I figure the correct replacement for "Category:Category"? --Asset 17:44, 18 July 2008 (UTC)Reply

Conflict with Terminology extension ?

Does anyone have the same issue ? when activating terminology extension on my MW 12 then I can use the NCL tag only once in a page, all the rest of the page is ignored... Help... :)

Thanks Doc

Does not work with Konqueror

The Monospace layout is strongly disturbed on pages with NCL. See www.opus-info.org

Thanks for your help. Gabuzo 10:58, 14 November 2008 (UTC)Reply

skipping images

I don't like images to turn up in my pagelist. To exclude images (my default), I added some code.

Org:

    private $settings = array(
        'maxdepth'  => 32,           // Sanity stop level.
        'style'     => 'bullet',     // Default style for "leaf" level.
        'showcats'  => 0,            // Non-0 to display sub-cat links in a category.
        'showarts'  => 1,            // Non-0 to display article links in a category.
        'headings'  => 'head',       // Show category headings as headings.
        'headstart' => 1,            // Heading level to start at.
        'sort'      => 0,            // Non-0 to sort the list alphabetically;
                                     // else sort the list according to the
                                     // index key.
    );

New (added line 183):

    private $settings = array(
        'maxdepth'  => 32,           // Sanity stop level.
        'style'     => 'bullet',     // Default style for "leaf" level.
        'showcats'  => 0,            // Non-0 to display sub-cat links in a category.
        'showarts'  => 1,            // Non-0 to display article links in a category.
        'headings'  => 'head',       // Show category headings as headings.
        'headstart' => 1,            // Heading level to start at.
        'sort'      => 0,            // Non-0 to sort the list alphabetically;
                                     // else sort the list according to the
                                     // index key.
        'showimages'=> 0,            // Non-0 to display image links
    );

And changed

        // Output each article in the category, if settings['showarts'].
        if ($this->settings['showarts']) {
                $articleTitles = $category->getArtTitles();
            foreach ($articleTitles as $link) {
                $ptitle = $link->getPrefixedText();
                $title = $link->getText();
                $disp = "[[:" . $ptitle . "|" . $title . "]]";
                $pieces[] = $disp;
            }
        }

to look like this (starts at my line 389, added 2 extra if's)

        // Output each article in the category, if settings['showarts'].
        if ($this->settings['showarts']) {
                $articleTitles = $category->getArtTitles();
            foreach ($articleTitles as $link) {
                $ptitle = $link->getPrefixedText();
                $title = $link->getText();
                $disp = "[[:" . $ptitle . "|" . $title . "]]";
                if ($this->settings['showimages']) {
                    $pieces[] = $disp;
                } else {
                    if ($link->getNamespace() != NS_IMAGE) {
                            $pieces[] = $disp;
                    } 
                }
            }
        }

hear say: “I'm not a programmer, just a network guy. I don't know how well this will work with other combinations, but it did just what I wanted on my system. If someone with better programming skills wants to look at this and clean it up some so it works seamlessly for others, have at it.” (qoute Herb Parsons)

wiki font size changed after installed NCL2

In IE8, font size become larger and the login page becomes blank(the login input box and it's title text does not appear). When I clikc "Compatible Mode", the login page returns normal, but the size is still incorrect.

The NCL version is 2.2.

123.112.62.102 02:22, 18 March 2009 (UTC)Reply

Incompatible with MediaWiki 1.13.2?

Hello, I've installed NiceCategoryList on MediaWiki 1.13.2, but no subcategories are displayed. I am using NiceCategory List 2.2. Is this a known issue?

Stefan

working only for logged-in users

I'm using NCL2.2 on MW1.14 and some strange things happen. NCL behaves correctly if a user is logged in into the wiki, but it does not display the tree if a mere visitor passes by this page: http://wiki.piratenpartei.de/Kategoriebaum now I'm puzzled how to debug this behaviour. --Jamasi 12:30, 15 June 2009 (UTC)Reply

Categories are available twice

Hello, I implemented this extension on my website and it works fine in general, but: I put < ncl > tags in one of Category: pages and I can see the subcategories list from NCL extension, but I see original Mediawiki list of subcategories below. Is it possible to fix via extension or should I write my own hack ? Thank you in advance.

Vadim

Some update for this Extension

This update will allow you to choose how many article to show on the list. Settings will include an object name 'number'. Default, 'number'=0. It's mean all articles in the Category will be shown. If 'number' != 0, number of article(s) will be shown is 'number', randomly. If Articles's count < 'number', all article(s) will be shown.


For example: <ncl number=3>Category Name</ncl>
Add an option to settings:

    private $settings = array(
        'maxdepth'  => 32,           // Sanity stop level.
        'style'     => 'bullet',     // Default style for "leaf" level.
        'showcats'  => 0,            // Non-0 to display sub-cat links in a category.
        'showarts'  => 1,            // Non-0 to display article links in a category.
        'headings'  => 'head',       // Show category headings as headings.
        'headstart' => 1,            // Heading level to start at.
        'sort'      => 0,            // Non-0 to sort the list alphabetically; else sort the list according to the index key.
        'number'    => 0,            // Number of articles to show
    );

Show randomly 'number' of articles:

        // Output each article in the category, if settings['showarts'].
        $show=$this->settings['number'];
        if ($this->settings['showarts']) {
                 $articleTitles = $category->getArtTitles();
            if (count($articleTitles)<$show || $show==0) {
               foreach ($articleTitles as $link) {
                   $ptitle = $link->getPrefixedText();
                   $title = $link->getText();
                   $disp = "[[:" . $ptitle . "|" . $title . "]]";
                   $pieces[] = $disp;
               }
            }else {
              $articleShow = array_rand($articleTitles, $show);
              for($i=0;$i<$show;$i++) {
                   $ptitle = $articleTitles[$articleShow[$i]]->getPrefixedText();
                   $title = $articleTitles[$articleShow[$i]]->getText();
                   $disp = "[[:" . $ptitle . "|" . $title . "]]";
                   $pieces[] = $disp;
               }
            }
        }

Using this for category pages

How would I use this extension or something similar for the category pages in MediaWiki? I don't want the alphabetical ordering that MW provides automatically.


When I use the Magic Word, the page previews without showing the Section Edit links for the sections generated by the extension. But when I save the page, it renders the Section Edit links. I have tried putting the magic word on various places on the page with no succes. Is there any way around this?

This is happening in Mediawiki 1.15.1 with the simplest use of the extension:

<ncl>Category:Software</ncl>

Does not work in my configuration

It doesn't work in the following configuration (Windows 7 64-bit, running MoWeS):

MediaWiki: 1.15.0
PHP: 5.3.0 (apache2handler)
MySQL: 5.1.35-community

Absolutely nothing shows up even when using the simpliest tag.

Paragraph Spacing on Multiple Lists is Too Big

When I enter 2 ncl tags, one after the other - there is 66 pixels of vertical space seperating the 2 lists instead of just a normal paragraph worth of space. This is an example of what I entered:

<ncl>Sony Products</ncl>
<ncl>Samsung Products</ncl>

You can test this on my page http://feedbackwiki.org/wiki/Reviews:Forza_3 by editing the page. Is there a setting where I can change the paragraph spacing between lists or is there some CSS I can add?

Paragraph Spacing after every output

In the source-code on the page I found this after the output of NCL2:

p><br />
</p>
<p><!-- 
NewPP limit report
Preprocessor node count: 1/1000000
Post-expand include size: 0/2097152 bytes
Template argument size: 0/2097152 bytes
Expensive parser function count: 0/100
-->
</p>

The following code shows the separation.

p><br />
</p>

How can I avoid this??

--Red Garfield 08:09, 29 July 2010 (UTC)Reply

Extension:NiceCategoryList2 v2.3

I have updated the extension to use CSS styles and fixed some minor issues, like the duplicated list bullets. For now, you can find the updated extension page at User:*Surak*/Extension:NiceCategoryList and the code at User:*Surak*/Extension:NiceCategoryList/2.3. Since this is a major change, I did not activate it (extension templatemode=nocats), and I did not dare to save it in your extension namespace. Do you allow me saving it there, or do you suggest a different way to handle this? Thanks in advance, --SurakΔ 13:11, 28 May 2011 (UTC)Reply

Enable template argument parsing in <ncl> tags (e.g. <ncl>{{{1}}}</ncl>)

According to http://www.mediawiki.org/wiki/Manual:Tag_extensions , since MW 1.16alpha (r55682), text within tags can be parsed within extensions, making template arguments expanding possible. However, this feature is not built into the NCL extension as of Sep 2011.

The good news is, you only need to change 2 lines to achieve that.

Original code in the extension PHP:

   public function hookNcl($category, $argv, &$parser) {
       // Get any user-specified parameters, and save them in $this->settings.
       $this->settings = array_merge($this->settings, $argv);

Change the code to: (pay attention to the extra 4th argument from the function definition

   public function hookNcl($category, $argv, &$parser, $frame) {
       $category = $parser->recursiveTagParse( $category, $frame );
       // Get any user-specified parameters, and save them in $this->settings.
       $this->settings = array_merge($this->settings, $argv);

Enjoy.

User:Ewcy - 13 Sep 2011

It would be great to be able select whether the Categories / headings showed up as flat text or wiki links, regardless of 'style' setting. Although I can't find it documented anywhere, it seems that it will always wiki link Categories in "compact" style, but never in "Bullet" style. Another option such as <ncl linkcats=0/1> could be used to control this behaviour.

I've hacked this feature in as per the diff below, but have never touched PHP before so I'm sure someone could do better. Would love to see a feature like this in the next release.


148a151
>     'linkcats'  => 0,
345a349
>         $disp    = $this->settings['linkcats'] ? $link : $title;
349c353
<                 $output .= "<h" . $heading . " class='ncl-heading ncl-heading-" . $level . "'>" . $title . "</h" . $heading . ">";
---
>                 $output .= "<h" . $heading . " class='ncl-heading ncl-heading-" . $level . "'>" . $disp . "</h" . $heading . ">";
352c356
<                 $output .= "<div class='ncl-heading ncl-heading-" . $level . "'>\n* " . $link . "\n</div>";
---
>                 $output .= "<div class='ncl-heading ncl-heading-" . $level . "'>\n* " . $disp . "\n</div>";

134.159.154.133 07:58, 8 February 2012 (UTC)Reply

Proper indentation for nested lists.

As http://ddowiki.com/page/Deathblock for an example, how can I make the ncl listing indented properly under the "found on" section? Currently it looks like:

  • Found on:
  • This item
  • That item
  • Poor item

When I would like to have it show up as:

  • Found on:
    • This item
    • That item
    • Poor item

-- ShoeMaker   ( Contributions Message )   02:51, 2 February 2013 (UTC)Reply

extension:Translate fix and fixed two errors in the code.

The code had NiceCategoryList2 as an installation directory and the instructions states that the extension should be installed in .../extensions/NiceCategoryList, so I fixed that in the code.

I also added a check so that the HTML headings can't increase beyond 6.

if($heading > 6) {
    $heading = 6;
}

There should be a more elegant solution, but at least that one doesn't print wrong HTML.

If you are interested in using the extension with extension:Translate you can do the following changes to the code:

If you want the list to print Translate links, change

$link    = "[[:" . $ctitle . "|" . $title . "]]";

To

$link    = "[[Special:MyLanguage/" . $ctitle . "|" . $title . "]]";

in function outputCategory($category, $level = 0).

That only works for the compact list. If you want MyLanguage links to for instance the normal <ncl>...</ncl> list, you should ctrl+f and replace all "[[:" with "[[Special:MyLanguage/".

If you don't want to show all the translated pages in the list (you shouldn't, the MyLanguage link handles the language for you) you can add a regex check to function getCategoryLinks($dbr, $title).

while ($x = $dbr->fetchObject($res)){
    if(!preg_match('~\/.{2,3}$~', $x->page_title))            
        $list[] = $x;
    }

I hope someone finds this useful :)

Sanelith 2013-08-07 16:57 UTC

Changes to Categories not reflected on page reload.

  • MediaWiki: 1.21.2
  • PHP: PHP 5.3.10
  • NCL: 2.2.3 (2011-05-01)

This comment:

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

Appears to apply when in a page or template regardless. Is there a fix? One should not have to edit/save pages using the <ncl> tag to refresh the list. It should be dynamic. --Achowe (talk) 17:01, 7 October 2013 (UTC)Reply

I'm writing an 'ordered' category on a wiki and thought that along with including the category list, having previous/next links would be a very useful addition. I added a few lines to track previous/next articles while generating the list, and then draw links to them as part of the output.

class NiceCategoryList {
  ...
  private $lastlink = '';
  private $prevlink = '';
  private $nextlink = '';
  private $currenttitle = '';

  ...

  public function hookNcl($category, $argv, $parser) {
    $this->currenttitle = $parser->getTitle();
  ...
  # generate the category listing
    $output = "<div class='ncl-nicecategorylist'>" . $this->outputCategory($catData) . "</div>";
    $output .= "<div class='catlinks ncl-prev'>Prev: [[$this->prevlink]]</div>";
    $output .= "<div class='catlinks ncl-next'>Next: [[$this->nextlink]]</div>";

  ...

  function outputCategory($category, $level = 0) {
  ...
    foreach ($articleTitles as $link) {
    ...
      if( $this->lastlink == $this->currenttitle )
        $this->nextlink = $title;
      if( $title == $this->currenttitle )
        $this->prevlink = $this->lastlink;
      $this->lastlink = $title;

And finally in CSS, to make the category list appear at the bottom (bit of a hack, must be a better way):

    div.ncl-next                       { position: absolute; bottom: 40px; }

How to show pages in a specific namespace?

I want to show pages either in a specific category and a namespace , how to do?

NiceCategoryList2/2.3 works on Mediawiki 1.25, PHP 5.6.9 with some changes

Files on GitHub

Serge3576 (talk) 06:51, 12 September 2015 (UTC)Reply

Thanks for that ... Runs even with Mediawki 1.27, PHP 7.0.1