Extension:RequireCategory

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
RequireCategory

Release status: experimental

Implementation Page action
Description Requires pages to be placed at least to one category.
Author(s) Hendrik BrummermannTalk
Last version 1.0
MediaWiki 1.7+
License CC-BY, GPL
Download see below
Hooks used
EditFilter

Check usage (experimental)

This extension will force all pages to be put in at least one category. Otherwise you are not able to save.

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

  1. copy the code to a file called RequireCategory.php in your mediawiki/extensions folder
  2. 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.

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox