Abrir menu principal

UESPWiki β

Alterações

Utilizador:Nx/RestrictBlock

3 655 bytes adicionados, 18h05min de 22 de março de 2010
fresh out of the oven
RestrictBlock is an extension that can do two things: prevent blocks longer than a specified amount of time, and prevent blocks that block the user from editing their talk page.

==Source and installation==

The following goes into extensions/RestrictBlock/RestrictBlock.php:

<pre>
<?php

if ( !defined( 'MEDIAWIKI' ) ) {
exit;
}

//configuration
//Give sysops the right to block editors from editing their talk page and for any length of time
$wgGroupPermissions['sysop']['blocktalk'] = true;
$wgGroupPermissions['sysop']['unrestrictedblock'] = true;
//Maximum block length, in seconds
$wgRestrictBlockLength=14400;

$wgExtensionCredits['other'][] = array(
'name' => 'RestrictBlock',
'author' => '[http://www.mediawiki.org/wiki/User:Nx Nx]',
'description' => 'Places restrictions on block length and options'
);

$wgRestrictBlockIP = dirname( __FILE__ );
$wgExtensionMessagesFiles['RestrictBlock'] = "$wgRestrictBlockIP/RestrictBlock.i18n.php";

$wgHooks['BlockIp'][] = 'RestrictBlockHook';

//Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) {
$wgHooks['ParserFirstCallInit'][] = 'RestrictBlockInit';
} else { // Otherwise do things the old fashioned way
$wgExtensionFunctions[] = 'RestrictBlockInit';
}

function RestrictBlockInit()
{
//Load messages so that color-coding works.
wfLoadExtensionMessages( 'RestrictBlock' );
return true;
}

//intercept blocks
function RestrictBlockHook( &$ban, &$user )
{
//check if the ban disables talk page editing
global $wgBlockAllowsUTEdit;
if ( $wgBlockAllowsUTEdit && !$ban->mAllowUsertalk && !$user->isAllowed('blocktalk') ) {
return wfMsgWikiHtml('restrictblock-denied-utalk');
}
//check for block length
if ( !$user->isAllowed('unrestrictedblock') ) {
global $wgRestrictBlockLength;
//infinity is right out
if ( $ban->mExpiry === 'infinity' ) {
return wfMsgWikiHtml('restrictblock-denied', $wgRestrictBlockLength);
}
$timediff = (wfTimestamp(TS_UNIX,$ban->mExpiry) - time());
if ($timediff > $wgRestrictBlockLength) {
return wfMsgWikiHtml('restrictblock-denied', $wgRestrictBlockLength);
}
}
return true;
}
</pre>

And this goes into extensions/RestrictBlock/RestrictBlock.i18n.php:

<pre>
<?php
$messages = array();

$messages['en'] = array(
'right-blocktalk' => 'Block a user from editing their talk page',
'right-unrestrictedblock' => 'Block for any length of time',
'restrictblock-denied-utalk' => '<div class="error">You are not allowed to block a user from editing their talk page.</div>',
'restrictblock-denied' => '<div class="error">You are not allowed to block for more than $1 seconds.</div>',
);
</pre>

Finally put
<pre>
require_once( "$IP/extensions/RestrictBlock/RestrictBlock.php" );
</pre>
into LocalSettings.php

==Configuration==

The ''blocktalk'' right allows blocking a user from editing their talk page. The ''unrestrictedblock'' right allows blocking for any length of time. Both are given to sysops by the extension. The description of these (shown on [[Special:ListGroupRights]]) is at [[MediaWiki:right-blocktalk]] and [[MediaWiki:right-unrestrictedblock]].

''$wgRestrictBlockLength'' is the maximum length for a block that a user without the unrestrictedblock right can issue, in seconds. This defaults to 4 hours (14400 seconds).

There are two error messages: [[MediaWiki:restrictblock-denied-utalk]] for when the user is not allowed to block editing user talk pages, and [[MediaWiki:restrictblock-denied]] for when the user tries to block for longer than the allowed time.
438
edições