X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSpecialBlockip.php;h=b9d21fc4dd2e9d32233220f1b4135789e04e65c8;hb=f059e0952407f368a6fbcccefe57982c4d63ba2a;hp=942ebe8bde2c21d6b3c499626da82f8d967a3512;hpb=9be2c3676a794dbd0f393954c69a0d67185165c8;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/SpecialBlockip.php b/includes/SpecialBlockip.php
index 942ebe8bde..b9d21fc4dd 100644
--- a/includes/SpecialBlockip.php
+++ b/includes/SpecialBlockip.php
@@ -82,7 +82,6 @@ class IPBlockForm {
$mIpbothertime = wfMsgHtml( 'ipbotheroption' );
$mIpbreasonother = Xml::label( wfMsg( 'ipbreason' ), 'wpBlockReasonList' );
$mIpbreason = Xml::label( wfMsg( 'ipbotherreason' ), 'mw-bi-reason' );
- $mIpbreasonotherlist = wfMsgHtml( 'ipbreasonotherlist' );
$titleObj = SpecialPage::getTitleFor( 'Blockip' );
$action = $titleObj->escapeLocalURL( "action=submit" );
@@ -111,38 +110,9 @@ class IPBlockForm {
$blockExpiryFormOptions .= "$show ";
}
- $scBlockReasonList = wfMsgForContent( 'ipbreason-dropdown' );
- $blockReasonList = '';
- if ( $scBlockReasonList != '' && $scBlockReasonList != '-' ) {
- $blockReasonList = "$mIpbreasonotherlist ";
- $optgroup = "";
- foreach ( explode( "\n", $scBlockReasonList ) as $option) {
- $value = trim( htmlspecialchars($option) );
- if ( $value == '' ) {
- continue;
- } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
- // A new group is starting ...
- $value = trim( substr( $value, 1 ) );
- $blockReasonList .= "$optgroup";
- $optgroup = " ";
- } elseif ( substr( $value, 0, 2) == '**' ) {
- // groupmember
- $selected = "";
- $value = trim( substr( $value, 2 ) );
- if ( $this->BlockReasonList === $value)
- $selected = ' selected="selected"';
- $blockReasonList .= "$value ";
- } else {
- // groupless block reason
- $selected = "";
- if ( $this->BlockReasonList === $value)
- $selected = ' selected="selected"';
- $blockReasonList .= "$optgroup$value ";
- $optgroup = "";
- }
- }
- $blockReasonList .= $optgroup;
- }
+ $reasonDropDown = Xml::listDropDown( 'wpBlockReasonList',
+ wfMsgForContent( 'ipbreason-dropdown' ),
+ wfMsgForContent( 'ipbreasonotherlist' ), '', 'wpBlockDropDown', 4 );
$token = $wgUser->editToken();
@@ -182,17 +152,13 @@ class IPBlockForm {
array( 'tabindex' => '3', 'id' => 'mw-bi-other' ) ) . "
");
- if ( $blockReasonList != '' ) {
- $wgOut->addHTML("
-
- {$mIpbreasonother}
-
-
- $blockReasonList
-
-
- ");
- }
+ $wgOut->addHTML("
+
+ {$mIpbreasonother}
+
+ $reasonDropDown
+
+ ");
$wgOut->addHTML("
{$mIpbreason}
@@ -227,34 +193,35 @@ class IPBlockForm {
");
- // Allow some users to hide name from block log, blocklist and listusers
- if ( $wgUser->isAllowed( 'hideuser' ) ) {
+
+ global $wgSysopEmailBans;
+ if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
$wgOut->addHTML("
-
+
- " . wfCheckLabel( wfMsgHtml( 'ipbhidename' ),
- 'wpHideName', 'wpHideName', $this->BlockHideName,
- array( 'tabindex' => '9' ) ) . "
+ " . wfCheckLabel( wfMsgHtml( 'ipbemailban' ),
+ 'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
+ array( 'tabindex' => '10' )) . "
");
}
- global $wgSysopEmailBans;
-
- if ( $wgSysopEmailBans && $wgUser->isAllowed( 'blockemail' ) ) {
+ // Allow some users to hide name from block log, blocklist and listusers
+ if ( $wgUser->isAllowed( 'hideuser' ) ) {
$wgOut->addHTML("
-
+
- " . wfCheckLabel( wfMsgHtml( 'ipbemailban' ),
- 'wpEmailBan', 'wpEmailBan', $this->BlockEmail,
- array( 'tabindex' => '10' )) . "
+ " . wfCheckLabel( wfMsgHtml( 'ipbhidename' ),
+ 'wpHideName', 'wpHideName', $this->BlockHideName,
+ array( 'tabindex' => '9' ) ) . "
");
}
+
$wgOut->addHTML("
@@ -281,8 +248,14 @@ class IPBlockForm {
}
}
- function doSubmit() {
- global $wgOut, $wgUser, $wgSysopUserBans, $wgSysopRangeBans;
+ /**
+ * Backend block code.
+ * $userID and $expiry will be filled accordingly
+ * @return array(message key, arguments) on failure, empty array on success
+ */
+ function doBlock(&$userId = null, &$expiry = null)
+ {
+ global $wgUser, $wgSysopUserBans, $wgSysopRangeBans;
$userId = 0;
# Expand valid IPv6 addresses, usernames are left as is
@@ -299,27 +272,23 @@ class IPBlockForm {
# IPv4
if ( $wgSysopRangeBans ) {
if ( !IP::isIPv4( $this->BlockAddress ) || $matches[2] < 16 || $matches[2] > 32 ) {
- $this->showForm( wfMsg( 'ip_range_invalid' ) );
- return;
+ return array('ip_range_invalid');
}
$this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
} else {
# Range block illegal
- $this->showForm( wfMsg( 'range_block_disabled' ) );
- return;
+ return array('range_block_disabled');
}
} else if ( preg_match( "/^($rxIP6)\\/(\\d{1,3})$/", $this->BlockAddress, $matches ) ) {
# IPv6
if ( $wgSysopRangeBans ) {
if ( !IP::isIPv6( $this->BlockAddress ) || $matches[2] < 64 || $matches[2] > 128 ) {
- $this->showForm( wfMsg( 'ip_range_invalid' ) );
- return;
+ return array('ip_range_invalid');
}
$this->BlockAddress = Block::normaliseRange( $this->BlockAddress );
} else {
# Range block illegal
- $this->showForm( wfMsg( 'range_block_disabled' ) );
- return;
+ return array('range_block_disabled');
}
} else {
# Username block
@@ -327,15 +296,13 @@ class IPBlockForm {
$user = User::newFromName( $this->BlockAddress );
if( !is_null( $user ) && $user->getID() ) {
# Use canonical name
- $this->BlockAddress = $user->getName();
$userId = $user->getID();
+ $this->BlockAddress = $user->getName();
} else {
- $this->showForm( wfMsg( 'nosuchusershort', htmlspecialchars( $this->BlockAddress ) ) );
- return;
+ return array('nosuchusershort', htmlspecialchars($user->getName()));
}
} else {
- $this->showForm( wfMsg( 'badipaddress' ) );
- return;
+ return array('badipaddress');
}
}
}
@@ -353,8 +320,7 @@ class IPBlockForm {
$expirestr = $this->BlockOther;
if (strlen($expirestr) == 0) {
- $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
- return;
+ return array('ipb_expiry_invalid');
}
if ( $expirestr == 'infinite' || $expirestr == 'indefinite' ) {
@@ -364,8 +330,7 @@ class IPBlockForm {
$expiry = strtotime( $expirestr );
if ( $expiry < 0 || $expiry === false ) {
- $this->showForm( wfMsg( 'ipb_expiry_invalid' ) );
- return;
+ return array('ipb_expiry_invalid');
}
$expiry = wfTimestamp( TS_MW, $expiry );
@@ -381,9 +346,7 @@ class IPBlockForm {
if (wfRunHooks('BlockIp', array(&$block, &$wgUser))) {
if ( !$block->insert() ) {
- $this->showForm( wfMsg( 'ipb_already_blocked',
- htmlspecialchars( $this->BlockAddress ) ) );
- return;
+ return array('ipb_already_blocked', htmlspecialchars($this->BlockAddress));
}
wfRunHooks('BlockIpComplete', array($block, $wgUser));
@@ -400,10 +363,28 @@ class IPBlockForm {
$reasonstr, $logParams );
# Report to the user
+ return array();
+ }
+ else
+ return array('hookaborted');
+ }
+
+ /**
+ * UI entry point for blocking
+ * Wraps around doBlock()
+ */
+ function doSubmit()
+ {
+ global $wgOut;
+ $retval = $this->doBlock();
+ if(empty($retval)) {
$titleObj = SpecialPage::getTitleFor( 'Blockip' );
$wgOut->redirect( $titleObj->getFullURL( 'action=success&ip=' .
urlencode( $this->BlockAddress ) ) );
+ return;
}
+ $key = array_shift($retval);
+ $this->showForm(wfMsgReal($key, $retval));
}
function showSuccess() {