Jack Phoenix has uploaded a new change for review. https://gerrit.wikimedia.org/r/254434
Change subject: Version 1.3: extension registration support ...................................................................... Version 1.3: extension registration support Change-Id: I1c0c872966d2e2290875f90feb0bb417d9cc5692 --- A StaffPowers.class.php M StaffPowers.php A extension.json 3 files changed, 108 insertions(+), 54 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/StaffPowers refs/changes/34/254434/1 diff --git a/StaffPowers.class.php b/StaffPowers.class.php new file mode 100644 index 0000000..c3010f2 --- /dev/null +++ b/StaffPowers.class.php @@ -0,0 +1,67 @@ +<?php +/** + * Applies staff powers, like unblockableness, superhuman strength and + * general awesomeness to select users. + * + * @file + * @ingroup Extensions + * @version 1.3 + * @date 20 November 2015 + * @author Łukasz Garczewski <[email protected]> + * @author Jack Phoenix <[email protected]> + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later + * @link https://www.mediawiki.org/wiki/Extension:StaffPowers Documentation + */ + +class StaffPowers { + + /** + * @param Block $block The Block object about to be saved + * @param User $user The user _doing_ the block (not the one being blocked) + * @param array $reason Custom reason as to why blocking isn't possible + * @return bool + */ + public static function makeUnblockable( $block, $user, $reason ) { + $blockedUser = User::newFromName( $block->getRedactedName() ); + + if ( empty( $blockedUser ) ) { + return true; + } + + if ( User::isIP( $blockedUser ) ) { + return true; + } + + $userIsSteward = in_array( 'steward', $blockedUser->getEffectiveGroups() ); + if ( !$blockedUser->isAllowed( 'unblockable' ) && !$userIsSteward ) { + return true; + } + + // This exists for interoperability purposes with Wikia's StaffLog extension + Hooks::run( 'BlockIpStaffPowersCancel', array( $block, $user ) ); + + // Display a custom reason as to why blocking the specified user isn't + // possible instead of the totally unhelpful, default core message + $userIsStaff = in_array( 'staff', $blockedUser->getEffectiveGroups() ); + $blockerIsStaff = in_array( 'staff', $user->getEffectiveGroups() ); + + // Don't allow staff to be blocked in any circumstances + if ( $userIsStaff ) { + $reason = array( 'staffpowers-ipblock-abort' ); + } elseif ( $userIsSteward && !$blockerIsStaff ) { + // and also don't allow stewards to be blocked by non-staff, as per IRC + // discussion on 19 January 2014 + $reason = array( 'staffpowers-steward-block-abort' ); + } elseif ( $userIsSteward && $blockerIsStaff ) { + // This is a possible scenario - staff are allowed to block stewards. + // We need to address this situation 'cause this function returns false + // by default, so w/o this elseif loop, staff trying to block a steward + // will bump into the default core hookaborted message and the block + // will fail. + return true; + } + + return false; + } + +} \ No newline at end of file diff --git a/StaffPowers.php b/StaffPowers.php index 7c2ec78..eda91a6 100644 --- a/StaffPowers.php +++ b/StaffPowers.php @@ -5,8 +5,8 @@ * * @file * @ingroup Extensions - * @version 1.2 - * @date 28 January 2014 + * @version 1.3 + * @date 20 November 2015 * @author Łukasz Garczewski <[email protected]> * @author Jack Phoenix <[email protected]> * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later @@ -17,7 +17,7 @@ $wgExtensionCredits['other'][] = array( 'path' => __FILE__, 'name' => 'StaffPowers', - 'version' => '1.2.1', + 'version' => '1.3', 'author' => array( 'Łukasz Garczewski', 'Jack Phoenix' ), 'description' => 'Applies staff powers, like unblockableness, superhuman strength and general awesomeness to [[Special:ListUsers/staff|select users]]', 'url' => 'https://www.mediawiki.org/wiki/Extension:StaffPowers', @@ -25,57 +25,10 @@ $wgMessagesDirs['StaffPowers'] = __DIR__ . '/i18n'; +$wgAutoloadClasses['StaffPowers'] = __DIR__ . '/StaffPowers.class.php'; + // Power: unblockableness -$wgHooks['BlockIp'][] = 'efPowersMakeUnblockable'; +$wgHooks['BlockIp'][] = 'StaffPowers::makeUnblockable'; $wgAvailableRights[] = 'unblockable'; -$wgGroupPermissions['staff']['unblockable'] = true; - -/** - * @param Block $block The Block object about to be saved - * @param User $user The user _doing_ the block (not the one being blocked) - * @param array $reason Custom reason as to why blocking isn't possible - * @return bool - */ -function efPowersMakeUnblockable( $block, $user, $reason ) { - $blockedUser = User::newFromName( $block->getRedactedName() ); - - if ( empty( $blockedUser ) ) { - return true; - } - - if ( User::isIP( $blockedUser ) ) { - return true; - } - - $userIsSteward = in_array( 'steward', $blockedUser->getEffectiveGroups() ); - if ( !$blockedUser->isAllowed( 'unblockable' ) && !$userIsSteward ) { - return true; - } - - // This exists for interoperability purposes with Wikia's StaffLog extension - Hooks::run( 'BlockIpStaffPowersCancel', array( $block, $user ) ); - - // Display a custom reason as to why blocking the specified user isn't - // possible instead of the totally unhelpful, default core message - $userIsStaff = in_array( 'staff', $blockedUser->getEffectiveGroups() ); - $blockerIsStaff = in_array( 'staff', $user->getEffectiveGroups() ); - - // Don't allow staff to be blocked in any circumstances - if ( $userIsStaff ) { - $reason = array( 'staffpowers-ipblock-abort' ); - } elseif ( $userIsSteward && !$blockerIsStaff ) { - // and also don't allow stewards to be blocked by non-staff, as per IRC - // discussion on 19 January 2014 - $reason = array( 'staffpowers-steward-block-abort' ); - } elseif ( $userIsSteward && $blockerIsStaff ) { - // This is a possible scenario - staff are allowed to block stewards. - // We need to address this situation 'cause this function returns false - // by default, so w/o this elseif loop, staff trying to block a steward - // will bump into the default core hookaborted message and the block - // will fail. - return true; - } - - return false; -} +$wgGroupPermissions['staff']['unblockable'] = true; \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..4845ecf --- /dev/null +++ b/extension.json @@ -0,0 +1,34 @@ +{ + "name": "StaffPowers", + "version": "1.3", + "author": [ + "Łukasz Garczewski", + "Jack Phoenix" + ], + "license-name": "GPL-2.0+", + "url": "https://www.mediawiki.org/wiki/Extension:StaffPowers", + "description": "Applies staff powers, like unblockableness, superhuman strength and general awesomeness to [[Special:ListUsers/staff|select users]]", + "type": "other", + "MessagesDirs": { + "StaffPowers": [ + "i18n" + ] + }, + "AutoloadClasses": { + "StaffPowers": "StaffPowers.class.php" + }, + "Hooks": { + "BlockIp": [ + "StaffPowers::makeUnblockable" + ] + }, + "AvailableRights": [ + "unblockable" + ], + "GroupPermissions": { + "staff": { + "unblockable": true + } + }, + "manifest_version": 1 +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/254434 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1c0c872966d2e2290875f90feb0bb417d9cc5692 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/StaffPowers Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
