Extension talk:SelectCategoryTagCloud

Errors
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 "No results found"; }       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)

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)

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

1.  & Manuel Schneider , 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. *

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) global $wgDBserver,$wgDBname,$wgDBuser,$wgDBpassword;
 * 1) Set MEDIAWIKI to avoid the "Part Of mediaWiki-Errors"
 * 1) now we can load from mediaWiki globals

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 "No results found"; }       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)

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

Setting wgSelectCategoryRoot has no Effect

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

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)

Errors When trying to Input Categories Manually
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 .= "\n"; --- >              $m_pageObj->$m_place .= "\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
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)

SelectCategoryTagCloud is stripping Leading spaces from text lines
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
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)

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

Applying to a new namespace
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) (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)

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)

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

Adding Categories with ampersands in their title
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

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

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

nowiki exclusion
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)


 * Did it myself. Fixed multiple categories on one line bug, and noinclude bug.


 * Changes:


 * Added file SelectCategoryTagCloudHack.php:


 * Fixed the last newline bug. --Kaspera 13:12, 14 December 2007 (UTC)

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:

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

Preview edits loses categories
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:

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

tagcloud suggestion
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
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)


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

Only works for editing Categories
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
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.