Extension talk:SelectCategoryTagCloud

From mediawiki.org
Latest comment: 11 years ago by Girlwithglasses in topic Titles wrong (and other)

Categories don't be saved when uploading (and categorizing) a file[edit]

Hi there, the extension works very well on articles. But when I select categories in the event of uploading a new file the categories selected won't be saved. I have to edit the file and select them again to save the categories.

--Trop 23:00, 26 April 2009 (UTC)Reply

We resolved like below. Code will give reference

# If it is an upload we have to call a different method:
  if ( $m_isUpload ) {
     //$m_pageObj->mUploadDescription .= $m_text;
     //Fixed Ticket#162 category availabe when upload

     //FIXME: xiping.wang@gmail.com 20100429 
     //  mComment becomes protected variable in MW 1.16.0. This feature is disabled before 
     //  we have other soultion 
     // mComment variable must be public in SpecialUpload.php file of includes folder. 
     $m_pageObj->mComment .= $m_text;
  } else{
     $m_pageObj->textbox1 .= $m_text;
  }

Errors[edit]

I've got an errors caused by SelectCategoryTagCloudSuggest.php:

1 result set(s) not freed

An other thing is the structure of this php-program, where at first query is executed and later checked if searchString perhaps is NULL. I've fixed the Error with mysql_free_result and changed the structure a little bit. My opinion is that this script may should more look like that:

if(isset($_GET['q'])) {
    $searchString = mysql_real_escape_string($_GET['q']);
    if($searchString != NULL) {
        $sql = mysql_query("SELECT DISTINCT cl_to as cats FROM categorylinks WHERE cl_to LIKE '".$searchString."%'");
        $suggestStrings=array();
        while($row = mysql_fetch_assoc($sql)) {
                array_push($suggestStrings,$row['cats']);
        }
        echo implode(";",$suggestStrings);
        //echo $suggestStrings;
        if(mysql_num_rows($sql) == 0) {
         //echo "<i>No results found</i>";
        }
        mysql_free_result($sql);
    }
}

The last problem is to have redundant DB-Access-Parameters on the top of the script, but the same data is provided by LocalSettings.php. Is there no way to require LocalSettings.php to use this params? Thanks -Stefan- ---79.211.199.108 14:46, 14 September 2007 (UTC)Reply

Thanks for the suggestion, I included it in version 1.1 and updated the source file. Regarding the database credentials, the page is basically a standalone program and not part of the MediaWiki code. I have yet to find a work-around to get to the details in LocalSettings.php. Any suggestions are welcome. Thanks, --Lindele 16:10, 14 September 2007 (UTC)Reply


It's me again I've found a Solution but its a bad one for a rich extended mediaWiki:

1.

<?php
/* SelectCategoryTagCloud Mediawiki Extension
 *
 * @author Andreas Rindler (mediawiki at jenandi dot com)
 * @credits Leon Weber <leon.weber@leonweber.de> & Manuel Schneider <manuel.schneider@wikimedia.ch>, Daniel Friesen http://wiki-tools.com
 * @licence GNU General Public Licence 2.0 or later
 * @description Adds a category selection tag cloud to the edit and upload pages and enables a Google Suggest like completion of categories entered by the user.
 *
*/

# Set MEDIAWIKI to avoid the "Part Of mediaWiki-Errors"
define( 'MEDIAWIKI', true);
require_once('../../includes/Defines.php'); # Grabb Defines to avoid Errors in LocalSettings
require_once('../../LocalSettings.php'); # Load LocalSetting with all Settings but all Extensions (very dirty)
# now we can load from mediaWiki globals
global $wgDBserver,$wgDBname,$wgDBuser,$wgDBpassword;

mysql_connect($wgDBserver,$wgDBuser,$wgDBpassword);

mysql_select_db($wgDBname);

if(isset($_GET['q'])) {
    $searchString = mysql_real_escape_string($_GET['q']);
    if($searchString != NULL) {
        $sql = mysql_query("SELECT DISTINCT cl_to as cats FROM categorylinks WHERE cl_to LIKE '".$searchString."%'");
        $suggestStrings=array();
        while($row = mysql_fetch_assoc($sql)) {
                array_push($suggestStrings,$row['cats']);
        }
        echo implode(";",$suggestStrings);
        //echo $suggestStrings;
        if(mysql_num_rows($sql) == 0) {
         //echo "<i>No results found</i>";
        }
        mysql_free_result($sql);
    }

}
?>

This works, but slowes up the CategorySuggest, because every extension and every setting is allocated per one request of suggest.

2. I think mediaWiki it self, should perhaps better provide a distributed Setting, something like "DatabaseSettings.php" as separate Solution. So you can require this Config-File in LocalSettings.php and every other Application that need this Params without running directly under mediaWiki, within one of the few Hook-Callbacks, although it will give the possibility to load only needed Settings under MediaWiki. Did you have some connections to mediaWiki core developers?

3. An other way could be to use the separat AdminSetting.php file, but not everyone might set this config file.

4. Perhaps you can grab the Settings in SelectCategoryTagCloud.php where they are available and write it to a file which can be included to SelectCategoryTagCloudSuggest.php, that will never be a Problem, because SelectCategoryTagCloud.php is called earlier than SelectCategoryTagCloudSuggest.php will be called first time.

5. You could do not require LocalSettings.php but read it with fopen or e.g. and use a regular expression to get the Settings without parsing LocalSettings.php

But nothing seems to be very great. All Solutions are dirty Solutions, in exception of creating a separate DatabaseSettings.php which will be included in LocalSettings and SelectCategoryTagCloudSuggest but that will make the installation quite more difficult. In this case(not a special one) I belive mediaWiki it self should be improved or I'm very interessted too in a good Solution with current mediaWiki. Whats your idea about this?


I would think that the easiest and cleanest way to solve this to extend the MediaWiki API to allow a list of all categories. This would be optimised for speed, secure and part of the core and therefore available for other projects to reuse. --Lindele 10:46, 27 September 2007 (UTC)Reply


The native reason because I browsed to this talkpage follows...

Setting wgSelectCategoryRoot has no Effect[edit]

I wanna make a Playground Namespace with Playground Categories.
There for I've created a special categorie "Playground" wich should be the root category for NS_PLAYGROUND
My setting of wgSelectCategoryRoot doesnt have any effect, so I've read the Code and found out, that there is no usage
of the parameter wgSelectCategoryRoot in SelectCategoryTagCloudFunctions.php
Than I've seen the Code:
   $m_allCats = fnSelectCategoryGetAllCategories();
and thats the only thing where categories are grapped from database, for the cloud.
There is no fnSelectCategoryGetAllSubCategoriesUnderRoot($wgSelectCategoryRoot[$current_namespace]) or e.g.
Is the wgSelectCategoryRoot setting only for normal SelectCategory-Extension available and not for this one?

Sorry my english is perhaps a little bit roughly :)

Thanks again -Stefan- 79.211.199.89 10:40, 25 September 2007 (UTC)Reply

To be honest, that's the part of the code that I took 'as-is' from the existing Extension:SelectCategory. Maybe you can find some ideas there? --Lindele 10:43, 27 September 2007 (UTC)Reply

I've been looking for a while and I've made something that works fine. Use function fnSelectCategoryGetAllCategories() that is defined in selectCategory ext. in some php-file. You have to redefine method of building CloudTag, so that only things returned by this function are used.
It has still no effect! And 'SelectCategoryTagCloudFunctions.php' has been replaced with the Mediawiki built-in AJAX framework. Does anyone know a solution that works with current release of MediaWiki? Pmaas 11:56, 5 December 2010 (UTC)Reply

Errors When trying to Input Categories Manually[edit]

I just installed the SelectCategoryTagCloud extension and it works fine when a user is clicking to select from the list of "Popular Categories". However, if you try to manually enter anything into the Categories text box, the following 2 warnings are displayed:

Warning: mysql fetch assoc(): supplied argument is not a valid MySQL result resource
in /var/www/wiki/extemsopms/SelectCategoryTagCloud/SelectCategoryTagCloudSuggest.php on linne 20

Warning: mysql free result(): supplied argument is not a valid MySQL result resource
in /var/www/wiki/extemsopms/SelectCategoryTagCloud/SelectCategoryTagCloudSuggest.php on linne 26

In addition, there is no "auto-suggest" based on the initial letters that are manually input in the text box.

If I ignore the warnings, type something in the box anyway, and then save the page, it will properly add the new or existing tag to the page.

In short, everything seems to be working fine except for the auto-suggest and the error messages (presumably related). Thoughts?

--jaysailor 9 October 2007


I had this same error today, after installing this extension. In SelectCategoryTagCloudSuggest.php I forgot to update the name of the database to "wikidb". If "wikidb" is the default database name for MediaWiki, then I think that the next release should use that instead of "DBNAME" (unless "Move SelectCategoryTagCloudSuggest.php configuration for database access into Mediawiki framework to simplify configuration" is checked off the to do list).

The line I modified in SelectCategoryTagCloudSuggest.php is:

mysql_select_db("DBNAME");

-d 4 January 2008


I am seeing a similar issue. When I manually type in category names using Firefox on Mac I do not get any autocompletion. I get these errors in the error console:

Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE)
 [nsIXMLHttpRequest.status]"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: 
 http://-snip-]/extensions/SelectCategoryTagCloud/SelectCategoryTagCloud.js :: handleResponse :: line 118"  data: no]
 Source File: http://-snip-/wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloud.js
 Line: 118
Error: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) 
 [nsIXMLHttpRequest.send]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: 
 http://-snip-/wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloud.js :: sendRequest :: line 112"  data: no]

In Opera on Mac OS I do get autocompletion, but I am seeing two copies of every possible complemetion.

In Safari, autocompletion works as expected.

Any thoughts?

Tnabtaf, 24 January 2008


I fixed the problems in Opera and Firefox by removing the onkeydown from SelectCategoryTagCloudFunctions.php:

70c70
<               $m_pageObj->$m_place .= "<input onkeydown='sendRequest(this.value);' onkeyup='sendRequest(this.value);' autocomplete='off' type='text' name='txtSelectedCategories' id='txtSelectedCategories' maxlength='200' size='105' value='".str_replace("_"," ",implode(";", $arrExistingCats))."'/>\n";
---
>               $m_pageObj->$m_place .= "<input onkeyup='sendRequest(this.value);' autocomplete='off' type='text' name='txtSelectedCategories' id='txtSelectedCategories' maxlength='200' size='105' value='".str_replace("_"," ",implode(";", $arrExistingCats))."'/>\n";

With many thanks to Kevin S at ZFIN.

Tnabtaf, 25 January 2008


Removing the onkeydown does work but when I remove my courser from that field I get the same error. So I took the onkeyup off and it fixed the problem...but it doesn't have auto suggest now. Any suggestions how I can fix this problem? (Ed March 27, 2008)

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 automatic "*template*" exclude? Any help/advice much appreciated. Thanks

That would be valuable, I agree! There is no out of the box functionality for this right now. Any suggestions how to build it into the extension gracefully would be appreciated. A short term fix could be to modify the SQL statement in the SelectCategoryTagCloudSuggest.php file along the lines of

[...] WHERE cl_to LIKE '".$searchString."%' AND LOWER(cl_to) NOT LIKE LOWER('%TEMPLATE%')

The LOWER() function is included to ignore case differences in how you spell template.

I haven't tested this, let me know if it works...

- Lindele 21:10, 23 October 2007 (UTC)Reply

I haven't been able to get this to work, what needs to be done? 200.49.167.178 20:46, 15 July 2011 (UTC)Reply

SelectCategoryTagCloud is stripping Leading spaces from text lines[edit]

Hey all, first off I just wanted to say I love this extension. I tend to forget the spelling of my categories and always get them messed up this is a huge help. That being said I discovered a problem with the extension. It strips out the leading text from your wiki page. This is only a problem if you are trying to use the leading spaces to create sections on the page. I tracked the problem back to "SelectCategoryTagCloudFunctions.php" file. In here you are using the "trim" function which strips the blanks from BOTH the front and end of the lines. I changed all 4 "trim" commands to "rtrim" and the extension is now working fantastically. Anyway I wanted to pass this info on so it can be included into the new versions.

- John P 18 Nov 2007

Same Issue[edit]

Hi, I'm getting the same issue today. I can't find the SelectCategoryTagCloudFunctions.php file to verify that trim is now rtrim. I'm using version 1.3.

Strmtrupr2 18:49, 28 May 2008 (UTC)Reply

Issue here[edit]

Found the same issue and performed the change to five 'trim' functions in "SelectCategoryTagCloud.body.php". Now leading spaces are no longer removed.

Fix to Issue[edit]

As far as I can tell, the only place trim() was causing a problem was on the line

$m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine )  ) . "\n";

Inside the fnSelectCategoryStripCats($texttostrip, &$catsintext) function. I changed it to

$m_cleanText .= preg_replace( "/{$m_pattern}/i", "", $m_textLine ) . "\n";

And everything appears to be working properly. --64.140.241.82 16:58, 21 October 2008 (UTC) (Kevin Hamer)Reply

Also fixed with rtrim:

$m_cleanText .= rtrim( preg_replace( "/{$m_pattern}/i", "", $m_textLine )  ) . "\n";

89.223.122.29 15:49, 11 May 2010 (UTC)Reply

Applying to a new namespace[edit]

Hi, and thanks for this piece of code.

Here's my problem : I've created a "Doc" namespace, and the cloud doesn't appear in it.

My LocalSettings has this:

$wgExtraNamespaces[100] = "Doc";
$wgExtraNamespaces[101] = "Doc_talk";

I can create pages in Doc namespace and it appears well in the Special Search page - so I guess it works.

Then I added a line to wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloud.php: (the Cloud works well on "standard" pages)

## Options:
# $wgSelectCategoryNamespaces - list of namespaces in which this extension should be active
if( !isset( $wgSelectCategoryNamespaces ) ) $wgSelectCategoryNamespaces = array(
        NS_MEDIA                => true,
        NS_MAIN                 => true,
        NS_TALK                 => true,
        NS_USER                 => false,
        NS_USER_TALK            => false,
        NS_PROJECT              => true,
        NS_PROJECT_TALK         => false,
        NS_IMAGE                => true,
        NS_IMAGE_TALK           => false,
        NS_MEDIAWIKI            => false,
        NS_MEDIAWIKI_TALK       => false,
        NS_TEMPLATE             => true,
        NS_TEMPLATE_TALK        => false,
        NS_HELP                 => true,
        NS_HELP_TALK            => false,
        NS_CATEGORY             => true,
        NS_CATEGORY_TALK        => false,
        NS_DOC                  => true
);

(Last line with Doc)

I don't know if I made a mistake, or if the code is limited on this topic?

(I wasn't lucky either with :

$wgSelectCategoryNamespaces[NS_DOC] = true;


BTW, thanks for the 1.2 version, I can use "spaces in 1st line" again ! --FredT34 12:05, 27 November 2007 (UTC)Reply

I checked and I hadn't realised that it doesn't work for me either. But the solution is simple, you need to use the following syntax:

100             => true

and not

NS_DOC                  => true

Cheers, Lindele 18:35, 27 November 2007 (UTC)Reply

YES, 100 => true does the trick. Thanks ! --FredT34 22:11, 28 November 2007 (UTC)Reply

Adding Categories with ampersands in their title[edit]

In some cases it is possible to have Short URL's (mod rewrite) and ampersands in titles. To Add Categories with ampersands (&), you need to modify the js-code to something like this:

/extensions/SelectCategoryTagCloud/SelectCategoryTagCloud.js

function selectEntry () {
var strExistingValues = document.getElementById('txtSelectedCategories').value;
+		var insert = this.innerHTML.replace(/&amp;/gi,"&");;
if(strExistingValues.lastIndexOf(';')!=-1){
var intIndex = strExistingValues.lastIndexOf(';');
strExistingValues = strExistingValues.substr(0, intIndex+1);
-		  	document.getElementById('txtSelectedCategories').value = strExistingValues + this.innerHTML;
+		  	document.getElementById('txtSelectedCategories').value = strExistingValues + insert;
} else {
-			document.getElementById('txtSelectedCategories').value = this.innerHTML;
+			document.getElementById('txtSelectedCategories').value = insert;
}
document.getElementById('searchResults').style.visibility='hidden';

This ensures that escaped innerHTML content is put correctyl in the input-field.

--Kaspera 15:55, 5 December 2007 (UTC)Reply

This is great! But it doesn't work completely:
  1. when I click on a category in the cloud it still displays &amp at first.
  2. if I have added a category called A&B to a page and then, after saving the page, click on the category I get a link to Category:A instead of Category:A&B

--Robinson Weijman 11:55, 5 November 2010 (UTC)Reply

nowiki exclusion[edit]

I am a little confused by the extension SelectCategory, what are the main differences?

I would like to know if the request to escape categories between nowiki has been noticed, solved or could be solved with a quick fix. The main reason is template inclusion, wich are categorised and show up on articles.

--Kaspera 15:55, 5 December 2007 (UTC)Reply

Did it myself. Fixed multiple categories on one line bug, and noinclude bug.
Changes:
Index: /wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloudFunctions.php
===================================================================
@@ -176,4 +175,5 @@
 	$m_cleanText = '';
 
+/*
 	# Check linewise for category links:
 	foreach( explode( "\n", $m_pageText ) as $m_textLine ) {
@@ -185,4 +185,7 @@
 		$m_catLinks[ preg_replace( "/.*{$m_pattern}/i", $m_replace, $m_textLine ) ] = true;
 	}
+*/
+	require_once('SelectCategoryTagCloudHack.php');
+	
 	# Place the cleaned text into the text box:
 	$m_pageObj->textbox1 = rtrim( $m_cleanText );
Added file SelectCategoryTagCloudHack.php:
<?php
$m_pattern = "\[\[({$m_catString}|category):(.*?)\]\]"; // sub-pattern is not allowed to be greedy
$m_catLinks = array ();


$count = false;
$t_open = "/(.*?)(<noinclude(.*?)>|<pre(.*?)>|<nowiki(.*?)>)/i";
$t_close = "/(.*?)(<\/noinclude>|<\/pre>|<\/nowiki>)/i";
$state = "close";
foreach(explode( "\n", $m_pageText ) as $m_textLine){
	$m_textLine = $m_textLine."\n";
	$offset2 = -1;
	$offset = 0;
	$len = (strlen($m_textLine)-1);
	while($offset != $offset2){
		$offset2 = $offset;
		$matches = $matches2 = false;
		if($state == 'close'){
			preg_match($t_open,$m_textLine,$matches,PREG_OFFSET_CAPTURE,$offset);
			if(isset($matches[0])){
				$m_cleanText[] =  preg_replace( "/{$m_pattern}/i", "", $matches[1][0], -1, $count );
				preg_match_all("/{$m_pattern}/i", $matches[1][0],$matches2);
				if($count > 0){
					foreach($matches2[2] as $value){
						$m_catLinks[$value] = true;
					}
				}
				$count = false;
				$state = 'open';
				$offset = $matches[2][1];
			}
		}
		$matches = false;
		if($state == 'open'){
			preg_match($t_close,$m_textLine,$matches,PREG_OFFSET_CAPTURE,$offset);
			if(isset($matches[0])){
				$m_cleanText[] = $matches[0][0];
				$state = 'close';
				$offset = ($matches[0][1] + strlen($matches[0][0]));
			}
		}
	}
	if($offset<=$len){
		$tail = substr($m_textLine,$offset);
		if($state == 'close'){
			$matches3 = false;
			$m_cleanText[] = preg_replace( "/{$m_pattern}/i", "", $tail, -1, $count );
			preg_match_all("/{$m_pattern}/i", $tail,$matches3);
			if($count > 0){
				foreach($matches3[2] as $value){
					$m_catLinks[$value] = true;
				}
			}
		}
		if($state == 'open'){
			$m_cleanText[] = $tail;
		}
	}
}
$m_cleanText = ($m_cleanText=='')?$m_pageText:implode($m_cleanText);
Fixed the last newline bug. --Kaspera 13:12, 14 December 2007 (UTC)Reply

Disclaimer: I havent'had time to document this script. Due to the lack of documentation, I recommend to make no changes to the regular expression unless you really know what you are doing. The matches variable will be populated depending on how many subpatterns the regexp contains.

What it does:[edit]

First of all, the script devides the text into two arrays, one part is everything but the nowiki part (it even spans multiple lines) and the other continaing everything within the nowiki tags.
Only text in the first part will be 'parsed'. At the end, both parts are joined and returned.
I slightly modified the regular expressions to be less greedy, and solved the 'multiple categories on one line ignored' bug by recoding that part.
Feel free to modify the code (keep me posted)! --Kaspera 14:18, 10 December 2007 (UTC)Reply


I've noticed that the latest version of the extension adds extra spaces around a nowiki tag everytime you edit it. Does this hack fix that behavior? Or was this hack folded in to the extension and causes it? 98.215.227.116 09:55, 5 October 2008 (UTC)Reply

Preview edits loses categories[edit]

When previewing changes, all categories are lost. The suggested bugfix only applies to the SelectCategory extension.

The given solution works with an array, submitted by $_POST, the SelectCategoryTagCloud extension however submits a string.

To solve this error with this extension, use this:

Index: wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloudFunctions.php
===================================================================
--- wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloudFunctions.php (revision 2086)
+++ wiki/extensions/SelectCategoryTagCloud/SelectCategoryTagCloudFunctions.php (revision 2252)
@@ -161,4 +161,14 @@
 ## Also removes them from the text the user views in the editbox.
 function fnSelectCategoryGetPageCategories( $m_pageObj ) {
+	if (array_key_exists('txtSelectedCategories', $_POST)) {
+		# We have already extracted the categories, return them instead
+		# of extracting zero categories from the page text.
+		$m_catLinks = array();
+		$preview_categories = explode(";",$_POST['txtSelectedCategories']);
+		foreach( $preview_categories as $m_cat ) {
+			$m_catLinks[ $m_cat ] = true;
+		}
+		return $m_catLinks;
+	}
 	global $wgContLang;

--Kaspera 15:04, 20 December 2007 (UTC)Reply

tagcloud suggestion[edit]

Hello,

I got a bug on the tagcloud suggestion tool.When a user want to modify an article, the tag suggestion doesn't work. I tried to debug the script and the function Handleresponse is never called.Maybe because the readyStatus doesn't change. The suggestion tool works well only when the user want to upload a picture or a sound.

I am a "beginner" so I don't really know where can I find the solution.

Can someone help me please?

Thanks



Finally I fixed my problem.

The problem came from a conflict between the Tag cloud extension and the rating extension. When the http.readyState changes,HandleResponse is called.In my case there were two functions HandleResponse,so only the HandleRespone() in the Rating extension was called.

To fix it maybe rename the function like: HandleResponseRating() and HandleResponseSuggest().

The fnSelectCategoryGetPageCategories removes empty lines in code listings[edit]

The fnSelectCategoryGetPageCategories uses the rtrim function which transforms lines with a single whitespace (necessary in longer code listings that have empty lines) into empty lines, thus breaking the code listings in two parts in the wiki markup.

Here is the diff to SelectCategoryTagCloudFunctions.php from version 1.2 (2007-09-27):

@@ -177,7 +177,7 @@
 	# Check linewise for category links:
 	foreach( explode( "\n", $m_pageText ) as $m_textLine ) {
 		# Filter line through pattern and store the result:
-                $m_cleanText .= rtrim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) . "\n";
+                $m_cleanText .= ((substr($m_textLine,0,1) == " ") ? $m_textLine : rtrim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) ) . "\n";
 		# Check if we have found a category, else proceed with next line:
                 if( !preg_match( "/{$m_pattern}/i", $m_textLine) ) continue;
 		# Get the category link from the original text and store it in our list:

Ivan Pepelnjak 20:41, 27 March 2008 (UTC)Reply

I introduced rtrim() in order to fix a previous bug. I don't understand your problem statement. Do you have an example?
--Lindele 17:00, 1 April 2008 (UTC)Reply

actually i think that we should not change any chars of the original content, even the white spaces of each line are always useles. so i agree with him, leave the white space where they are is safe. 121.8.153.6 09:38, 13 August 2010 (UTC)Reply

Only works for editing Categories[edit]

I am trying this with the latest version of mediawiki (1.12?) and it only works when editing a category page (category:example). For any other page, it comes out lookng garbled. There is no nice box around the category suggestion section and the category cloud over laps on top of the Popular Categories and Category Hierarchy tabs. Also,I have been unable to get the auto suggestion to work when typing in the search box (no drop down ever appears- which may be related to this problem.

  • Yeah. I'm having the same problem with formating. It seems that mediawiki 1.13 strips the CSS from v1.2 of this extension. Does anybody know how to fix this? I'd update to v1.3 but it doesn't seem to work with my fix width skin. (Ed D May 7,2008)

problem with mediawiki + postgres[edit]

This extension don't run on mediawiki 1.12 + postgres 8.1:

Warning: pg_query() [function.pg-query]: Query failed: ERROR: no existe la columna «count» in /var/www/wikipalme/includes/DatabasePostgres.php on line 553
Error interno

Set $wgShowExceptionDetails = true; at the bottom of LocalSettings.php to show detailed debugging information.

To fix this, you need to edit the line 350 of the SelectCategoryTagCloud.body.php:

Original:

$sql = "SELECT cl_to as title, COUNT(*) as count FROM $categorylinks  " . $exclude_condition . " GROUP BY cl_to HAVING count >= $min_count_input ORDER BY cl_to ASC";

Fixed:

$sql = "SELECT cl_to as title, COUNT(*) as count FROM $categorylinks  " . $exclude_condition . " GROUP BY cl_to HAVING count(*) >= $min_count_input ORDER BY cl_to ASC";

A little modification on fnSelectCategoryTagCloudAjax function[edit]

The use of mysql_real_escape_string function requires connection parameter. It is better to use strencode function from Database object. It does the same thing:

 
 ## Entry point for Ajax, registered in $wgAjaxExportList; returns all cats starting with $query
 function fnSelectCategoryTagCloudAjax( $query ) {
        if(isset($query) && $query != NULL) {
-               $searchString = mysql_real_escape_string($query);
-               # % and _ are not escaped so do it here
+               $dbr =& wfGetDB( DB_SLAVE );
+               $searchString = $dbr->strencode( $query );
                $searchString = str_replace( '%' , '\%' , $searchString );
                $searchString = str_replace( '_' , '\_' , $searchString );
                $searchString = str_replace( '|' , '%' , $searchString );
-               $dbr =& wfGetDB( DB_SLAVE );
                $categorylinks = $dbr->tableName('categorylinks');
                $page          = $dbr->tableName('page');
                $sql =

Fix for uploading files in MediaWiki 13alpha[edit]

In MediaWiki 13alpha (maybe, earlier -- I can't tell you for sure) there's no mUploadDescription method for uploading objects. It has been renamed to mComment. So, I've fixed this problem in SelectCategoryTagCloud.body.php by changing this method:

		# If it is an upload we have to call a different method:
		if ( $m_isUpload ) {
-			$m_pageObj->mUploadDescription .= $m_text;
+			$m_pageObj->mComment .= $m_text;

Bugs when FCK-Editor is active[edit]

We've got a project running and found out this nice extension doesn't work well together with fck because fck uses html-syntax so the regex for finding the categories will not work. The result is, that used categories are not marked and cannot be removed via clicks.

After struggling around for some hours here's a working solution to overcome this problem

in function fnSelectCategoryGetPageCategories determine fck-usage

 // use fck-editor?
 $edit_export = var_export($m_pageObj, true);
 if(strpos( $edit_export, "FCKeditorEditPage") === false)
 $fckusage = false;
 else $fckusage = true;

add third param to fnSelectCategoryStripCats

 function fnSelectCategoryStripCats($texttostrip, &$catsintext, $fckusage = false)

change this in fnSelectCategoryStripCats

 # The regular expression to find the category links:
 $m_pattern = "\[\[({$m_catString}|category):(.*?)\]\]";
 //pattern for FCK-Editor!!
 if($fckusage)
$m_pattern = '<a _fcknotitle=\"true\" href=\"('."{$m_catString}".'|Category):(.*?)\">(.*?)<\/a>';

change lines

 $cleanedtext = fnSelectCategoryStripCats($regulartext,$arrAllCats); 

to

 $cleanedtext = fnSelectCategoryStripCats($regulartext,$arrAllCats,$fckusage );


Now Tagcloud will work just fine together with FCK

Greetings


good job, but i still found that there remains a problem, only in the rich edit model this extension can show these categories in the textbox. If change to none rich edit model and edit, there's nothing. This regular expression has something i don't understand. why do you use @@@"('."{$m_catString}".'|@@@ but not @@@"({$m_catString}|@@@ . I fixed this regular expresion to suit both the old type as @@@@[[Category:xxx]]@@@@ and the new type as @@@@<a _fcknotitle="ture" herf="Category:xxx"</a>@@@@. So no matter in rich edit model or none rich edit model, both conditions are ok. I am using the decode of zh-hans, i am afraid this problem is only occure to me. So if others meet with the same problem can give me an email, extirpate0832@gmail.com

121.8.153.6 01:19, 24 August 2010 (UTC)Reply

For those who want to include pages without the categories[edit]

Hi... I wanted to get the categories not includable when we set them... So I use to put

$m_text .= "\n<noinclude>[[$m_catString:" . mysql_escape_string(trim($m_cat)) . "]]</noinclude>";

on line 149 in the fnSelectCategorySaveHook() function

and place

$finaltext =  ereg_replace('\<\noinclude\>\<\/noinclude\>','',$finaltext);

on line 241, like this

	$cleanedtext = fnSelectCategoryStripCats($regulartext,$arrAllCats);
		$finaltext .= $cleanedtext;
	}
			$finaltext =  ereg_replace('\<\noinclude\>\<\/noinclude\>','',$finaltext);

	//Place cleaned text back into the text box:
	$m_pageObj->textbox1 = trim( $finaltext );

This code also remove unnecessary noinclude tags. Just to share it with you...

Kronoxt 22:00, 5 April 2009 (UTC)Reply

Categories and Sections[edit]

There are two issues regarding category selection and section editing:

  • When editing a section, the page categories are not shown. For well-developed pages, most editing is probably done inside of a section, making it hard to use the full potential of this extension.
  • In some use cases, category references are intended to be linked with a particular section. This extension does not support that capability.

Any thoughts on these? I know these are more design issues than "bugs". -- Joeclarkia 16:45, 12 May 2009 (UTC)Reply

Causes some problems Semantic MediaWiki inline queries[edit]

When I enter the Semantic MediaWiki inline query 

{{#ask: [[Category:City]] [[located in::Germany]] 
  | ?population 
  | ?area#km² = Size in km²
  }}

on saving the page, SelectCategoryTagCloudSuggest strips the category out of the query and puts it at the end of the article. This functionality breaks some inline queries.

I tried getting around this by using the notationCategory:City, i.e.,

{{#ask: [[:Category:City]] [[located in::Germany]] 
  | ?population 
  | ?area#km² = Size in km²
  }}

Now SelectCategoryTagCloudSuggest does not strip out the Category, however the inline query does not seem to work.

Apply the fix described in #Preview_edits_loses_categories. that should solve the problem
--Jackeapen 11:17, 21 July 2009 (UTC)Reply

problems with <nowiki> sections[edit]

This thing is sticking line breaks around nowiki sections; here's how I fixed it. SelectCatgoryTagCloud.body.php before:

        # Check linewise for category links:
        foreach( explode( "\n", $texttostrip ) as $m_textLine ) {
                # Filter line through pattern and store the result:
                $m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) . "\n";

after:

        $i = 1;
        # Check linewise for category links:
        $texttostrip = explode( "\n", $texttostrip );
        foreach( $texttostrip as $m_textLine ) {
                # Filter line through pattern and store the result:
                $m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) );
                if ( $i !== count( $texttostrip ) ) $m_cleanText .= "\n";

All it does is check if it's on the last line of the text it's passed. If it is, then it doesn't add a carriage return.


good job! thx! finnally you solved this problem, i like you ! seems that you forget the

$i=$i+1;

and i found that this solutions get another problem. every time editing a section, the "\n" after the headings is always eatten up by this action. i don't know why. So i just add these codes " if($i==1) $m_cleanText .= "\n";", assuming that the first \n is belonged to the headings all the time.

so the finnal codes to solve the <nowiki> problem is:

     .....
        $i = 1;
        # Check linewise for category links:
        $texttostrip = explode( "\n", $texttostrip );
        foreach( $texttostrip as $m_textLine ) {
                # Filter line through pattern and store the result:
                $m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) );
                if($i==1) $m_cleanText .= "\n";
                if ( $i !== count( $texttostrip ) ) $m_cleanText .= "\n";
                $i = $i+1;
          .....

121.8.153.6 02:32, 13 August 2010 (UTC)Reply

Enable only for Category edits?[edit]

I'm trying to get it so that the category tag cloud only shows up when editing Categories. I have this defined for $wgSelectCategoryNamespaces:

if( !isset( $wgSelectCategoryNamespaces ) ) $wgSelectCategoryNamespaces = array(
        NS_MEDIA                  => false,
        NS_MAIN                   => false,
        NS_TALK                   => false,
        NS_USER                   => false,
        NS_USER_TALK      => false,
        NS_PROJECT                => false,
        NS_PROJECT_TALK   => false,
        NS_IMAGE                  => false,
        NS_IMAGE_TALK     => false,
        NS_MEDIAWIKI      => false,
        NS_MEDIAWIKI_TALK => false,
        NS_TEMPLATE               => false,
        NS_TEMPLATE_TALK  => false,
        NS_HELP                   => false,
        NS_HELP_TALK      => false,
        NS_CATEGORY               => true,
        NS_CATEGORY_TALK  => false,
        100               => false
);

Yet when I click on "Upload file" I still see the Category Cloud beneath the Summary box. How can this be turned off? --Gkullberg 16:40, 2 November 2009 (UTC)Reply

Category Hierarchy[edit]

On the Category Hierarchy tab it says "Coming soon..." What is meant by that (i.e. what exactly is coming and when)? More importantly, is there a way to switch this tab off? I don't want my users to get confused by this. --Robinson Weijman 13:00, 18 February 2010 (UTC)Reply


find these codes

document.write("<table class='table' id='table' cellpadding='0' cellspacing='0'><tr><td id='button1' class='buttonhighlight' onclick='ChangeColor(\"button1\",\"button2\");showhide(\"tagcloud\",\"hide\");'> Popular Categories</td><td class='buttonspace'> </td><td id='button2' class='buttonunhighlight' onclick='ChangeColor(\"button2\",\"button1\");showhide(\"hide\",\"tagcloud\");'> Category Hierarchy</td><td class='buttonspace'> </td><td class='buttonspacewide' colspan='2'><!-- Blank Tab to fill up the form --> </td></tr></table>");

change it into

document.write("<table class='table' id='table' cellpadding='0' cellspacing='0'><tr><td id='button1' class='buttonhighlight' onclick='ChangeColor(\"button1\",\"button2\");showhide(\"tagcloud\",\"hide\");'> Popular Categories</td><td class='buttonspace'> </td><td class='buttonspace'> </td><td class='buttonspacewide' colspan='2'><!-- Blank Tab to fill up the form --> </td></tr></table>");

can make the Category Hierarchy disappear 121.8.153.6 02:43, 13 August 2010 (UTC)Reply

Sorry for the late reply - thanks! --Robinson Weijman 12:57, 24 September 2010 (UTC)Reply

Every pages' layout has been changed since i installed this extension----solved[edit]

everything works well as the extension has said, but i found that every page of my mediawiki has changed. For example, all the words's size get bigger and the lay out of the pages are weird.

i disabled the extension in the localsettings.php page, and everyting get back as normal.

i use my smart phone (neuxs one and iphone) to launch my mediawiki, the page layout is normal.

i tried to disable the 4 hooks, didn't work. i don't know what is wrong, and how i can change it. this is such a good extension, i really want to fix this problem and use it normally.

who can help me ?219.137.235.162 13:00, 15 August 2010 (UTC)Reply


I solved this problem. At first I saved the "SelectCategoryTagCloud.body.php" as utf-8 file type, then these strange things happened. The original codes are ok. When i reinstalled the extension, everything turned good. But i still don't know what has actually happend when i save it as "utf-8". Such a weird thing. 219.137.235.162 13:00, 15 August 2010 (UTC)Reply


oh, i found that the problem was caused by the bom of the utf-8, when i save the .php file as "utf-8 without bom", then everything remains normal.

many thx to www.baidu.com, i found the answer through it219.137.235.162 13:10, 15 August 2010 (UTC)Reply

PHP > 5.3.0 bug[edit]

After upgrading an Ubuntu installation from 9.10 to 10.04, I started having a problem with this extension. It's the same problem documented here. I'm guessing it has to do with the PHP changes in 5.3.1 (I have php 5.3.2 now, but I have a feeling some of the "bugs" in 5.3.1 are still present, or were not really bugs). In any case, will this extension be updated to work with current versions of PHP? For completeness: my MediaWiki version is 1.15.4, in case this actually is a MediaWiki version-related bug. Joeclarkia 05:53, 30 August 2010 (UTC)Reply

Fix Issue for PHP 5.3.x[edit]

Just change SelectCategoryTagCloud.body.php from version 1.4

Line 166
function fnSelectCategoryOutputHook( &$m_pageObj, &$m_parserOutput ) {
to
function fnSelectCategoryOutputHook( &$m_pageObj, $m_parserOutput ) {

Next Version[edit]

1 Please replace in SelectCategoryTagCloud.body.php (leading white spaces problem)

$m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) . "\n";
with
$m_cleanText .= rtrim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) . "\n";

2 Please correct the version-number.


Turn off the Cloud and only use Category Suggest ?[edit]

because extension:categorysuggest doesn't work with mediawiki 1.16 and php5.3 -> is it possible to "switch off" the cloud in this extension and only use the "categorySuggest" Part? The cloud is much to big in our Wiki because there are a lot of categories and so we wont use it.

Support for 1.18?[edit]

Are there plans to update this extension? It seems 1.18 breaks it (Fatal error: Call to a member function addMessages() on a non-object in ... upon page edit) and our users love this functionality. :)

me too: got this problem and need help! :)

Let me third the request for a 1.8 update!

And I'll "fourth" it! ;)

did this, but my SelectCategory-Extension won't show mee a title after comment our this line. yes, deprecated method, but what to do? anybody else uses this extension?

I'm no. five, hoping to get an 1.18 update :-)

-- stadtkoeln_programmer 14:08, 15. June 2012 (UTC) You can do it this way:
As Eurodomenii wrote, in the file SelectCategoryTagCloud.body.php comment the line
$wgMessageCache->addMessages( $messages );
This is line number 198 by me.
Then, in #196 (just after the include( 'i18n/SelectCategory)... line), add:
$wgExtensionMessagesFiles['SelectCategoryTagCloud'] = 'i18n/SelectCategory.i18n.' . $wgLang->getCode() . '.php';
This is the recommended method of mediawiki/261958 (see above). On our MW 1.18.1, the error was gone, and the page showed the edit area with the Tagcloud under it.

Grunzh (talk) 25 July 2012: and another, hoping for an ”official“ fix to this issue. Work-around suggested by Eurodomenii (above) works for me.

Rickster mediawiki (talk) 09:07, 26 July 2012 (UTC) i run into the same problem and hope there will be a patch for it.Reply

Unable to change text[edit]

 <selectcategory-title>
 <selectcategory-subtitle>
 <selectcategory-boxlabel>:

I can't get the following to change. I have tried editing the i18n files but this does not seem to take affect? Where else do I need to make changes for this to change?

Fix for internationalization settings[edit]

Here's the fix that I used for this problem.

in SelectCategoryTagCloud.php, add the following line:

 $wgExtensionMessagesFiles['SelectCategoryTagCloud'] = dirname( __FILE__ ) . '/SelectCategory.i18n.php';

I put it in around line 90, after the line $wgAjaxExportList[] = 'fnSelectCategoryTagCloudAjax';

in SelectCategoryTagCloud.body.php, around line 40, comment out the code that currently loads the messages:

  # Load system messages:
  #  fnSelectCategoryMessageHook();  ## Disabling for this wiki

in the same file, comment out the whole of fnSelectCategoryMessageHook() (i.e. surround it by /* and */:

  /*	
  function fnSelectCategoryMessageHook() {
	global $wgLang;
  ...
	# Be nice:
	return true;
  }
  */

find all the instances of wfMsg and replace them with wfMessage, e.g.:

#       $m_textBefore = '<b>' . wfMsg( 'categorysuggest-title' ) . '</b>:';
       $m_textBefore = '<b>' . wfMessage( 'categorysuggest-title' ) . '</b>:';

Now create a new file, SelectCategory.i18n.php, in the same directory as the other SelectCategoryTagCloud files. Put the internationalization strings in it in the following format:

  <?php
  # Internationalisation file for the SelectCategory extension for MediaWiki

  $messages = array();

  $messages['en'] = array(
  'selectcategory-title' => 'CATEGORY SELECTION',
  'selectcategory-subtitle' => 'Please enter a category for this article or select from the list of popular categories.',
   ...
  'selectcategory-tooltip' => 'Click here to add or remove this category!',
  );
  
  $messages['de'] = array(
  'selectcategory-title' => 'Kategorien auswählen',
  'selectcategory-subtitle' => 'Shift-Maus um mehrere nachfolgende Einträge zu (de-)selektieren, Strg-Maus um einzelne Einträge zu (de-)selektieren.',
  );
  
  # (and so on, for the other languages)

That will fix your message problems.

I've uploaded a version with these fixes, D0li0's fixes (below), the 'Category Hierarchy' tab removed, and a few CSS/HTML fixes to my GitHub repository.

- Girlwithglasses (talk) 15:12, 11 October 2012 (UTC)Reply

Patch for leading white space, nowiki, php5.3.[edit]

Per the #problems with <nowiki> sections and #Next_Version and #Fix_Issue_for_PHP_5.3.x sections. I have a patch integrating all the applicable changes to solve both the "leading white space" and <nowiki> tags issue where be leading white space is stripped or added and/or additional empty lines are added. I'm also planning to migrate from older php into 5.3.x soon, so applied that fix as well, which seems to have no effect for older php. Copy the patch text into the extension folder in a file named SelectCategoryTagCloud.body.php.diff, then apply with the command patch -p0 < SelectCategoryTagCloud.body.php.diff. --D0li0 (talk) 21:16, 23 March 2012 (UTC)Reply

--- SelectCategoryTagCloud/SelectCategoryTagCloud.body.php      2012-03-22 14:26:14.000000000 -0700
+++ SelectCategoryTagCloud/SelectCategoryTagCloud.body.php      2012-03-23 14:05:12.000000000 -0700
@@ -163,7 +163,7 @@
 
 /*************************************************************************************/
 ## Entry point for the hook for printing the CSS:
-function fnSelectCategoryOutputHook( &$m_pageObj, $m_parserOutput ) {
+function fnSelectCategoryOutputHook( &$m_pageObj, &$m_parserOutput ) {
        global $wgScriptPath;
 
        # Register CSS file for our select box:
@@ -231,7 +231,7 @@
                //ignore cats here
                $nowikitext = $arrBlocks2[0];
                //add to final text
-               $finaltext .= '<nowiki>' . $nowikitext . '</nowiki> ';
+               $finaltext .= '<nowiki>' . $nowikitext . '</nowiki>';
 
                //strip cats here
                $regulartext = $arrBlocks2[1];
@@ -266,10 +266,16 @@
 
 
        # Check linewise for category links:
-       foreach( explode( "\n", $texttostrip ) as $m_textLine ) {
-               # Filter line through pattern and store the result:
-        $m_cleanText .= trim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ) . "\n";
-
+       $i = 1;
+       $texttostrip = explode( "\n", $texttostrip );
+        foreach( $texttostrip as $m_textLine ) {
+                # Filter line through pattern and store the result:
+//              $m_cleanText .= rtrim( preg_replace( "/{$m_pattern}/i", "", $m_textLine ) ); // Trimming removed leading and trailing white space unnessecarily.
+                $m_cleanText .= preg_replace( "/{$m_pattern}/i", "", $m_textLine );
+//              if($i==1) $m_cleanText .= "\n"; // This causes additional newlines before leading white space lines.
+                if ( $i !== count( $texttostrip ) ) $m_cleanText .= "\n";
+                $i++;
+                                                                                        
                # Check if we have found a category, else proceed with next line:
         if( preg_match_all( "/{$m_pattern}/i", $m_textLine,$catsintext2,PREG_SET_ORDER) ){
 //debug

Bugs reported in bugzilla[edit]

Just to avoid they get lost - the following reports for SelectCategoryTagCloud were reported in bugzilla:

Titles wrong (and other)[edit]

Hi,
In the editor I see:
<selectcategory-title>
<selectcategory-subtitle>
<selectcategory-boxlabel>:

How I can fix this?

In my wiki (1.19.2) I see all the categories, also if I defined in $wgSelectCategoryRoot which I wish. So, without a fix tis extension is useful only for sysop, not simple user because can see also "services categories".

Can I know your plans about "Category Hierarchy"?

Thanks in advance

--WhiteTigerItaly (talk) 10:43, 2 October 2012 (UTC)Reply

See #Fix_for_internationalization_settings above for the selectcategory-title, selectcategory-subtitle, etc., errors.

- Girlwithglasses (talk) 15:14, 11 October 2012 (UTC)Reply

Problem with templates[edit]

When SelectCategoryTagCloud (SCTC) open a page removes the category and show it in the box and in the cloud.

If the page is a template with CategoryX SCTC does the same thing.
The result is that if a page load the template, then it loads and it is classified as "CategoryX".

For this reason a lot of pages are now classified in wrong mode.
If now I disable SCTC this insert newly the category in the pages, but obviously not between Include tags, so the pages now have:

(empty row) CategoryX

The empty row is a problem in the problem, because if the templates is for layout, then a row more or less makes the difference between a page paginated well and a page paginated bad.

There is a manner to fix this?

Thanks in advance.

--79.24.252.227 04:01, 3 October 2012 (UTC)Reply