Extension:SelectCategory
From MediaWiki.org
|
SelectCategory Release status: stable |
|
|---|---|
| Implementation | Page action |
| Description | Allows the user to select from existing categories when editing a page. |
| Author(s) | Leon Weber & Manuel Schneider |
| Version | 0.6 (2008-01-19) |
| MediaWiki | > 1.8.2 |
| Download | download 0.5, SVN trunk README CHANGELOG |
| Parameters | $wgSelectCategoryNamespaces $wgSelectCategoryRoot |
| Hooks used |
EditPage::showEditForm:initial |
The SelectCategory extension provides three functions:
- It shows a list of all categories (unless a custom root category is configured) in their hierarchical structure on the edit page.
- It strips all categories linked within a page upon editing and selects them in the category list list.
- It adds selected categories from the list to the text body of the page on saving.
Contents |
[edit] Installation
[edit] Stable release (recommended for most uses)
To use the stable release, download the tarball linked in the box on the right, and uncompress it. Copy the SelectCategory directory into the extensions folder of your MediaWiki installation. Then add the following lines to your LocalSettings.php file (near the end):
require_once( 'extensions/SelectCategory/SelectCategory.php' );
[edit] Download from SVN trunk
To use the current SVN version, which might be unstable and full of bugs, use the following URL for your subversion client:
http://svn.wikimedia.org/svnroot/mediawiki/trunk/extensions/SelectCategory
[edit] Parameters
[edit] $wgSelectCategoryNamespaces
This is in your SelectCategory.php file
Defines in which namespaces the Extension should be active.
All namespaces are already predefined in the array. Set a specific namespace to true to enable or to false to disable the extension.
Active per default are: Media, Main, Project, Image, Help, Category.
- Example
$wgSelectCategoryNamespaces[NS_PROJECT] = false; $wgSelectCategoryNamespaces[NS_CATEGORY] = false;
- Or
$wgSelectCategoryNamespaces = array( NS_MEDIA => true, NS_MAIN => true, NS_TALK => false, 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 => false, NS_TEMPLATE_TALK => false, NS_HELP => true, NS_HELP_TALK => false, NS_CATEGORY => true, NS_CATEGORY_TALK => false, 100 => true, # customized namespace, e.g. ''Portal'', c.f. [[Manual:Using custom namespaces]] 101 => false # customized namespace, e.g. ''Portal talk'', c.f. [[Manual:Using custom namespaces]] );
[edit] $wgSelectCategoryRoot
Set a specific root category depending the namespace. Only categories within this root will be displayed when editing a page in a certain namespace.
Useful on big wiki sites to keep the database load down.
If not set (default) the extension searches for all root categories and displays them including all children.
[edit] Example
$wgSelectCategoryRoot = array( NS_MEDIA => false, NS_MAIN => "My Article Root Category", NS_TALK => false, NS_USER => false, NS_USER_TALK => false, NS_PROJECT => false, NS_PROJECT_TALK => false, NS_IMAGE => "My Image Root Category", 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 => false, NS_CATEGORY_TALK => false );
[edit] $wgSelectCategoryEnableSubpages
Defines if the extension should be active when editing subpages.
[edit] Example
$wgSelectCategoryEnableSubpages = false;
[edit] Style
To customize the design of the select box use the CSS id "SelectCategoryBox" and attach your own settings to [[MediaWiki:Monobook.css]] or your users [[User:USERNAME/Monobook.css]].
[edit] Bugs & Hotfixes
- if a category name has an apostrophe in it, a mysql error occurs in the fnSelectCategoryGetChildren function. Add marked ("+") line before the sql query to fix the problem (revision 29737 still contains this bug):
# The normal query to get all children of a given root category:
+ $m_root = str_replace("'","\'",$m_root);
$m_sql = " SELECT tmpSelectCatPage.page_title AS title
FROM $m_tblCatLink AS tmpSelectCat
LEFT JOIN $m_tblPage AS tmpSelectCatPage ON tmpSelectCat.cl_from = tmpSelectCatPage.page_id
WHERE tmpSelectCat.cl_to LIKE '$m_root' AND tmpSelectCatPage.page_namespace = 14";
- following warning "Warning: Call-time pass-by-reference"...
Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in .../extensions/SelectCategory/SelectCategoryFunctions.php on line 21 Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in .../wiki/extensions/SelectCategory/SelectCategoryFunctions.php on line 84
- ...can be fixed by following changes in fnSelectCategoryShowHook...
function fnSelectCategoryShowHook( $m_isUpload = false, &$m_pageObj ) {
# check if we should do anything or sleep
- if ( fnSelectCategoryCheckConditions( $m_isUpload, &$m_pageObj ) ) {
+ if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) {
- ...and fnSelectCategorySaveHook...
function fnSelectCategorySaveHook( $m_isUpload, &$m_pageObj ) {
global $wgContLang;
global $wgTitle;
# check if we should do anything or sleep
- if ( fnSelectCategoryCheckConditions( $m_isUpload, &$m_pageObj ) ) {
+ if ( fnSelectCategoryCheckConditions( $m_isUpload, $m_pageObj ) ) {
| patch | |
|---|---|
| file | SelectCategoryFunctions.php |
| function | fnSelectCategoryGetPageCategories() |
| description | Support for categories with spaces |
| author(s) | Jlerner |
| source | diff |
| date | 2008-05-07 |
|
# Check linewise for category links:
foreach( explode( "\n", $m_pageText ) as $m_textLine ) { # Filter line through pattern and store the result: $m_cleanText .= 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: - $m_catLinks[ preg_replace( "/.*{$m_pattern}/i", $m_replace, $m_textLine ) ] = true; + $m_catLinks[ preg_replace( '# #', '_', preg_replace( "/.*{$m_pattern}/i", $m_replace, $m_textLine ) ) ] = true; } |
|
- Dont combine SelectCategory with the extension "RequireCategory" ... it doesnt work! --Nyks 01:16, 21 December 2006 (UTC)
- I am running 1.9. when I install this extension I just get a blank page when editing. -- Magick 10:46, 12 January 2007 (UTC)
- I get the same error have had to disable --Markw21 17:08, 19 September 2007 (UTC)
- This error still happens occasionally on 1.10 and 1.11, I've not been able to find a common cause for it. It seems to run fine for weeks, then when server load increases, it just dies. optimize your categorylinks table, and things improve quickly. -- Shannon Lowder 20070921
- I also found that if you have recursive categories (a parent with a child that shows the parent as ITS child) will cause this issue. Run a query on your categorylinks table, look for this, and remove instances of it, it clears the problem easily!-- Shannon Lowder 20071129
- It doesn't detect cycles in the category graph, so editing just seems to hang if it hits one. -Steve Sanbeg 19:16, 19 January 2007 (UTC)
- I get a blank page by loading the same page twice, and only with Firefox, not with Internet Explorer. --WIKImaniac 14:48, 14 January 2008 (UTC)
- Placing two or more categories on the same line results in only the last category being read. [[Category:Cat1]] [[Category:Cat2]] Only Cat2 shows up as selected in the list. --PaulHat 22:57, 12 July 2007 (UTC) still in revision 29737
- Fixed this, see SelectCategoryTagCloud --Kaspera 14:32, 10 December 2007 (UTC)
- Categories placed in between "pre" and "includeonly" tags should be ignored. --Paul 16:52, 20 August 2007 (UTC) still in revision 29737
- Same as above
(fixes only the nowiki issue, modifying the regexp could solve pre issue, working on it). --Kaspera 14:32, 10 December 2007 (UTC)
- Same as above
[edit] Feature Requests
- I cannot add an article to a new (not existing) category by adding it in the wiki way (I mean by adding [[Category:Categornotinlist]] at the end of an article)
- It would be nice to incorporate the creation of additional categories into this extension. --Oreo masta 17:40, 12 February 2007 (UTC)
- The UI makes it too easy to erase all your carefully assigned categories from a page. One accidental mouseclick (on the category list) will deselect all the categories on a page. I suggest you make the category list read-only, and add a dropdown with buttons to "add category" and "remove category" through JavaScript. Also add a "Revert" button to go back to the original saved set of categories. Otherwise this extension is too dangerous to existing categories on a page.
- I recommend an additional text field for each entry of the category list. There you could type an alternative text, which will be used to modify the displayed order of the articles in a category, e.g. [[Category:Presidents of the United States|Lincoln, Abraham]], cf. w:Wikipedia:Categorization#Pipe tricks and sort keys. --WIKImaniac 19:12, 11 July 2007 (UTC)
- Would be nice if we could use SelectCategory with the Extension:Semantic Forms (The Category select box apear in Spezial:EditData).

