Index: trunk/extensions/Makebot/Makebot.class.php |
— | — | @@ -14,19 +14,19 @@ |
15 | 15 | function MakeBot() { |
16 | 16 | SpecialPage::SpecialPage( 'Makebot', 'makebot' ); |
17 | 17 | } |
18 | | - |
| 18 | + |
19 | 19 | /** |
20 | 20 | * Main execution function |
21 | 21 | * @param $par Parameters passed to the page |
22 | 22 | */ |
23 | 23 | function execute( $par ) { |
24 | 24 | global $wgRequest, $wgOut, $wgMakeBotPrivileged, $wgUser; |
25 | | - |
| 25 | + |
26 | 26 | if( !$wgUser->isAllowed( 'makebot' ) ) { |
27 | 27 | $wgOut->permissionRequired( 'makebot' ); |
28 | 28 | return; |
29 | 29 | } |
30 | | - |
| 30 | + |
31 | 31 | $this->setHeaders(); |
32 | 32 | |
33 | 33 | $this->target = $par |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | |
37 | 37 | $wgOut->addWikiText( wfMsgNoTrans( 'makebot-header' ) ); |
38 | 38 | $wgOut->addHtml( $this->makeSearchForm() ); |
39 | | - |
| 39 | + |
40 | 40 | if( $this->target != '' ) { |
41 | 41 | $wgOut->addHtml( wfElement( 'p', NULL, NULL ) ); |
42 | 42 | $user = User::newFromName( $this->target ); |
— | — | @@ -49,34 +49,35 @@ |
50 | 50 | # Valid username, check existence |
51 | 51 | if( $user->getID() ) { |
52 | 52 | # 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() ) ); |
80 | 78 | } |
| 79 | + # Show log entries |
| 80 | + $this->showLogEntries( $user, 'makebot' ); |
| 81 | + $this->showLogEntries( $user, 'rights' ); |
81 | 82 | } else { |
82 | 83 | # Doesn't exist |
83 | 84 | $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $this->target ) ) ); |
— | — | @@ -86,9 +87,8 @@ |
87 | 88 | $wgOut->addWikiText( wfMsg( 'noname' ) ); |
88 | 89 | } |
89 | 90 | } |
90 | | - |
91 | 91 | } |
92 | | - |
| 92 | + |
93 | 93 | /** |
94 | 94 | * Produce a form to allow for entering a username |
95 | 95 | * @return string |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | $form .= wfCloseElement( 'form' ); |
104 | 104 | return $form; |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | /** |
108 | 108 | * Produce a form to allow granting or revocation of the flag |
109 | 109 | * @param $type Either MW_MAKEBOT_GRANT or MW_MAKEBOT_REVOKE |
— | — | @@ -119,7 +119,7 @@ |
120 | 120 | $grant = false; |
121 | 121 | $revoke = true; |
122 | 122 | } |
123 | | - |
| 123 | + |
124 | 124 | # Start the table |
125 | 125 | $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) ); |
126 | 126 | $form .= wfOpenElement( 'table' ) . wfOpenElement( 'tr' ); |
— | — | @@ -160,16 +160,16 @@ |
161 | 161 | $targetPage = $target->getUserPage(); |
162 | 162 | $log->addEntry( $type, $targetPage, $comment ); |
163 | 163 | } |
164 | | - |
| 164 | + |
165 | 165 | /** |
166 | 166 | * Show the bot status log entries for the specified user |
167 | 167 | * @param $user User to show the log for |
168 | 168 | */ |
169 | | - function showLogEntries( &$user ) { |
| 169 | + function showLogEntries( &$user, $logtype = 'makebot' ) { |
170 | 170 | global $wgOut; |
171 | 171 | $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 ) ) ) ); |
174 | 174 | $logViewer->showList( $wgOut ); |
175 | 175 | } |
176 | 176 | |
— | — | @@ -186,7 +186,4 @@ |
187 | 187 | ( !in_array( 'sysop', $user->mGroups ) && |
188 | 188 | !in_array( 'bureaucrat', $user->mGroups ) ); |
189 | 189 | } |
190 | | - |
191 | 190 | } |
192 | | - |
193 | | - |