Extension talk:NiceCategoryList2

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: Category:Books 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)

Cannot add more than one set of ncl tags
Why can't I add more than one set of 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)

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? &#8465;ilver&#167;&#8465;ide 18:39, 4 January 2007 (UTC)


 * 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)


 * 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)

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 category:... , 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)


 * 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)


 * 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)


 * 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)



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):

Category:
 * 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)
 * 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)

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:
 * Category 1
 * Article X • Article Y


 * Category 1.1
 * 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.,


 * Category 1 :Article X • Article Y
 * Category 1.1
 * 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

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:

Category:Universal Foundation

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):

and added an elseif as shown below

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)

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)

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:

replace it with:

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 Category:Scripts 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)

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)

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)

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

Org:

New (added line 183):

And changed

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

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)

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)

Categories are available twice
Hello, I implemented this extension on my website and it works fine in general, but: I put 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'. If Articles's count < 'number', all article(s) will be shown.

For example: Category Name

Category:Some Category * * 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: *     Category:Some Category *   generates a full, recursive listing. * * 2. Use this in a template: *     Category: *   and include it in major category pages to provide a nice 2-level (or however *    many you like) index of the category. * * 3. This: *     Category:Categories *   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'; $wgExtensionCredits['parserhook'][] = array( 'name' =>        'NiceCategoryList',  'author' =>      'Kichik, Johan the Ghost',  'url' =>         'http://www.mediawiki.org/wiki/Extension:NiceCategoryList2',  'description' => 'generate a category page showing all pages in a category, including subcategories', ); /* * Setup Nice Category List extension. * Sets a parser hook for. */ 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.        'number' => 0,          //Number of articles to show    ); ////////////////////////////////////////////////////////////////////////   // Constructor ////////////////////////////////////////////////////////////////////////   /*     * Setup Nice Category List extension. * Sets a parser hook for. */   public function __construct { global $wgParser; $wgParser->setHook('ncl', array(&$this, 'hookNcl')); }   ////////////////////////////////////////////////////////////////////////    // Hook ////////////////////////////////////////////////////////////////////////   /*     * The hook function. Handles. *    $category   The tag's text content (between and ); *                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]; // Replace variables in $category by calling the parser on it. This // allows it to use, etc.       $localParser = new Parser; $category = $localParser->preprocess($category, $parser->mTitle, $parser->mOptions, false); // Make a Title objhect for the requested category. $title = Title::newFromText($category); if (!$title) return ' Failed to create title! ';       // 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 .= "\n"; // 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 = "" . $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 .= " \n". $stars. " " . $link. " \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 = "" . $title . ""; $pieces[] = $disp; }       }        // 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 = "" . $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 = "" . $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 { $output .= $pre. implode(" &bull; ", $pieces). $post ." • ... " ; }       }        // Recurse into each subcategory. $subCategories = $category->getCategories; foreach ($subCategories as $cat) $output .= $this->outputCategory($cat, $level + 1); return $output; } }