Extension:RequireCategory
From MediaWiki.org
This extension requires patches to core MediaWiki code when used with MediaWiki 1.6 and before. Extensions implemented using patches may be disabled by or interfere with upgrades and security patches. If you would like to use this extension, we strongly recommend you upgrade to a version later than 1.6. Alternatively, if a suitable alternative without a patch is available, we recommend you use that extension instead.
|
RequireCategory Release status: unknown |
|
|---|---|
| Implementation | Page action |
| Description | Requires pages to be placed at least to one category. |
| Author(s) | Hendrik Brummermann |
| Version | 1.0 |
| MediaWiki | 1.7+ |
| Download | see below |
| Hooks used | |
This extension will force all pages to be put in at least one category. Otherwise you are not able to save. It requires at least MediaWiki 1.7alpha or this patch for MediaWiki 1.6.
Notice, it will prompt for category especially if editing fragment of the page, it does not detect yet the categories defined in the whole page (only in edited text).
[edit] Installation
- copy the code to a file called RequireCategory.php in your mediawiki/extensions folder
- add this line at the bottom to your LocalSettings.php:
require_once($IP.'/extensions/RequireCategory.php');
[edit] Code
<?php if ( ! defined( 'MEDIAWIKI' ) ) die(); /** * Requires all edited pages to be at least in one category * * @author Hendrik Brummermann * @version 1.0 */ $wgExtensionFunctions[] = 'requireCategorySetup'; $wgHooks['EditFilter'][] = 'editFilterRequireCategory'; function requireCategorySetup() { global $wgMessageCache; $wgMessageCache->addMessage('category_required', "'''NOTICE''': There '''must''' be at least one <nowiki>[[Category:</nowiki>''something'']] link.<br/>" ." Right click on the link and select ''\"Open in a new window\"'' to get a " ."[{{SERVER}}{{LOCALURL:Special:Allpages|namespace=14}} list of all categories]" ); } function editFilterRequireCategory ( $editpage, $textbox, $section, &$error) { global $wgTitle, $wgContLang; if ($wgTitle->getNamespace() != NS_MAIN) { return true; } preg_match_all( "/Category:/im", $textbox, $list, PREG_SET_ORDER ); if( count($list) == 0) { $localCategory = $wgContLang->getNsText( NS_CATEGORY ); preg_match_all( '/'.$localCategory.':/im', $textbox, $list, PREG_SET_ORDER ); if( count($list) == 0) { $error .= wfMsg( 'category_required'); } } return true; } $wgExtensionCredits['other'][] = array( 'name' => 'RequireCategory ', 'version' => '1.0', 'author' => 'Hendrik Brummermann', 'url' => 'http://www.mediawiki.org/wiki/Extension:RequireCategory', 'description' => 'all saved pages must be in at least one category' ); ?>
[edit] Customization
Remember to go to the Special:Allmessages on YOUR wiki and search for something - you will find the message you want to alter for users, to suit your wiki language, design and style.

