r43400 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43399‎ | r43400 | r43401 >
Date:00:29, 12 November 2008
Author:soxred93
Status:old
Tags:
Comment:
Add EmergencyDeSysop extension to SVN repo
Modified paths:
  • /trunk/extensions/EmergencyDeSysop (added) (history)
  • /trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.alias.php (added) (history)
  • /trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.i18n.php (added) (history)
  • /trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.php (added) (history)
  • /trunk/extensions/EmergencyDeSysop/README (added) (history)
  • /trunk/extensions/EmergencyDeSysop/SpecialEmergencyDeSysop.php (added) (history)

Diff [purge]

Index: trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.alias.php
@@ -0,0 +1,7 @@
 2+<?php
 3+$messages = array();
 4+
 5+/** English */
 6+$messages['en'] = array(
 7+ 'EmergencyDeSysop' => array( 'EmergencyDeSysop', 'EmergencyDesysop' ),
 8+);
\ No newline at end of file
Property changes on: trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.alias.php
___________________________________________________________________
Name: svn:eol-style
19 + native
Index: trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.i18n.php
@@ -0,0 +1,25 @@
 2+<?php
 3+$messages = array();
 4+$messages['en'] = array(
 5+ //About the Extension
 6+ 'emergencydesysop' => 'Emergency DeSysop',
 7+ 'emergencydesysop-desc' => 'Allows a Sysop to sacrifice their own bit, in order to desysop another',
 8+
 9+ //Extension Messages
 10+ 'emergencydesysop-title' => 'Remove sysop access from both current user and another sysop',
 11+ 'emergencydesysop-otheradmin' => 'Other Sysop to degroup',
 12+ 'emergencydesysop-reason' => 'Reason for removal',
 13+ 'emergencydesysop-submit' => 'Submit',
 14+ 'emergencydesysop-incomplete' => 'All form fields are required, please try again.',
 15+ 'emergencydesysop-notasysop' => 'The target user is not in the sysop group.',
 16+ 'emergencydesysop-nogroups' => 'None',
 17+ 'emergencydesysop-done' => 'Action complete, both you and [[$1]] have been desysopped.',
 18+ 'emergencydesysop-invalidtarget' => 'The target user does not exist.',
 19+ 'emergencydesysop-blocked' => 'You cannot access this page while blocked',
 20+ 'emergencydesysop-noright' => 'You do not have sufficient permissions to access this page',
 21+
 22+
 23+ //Rights Messages
 24+ 'right-emergencydesysop' => 'Able to desysop another user, mutually.',
 25+
 26+);
Property changes on: trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.i18n.php
___________________________________________________________________
Name: svn:eol-style
127 + native
Index: trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.php
@@ -0,0 +1,46 @@
 2+<?php
 3+
 4+if (!defined('MEDIAWIKI')) {
 5+ echo <<<EOT
 6+To install our extension, put the following line in LocalSettings.php:
 7+require_once( "$IP/extensions/EmergencyDeSysop/EmergencyDeSysop" );
 8+EOT;
 9+ exit( 1 );
 10+}
 11+
 12+$wgExtensionCredits['specialpage'][] = array(
 13+ 'author' => 'SQL',
 14+ 'name' => 'EmergencyDeSysop',
 15+ 'svn-date' => '$LastChangedDate$',
 16+ 'svn-revision' => '$LastChangedRevision$',
 17+ 'url' => 'http://www.mediawiki.org/wiki/Extension:EmergencyDeSysop',
 18+ 'description' => 'Allows a Sysop to sacrifice their own bit, in order to desysop another',
 19+ 'descriptionmsg' => 'emergencydesysop-desc',
 20+);
 21+
 22+$dir = dirname(__FILE__);
 23+
 24+$wgExtensionMessagesFiles['EmergencyDeSysop'] = "$dir/EmergencyDeSysop.i18n.php";
 25+
 26+$wgAutoloadClasses['SpecialEmergencyDeSysop'] = "$dir/SpecialEmergencyDeSysop.php";
 27+
 28+$wgSpecialPages['EmergencyDeSysop'] = 'SpecialEmergencyDeSysop';
 29+
 30+$wgSpecialPageGroups['EmergencyDeSysop'] = 'users';
 31+
 32+$wgAvailableRights[] = 'emergencydesysop';
 33+
 34+$wgGroupPermissions['sysop']['emergencydesysop' ] = true;
 35+
 36+//Load Defaults
 37+$wgEmDesysop = array('Requestor' => NULL, 'Target' => NULL);
 38+
 39+function EmergencyDeSysopLocalizedPageName(&$specialPageArray, $code) {
 40+ wfLoadExtensionMessages('EmergencyDeSysop');
 41+ $text = wfMsg('emergencydesysop');
 42+
 43+ $title = Title::newFromText($text);
 44+ $specialPageArray['emergencydesysop']['emergencydesysop'] = $title->getDBKey();
 45+ return true;
 46+}
 47+
Property changes on: trunk/extensions/EmergencyDeSysop/EmergencyDeSysop.php
___________________________________________________________________
Name: svn:eol-style
148 + native
Index: trunk/extensions/EmergencyDeSysop/SpecialEmergencyDeSysop.php
@@ -0,0 +1,198 @@
 2+<?php
 3+
 4+if ( ! defined( 'MEDIAWIKI' ) )
 5+ die();
 6+
 7+class SpecialEmergencyDeSysop extends SpecialPage {
 8+
 9+ function __construct() {
 10+ wfLoadExtensionMessages( 'EmergencyDeSysop' );
 11+ parent::__construct( 'EmergencyDeSysop' );
 12+ parent::__construct( "EmergencyDeSysop", "emergencydesysop" );
 13+ }
 14+
 15+ /**
 16+ * @brief takeGroups function
 17+ *
 18+ * This function decides which groups to take the user out of, and does so.
 19+ * @param object reqUser A MW User object, for the user making the request
 20+ * @param object targetUser A MW User object, for the user targeted by the request
 21+ */
 22+ function takeGroups( $reqUser, $targetUser ) {
 23+ global $wgEmDesysop;
 24+
 25+ //Get groups for instigating user
 26+ $reqGroups = $reqUser->getGroups();
 27+
 28+ //Get groups for target user
 29+ $targetGroups = $targetUser->getGroups();
 30+
 31+ //Take them all from the requesting user?
 32+ if( $wgEmDesysop['Requestor'] == "All" ) {
 33+ foreach( $reqGroups as $reqGroup ) { $reqUser->removeGroup( $reqGroup ); }
 34+
 35+ //Take sysop AND crat?
 36+ } elseif( array_search( 'bureaucrat', $reqGroups ) !== FALSE && $wgEmDesysop['Requestor'] == "Crat" ) {
 37+ $reqUser->removeGroup( 'sysop' );
 38+ $reqUser->removeGroup( 'bureaucrat' );
 39+
 40+ //Fall back on just taking sysop
 41+ } else {
 42+ $reqUser->removeGroup( 'sysop' );
 43+ }
 44+
 45+ //Take all groups away from target user?
 46+ if( $wgEmDesysop['Target'] == "All" ) {
 47+ foreach( $targetGroups as $targetGroup ) { $targetUser->removeGroup( $targetGroup ); }
 48+
 49+ //Crat AND sysop?
 50+ } elseif( array_search( 'bureaucrat', $targetGroups ) !== FALSE && $wgEmDesysop['Target'] == "Crat" ) {
 51+ $targetUser->removeGroup( 'bureaucrat' );
 52+ $targetUser->removeGroup( 'sysop' );
 53+
 54+ //Default, just sysop
 55+ } else {
 56+ $targetUser->removeGroup( 'sysop' );
 57+ }
 58+
 59+ }
 60+
 61+ /**
 62+ * @brief validateTarget function
 63+ *
 64+ * This function checks that the user exists, and, is a member of the sysop usergroup
 65+ * @param object targetUser A MW User object, for the user to be checked.
 66+ */
 67+ function validateTarget( $targetUser ) {
 68+ global $wgOut;
 69+
 70+ //Is it a valid user?
 71+ if( $targetUser->getid() == 0 ) {
 72+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-invalidtarget' ) );
 73+ $this->showForm();
 74+ return False;
 75+ }
 76+
 77+ $targetGroups = $targetUser->getGroups();
 78+
 79+ //Is the target a sysop?
 80+ if( !is_array( $targetGroups ) && $targetGroups != 'sysop' ) {
 81+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-notasysop' ) );
 82+ $this->showForm();
 83+ return False;
 84+ } elseif ( !array_search( 'sysop', $targetGroups ) ) {
 85+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-notasysop' ) );
 86+ $this->showForm();
 87+ return False;
 88+ }
 89+
 90+ return True;
 91+ }
 92+
 93+ /**
 94+ * @brief formatGroups function
 95+ *
 96+ * This function formats an array of groups for logging
 97+ * @param array groups an array of user groups
 98+ */
 99+ function formatGroups ( $groups ) {
 100+ if( empty( $groups ) ) {
 101+ $groups = wfMsg( 'emergencydesysop-nogroups' );
 102+ } else {
 103+ $groups = implode( ', ', $groups );
 104+ }
 105+ return $groups;
 106+ }
 107+
 108+ /**
 109+ * @brief showForm function
 110+ *
 111+ * This function shows the request form
 112+ */
 113+ function showForm() {
 114+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 115+
 116+ $action = $wgTitle->escapeLocalUrl();
 117+ $f = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'name' => 'request' ) );
 118+
 119+
 120+ $f .= Xml::openElement( 'fieldset' ) .
 121+ Xml::element( 'legend', array(), wfMsg( 'emergencydesysop-title' ) ) .
 122+ Xml::tags( 'label', array( 'for' => 'otheradmin' ), wfMsgExt( 'emergencydesysop-otheradmin', 'parseinline' ) ) . ' ' .
 123+ Xml::input( 'otheradmin', 20) . ' '.
 124+ Xml::label( wfMsg( 'emergencydesysop-reason' ), 'reason' ) . ' ' .
 125+ Xml::input( 'reason', 45) . ' '.
 126+ Xml::submitButton( wfMsg( 'emergencydesysop-submit' ) ) .
 127+ Xml::closeElement( 'fieldset' ) .
 128+ Xml::closeElement( 'form' );
 129+
 130+ $wgOut->addHTML( $f );
 131+ }
 132+
 133+ /**
 134+ * @brief function executed when the special page is opened.
 135+ */
 136+ function execute( $subpage ) {
 137+ global $wgRequest, $wgOut, $wgUser, $wgTitle;
 138+ $this->setHeaders();
 139+
 140+ //if the user is blocked, deny access.
 141+ if ( $wgUser->IsBlocked() ) {
 142+ //show the blocked message.
 143+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-blocked' ) );
 144+ return;
 145+ } else if ( $wgUser->isAnon() || !$wgUser->isAllowed( 'emergencydesysop' ) ) {
 146+ //You've got to have the right
 147+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-noright' ) );
 148+ return;
 149+ } else if ( wfReadOnly() ) {
 150+ //if the database is read-only, prevent access.
 151+ $wgOut->readOnlyPage();
 152+ return;
 153+ }
 154+
 155+ //if page was posted, then data has been sent
 156+ if ( $wgRequest->wasPosted() ) {
 157+ if( !$wgRequest->getText( 'otheradmin' ) or !$wgRequest->getText( 'reason' ) ) {
 158+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-incomplete' ) );
 159+ $this->showForm();
 160+ return;
 161+ }
 162+ //Start new user object, for the target user
 163+ $targetUser = User::newFromName( $wgRequest->getText( "otheradmin" ) );
 164+
 165+ //Is the target user BOTH a sysop, and a valid user?
 166+ if( !$this->validateTarget( $targetUser ) ) { return; }
 167+
 168+ $targetUserGroupsOld = $targetUser->getGroups( );
 169+ $doerUserGroupsOld = $wgUser->getGroups( );
 170+
 171+ //Do the desysop
 172+ $this->takeGroups( $wgUser, $targetUser );
 173+
 174+ $targetUserGroupsNew = $targetUser->getGroups( );
 175+ $doerUserGroupsNew = $wgUser->getGroups( );
 176+
 177+ //Log it
 178+ $log = new LogPage( "rights" );
 179+ $log->addEntry(
 180+ "rights",
 181+ $targetUser->getUserPage( ),
 182+ 'Emergency Desysop: ' . $wgRequest->getText( 'reason' ),
 183+ array( $this->formatGroups( $targetUserGroupsOld ), $this->formatGroups( $targetUserGroupsNew ) ) );
 184+
 185+ $log->addEntry(
 186+ "rights",
 187+ $wgUser->getUserPage( ),
 188+ 'Emergency Desysoped [[' . $targetUser->getUserPage( ) . ']]: ' . $wgRequest->getText( 'reason' ),
 189+ array( $this->formatGroups( $doerUserGroupsOld ), $this->formatGroups( $doerUserGroupsNew ) ) );
 190+ $wgOut->addWikiText( wfMsg( 'emergencydesysop-done', $targetUser->getUserPage( ) ) );
 191+
 192+ } else {
 193+ //show form
 194+ $this->showForm();
 195+ }
 196+
 197+ return;
 198+ }
 199+}
Property changes on: trunk/extensions/EmergencyDeSysop/SpecialEmergencyDeSysop.php
___________________________________________________________________
Name: svn:eol-style
1200 + native
Index: trunk/extensions/EmergencyDeSysop/README
@@ -0,0 +1,31 @@
 2+EmergencyDeSysop by SQL ( http://en.wikipedia.org/wiki/User:SQL )
 3+
 4+Subversion repository: https://svn.cluenet.org/svn/sql/trunk/MediaWiki/extensions/EmergencyDeSysop/
 5+
 6+INSTALLATION:
 7+
 8+1. Check out the latest version from our subversion repository, and place it into your extensions directory
 9+2. Add the following to the bottom of LocalSettings.php
 10+ " require_once( "$IP/extensions/EmergencyDeSysop/EmergencyDeSysop.php" ); "
 11+3. Configure as needed
 12+
 13+CONFIGURATION:
 14+
 15+The following may be added to your LocalSettings.php file anywhere below where the extension is loaded. The default is all options off.
 16+
 17+$wgEmDesysop['Requestor'] = "Crat";
 18+
 19+Setting this variable, will remove the user making the desysop request from the 'bureaucrat' group as well, if they are in that group.
 20+
 21+$wgEmDesysop['Target'] = "Crat";
 22+
 23+Setting this variable, will remove the user targeted by the desysop request from the 'bureaucrat' group as well, if they are in that group.
 24+
 25+$wgEmDesysop['Requestor'] = "All";
 26+
 27+Setting this variable, will remove the user making the desysop request from all groups that they are in.
 28+
 29+$wgEmDesysop['Target'] = "All";
 30+
 31+Setting this variable, will remove the user targeted by the desysop request from all groups that they are in.
 32+

Status & tagging log