r26307 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r26306‎ | r26307 | r26308 >
Date:10:34, 2 October 2007
Author:raymond
Status:old
Tags:
Comment:
* Allow revocation of bot flag when user has got sysop/bureaucrat status in the meantime
* Show userrights log additional to bot log for convenience too.
* Kill whitespaces
Modified paths:
  • /trunk/extensions/Makebot/Makebot.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Makebot/Makebot.class.php
@@ -14,19 +14,19 @@
1515 function MakeBot() {
1616 SpecialPage::SpecialPage( 'Makebot', 'makebot' );
1717 }
18 -
 18+
1919 /**
2020 * Main execution function
2121 * @param $par Parameters passed to the page
2222 */
2323 function execute( $par ) {
2424 global $wgRequest, $wgOut, $wgMakeBotPrivileged, $wgUser;
25 -
 25+
2626 if( !$wgUser->isAllowed( 'makebot' ) ) {
2727 $wgOut->permissionRequired( 'makebot' );
2828 return;
2929 }
30 -
 30+
3131 $this->setHeaders();
3232
3333 $this->target = $par
@@ -35,7 +35,7 @@
3636
3737 $wgOut->addWikiText( wfMsgNoTrans( 'makebot-header' ) );
3838 $wgOut->addHtml( $this->makeSearchForm() );
39 -
 39+
4040 if( $this->target != '' ) {
4141 $wgOut->addHtml( wfElement( 'p', NULL, NULL ) );
4242 $user = User::newFromName( $this->target );
@@ -49,34 +49,35 @@
5050 # Valid username, check existence
5151 if( $user->getID() ) {
5252 # Exists; check current privileges
53 - if( $this->canBecomeBot( $user ) ) {
54 - if( $wgRequest->getCheck( 'dosearch' ) || !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), 'makebot' ) ) {
55 - # Exists, check botness
56 - if( in_array( 'bot', $user->mGroups ) ) {
57 - # Has a bot flag
58 - $wgOut->addWikiText( wfMsg( 'makebot-isbot', $user->getName() ) );
59 - $wgOut->addHtml( $this->makeGrantForm( MW_MAKEBOT_REVOKE ) );
60 - } else {
61 - # Not a bot; show the grant form
62 - $wgOut->addHtml( $this->makeGrantForm( MW_MAKEBOT_GRANT ) );
63 - }
64 - } elseif( $wgRequest->getCheck( 'grant' ) ) {
65 - # Grant the flag
66 - $user->addGroup( 'bot' );
67 - $this->addLogItem( 'grant', $user, trim( $wgRequest->getText( 'comment' ) ) );
68 - $wgOut->addWikiText( wfMsg( 'makebot-granted', $user->getName() ) );
69 - } elseif( $wgRequest->getCheck( 'revoke' ) ) {
70 - # Revoke the flag
71 - $user->removeGroup( 'bot' );
72 - $this->addLogItem( 'revoke', $user, trim( $wgRequest->getText( 'comment' ) ) );
73 - $wgOut->addWikiText( wfMsg( 'makebot-revoked', $user->getName() ) );
74 - }
75 - # Show log entries
76 - $this->showLogEntries( $user );
77 - } else {
78 - # User account is privileged and can't be given a bot flag
79 - $wgOut->addWikiText( wfMsg( 'makebot-privileged', $user->getName() ) );
 53+ $canBecomeBot = $this->canBecomeBot( $user );
 54+ if( $wgRequest->getCheck( 'dosearch' ) || !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), 'makebot' ) ) {
 55+ # Exists, check botness
 56+ if( in_array( 'bot', $user->mGroups ) ) {
 57+ # Has a bot flag
 58+ $wgOut->addWikiText( wfMsg( 'makebot-isbot', $user->getName() ) );
 59+ $wgOut->addHtml( $this->makeGrantForm( MW_MAKEBOT_REVOKE ) );
 60+ } elseif ( $canBecomeBot ) {
 61+ # Not a bot; show the grant form
 62+ $wgOut->addWikiText( wfMsg( 'makebot-notbot', $user->getName() ) );
 63+ $wgOut->addHtml( $this->makeGrantForm( MW_MAKEBOT_GRANT ) );
 64+ } else {
 65+ # User account is privileged and can't be given a bot flag
 66+ $wgOut->addWikiText( wfMsg( 'makebot-privileged', $user->getName() ) );
 67+ }
 68+ } elseif( $canBecomeBot && $wgRequest->getCheck( 'grant' ) ) {
 69+ # Grant the flag
 70+ $user->addGroup( 'bot' );
 71+ $this->addLogItem( 'grant', $user, trim( $wgRequest->getText( 'comment' ) ) );
 72+ $wgOut->addWikiText( wfMsg( 'makebot-granted', $user->getName() ) );
 73+ } elseif( $wgRequest->getCheck( 'revoke' ) ) {
 74+ # Revoke the flag, also if bot has got sysop/bureaucrat status in the meantime
 75+ $user->removeGroup( 'bot' );
 76+ $this->addLogItem( 'revoke', $user, trim( $wgRequest->getText( 'comment' ) ) );
 77+ $wgOut->addWikiText( wfMsg( 'makebot-revoked', $user->getName() ) );
8078 }
 79+ # Show log entries
 80+ $this->showLogEntries( $user, 'makebot' );
 81+ $this->showLogEntries( $user, 'rights' );
8182 } else {
8283 # Doesn't exist
8384 $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $this->target ) ) );
@@ -86,9 +87,8 @@
8788 $wgOut->addWikiText( wfMsg( 'noname' ) );
8889 }
8990 }
90 -
9191 }
92 -
 92+
9393 /**
9494 * Produce a form to allow for entering a username
9595 * @return string
@@ -102,7 +102,7 @@
103103 $form .= wfCloseElement( 'form' );
104104 return $form;
105105 }
106 -
 106+
107107 /**
108108 * Produce a form to allow granting or revocation of the flag
109109 * @param $type Either MW_MAKEBOT_GRANT or MW_MAKEBOT_REVOKE
@@ -119,7 +119,7 @@
120120 $grant = false;
121121 $revoke = true;
122122 }
123 -
 123+
124124 # Start the table
125125 $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
126126 $form .= wfOpenElement( 'table' ) . wfOpenElement( 'tr' );
@@ -160,16 +160,16 @@
161161 $targetPage = $target->getUserPage();
162162 $log->addEntry( $type, $targetPage, $comment );
163163 }
164 -
 164+
165165 /**
166166 * Show the bot status log entries for the specified user
167167 * @param $user User to show the log for
168168 */
169 - function showLogEntries( &$user ) {
 169+ function showLogEntries( &$user, $logtype = 'makebot' ) {
170170 global $wgOut;
171171 $title = $user->getUserPage();
172 - $wgOut->addHtml( wfElement( 'h2', NULL, htmlspecialchars( LogPage::logName( 'makebot' ) ) ) );
173 - $logViewer = new LogViewer( new LogReader( new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'makebot' ) ) ) );
 172+ $wgOut->addHtml( wfElement( 'h2', NULL, htmlspecialchars( LogPage::logName( $logtype ) ) ) );
 173+ $logViewer = new LogViewer( new LogReader( new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => $logtype ) ) ) );
174174 $logViewer->showList( $wgOut );
175175 }
176176
@@ -186,7 +186,4 @@
187187 ( !in_array( 'sysop', $user->mGroups ) &&
188188 !in_array( 'bureaucrat', $user->mGroups ) );
189189 }
190 -
191190 }
192 -
193 -

Status & tagging log