Is it possib开发者_运维技巧le to protect specific category so that e.g. the category 'category1' cannot be assigned to an article without certain permission?
I believe you could check if the category was added to the page in the ArticleSave
hook and issue an error if the user doesn't have the required permission.
Edit: Something along these lines (quick & dirty):
$wgForbiddenCats = array( 'Forbidden' => 'sysop' );
$wgHooks['ArticleSave'][] = 'checkForbiddenCats';
function checkForbiddenCats( $article, $user, $text, $summary, $minor,
$_, $_, $flags, $status )
{
global $wgForbiddenCats, $wgParser;
// Firstly, get categories in the new text
$parser_output = $wgParser->parse( $text, $article->getTitle(),
$article->getParserOptions() );
$new_cats = array_keys( $parser_output->getCategories() );
// For now, the only added categories are the ones in the submitted text
$added_cats = $new_cats;
// If the page already exists, it can have some categories already
if( !( $flags & EDIT_NEW ) ) {
$dbr = wfGetDB( DB_SLAVE );
$query_result = $dbr->select(
'categorylinks',
'cl_to',
array( 'cl_from' => $article->getID() ) );
$old_cats = array();
while( $row = $query_result->fetchRow() )
$old_cats[] = $row[0];
$dbr->freeResult( $query_result );
$added_cats = array_diff( $new_cats, $old_cats );
}
$user_groups = $user->getGroups();
foreach( $wgForbiddenCats as $category => $group ) {
if( array_search( $category, $added_cats ) !== false &&
array_search( $group, $user_groups ) === false )
{
$status->fatal( 'forbidden-cat' );
return false;
}
}
return true;
}
It might be a little over the top for what you want but I think you can use SimpleSecurity for this, but it might also ensure people without permission cannot view the category either.
Unlikely, since adding a category is as simple as adding some text, this isn't an action that can be restricted with the default installation, or an extension I could find.
I guess one could write and extension that would remove the text if you don't have permission to add that category.
精彩评论