Index: trunk/extensions/Sudo/Sudo.php |
— | — | @@ -0,0 +1,63 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Sudo |
| 5 | + * @package Sudo |
| 6 | + * @author Daniel Friesen (http://mediawiki.org/wiki/User:Dantman) <wiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$wgExtensionCredits['otjher'][] = array ( |
| 27 | + 'name' => 'Sudo', |
| 28 | + 'url' => 'http://wiki-tools.com/wiki/Sudo', |
| 29 | + 'version' => '0.1a', |
| 30 | + 'author' => "[http://mediawiki.org/wiki/User:Dantman Daniel Friesen] [mailto:Daniel%20Friesen%20%3Cwiki@danielfriesen.name%3E <dan_the_man@telus.net>]", |
| 31 | + 'description' => "Allows sudoers to login as other users." |
| 32 | +); |
| 33 | + |
| 34 | +$wgAvailableRights[] = 'sudo'; |
| 35 | +$wgExtensionMessagesFiles['Sudo'] = dirname(__FILE__).'/Sudo.i18n.php'; |
| 36 | +$wgAutoloadClasses['SpecialSudo'] = dirname(__FILE__).'/SpecialSudo.php'; |
| 37 | +$wgSpecialPages['Sudo'] = 'SpecialSudo'; |
| 38 | +$wgSpecialPageGroups['Sudo'] = 'users'; |
| 39 | + |
| 40 | +$wgLogTypes[] = 'sudo'; |
| 41 | +$wgLogNames['sudo'] = 'sudo-logpagename'; |
| 42 | +$wgLogHeaders['sudo'] = 'sudo-logpagetext'; |
| 43 | +$wgLogActions['sudo/sudo'] = 'sudo-logentry'; |
| 44 | + |
| 45 | +$wgHooks['UserLogoutComplete'][] = 'efSudoLogout'; |
| 46 | +$wgHooks['PersonalUrls'][] = 'efSudoPersonalUrls'; |
| 47 | + |
| 48 | +function efSudoLogout( &$user, &$inject_html ) { |
| 49 | + ## Unset wsSudoId when we logout. We don't want to be in a sudo login while logged out. |
| 50 | + unset($_SESSION['wsSudoId']); |
| 51 | + return true; |
| 52 | +} |
| 53 | + |
| 54 | +function efSudoPersonalUrls( &$personal_urls, &$wgTitle ) { |
| 55 | + ## Replace logout link with a unsudo link while in a sudo login. |
| 56 | + if( isset($_SESSION['wsSudoId']) && $_SESSION['wsSudoId'] > 0 ) { |
| 57 | + $personal_urls['logout'] = array( |
| 58 | + 'text' => wfMsg( 'sudo-personal-unsudo' ), |
| 59 | + 'href' => Skin::makeSpecialUrl( 'Sudo', 'mode=unsudo' ), |
| 60 | + 'active' => false |
| 61 | + ); |
| 62 | + } |
| 63 | + return true; |
| 64 | +} |
Property changes on: trunk/extensions/Sudo/Sudo.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 65 | + native |
Index: trunk/extensions/Sudo/SpecialSudo.php |
— | — | @@ -0,0 +1,167 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Sudo |
| 5 | + * @package Sudo |
| 6 | + * @author Daniel Friesen (http://www.wikia.com/wiki/User:Dantman) <wiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +class SpecialSudo extends SpecialPage { |
| 27 | + protected $mMode, $mSkin, $mTarget, $mReason, $mErrors; |
| 28 | + |
| 29 | + function __construct() { |
| 30 | + SpecialPage::SpecialPage( 'Sudo', 'sudo' ); |
| 31 | + wfLoadExtensionMessages('Sudo'); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * Execute |
| 36 | + */ |
| 37 | + function execute( $par = '' ) { |
| 38 | + global $wgOut, $wgRequest, $wgUser; |
| 39 | + |
| 40 | + $this->mMode = $wgRequest->getText('mode'); |
| 41 | + if( $this->mMode == 'success' ) return $this->showSuccessPage(); |
| 42 | + if( $this->mMode == 'unsudo' ) return $this->showUnsudoPage(); |
| 43 | + |
| 44 | + if( !$wgUser->isAllowed( 'sudo' ) ) { |
| 45 | + $wgOut->permissionRequired( 'sudo' ); |
| 46 | + return; |
| 47 | + } |
| 48 | + if( $wgUser->isBlocked() ) { |
| 49 | + $wgOut->blockedPage(); |
| 50 | + return; |
| 51 | + } |
| 52 | + if( wfReadOnly() ) { |
| 53 | + $wgOut->readOnlyPage(); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + $this->setHeaders(); |
| 58 | + |
| 59 | + $this->mSkin = $wgUser->getSkin(); |
| 60 | + $this->mTarget = $wgRequest->getText('target', $par); |
| 61 | + $this->mReason = $wgRequest->getText('reason', ''); |
| 62 | + $this->mErrors = array(); |
| 63 | + |
| 64 | + $this->showSudoForm(); |
| 65 | + if( $this->mTarget != '' && $wgRequest->wasPosted() ) $this->doSudo(); |
| 66 | + $this->showErrors(); |
| 67 | + } |
| 68 | + |
| 69 | + function showSuccessPage() { |
| 70 | + global $wgOut, $wgUser; |
| 71 | + if( !isset($_SESSION['wsSudoId']) || $_SESSION['wsSudoId'] < 0 ) { |
| 72 | + $this->showError('sudo-error-nosudo'); |
| 73 | + } else { |
| 74 | + $this->setHeaders(); |
| 75 | + $s = $wgUser->getSkin(); |
| 76 | + $suUser = User::newFromId($_SESSION['wsSudoId']); |
| 77 | + $wgOut->addWikiMsgArray( 'sudo-success', array( |
| 78 | + $s->makeLinkObj( $suUser->getUserPage(), $suUser->getName() ), |
| 79 | + $s->makeLinkObj( $wgUser->getUserPage(), $wgUser->getName() ) ), |
| 80 | + array('replaceafter') ); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + function showUnsudoPage() { |
| 85 | + global $wgOut, $wgUser, $wgRequest; |
| 86 | + if( !isset($_SESSION['wsSudoId']) || $_SESSION['wsSudoId'] < 0 ) { |
| 87 | + $this->showError('sudo-error-nosudo'); |
| 88 | + } else { |
| 89 | + $suUser = User::newFromId($_SESSION['wsSudoId']); |
| 90 | + if( $wgRequest->wasPosted() ) { |
| 91 | + unset($_SESSION['wsSudoId']); |
| 92 | + $suUser->setCookies(); |
| 93 | + $wgOut->redirect($this->getTitle()->getFullURL()); |
| 94 | + return; |
| 95 | + } |
| 96 | + $this->setHeaders(); |
| 97 | + $wgOut->setPageTitle(wfMsg('unsudo')); |
| 98 | + $s = $wgUser->getSkin(); |
| 99 | + |
| 100 | + $wgOut->addHTML( |
| 101 | + Xml::openElement('form', array( 'method' => 'post', |
| 102 | + 'action' => $this->getTitle()->getFullURL('mode=unsudo') )). |
| 103 | + Xml::hidden('title', $this->getTitle()->getPrefixedText()) ); |
| 104 | + $wgOut->addWikiMsgArray( 'sudo-unsudo', array( |
| 105 | + $s->makeLinkObj( $suUser->getUserPage(), $suUser->getName() ), |
| 106 | + $s->makeLinkObj( $wgUser->getUserPage(), $wgUser->getName() ) ), |
| 107 | + array('replaceafter') ); |
| 108 | + $wgOut->addHTML( |
| 109 | + Xml::submitButton(wfMsg('sudo-unsudo-submit')). |
| 110 | + Xml::closeElement('form')); |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + function showSudoForm() { |
| 115 | + global $wgOut; |
| 116 | + $wgOut->addHTML( |
| 117 | + Xml::openElement( 'form', array( 'method' => 'post', |
| 118 | + 'action' => $this->getTitle()->getLocalURL() ) ) . |
| 119 | + Xml::hidden( 'title', $this->getTitle()->getPrefixedText() ) . |
| 120 | + Xml::openElement( 'fieldset' ) . |
| 121 | + Xml::element( 'legend', array(), wfMsg( 'sudo-form' ) ) . |
| 122 | + Xml::inputLabel( wfMsg( 'sudo-user' ), 'target', 'sudo-user', 20, $this->mTarget ) . ' ' . |
| 123 | + Xml::inputLabel( wfMsg( 'sudo-reason' ), 'reason', 'sudo-reason', 45, $this->mReason ) . ' ' . |
| 124 | + Xml::submitButton( wfMsg( 'sudo-submit' ) ) . |
| 125 | + Xml::closeElement( 'fieldset' ) . |
| 126 | + Xml::closeElement( 'form' ) . "\n" |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + function addError( $error = '' ) { |
| 131 | + $this->mErrors[] = $error; |
| 132 | + return; |
| 133 | + } |
| 134 | + |
| 135 | + function showError( $error ) { |
| 136 | + $wgOut->addHTML( |
| 137 | + Xml::openElement('div', array( 'class' => 'sudo-error' )). |
| 138 | + wfMsgHtml('sudo-error',wfMsg($error)). |
| 139 | + Xml::closeElement('div') |
| 140 | + ); |
| 141 | + } |
| 142 | + |
| 143 | + function showErrors() { |
| 144 | + global $wgOut; |
| 145 | + foreach( $this->mErrors as $error ) { |
| 146 | + $this->showError( $error ); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + function doSudo() { |
| 151 | + global $wgOut, $wgUser; |
| 152 | + $u = User::newFromName( $this->mTarget ); |
| 153 | + if( is_null($u) ) return $this->addError('sudo-error-sudo-invaliduser'); |
| 154 | + if( User::isIP($u->getName()) || User::isIPv6($u->getName()) ) return $this->addError('sudo-error-ip'); |
| 155 | + if( $u->isAnon() ) return $this->addError('sudo-error-sudo-nonexistant'); |
| 156 | + if( $u->getName() === $wgUser->getName() ) return $this->addError('sudo-error-sudo-self'); |
| 157 | + |
| 158 | + $s = $wgUser->getSkin(); |
| 159 | + $log = new LogPage( 'sudo' ); |
| 160 | + $log->addEntry( 'sudo', $wgUser->getUserPage(), $this->mReason, |
| 161 | + array( $s->makeLinkObj( $u->getUserPage(), $u->getName() ) ) ); |
| 162 | + |
| 163 | + if( !isset($_SESSION['wsSudoId']) || $_SESSION['wsSudoId'] < 0 ) $_SESSION['wsSudoId'] = $wgUser->getId(); |
| 164 | + $u->setCookies(); |
| 165 | + |
| 166 | + $wgOut->redirect( $this->getTitle()->getFullURL( 'mode=success' ) ); |
| 167 | + } |
| 168 | +} |
Property changes on: trunk/extensions/Sudo/SpecialSudo.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 169 | + native |
Index: trunk/extensions/Sudo/Sudo.i18n.php |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Sudo |
| 5 | + * @package Sudo |
| 6 | + * @author Daniel Friesen (http://www.wikia.com/wiki/User:Dantman) <wiki@danielfriesen.name> |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 25 | + |
| 26 | +$messages = array(); |
| 27 | + |
| 28 | +/** English |
| 29 | + * @author Daniel Friesen |
| 30 | + */ |
| 31 | +$messages['en'] = array( |
| 32 | + 'sudo' => 'Sudo', |
| 33 | + 'unsudo' => 'Unsudo', |
| 34 | + 'sudo-personal-unsudo' => 'unsudo', |
| 35 | + 'sudo-form' => 'Sudo into:', |
| 36 | + 'sudo-user' => 'Username: ', |
| 37 | + 'sudo-reason' => 'Reason: ', |
| 38 | + 'sudo-submit' => 'sudo', |
| 39 | + 'sudo-unsudo' => 'Welcome $1, you are currently sudoed into the wiki as $2, just submit the form to return to your normal login.', |
| 40 | + 'sudo-unsudo-submit' => 'unsudo', |
| 41 | + 'sudo-success' => 'Welcome $1, you are now sudoed into the wiki as $2.', |
| 42 | + 'sudo-error' => 'Could not Sudo: $1', |
| 43 | + 'sudo-error-sudo-invaliduser' => 'Invalid Username', |
| 44 | + 'sudo-error-sudo-ip' => 'Cannot login to an IP', |
| 45 | + 'sudo-error-sudo-nonexistant' => 'That user does not exist', |
| 46 | + 'sudo-error-sudo-self' => 'Cannot sudo into yourself', |
| 47 | + 'sudo-error-nosudo' => 'You do not appear to be inside of a sudo login', |
| 48 | + 'sudo-logpagename' => 'Sudo log', |
| 49 | + 'sudo-logpagetext' => 'This is a log of all uses of sudo.', |
| 50 | + 'sudo-logentry' => 'sudoed into $2', |
| 51 | +); |
Property changes on: trunk/extensions/Sudo/Sudo.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 52 | + native |