Extension talk:RequireCategory

From MediaWiki.org
Jump to: navigation, search
The following discussion has been transferred from Meta-Wiki.
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).

Unfortunately with 1.6.6 and with the patch Installed... the extension returns a 0 and not the message itself... any ideas? teddy

This extension does not work with section editing. It does not let you save the section without adding a category even though the category was added to the page.

Sue

Contents

Section edit[edit]

Does this mean, you cant save a section-edit, unless u insert a category in the section you are actually edit? --Nyks 18:16, 29 November 2006 (UTC)

Yes. Patches are welcomed :-) Hendrik Brummermann 89.22.76.183 15:13, 29 December 2006 (UTC)

/* Add MarS2701 */
I've started a try to fix this problem. RequireCategory

Link to fix doesnt work[edit]

Does anybody have a working link to a version which fixes the section-problem?

Fix Section edit[edit]

To don't showing message when you are editing a partial page, change the editFilterRequireCategory function.

Do this:

if ($wgTitle->getNamespace() != NS_MAIN || $section) { return true; }

1.18+ Fix[edit]

$wgMessageCache->addMessage no longer works in 1.18+. To fix:

  • create new file RequireCategory.i18n.php, populate with the message
<?php
/**
 * Internationalisation file for extension LdapAuthentication.
 *
 * @file
 * @ingroup Extensions
 */
$dir = dirname( __FILE__ ) . '/';
$wgExtensionMessagesFiles['RequireCategory'] = $dir . 'RequireCategory.i18n.php';
$messages = array();

/** English
 * @author Ryan Lane
 */
$messages['en'] = array(
        'category_required' => "'''NOTICE''': There '''must''' be at least one
'''[[Category:''something'']]''' link.<br>"
."Right click on the link and select ''\"Open in a new window\"'' to get a [[:Special:Categories list of all"
."available categories]].<br>Try to use an existing category if at all possible.<br>");
?>
  • Remove requireCategorySetup function from from RequireCategory.php
  • add line to RequireCategory.php
$dir = dirname( __FILE__ ) . '/';
$wgExtensionMessagesFiles['RequireCategory'] = $dir . 'RequireCategory.i18n.php';

1.18+ addition[edit]

I have changed the above code so that the extension calls a special page so that the message can be edited easily.

$messages['en'] = array(
        'category_required' => "{{MediaWiki:RequireCategory}}<br>"
."<br>");

Amblerllc (talk) 14:25, 18 July 2012 (UTC)

Need more info[edit]

Hi, can you give the full code, this still does not seem to be working for 1.18, gives me the following error: Warning: call_user_func() expects parameter 1 to be a valid callback, function not found or invalid function name in /opt/mediawiki/includes/Setup.php on line 496

Full Code for 1.19.2[edit]

The extension won't work for my Wiki, so I changed the code a little and thought I could share it with you. So here it is:

<?php
if ( ! defined( 'MEDIAWIKI' ) )
    die();
 
/**
 * Requires all edited pages to be at least in one category
 *
 * @author Hendrik Brummermann
 * @version 1.0
 */
 
 
$wgHooks['EditFilter'][] = 'editFilterRequireCategory';
 
 
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 = '<br>{{MediaWiki:RequireCategory}}<br>';
                }
        }
        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'
);
?>

The error message is now a special page like in a topic above. You have to create this page yourself for the error message to show up. I created it at "MediaWiki:RequireCategory" but you could also create it in the template namespace and change the code to that. If you're not familiar with templates you can use the one I created:

{| style="padding: 5px; border: 1px solid #bd3b3b; text-align: center; background: #ff8282; width: 100%;"
|-
| <span style="font-size: larger;">'''Please insert at least one category!'''</span>
|}

It should look like this:

Please insert at least one category!

Also you don't need to set up a *.i18n.php file.

Hope this post was helpful!

Cheers from Germany!