Index: trunk/extensions/Resign/SpecialResign_body.php |
— | — | @@ -0,0 +1,94 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ResignPage extends SpecialPage { |
| 5 | + private $mGroups, $mReason, $mConfirm, $mSubmit; |
| 6 | + |
| 7 | + function __construct() { |
| 8 | + parent::__construct( 'Resign', 'resign' ); |
| 9 | + |
| 10 | + global $wgUser, $wgRequest; |
| 11 | + $this->mGroups = array(); |
| 12 | + foreach( $wgUser->getGroups() as $group ) { |
| 13 | + if ( $wgRequest->getBool( "wpGroup-$group" ) ) { |
| 14 | + $this->mGroups[] = $group; |
| 15 | + } |
| 16 | + } |
| 17 | + $this->mReason = $wgRequest->getText( 'wpReason' ); |
| 18 | + $this->mConfirm = $wgRequest->getBool( 'wpConfirm' ); |
| 19 | + $this->mSubmit = $wgRequest->wasPosted() && $wgUser->matchEditToken( $wgRequest->getVal( 'wpToken' ) ); |
| 20 | + } |
| 21 | + |
| 22 | + function execute( $par ) { |
| 23 | + global $wgOut, $wgUser, $wgRequest; |
| 24 | + |
| 25 | + $this->setHeaders(); |
| 26 | + |
| 27 | + if ( !$wgUser->isAllowed( 'resign' ) ) { |
| 28 | + $wgOut->permissionRequired( 'resign' ); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + if ( wfReadOnly() ) { |
| 33 | + $wgOut->readOnlyPage(); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + if ( $this->mSubmit ) { |
| 38 | + $this->doSubmit(); |
| 39 | + } |
| 40 | + |
| 41 | + $this->showForm(); |
| 42 | + } |
| 43 | + |
| 44 | + function showForm() { |
| 45 | + global $wgOut, $wgUser; |
| 46 | + $wgOut->addHTML( |
| 47 | + Xml::openElement( 'form' , array( 'method' => 'post' ) ) . |
| 48 | + wfMsgExt( 'resign-text', array( 'parse' ) ) . |
| 49 | + Xml::openElement( 'ul' ) |
| 50 | + ); |
| 51 | + foreach( $wgUser->getGroups() as $group ) { |
| 52 | + $wgOut->addHTML( |
| 53 | + Xml::tags( 'li', null, Xml::check( "wpGroup-$group", in_array( $group, $this->mGroups ) ) . ' ' . |
| 54 | + User::makeGroupLinkHTML( $group, User::getGroupMember( $group ) ) ) |
| 55 | + ); |
| 56 | + } |
| 57 | + $wgOut->addHTML( |
| 58 | + Xml::closeElement( 'ul' ) . |
| 59 | + Xml::tags( 'p', null, Xml::inputLabel( wfMsg( 'resign-reason' ), 'wpReason', 'wpReason', 60, $this->mReason ) ) . |
| 60 | + Xml::tags( 'p', null, Xml::checkLabel( wfMsgExt( 'resign-confirm', array( 'parseinline' ) ), 'wpConfirm', 'wpConfirm', $this->mConfirm ) ) . |
| 61 | + Xml::tags( 'p', null, Xml::submitButton( wfMsg( 'confirm' ) ) ) . |
| 62 | + Xml::hidden( 'wpToken', $wgUser->editToken() ) . |
| 63 | + Xml::closeElement( 'form' ) |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + function doSubmit() { |
| 68 | + global $wgOut, $wgUser; |
| 69 | + |
| 70 | + if ( !$this->mConfirm ) { |
| 71 | + $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), wfMsgExt( 'resign-noconfirm', array( 'parseinline' ) ) ) ); |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + if ( count( $this->mGroups ) == 0 ) { |
| 76 | + $wgOut->addHTML( Xml::tags( 'p', array( 'class' => 'error' ), wfMsgExt( 'resign-nogroups', array( 'parseinline' ) ) ) ); |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + foreach( $this->mGroups as $group ) { |
| 81 | + $wgUser->removeGroup( $group ); |
| 82 | + } |
| 83 | + |
| 84 | + $log = new LogPage( 'rights' ); |
| 85 | + $log->addEntry( 'resign', Title::makeTitle( NS_USER, $wgUser->getName() ), $this->mReason, array( $this->makeGroupNameList( $this->mGroups ) ) ); |
| 86 | + |
| 87 | + $wgOut->addHTML( Xml::tags( 'p', null, wfMsgExt( 'resign-success', array( 'parseinline' ) ) ) ); |
| 88 | + } |
| 89 | + |
| 90 | + function makeGroupNameList( $ids ) { |
| 91 | + return implode( ', ', $ids ); |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +?> |
Property changes on: trunk/extensions/Resign/SpecialResign_body.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 96 | + native |
Index: trunk/extensions/Resign/SpecialResign.i18n.php |
— | — | @@ -0,0 +1,36 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalisation file for Resign extension. |
| 5 | + * |
| 6 | + * @addtogroup Extensions |
| 7 | +*/ |
| 8 | + |
| 9 | +$wgResignMessages = array(); |
| 10 | + |
| 11 | +$wgResignMessages['en'] = array( |
| 12 | + 'resign' => 'Resign', |
| 13 | + 'resign-text' => "You can '''remove your permissions''' (e.g. sysop) in this page. Please check the permissions you would like to remove. |
| 14 | + |
| 15 | + Remember: '''You cannot get your permissions back this way!''' You will have to convince a bureaucrat or steward to grant you back the permissions. Please use this page very carefully.", |
| 16 | + 'resign-reason' => 'Reason:', |
| 17 | + 'resign-confirm' => 'I confirm I would like to remove all the permissions I checked, and I know I cannot get my permissions back this way.', |
| 18 | + 'resign-noconfirm' => 'Please check the confirm checkbox if you would like to remove your permissions.', |
| 19 | + 'resign-nogroups' => 'Please check the permissions you would like to remove.', |
| 20 | + 'resign-success' => "'''The permissions were successfully removed.'''", |
| 21 | + 'resign-logentry' => 'removed permissions $2 from himself', |
| 22 | +); |
| 23 | + |
| 24 | +$wgResignMessages['he'] = array( |
| 25 | + 'resign' => 'התפטרות', |
| 26 | + 'resign-text' => "בדף זה תוכלו '''להסיר את ההרשאות שלכם''' (למשל, הרשאות מפעיל מערכת). אנא סמנו את ההרשאות שברצונכם להסיר. |
| 27 | + |
| 28 | + להזכירכם: '''אינכם יכולים לקבל בחזרה את ההרשאות בדרך זו!''' יהיה עליכם לשכנע ביורוקרט או דייל להעניק לכם את הרשאותיכם בחזרה. אנא השתמשו בדף זה בזהירות רבה.", |
| 29 | + 'resign-reason' => 'סיבה:', |
| 30 | + 'resign-confirm' => 'אני מאשר שברצוני להסיר את כל ההרשאות שלי שסימנתי, וידוע לי שלא אוכל לקבל אותן בחזרה בדרך זו.', |
| 31 | + 'resign-noconfirm' => 'אנא סמנו את תיבת הסימון כדי לאשר את ההסרה.', |
| 32 | + 'resign-nogroups' => 'אנא בחרו את ההרשאות שברצונכם להסיר.', |
| 33 | + 'resign-success' => "'''ההרשאות הוסרו בהצלחה.'''", |
| 34 | + 'resign-logentry' => 'הסיר את ההרשאות $2 שלו', |
| 35 | +); |
| 36 | + |
| 37 | +?> |
Property changes on: trunk/extensions/Resign/SpecialResign.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 38 | + native |
Index: trunk/extensions/Resign/SpecialResign.php |
— | — | @@ -0,0 +1,44 @@ |
| 2 | +<?php |
| 3 | +if (!defined('MEDIAWIKI')) die(); |
| 4 | +/** |
| 5 | + * A Special Page extension to allow users to remove their permissions. |
| 6 | + * Should be included as the latest extension that sets user groups. |
| 7 | + * |
| 8 | + * @addtogroup Extensions |
| 9 | + * |
| 10 | + * @author Rotem Liss |
| 11 | + */ |
| 12 | + |
| 13 | +$wgExtensionFunctions[] = 'wfSpecialResign'; |
| 14 | +$wgExtensionCredits['specialpage'][] = array( |
| 15 | + 'author' => 'Rotem Liss', |
| 16 | + 'name' => 'Resign', |
| 17 | + 'description' => 'Gives users the ability to remove their permissions' |
| 18 | +); |
| 19 | + |
| 20 | +# Internationalisation file |
| 21 | +require_once( dirname(__FILE__) . '/SpecialResign.i18n.php' ); |
| 22 | + |
| 23 | +# Add resign permission for every group set in the database |
| 24 | +foreach( $wgGroupPermissions as $key => $value ) { |
| 25 | + if ( $key != '*' && $key != 'user' && $key != 'autoconfirmed' && $key != 'emailconfirmed' ) { |
| 26 | + $wgGroupPermissions[$key]['resign'] = true; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +# Add log action |
| 31 | +$wgLogActions['rights/resign'] = 'resign-logentry'; |
| 32 | + |
| 33 | +# Register special page |
| 34 | +if ( !function_exists( 'extAddSpecialPage' ) ) { |
| 35 | + require( dirname(__FILE__) . '/../ExtensionFunctions.php' ); |
| 36 | +} |
| 37 | +extAddSpecialPage( dirname(__FILE__) . '/SpecialResign_body.php', 'Resign', 'ResignPage' ); |
| 38 | + |
| 39 | +function wfSpecialResign() { |
| 40 | + # Add messages |
| 41 | + global $wgMessageCache, $wgResignMessages; |
| 42 | + $wgMessageCache->addMessagesByLang( $wgResignMessages ); |
| 43 | +} |
| 44 | + |
| 45 | +?> |
Property changes on: trunk/extensions/Resign/SpecialResign.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 46 | + native |