Jump to content

Extension talk:WikiCategoryTagCloud/Archive

Add topic
From mediawiki.org

FCKeditor causes "<tagcloud></tagcloud>" to render in edit mode

[edit]

when using fckeditor as default editor, the tagcloud tag gets interpreted in edit mode. --80.149.253.142 14:25, 25 July 2011 (UTC)Reply

How to exclude Templates from Showing

[edit]

This is a great extension. However, at the moment, it is showing all my templates as well as the more meaningful categories. Is there any way that I can change it so that it doesn't include any categories with the word template in them? A kind of wildcard *template* exclude? Any help/advice much appreciated. Thanks


Thanks

[edit]

--Sean.mcclowry 11:14, 5 November 2007 (UTC) Great extension! I am using it and here and it works very well. All categories are shown here.Reply


Additional Configuration Information

[edit]

--Sean.mcclowry 11:24, 5 November 2007 (UTC) Some additional config info that applies more broadly but I forgot when I initial configured this extension:Reply

  • Sometimes categories will take a while to refresh (i.e. if you delete a category it will stay in the cache a while
  • Don't use spaces after commas in the exclude list
  • Use underscores between multi word categories in the exclude list

Great Extension.

[edit]

I amended the code in my copy so that hovering over a link shows the number of pages in that category.

My first attempt at amending an extension so this may not work for everyone but did the job on my site and didn't seem to break anything else.


Replace Line 123 (In the version I downloaded - may differ in other versions!):

$currentRow = "<a class=\"" . implode( ' ', $link_classes ) . "\" style=\"{$style}\" href=\"" . $title->getLocalURL() . "\">" . $title->getText() . "</a>&nbsp; ";


With:

if ($tags[$i][1] == 1)
{
 $page_text = ' Page';
}
else
{
 $page_text = ' Pages';
}
$alt_text = $tags[$i][1] . $page_text . ' in ' . $title->getText();
$currentRow = "<a class=\"" . implode( ' ', $link_classes ) . "\" style=\"{$style}\" title=\"$alt_text \" href=\"" . $title->getLocalURL() . "\">" . $title->getText() . "</a>&nbsp; ";


BrillyuntWebby 20:02, 12 November 2007 (UTC)Reply

How to include all pages in a subcategory

[edit]

I was wondering if there was any way to include all the pages in the subcategory as "members" of the parent category so that the name of the category is given more prominence. Right now, a category with 2 articles and 2 subcategories is as large as a category with 4 articles, which is misleading since the category in the first case contains more information and, in theory, should be larger.

Bug?

[edit]

After Installation I get always a "Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /< mywikipath>/extensions/tag_cloud.php on line 44"

excluding the lines 40-46

 /*
 function invalidateCache() {
     $titles[0] = explode( "\n", wfMsg('tagcloudpages') );
     for ($i = 0; $i < count($titles); $i++) {
         Title :: newFromText($titles[$i])->invalidateCache();
     }
 }
 */

I'll get an cache delay after an update of my Tags

dite-at-campus.upb.de

Should be fixed in svn. Dantman 03:23, 10 July 2009 (UTC)Reply

strange cache problem

[edit]

the extension works and looks great but when i try submit anything the entire wiki is unreacable from the browser im using... all it gives me is a done page with nothing displayed. i can then use ie but after submitting in ie i get the same problem. only thing i can think that may be causing a problem is fckeditor

thanks westie

Problem with modern-skin (MW 1.13.5 and 1.14.0)

[edit]

Hi, I am using the modern-skin for MediaWiki. After installing the extension I get the following message:

Warning: Cannot modify header information - headers already sent by (output started at .../extensions/WikiCategoryTagCloud/WikiCategoryTagCloud.php:2) in .../includes/WebResponse.php on line 16

Is there anything that I can do about it. Help is greatly appreciaded. Thank you --Marbot 11:49, 5 July 2009 (UTC)Reply

Did I mention that this is a great extension. A must for a lot of wikis which increases the usability in respect of finding content. If working, it would be even better. --Marbot 11:54, 5 July 2009 (UTC)Reply

Problem with color-changes of Linkstyle

[edit]
<tagcloud style="background: #FF1414;" linkstyle="color: #FFFFFE;">
min_size=100
min_count=15
increase_factor = 200
exclude=browse
</tagcloud> 

You get the Error-Message:

Uninitialized string offset: -1 in /home/twiki/www/extensions/WikiCategoryTagCloud/WikiCategoryTagCloud.php on line 123 Notice:

To fix the problem, make following changes

Line 119 to 127

	for ($i = 0; $i < $count; $i++) {
		$textSize = $MIN_SIZE + ($INCREASE_FACTOR * ($tags[$i][1])) / ($max);
		$title = Title::makeTitle( NS_CATEGORY, $tags[$i][0] );
		$style = $link_style;
		if( $style != '' && $style{-1} != ';' ) $style .= ';'; 
		$style .= "font-size: {$textSize}%;";
		$currentRow = "<a class=\"" . implode( ' ', $link_classes ) . "\" style=\"{$style}\" href=\"" . $title->getLocalURL() . "\">" . $title->getText() . "</a>&nbsp; ";
		$htmlOut = $htmlOut . $currentRow;
	}

Replace with:

	for ($i = 0; $i < $count; $i++) {
		$textSize = $MIN_SIZE + ($INCREASE_FACTOR * ($tags[$i][1])) / ($max);
		$title = Title::makeTitle( NS_CATEGORY, $tags[$i][0] );
		$style = $link_style;
		if( $style != '' && substr($style,-1) != ';' ) $style .= ';'; 
		$style .= "font-size: {$textSize}%;";
		$currentRow = "<a class=\"" . implode( ' ', $link_classes ) . "\" style=\"{$style}\" href=\"" . $title->getLocalURL() . "\">" . $title->getText() . "</a>&nbsp; ";
		$htmlOut = $htmlOut . $currentRow;
	}

Shortform:

if( $style != '' && $style{-1} != ';' ) $style .= ';';


->

 if( $style != '' && substr($style,-1) != ';' ) $style .= ';';
Fix committed into svn. Dantman 03:17, 10 July 2009 (UTC)Reply
[edit]

In MediaWiki version 1.13.4, a link to the PopularCategories template fails to render properly on a page that also has a link to the Special:NewPages template if there are no new pages listed on the NewPages special page. Instead of showing the tag cloud, the infamous UNIQ...QINU string was displayed instead. Once the link to Special:NewPages was removed or prevented from rendering with nowiki tags, the tag cloud renders fine. The problem is worked around simply by adding a new page to the wiki, thereby populating the NewPages page.

Chances are that most people will never experience this issue, as it only happened to us because we were splitting our wiki and killed off the new pages data, but it could crop up under other circumstances as well so it might be worth a little debugging time by someone better versed in PHP than I, as I couldn't figure out a code fix to prevent it.

Memitim 16:13, 23 July 2009 (UTC)Reply

Category name

[edit]

Thank you for this extension! Is it possible to "exclude" a category if its name contains a comma? May you please add an 'exclude_like' parameter, in order to have the underlying SQL SELECT use the '%' SQL operator? Natmaka 13:43, 28 July 2009 (UTC)Reply

Nice extension! Minor problem: some automatically generated maintenance categories have a comma in their name, these keep showing. Alvaro Ortiz Troncoso (talk) 08:04, 28 July 2015 (UTC)Reply

Undefined index 'linkstyle' on line 66

[edit]

Here is the whole string mediawiki is returning:

Notice: Undefined index: linkstyle in $IP\extensions\WikiCategoryTagCloud\WikiCategoryTagCloud.php on line 66

Note I added the $IP variable above to mask my actual server name.

Any ideas? Thanks -- Gomeztogo 06:58, 20 November 2009 (UTC)Reply

Update

[edit]

My Solution to the Problem:

	/*$link_style = $params['linkstyle'];*/
	$link_style = '';
	if (isset($params) && isset($params['linkstyle'])) {
		$link_style = $params['linkstyle'];
	}

Solved in Git

[edit]

This problem is now solved in the newest version from Git, which will be the version for MediaWiki 1.21 and newer. --88.130.100.151 19:16, 23 May 2013 (UTC)Reply

PHP Error on save

[edit]

I get an PHP error if I try to save a page:

PHP Warning: Illegal offset type in isset or empty in D:\htdocs\wiki\includes\Title.php on line 117
PHP Warning: Illegal offset type in D:\htdocs\wiki\includes\Title.php on line 139 

Win2k3 IIS MediaWiki 1.16.1 PHP 5.2.14 (cgi-fcgi) MySQL 5.1.53-community --Pdcemulator 10:02, 15 March 2011 (UTC)Reply


I have exactly the same problem. In error_log file (Apache) I get following errors:

[error] [client IP] PHP Warning:  Illegal offset type in <media wiki>/includes/Title.php on line 139, referer: http://.../...&action=edit
[error] [client IP] PHP Notice:  Array to string conversion in <media wiki>/includes/Title.php on line 2286, referer: http://.../...&action=edit

MediaWiki 1.16.1 on CentOS (2.6.18-92.el5) with PHP 5.2.10

Any ideas? Thanks a lot! --Danny373 08:49, 20 May 2011 (UTC)Reply

Solution (?)

[edit]

Hi there! We had a similar error while using the MultiUpload-Extension along with WikiCategoryTagCloud. After every successful upload we got this for every uploaded file:

Warning: Illegal offset type in isset or empty in (...)/includes/Title.php on line 117
Warning: trim() expects parameter 1 to be string, array given in (...)/includes/Title.php on line 2286

We found out, that there is a minor bug in the code of function "invalidateCache" of WikiCategoryTagCloud. In the line

$titles[0] = explode( "\n", wfMsg( 'tagcloudpages' ) );

the whole "exploded" tagcloudpages go as a second array into the first slot of $titles[0]. So that later on in the code there is no single string to be handed, but a whole array ("expects parameter 1 to be string, array given"). To correct the error we changed the above line to this:

$titles = explode( "\n", wfMsg( 'tagcloudpages' ) );

This way all lines (page_titles) from the article Mediawiki:Tagcloudpages implicitly build up an array in the variable $titles and can be referenced correctly later on in the function’s code.

System: MediaWiki 1.16.5, PHP 5.3.3, MySQL 5.0.77

--Cram132 15:13, 30 June 2011 (UTC)Reply


SUCCESS! This solution worked for me. Thanks --webken 17:15, 15 September 2011 (UTC)Reply
SUCCESS! Cram132, your solution is working also in my case! :) Many, many thanks! --Danny373 10:50, 23 September
SUCCESS! this eliminated the "illegal offset" error for me too 29 December 2011 (UTC)

Feature request: parameter include

[edit]

Hi, it would be very cool to have an parameter allowing to set the categories to include rather than excluding them. I some cases this might be very useful. Thank you for considering this. Cheers --[[kgh]] 19:13, 17 April 2011 (UTC)Reply

Similar request: parameter to only include those categories the page is actually a member of. 198.182.56.5 19:08, 19 August 2015 (UTC)Reply

Database Binding

[edit]

PostgreSQL

[edit]

Error in SQL Statement. There is an incompatibility. The Select Statement looks like this:

SELECT cl_to as title, COUNT(*) as count FROM categorylinks GROUP BY cl_to HAVING count >= 0 ORDER BY cl_to ASC

In PostgreSQL the alias count is not working. Reason → http://archives.postgresql.org/pgsql-sql/2004-02/msg00143.php

You can change the code to

SELECT cl_to as title, COUNT(*) as count FROM categorylinks GROUP BY cl_to HAVING count(*) >= 0 ORDER BY cl_to ASC

this will also work on PostgreSQL and MySQL. There is no performance issue. PostgreSQL executes count(*) only once. The code should be patched or fixed. --Cinhtau 12:49, 28 July 2011 (UTC)Reply

[edit]

Is it possible to embedd the tag cloud in the sidebar or footer of mediawiki 1.17? Or is there another way to show it on every page? --Nilsja 14:32, 18 October 2011 (UTC)Reply

Include and namespace

[edit]

Great, but is it possible to add category (and not only exclude) and to manage namespace for include/exclude?

Furthermore, is it possible to manage only the parent of the categories. Now I'm listing every category in Wiki,tens and tens.

Thank in advance.

--WhiteTigerItaly (talk) 16:38, 4 October 2012 (UTC)Reply

Undefined index (Yes Done)

[edit]

Debug information: Notice: Undefined index: linkstyle in /home/www/web64951/html/extensions/WikiCategoryTagCloud/WikiCategoryTagCloud.php on line 66

You should upgrade to a newer version - both the wiki and then also WikiCategoryTagCloud. In current versions this error has been solved. --88.130.87.202 19:06, 4 May 2015 (UTC)Reply

Exclude Subcategories

[edit]

I just started to create subcategories by placing the parent category in the description of the new subcategory. It seems to work as expected. However, the WikiCategoryTagCloud is now listing the Category and both its subcategories. Proceeding, the Cloud would soon 'explode' by growing and growing. To prevent this, only Top-Categories (no Subcategories) should be displayed. Any chance to exclude all subcategories?

Patch

[edit]

I wrote a couple of functions to add the above feature. You can enable and disable it by placing onlyRootCategory=true in your tag on the page (like the exclude=browse option). This is written for only two layers (Top/RootCategories with one layer of SubCategories). You may use the hasSubCategories($currentCategory) function to implement a recursive loop for deeper subcategory trees.

diff -crBN WikiCategoryTagCloud_src/WikiCategoryTagCloud.php WikiCategoryTagCloud_new/WikiCategoryTagCloud.php
*** WikiCategoryTagCloud_src/WikiCategoryTagCloud.php	2015-06-19 10:34:34.000000000 +0200
--- WikiCategoryTagCloud_new/WikiCategoryTagCloud.php	2015-06-19 10:34:43.000000000 +0200
***************
*** 103,109 ****
  
  	$sql = "SELECT cl_to AS title, COUNT(*) AS count FROM {$dbr->tableName( 'categorylinks' )} " .
  		$exclude_condition . " GROUP BY cl_to HAVING COUNT(*) >= $min_count_input ORDER BY cl_to ASC";
! 
  	$res = $dbr->query( $sql, __METHOD__ );
  	$count = $dbr->numRows( $res );
  
--- 103,109 ----
  
  	$sql = "SELECT cl_to AS title, COUNT(*) AS count FROM {$dbr->tableName( 'categorylinks' )} " .
  		$exclude_condition . " GROUP BY cl_to HAVING COUNT(*) >= $min_count_input ORDER BY cl_to ASC";
! #echo "debug: $sql<br><br>";
  	$res = $dbr->query( $sql, __METHOD__ );
  	$count = $dbr->numRows( $res );
  
***************
*** 112,122 ****
  
  	$min = 1000000;
  	$max = - 1;
! 
  	for ( $i = 0; $i < $count; $i++ ) {
  		$obj = $dbr->fetchObject( $res );
! 		$tags[$i][0] = $obj->title;
! 		$tags[$i][1] = $obj->count;
  		if ( $obj->count < $min ) {
  			$min = $obj->count;
  		}
--- 112,177 ----
  
  	$min = 1000000;
  	$max = - 1;
! /*
! $ar_topCategories = array();
! $ar_topCategories = getRootCategories();
! echo "#####debug3:final result - only top categories:<br>";
! for ($k=0; $k < count($ar_topCategories); $k++ ) {
! 	echo " : [$ar_topCategories[$k]] : ";
! }
! echo " DEBUG end<br>";
! //$ar_parentExtraWeight = getParentExtraWeight();
! if ( hasSubCategory('Health')) {
! echo "#debug10: [ Health ] has SubCategories<br>";
! $ar_temp = getSubCategories('Health');
! for ($iTemp = 0; $iTemp < count($ar_temp); $iTemp++ ) {
! echo "#debug10: ==========> {$ar_temp[$iTemp]} : ";
! }
! echo "<br>";
! }else{
! echo "#debug10: [ Health ] has no SubCategories<br>";
! }
! if ( hasSubCategory('Coding')) {
! echo "#debug10: [ Coding ] has SubCategories<br>";
! }else{
! echo "#debug10: [ Coding ] has no SubCategories<br>";
! }
! */
! //$ar_topCategories = getRootCategories();
! $onlyRootCategories_input = false;
! $onlyRootCategories_input = getBoxExtensionOption( $input, 'onlyRootCategories' );
! //echo "onlyRootCategories_input = $onlyRootCategories_input";
  	for ( $i = 0; $i < $count; $i++ ) {
  		$obj = $dbr->fetchObject( $res );
! 		//deprecated - $tags[$i][0] = $obj->title; //e.g. Apache | Coding | Diabetes | Health | ...
! 		//deprecated - $tags[$i][1] = $obj->count; //e.g.      4 |    50  |       34 |      2 | ...
!                 //start
!                 $extraCount = 0;
!                 if (hasSubCategories($obj->title)){
!                         $extraCount = getTotalExtraWeight($obj->title);
!                 }
! 		if ( isRootCategory($obj->title) && $onlyRootCategories_input ){
! 			$tags[$i][0] = $obj->title;
!                 	$tags[$i][1] = ($obj->count + $extraCount);
! 			#echo "#debug0: {$tags[$i][0]} = {$tags[$i][1]}<br>";
! 			#if ($extraCount > 0){
! 			#	echo "#debug0:  {$obj->title} with totalCount: {$obj->count} + {$extraCount} = {$totalCount}<br>";
! 			#}
! 		#}else{
! 		#	$totalTemp = $obj->count + $extraCount;
! 		#	echo "#debug0: skipping {$obj->title} with totalCount: {$obj->count} + {$extraCount} = {$totalCount}<br>";
! 		}
! 		if ( $onlyRootCategories_input == false ){
!                 	$tags[$i][0] = $obj->title; //e.g. Apache | Coding | Dia_____ | Health | ...
!                 	$tags[$i][1] = $obj->count; //e.g.      4 |    50  |       34 |      2 | ...
! 		}
! 		if ( ($extraCount + $obj->count) < $min ){
! 			$min = ($extraCount + $obj->count);
! 		}
! 		if ( ($extraCount + $obj->count) > $max ){
! 			$max = ($extraCount + $obj->count);
! 		}
! 		//end
  		if ( $obj->count < $min ) {
  			$min = $obj->count;
  		}
***************
*** 132,138 ****
  		$currentRow = '<a class="' . $params['linkclass'] .
  			'" style="' . $style . '" href="' . $title->getLocalURL() . '">' .
  			$title->getText() . '</a>&#160; ';
! 		$htmlOut = $htmlOut . $currentRow;
  	}
  	$htmlOut = $htmlOut . '</div>';
  	return $htmlOut;
--- 187,195 ----
  		$currentRow = '<a class="' . $params['linkclass'] .
  			'" style="' . $style . '" href="' . $title->getLocalURL() . '">' .
  			$title->getText() . '</a>&#160; ';
! 		if (!empty($tags[$i][0])){ //only append if we did not previously skipped the category
! 			$htmlOut = $htmlOut . $currentRow;
! 		}
  	}
  	$htmlOut = $htmlOut . '</div>';
  	return $htmlOut;
***************
*** 147,149 ****
--- 204,327 ----
  		}
  	}
  }
+ // ---------------------------------------------- new ------------------------
+ //checks the currentCategory if it is part of the RootCategories
+ function isRootCategory($currentCategory){
+ 	$ar_rootCategories = getRootCategories();
+ 	return in_array($currentCategory, $ar_rootCategories, TRUE); //TRUE - case sensitive, FALSE - case insensitiv
+ 
+ }
+ 
+ // get all Top-Parent-Categories (Root Categories) by comparing Top and Sub-Categories)
+ function getRootCategories() {
+ 	 //return array_diff(getCategories(), getAllSubCategories());
+ 	return array_filter(array_diff(getCategories(), getAllSubCategories()));
+ }
+ 
+ // get all Categories of the Wiki
+ function getCategories() {
+ 	$dbr = wfGetDB( DB_SLAVE );
+ 	$query = "SELECT DISTINCT cl_to FROM {$dbr->tableName( 'categorylinks' )} ";//categorylinks;';
+ 	$res = $dbr->query( $query, __METHOD__ );
+ 	$countRows = $dbr->numRows( $res );
+ 	for ( $i = 0; $i < $countRows; $i++ ) {
+ 		$obj = $dbr->fetchObject( $res );
+ 		$ar_res[] = $obj->cl_to;
+ 	}
+ 
+ 	return $ar_res;
+ }
+ 
+ // get all SubCategories of the WiKi
+ function getAllSubCategories() {
+ 	$dbr = wfGetDB( DB_SLAVE );
+ 	// namespace 14 = category
+ 	$query = "SELECT cl_to as parent_category, cl_from, page_namespace, page_title as child_category FROM {$dbr->tableName( 'categorylinks' )} JOIN {$dbr->tableName( 'page' )} on cl_from = page_id WHERE page_namespace=14";
+ 	$res = $dbr->query( $query, __METHOD__ );
+ 	$countRows = $dbr->numRows( $res );
+ 	for ( $i = 0; $i < $countRows; $i++ ) {
+ 		$obj = $dbr->fetchObject( $res );
+ 		$ar_child_res[] = $obj->child_category;
+ 	}
+ 	return $ar_child_res; 
+ }
+ 
+ // returns array with all parent categories (top categories) containing their subcategories (non-recursive) 
+ // The second array element 'counter' returns the number of subcategories
+ // ar_rsult['name of Top-Parent-Category]['counter'], whereas counter contains a number. //counter does not include pages directly related to the Top-Parent-Category. Only Extra-pages in subCategories
+ function getAllParentsAndExtraWeight() {
+         $dbr = wfGetDB( DB_SLAVE );
+         // namespace 14 = category
+         $query = "SELECT cl_to as parent_category, cl_from, page_namespace, page_title as child_category FROM {$dbr->tableName( 'categorylinks' )} JOIN {$dbr->tableName( 'page' )} on cl_from = page_id WHERE page_namespace=14";
+ 	$ar_parentExtraWeight = array();
+         $res = $dbr->query( $query, __METHOD__ );
+         $countRows = $dbr->numRows( $res );
+         for ( $i = 0; $i < $countRows; $i++ ) {
+                 $obj = $dbr->fetchObject( $res );
+                 $ar_child_res[] = $obj->child_category;
+ 		$curCount = $ar_parentExtraWeight[$obj->parent_category]['counter'];
+ 		if (isset($curCount)){
+ 			$ar_parentExtraWeight[$obj->parent_category]['counter'] = $curCount+1;
+ 			#echo "###debug0: increased counter of {$obj->parent_category} to { $curCount+1 }";
+ 		}else{
+ 			$ar_parentExtraWeight[$obj->parent_category]['counter'] = 1;
+ 			#echo "###debug0: initiated element {$obj->parent_category} with 1";
+ 			//$testCount = getTotalWeight($obj->parent_category);
+ 			//$testCount2 = getTotalWeight($obj->child_category);
+ 		}
+         }
+         return $ar_parentExtraWeight;
+ }
+ 
+ //get the total number of pages contained by subcategories (non-recursive)
+ //returns number of total pages of Category= pages + subcategories + their pages
+ function getTotalExtraWeight($myParentCategory){ //former called getTotalWeight - but this is the more precise name now
+         $dbr = wfGetDB( DB_SLAVE );
+ 	$totalCount = 0;
+         // namespace 14 = category
+         $query = "SELECT cl_to as parent_category, cl_from, page_namespace, page_title as child_category FROM {$dbr->tableName( 'categorylinks' )} JOIN {$dbr->tableName( 'page' )} on cl_from = page_id WHERE page_namespace=14";
+         $res = $dbr->query( $query, __METHOD__ );
+         $countRows = $dbr->numRows( $res );
+         for ( $i = 0; $i < $countRows; $i++ ) {
+                 $obj = $dbr->fetchObject( $res );
+                 $ar_child_res[] = $obj->child_category;
+ 		if ($obj->parent_category == $myParentCategory){
+ 			$query2 = "SELECT count(*) as counter FROM {$dbr->tableName( 'categorylinks' )} JOIN {$dbr->tableName( 'page' )} on cl_from = page_id WHERE cl_to = '{$obj->child_category}';";
+ 			$res2 = $dbr->query( $query2, __METHOD__ );
+ 			$countRows2 = $dbr->numRows( $res2 );
+ 			$curCount = 0;
+ 			for ($it = 0; $it < $countRows2; $it++ ) {
+ 				$obj2 = $dbr->fetchObject( $res2 );
+ 				$curCount = $obj2->counter;
+ 			}
+ 			$totalCount = $totalCount + $curCount;
+ 		}
+         }
+         return $totalCount;
+ }
+ 
+ // Checks currentCategory for existence of subCategories
+ function hasSubCategories($currentCategory){
+ 	$ar_subCategories = getSubCategories($currentCategory);
+ 	if (empty($ar_subCategories)){
+ 		return false;
+ 	}else{
+ 		return true;
+ 	}
+ }
+ 
+ function getSubCategories($currentCategory){
+ $ar_subCategories = array();
+         $dbr = wfGetDB( DB_SLAVE );
+         // namespace 14 = category
+         $query = "SELECT cl_to as parent_category, cl_from, page_namespace, page_title as child_category FROM {$dbr->tableName( 'categorylinks' )} JOIN {$dbr->tableName( 'page' )} on cl_from = page_id WHERE page_namespace=14";
+         $res = $dbr->query( $query, __METHOD__ );
+         $countRows = $dbr->numRows( $res );
+         for ( $i = 0; $i < $countRows; $i++ ) {
+                 $obj = $dbr->fetchObject( $res );
+                 if ($obj->parent_category == $currentCategory){ //only store if the parent_category belongs to the searched currentCategory
+                         $ar_subCategories[] = $obj->child_category;
+                 }
+         }
+ return $ar_subCategories;
+ }

Save content in WikiCategoryTagCloud_new.patch and apply:

cd WikiCategoryTagCloud
patch --dry-run -p1 -i ../WikiCategoryTagCloud_new.patch

patch -p1 -i ../WikiCategoryTagCloud_new.patch

Vulnerable to SQL Injection?

[edit]

Isn't the loop that processes $exclude_condition vulnerable to SQLI? There's nothing that sanitizes $excluded_categories[$i], so a hostile agent could use this as a vector. Not hip to PHP enough to suggest any remediation, but thought I'd bring it to your attention to address. 198.182.56.5 19:04, 19 August 2015 (UTC)Reply

Thanks for informing people about (possible) security problems! This one has in the meantime been fixed.
In the future, please do not disclose security issues to the public! Instead, follow the procedure on reporting security bugs! --88.130.88.113 23:05, 8 December 2015 (UTC)Reply

Category Sidebar

[edit]

I have just switched to this extension and it works great for our internal wiki. We upgrade to 1.26, the old extension no longer worked as a result and was no longer in development.

However the old extension had a sidebar, which just looked horrible yet I needed to add it back in. So I have done the below modifications. It is a complete mess I know that, just wanted it in quickly to keep the peace.

If someone wants to tidy it up and improve it, please feel free.

For the file extension.json I add the following hook;

	"Hooks": {
		"ArticleSave": [
			"WikiCategoryTagCloud::invalidateCache"
		],
		"SkinBuildSidebar": [
			"WikiCategoryTagCloud::cloudsidebar"
		],
		"ParserFirstCallInit": [
			"WikiCategoryTagCloud::register"
		]
	},


For the file WikiCategoryTagCloud.class.php I added the following code withing the class;

	public static function cloudsidebar( $skin, &$bar ) {
			
					$MIN_SIZE = 77;
		$INCREASE_FACTOR = 100;
$dbr = wfGetDB( DB_SLAVE );
				$res = $dbr->select(
			'categorylinks',
			array( 'cl_to AS title', 'COUNT(*) AS count' ),array(),
			__METHOD__,
			array(
				'GROUP BY' => 'cl_to',
				'ORDER BY' => 'cl_to ASC'
			)
		);
		$count = $dbr->numRows( $res );

		$htmlOut = '';

		$min = 1000000;
		$max = -1;

		for ( $i = 0; $i < $count; $i++ ) {
			$obj = $dbr->fetchObject( $res );
			$tags[$i][0] = $obj->title;
			$tags[$i][1] = $obj->count;
			if ( $obj->count < $min ) {
				$min = $obj->count;
			}
			if ( $obj->count > $max ) {
				$max = $obj->count;
			}
		}

		for ( $i = 0; $i < $count; $i++ ) {
			$textSize = $MIN_SIZE + ( $INCREASE_FACTOR * ( $tags[$i][1] ) ) / ( $max );
			$title = Title::makeTitle( NS_CATEGORY, $tags[$i][0] );
			$style = '';
			if ( $style != '' && substr( $style, -1 ) != ';' ) {
				$style .= ';';
			}
			$style .= "font-size: {$textSize}%;";
			$currentRow = '<a class="' .
				"\" style=\"{$style}\" href=\"" . $title->getLocalURL() . '">' .
				$title->getText() . '</a>&#160;<br>';
			$htmlOut = $htmlOut . $currentRow;
		}
		$out = $htmlOut . '</div>';	

			$bar[ 'Category Cloud' ] = $out;
		
		return true;
	}

Set a basecategory

[edit]

Is there a way to set a basecategory? As example: in a wiki of films; if i would collect the genre in an main-category named "genre". I would like to only show the categories in "genre", not other categories, like studio, producer something like that. is there a way to show only the cats (with the allready established filters (more than x) )? --Gunnar.offel (talk) 21:28, 10 October 2019 (UTC)Reply

I added this here for it not to be forgotten. --[[kgh]] (talk) 21:36, 17 October 2019 (UTC)Reply