r23936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23935‎ | r23936 | r23937 >
Date:06:22, 10 July 2007
Author:aaron
Status:old
Tags:
Comment:
*Fix rights revoke checking, document some code, alter filename a tad
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/Makevalidate.body.php (deleted) (history)
  • /trunk/extensions/FlaggedRevs/Makevalidate_body.php (added) (history)
  • /trunk/extensions/FlaggedRevs/SpecialMakevalidate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/Makevalidate.body.php
@@ -1,237 +0,0 @@
2 -<?php
3 -
4 -global $IP;
5 -require_once( "$IP/includes/LogPage.php" );
6 -require_once( "$IP/includes/SpecialLog.php" );
7 -
8 -class MakeValidate extends SpecialPage {
9 -
10 - var $target = '';
11 -
12 - /**
13 - * Constructor
14 - */
15 - function MakeValidate() {
16 - SpecialPage::SpecialPage( 'Makevalidate', 'makereview' );
17 - }
18 -
19 - /**
20 - * Main execution function
21 - * @param $par Parameters passed to the page
22 - */
23 - function execute( $par ) {
24 - global $wgRequest, $wgOut, $wgmakevalidatePrivileged, $wgUser;
25 -
26 - if( !$wgUser->isAllowed( 'makereview' ) ) {
27 - $wgOut->permissionRequired( 'makereview' );
28 - return;
29 - }
30 -
31 - $this->setHeaders();
32 -
33 - $this->target = $par
34 - ? $par
35 - : $wgRequest->getText( 'username', '' );
36 -
37 - $wgOut->addWikiText( wfMsgNoTrans( 'makevalidate-header' ) );
38 - $wgOut->addHtml( $this->makeSearchForm() );
39 -
40 - if( $this->target != '' ) {
41 - $wgOut->addHtml( wfElement( 'p', NULL, NULL ) );
42 - $user = User::newFromName( $this->target );
43 - if( is_object( $user ) && !is_null( $user ) ) {
44 - global $wgVersion;
45 - if( version_compare( $wgVersion, '1.9alpha' ) < 0 ) {
46 - $user->loadFromDatabase();
47 - } else {
48 - $user->load();
49 - }
50 - # Valid username, check existence
51 - if( $user->getID() ) {
52 - $oldgroups = $user->getGroups();
53 - if( $wgRequest->getCheck( 'dosearch' ) || !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), 'makevalidate' ) ) {
54 - # Exists, check editor & reviewer status
55 - # We never just assigned reviewer status alone
56 - if( in_array( 'editor', $user->mGroups ) && in_array( 'reviewer', $user->mGroups ) ) {
57 - # Has a reviewer flag
58 - $wgOut->addWikiText( wfMsg( 'makevalidate-iseditor', $user->getName() ) );
59 - $wgOut->addWikiText( wfMsg( 'makevalidate-isvalidator', $user->getName() ) );
60 - $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_REVOKE_REVOKE ) );
61 - } else if( in_array( 'editor', $user->mGroups ) ) {
62 - # Has a editor flag
63 - $wgOut->addWikiText( wfMsg( 'makevalidate-iseditor', $user->getName() ) );
64 - $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_REVOKE_GRANT ) );
65 - } else if( in_array( 'reviewer', $user->mGroups ) ) {
66 - # This shouldn't happen...
67 - $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_GRANT_REVOKE ) );
68 - } else {
69 - # Not a reviewer; show the grant form
70 - $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_GRANT_GRANT ) );
71 - }
72 - } elseif( $wgRequest->getCheck( 'grant2' ) ) {
73 - # Permission check
74 - if( !$wgUser->isAllowed( 'makevalidate' ) ) {
75 - $wgOut->permissionRequired( 'makevalidate' ); return;
76 - }
77 - # Grant the flag
78 - if( !in_array( 'editor', $user->mGroups ) )
79 - $user->addGroup( 'editor' );
80 - # All reviewers are editors too
81 - if( !in_array( 'reviewer', $user->mGroups ) )
82 - $user->addGroup( 'reviewer' );
83 - $this->addLogItem( 'grant2', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups);
84 - $wgOut->addWikiText( wfMsg( 'makevalidate-granted-r', $user->getName() ) );
85 - } elseif( $wgRequest->getCheck( 'revoke2' ) ) {
86 - # Permission check
87 - if( !$wgUser->isAllowed( 'makevalidate' ) ) {
88 - $wgOut->permissionRequired( 'makevalidate' ); return;
89 - }
90 - # Revoke the flag
91 - if ( in_array( 'reviewer', $user->mGroups ) )
92 - $user->removeGroup( 'reviewer' );
93 - $this->addLogItem( 'revoke2', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
94 - $wgOut->addWikiText( wfMsg( 'makevalidate-revoked-r', $user->getName() ) );
95 - } elseif( $wgRequest->getCheck( 'grant1' ) ) {
96 - # Grant the flag
97 - if( !in_array( 'editor', $user->mGroups ) )
98 - $user->addGroup( 'editor' );
99 - $this->addLogItem( 'grant1', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
100 - $wgOut->addWikiText( wfMsg( 'makevalidate-granted-e', $user->getName() ) );
101 - } elseif( $wgRequest->getCheck( 'revoke1' ) ) {
102 - if( in_array( 'reviewer', $user->mGroups ) ) {
103 - # Permission check
104 - if( !$wgUser->isAllowed( 'makevalidate' ) ) {
105 - $wgOut->permissionRequired( 'makevalidate' ); return;
106 - }
107 - # Reviewer flag falls of too
108 - $user->removeGroup( 'reviewer' );
109 - } else if( in_array( 'editor', $user->mGroups ) ) {
110 - # Revoke the flag
111 - $user->removeGroup( 'editor' );
112 - }
113 - $this->addLogItem( 'revoke1', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
114 - $wgOut->addWikiText( wfMsg( 'makevalidate-revoked-e', $user->getName() ) );
115 - }
116 - # Show log entries
117 - $this->showLogEntries( $user );
118 - } else {
119 - # Doesn't exist
120 - $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $this->target ) ) );
121 - }
122 - } else {
123 - # Invalid username
124 - $wgOut->addWikiText( wfMsg( 'noname' ) );
125 - }
126 - }
127 -
128 - }
129 -
130 - /**
131 - * Produce a form to allow for entering a username
132 - * @return string
133 - */
134 - function makeSearchForm() {
135 - $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
136 - $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
137 - $form .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'makevalidate-username' ) ) . ' ';
138 - $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'username', 'id' => 'username', 'value' => $this->target ) ) . ' ';
139 - $form .= wfElement( 'input', array( 'type' => 'submit', 'name' => 'dosearch', 'value' => wfMsg( 'makevalidate-search' ) ) );
140 - $form .= wfCloseElement( 'form' );
141 - return $form;
142 - }
143 -
144 - /**
145 - * Produce a form to allow granting or revocation of the flag
146 - * @param $type Either MW_makevalidate_GRANT or MW_makevalidate_REVOKE
147 - * where the trailing name refers to what's enabled
148 - * @return string
149 - */
150 - function makeGrantForm( $type ) {
151 - global $wgUser;
152 - $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
153 - if( $type == MW_MAKEVALIDATE_GRANT_GRANT ) {
154 - $grant1 = true; $revoke1 = false;
155 - $grant2 = true; $revoke2 = false;
156 - } else if ( $type == MW_MAKEVALIDATE_REVOKE_GRANT ) {
157 - $grant1 = false; $revoke1 = true;
158 - $grant2 = true; $revoke2 = false;
159 - } else if ( $type == MW_MAKEVALIDATE_REVOKE_REVOKE ) {
160 - $grant1 = false; $revoke1 = $wgUser->isAllowed('makevalidate');
161 - $grant2 = false; $revoke2 = true;
162 - } else {
163 - // OK, this one should never happen
164 - $grant1 = true; $revoke1 = $wgUser->isAllowed('makevalidate');
165 - $grant2 = false; $revoke2 = true;
166 - }
167 -
168 - # Start the table
169 - $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
170 - $form .= '<fieldset><legend>' . wfMsg('makevalidate-legend') . '</legend>';
171 - $form .= wfOpenElement( 'table' ) . wfOpenElement( 'tr' );
172 - # Grant/revoke buttons
173 - $form .= wfElement( 'td', array( 'align' => 'right' ), wfMsg( 'makevalidate-change-e' ) );
174 - $form .= wfOpenElement( 'td' );
175 - foreach( array( 'grant1', 'revoke1' ) as $button ) {
176 - $attribs = array( 'type' => 'submit', 'name' => $button, 'value' => wfMsg( 'makevalidate-' . $button ) );
177 - if( !$$button )
178 - $attribs['disabled'] = 'disabled';
179 - $form .= wfElement( 'input', $attribs );
180 - }
181 - $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
182 - // Check permissions
183 - if ( $wgUser->isAllowed('makevalidate') ) {
184 - $form .= wfElement( 'td', array( 'align' => 'right' ), wfMsg( 'makevalidate-change-r' ) );
185 - $form .= wfOpenElement( 'td' );
186 - foreach( array( 'grant2', 'revoke2' ) as $button ) {
187 - $attribs = array( 'type' => 'submit', 'name' => $button, 'value' => wfMsg( 'makevalidate-' . $button ) );
188 - if( !$$button )
189 - $attribs['disabled'] = 'disabled';
190 - $form .= wfElement( 'input', $attribs );
191 - }
192 - $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
193 - }
194 - # Comment field
195 - $form .= wfOpenElement( 'td', array( 'align' => 'right' ) );
196 - $form .= wfElement( 'label', array( 'for' => 'comment' ), wfMsg( 'makevalidate-comment' ) );
197 - $form .= wfOpenElement( 'td' );
198 - $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'comment', 'id' => 'comment', 'size' => 45 ) );
199 - $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
200 - # End table
201 - $form .= wfCloseElement( 'table' );
202 - # Username
203 - $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'username', 'value' => $this->target ) );
204 - # Edit token
205 - $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken( 'makevalidate' ) ) );
206 - $form .= '</fieldset>';
207 - $form .= wfCloseElement( 'form' );
208 - return $form;
209 - }
210 -
211 - /**
212 - * Add logging entries for the specified action
213 - * @param $type Either grant or revoke
214 - * @param $target User receiving the action
215 - * @param $comment Comment for the log item
216 - */
217 - function addLogItem( $type, &$target, $comment = '', $oldgroups ) {
218 - global $wgUser;
219 - $log = new LogPage( 'rights' );
220 - $targetPage = $target->getUserPage();
221 - $log->addEntry( 'rights', $targetPage, $comment, array(
222 - implode( ', ', $oldgroups ),
223 - implode( ', ', $target->getGroups() ) ) );
224 - }
225 -
226 - /**
227 - * Show the bot status log entries for the specified user
228 - * @param $user User to show the log for
229 - */
230 - function showLogEntries( &$user ) {
231 - global $wgOut;
232 - $title = $user->getUserPage();
233 - $wgOut->addHtml( wfElement( 'h2', NULL, htmlspecialchars( LogPage::logName( 'rights' ) ) ) );
234 - $logViewer = new LogViewer( new LogReader( new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'rights' ) ) ) );
235 - $logViewer->showList( $wgOut );
236 - }
237 -
238 -}
\ No newline at end of file
Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -32,11 +32,11 @@
3333 # Load promotion UI
3434 include_once('SpecialMakevalidate.php');
3535 # Load review UI
36 -extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage.body.php', 'Revisionreview', 'Revisionreview' );
 36+extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage_body.php', 'Revisionreview', 'Revisionreview' );
3737 # Load stableversions UI
38 -extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage.body.php', 'Stableversions', 'Stableversions' );
 38+extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage_body.php', 'Stableversions', 'Stableversions' );
3939 # Load unreviewed pages list
40 -extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage.body.php', 'Unreviewedpages', 'UnreviewedPages' );
 40+extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage_body.php', 'Unreviewedpages', 'UnreviewedPages' );
4141
4242 function efLoadReviewMessages() {
4343 global $wgMessageCache, $RevisionreviewMessages, $wgOut, $wgJsMimeType;
@@ -131,6 +131,7 @@
132132 $wgLogHeaders['review'] = 'review-logpagetext';
133133 $wgLogActions['review/approve'] = 'review-logentrygrant';
134134 $wgLogActions['review/unapprove'] = 'review-logentryrevoke';
 135+$wgLogActions['rights/erevoke'] = 'rights-editor-revoke';
135136
136137 class FlaggedRevs {
137138
@@ -174,6 +175,7 @@
175176 * @param int $id
176177 * @param ParserOptions $options
177178 * @param int $timeframe, when the revision was reviewed
 179+ * @returns ParserOutput
178180 * Get the HTML of a revision based on how it was during $timeframe
179181 */
180182 public static function parseStableText( $title, $text, $id=NULL, $options ) {
@@ -193,10 +195,10 @@
194196
195197 /**
196198 * @param int $rev_id
 199+ * @returns string
197200 * Get the text of a stable version
198201 */
199202 public static function getFlaggedRevText( $rev_id ) {
200 - wfProfileIn( __METHOD__ );
201203 $db = wfGetDB( DB_SLAVE );
202204 // Get the text from the flagged revisions table
203205 $result = $db->select(
@@ -208,18 +210,16 @@
209211 if( $row = $db->fetchObject($result) ) {
210212 return $row->fr_text;
211213 }
212 - wfProfileOut( __METHOD__ );
213214
214215 return NULL;
215216 }
216217
217218 /**
218219 * @param int $rev_id
219 - * Returns a revision row
 220+ * @returns Revision
220221 * Will not return if deleted
221222 */
222223 public static function getFlaggedRev( $rev_id ) {
223 - wfProfileIn( __METHOD__ );
224224 $db = wfGetDB( DB_SLAVE );
225225 // Skip deleted revisions
226226 $result = $db->select(
@@ -231,22 +231,20 @@
232232 if( $row = $db->fetchObject($result) ) {
233233 return $row;
234234 }
235 - wfProfileOut( __METHOD__ );
236235
237236 return NULL;
238237 }
239238
240239 /**
241240 * @param int $page_id
 241+ * @returns Row
242242 * Get rev ids of reviewed revs for a page
243243 * Will include deleted revs here
244244 */
245245 public static function getReviewedRevs( $page ) {
246 - $rows = array();
247 -
248 - wfProfileIn( __METHOD__ );
 246+ $rows = array();
 247+
249248 $db = wfGetDB( DB_SLAVE );
250 -
251249 $result = $db->select('flaggedrevs',
252250 array('fr_rev_id','fr_quality'),
253251 array('fr_namespace' => $page->getNamespace(), 'fr_title' => $page->getDBkey() ),
@@ -255,7 +253,6 @@
256254 while( $row = $db->fetchObject($result) ) {
257255 $rows[$row->fr_rev_id] = $row->fr_quality;
258256 }
259 - wfProfileOut( __METHOD__ );
260257
261258 return $rows;
262259 }
@@ -263,15 +260,14 @@
264261 /**
265262 * @param int $page_id
266263 * @param int $from_rev
 264+ * @returns int
267265 * Get number of revs since a certain revision
268266 */
269267 public static function getRevCountSince( $page_id, $from_rev ) {
270 - wfProfileIn( __METHOD__ );
271 - $db = wfGetDB( DB_SLAVE );
272 - $count = $db->selectField('revision', 'COUNT(*)',
 268+ $dbr = wfGetDB( DB_SLAVE );
 269+ $count = $dbr->selectField('revision', 'COUNT(*)',
273270 array('rev_page' => $page_id, "rev_id > $from_rev"),
274271 __METHOD__ );
275 - wfProfileOut( __METHOD__ );
276272
277273 return $count;
278274 }
@@ -284,7 +280,7 @@
285281 return null;
286282
287283 $dbr = wfGetDB( DB_SLAVE );
288 - // Skip deleted revisions
 284+ // Look for quality revision
289285 $result = $dbr->select(
290286 array('flaggedrevs', 'revision'),
291287 array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'),
@@ -292,7 +288,7 @@
293289 'fr_rev_id = rev_id', 'rev_page' => $title->getArticleID(), 'rev_deleted = 0'),
294290 __METHOD__,
295291 array('ORDER BY' => 'fr_rev_id DESC', 'LIMIT' => 1 ) );
296 - // Do we have one?
 292+ // Do we have one? If not, try any reviewed revision...
297293 if( !$row = $dbr->fetchObject($result) ) {
298294 $result = $dbr->select(
299295 array('flaggedrevs', 'revision'),
@@ -318,7 +314,6 @@
319315 $flags[$tag] = 0;
320316 }
321317
322 - wfProfileIn( __METHOD__ );
323318 $db = wfGetDB( DB_SLAVE );
324319 // Grab all the tags for this revision
325320 $result = $db->select('flaggedrevtags',
@@ -329,16 +324,26 @@
330325 while ( $row = $db->fetchObject($result) ) {
331326 $flags[$row->frt_dimension] = $row->frt_value;
332327 }
333 - wfProfileOut( __METHOD__ );
334 -
335328 return $flags;
336329 }
337330
 331+ /**
 332+ * @param int $title
 333+ * @returns bool
 334+ * Is $title the main page?
 335+ */
338336 public static function isMainPage( $title ) {
339337 $mp = Title::newMainPage();
340338 return ( $title->getNamespace()==$mp->getNamespace() && $title->getDBKey()==$mp->getDBKey() );
341339 }
342 -
 340+
 341+ /**
 342+ * @param array $flags
 343+ * @param bool $prettybox
 344+ * @param string $css
 345+ * @returns string
 346+ * Generates a review box/tag
 347+ */
343348 public function addTagRatings( $flags, $prettyBox = false, $css='' ) {
344349 global $wgFlaggedRevTags;
345350
@@ -373,7 +378,14 @@
374379
375380 return $tag;
376381 }
377 -
 382+
 383+ /**
 384+ * @param Row $trev, flagged revision row
 385+ * @param array $flags
 386+ * @param int $rev_since, revisions since review
 387+ * @returns string
 388+ * Generates a review box using a table using addTagRatings()
 389+ */
378390 function prettyRatingBox( $tfrev, $flags, $revs_since, $simpleTag=false ) {
379391 global $wgLang, $wgUser;
380392
@@ -404,7 +416,12 @@
405417
406418 return $box;
407419 }
408 -
 420+
 421+ /**
 422+ * @param Row $row
 423+ * @returns string
 424+ * Generates revision review notes
 425+ */
409426 public static function ReviewNotes( $row ) {
410427 global $wgUser, $wgFlaggedRevComments;
411428
@@ -422,7 +439,7 @@
423440
424441 /**
425442 * @param Array $flags
426 - * @output bool, is this revision at quality condition?
 443+ * @returns bool, is this revision at quality condition?
427444 */
428445 public static function isQuality( $flags ) {
429446 global $wgFlaggedRevTags;
@@ -435,7 +452,7 @@
436453
437454 /**
438455 * @param Array $flags
439 - * @output bool, is this revision at optimal condition?
 456+ * @returns bool, is this revision at optimal condition?
440457 */
441458 public static function isPristine( $flags ) {
442459 global $wgFlaggedRevValues;
@@ -448,7 +465,7 @@
449466
450467 /**
451468 * @param Array $flags
452 - * @output integer, lowest rating level
 469+ * @returns integer, lowest rating level
453470 */
454471 public static function getLCQuality( $flags ) {
455472 global $wgFlaggedRevValues;
@@ -462,6 +479,7 @@
463480
464481 /**
465482 * @param Article $article
 483+ * @returns ParserOutput
466484 * Get the page cache for the top stable revision of an article
467485 */
468486 public static function getPageCache( $article ) {
@@ -775,38 +793,38 @@
776794 $now = time();
777795 $usercreation = wfTimestamp(TS_UNIX,$user->mRegistration);
778796 $userage = floor(($now-$usercreation) / 86400);
779 - // Do not give this to bots
780 - if( in_array( 'bot', $groups ) )
 797+ // Do not give this to current holders or bots
 798+ if( in_array( array('bot','editor'), $groups ) )
781799 return true;
782800 // Check if we need to promote...
783 - $vars = $wgFlaggedRevsAutopromote;
784 - if( !in_array('editor',$groups) && $userage >= $vars['days'] && $user->getEditCount() >= $vars['edits']
785 - && ( !$vars['email'] || $wgUser->isAllowed('emailconfirmed') ) ) {
786 - $fname = 'FlaggedRevs::autoPromoteUser';
787 -
788 - # Do not re-add status if it was previously removed...
789 - $db = wfGetDB( DB_MASTER );
790 - $removed = $dbw->selectField( 'logging', '1',
791 - array( 'log_namespace' => NS_USER,
792 - 'log_title' => $wgUser->getName(),
793 - 'log_type' => 'rights',
794 - "log_params LIKE '%editor%'" ),
795 - __METHOD__,
796 - array('FORCE INDEX' => 'page_time') );
 801+ if( $userage < $wgFlaggedRevsAutopromote['days'] )
 802+ return true;
 803+ if( $user->getEditCount() < $wgFlaggedRevsAutopromote['edits'] )
 804+ return true;
 805+ if( $wgFlaggedRevsAutopromote['email'] && !$wgUser->isAllowed('emailconfirmed') )
 806+ return true;
 807+ # Do not re-add status if it was previously removed...
 808+ $db = wfGetDB( DB_MASTER );
 809+ $removed = $dbw->selectField( 'logging', '1',
 810+ array( 'log_namespace' => NS_USER,
 811+ 'log_title' => $wgUser->getName(),
 812+ 'log_type' => 'rights',
 813+ 'log_action' => 'erevoke' ),
 814+ __METHOD__,
 815+ array('FORCE INDEX' => 'page_time') );
797816
798 - if( $removed===false ) {
799 - $newGroups = $groups ;
800 - array_push( $newGroups, 'editor');
 817+ if( $removed===false ) {
 818+ $newGroups = $groups ;
 819+ array_push( $newGroups, 'editor');
801820
802 - # Lets NOT spam RC, set $RC to false
803 - $log = new LogPage( 'rights', false );
804 - $log->addEntry('rights', $user->getUserPage(), wfMsgHtml('makevalidate-autosum'),
805 - array( makeGroupNameList( $groups ), makeGroupNameList( $newGroups ) ) );
 821+ # Lets NOT spam RC, set $RC to false
 822+ $log = new LogPage( 'rights', false );
 823+ $log->addEntry('rights', $user->getUserPage(), wfMsgHtml('makevalidate-autosum'),
 824+ array( implode(', ',$groups), implode(', ',$newGroups) ) );
806825
807 - $user->addGroup('editor');
808 - }
 826+ $user->addGroup('editor');
809827 }
810 - return true;
 828+ return true;
811829 }
812830 }
813831
@@ -1394,10 +1412,6 @@
13951413
13961414 }
13971415
1398 -function makeGroupNameList( $ids ) {
1399 - return implode( ', ', $ids );
1400 -}
1401 -
14021416 // Our class instances
14031417 $flaggedRevsModifier = new FlaggedArticle();
14041418 // Main hooks, overrides pages content, adds tags, sets tabs and permalink
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php
@@ -111,6 +111,8 @@
112112 'viewunreviewed' => 'List unreviewed content pages',
113113 'included-nonquality' => 'Show only reviewed pages not marked as quality.',
114114 'unreviewed-list' => 'This page lists articles that have not yet been reviewed.',
 115+
 116+ 'rights-editor-revoke' => 'removed editor status from [[$1]]',
115117 );
116118
117119 // German (Raimond Spekking)
Index: trunk/extensions/FlaggedRevs/Makevalidate_body.php
@@ -0,0 +1,240 @@
 2+<?php
 3+
 4+global $IP;
 5+require_once( "$IP/includes/LogPage.php" );
 6+require_once( "$IP/includes/SpecialLog.php" );
 7+
 8+class MakeValidate extends SpecialPage {
 9+
 10+ var $target = '';
 11+
 12+ /**
 13+ * Constructor
 14+ */
 15+ function MakeValidate() {
 16+ SpecialPage::SpecialPage( 'Makevalidate', 'makereview' );
 17+ }
 18+
 19+ /**
 20+ * Main execution function
 21+ * @param $par Parameters passed to the page
 22+ */
 23+ function execute( $par ) {
 24+ global $wgRequest, $wgOut, $wgmakevalidatePrivileged, $wgUser;
 25+
 26+ if( !$wgUser->isAllowed( 'makereview' ) ) {
 27+ $wgOut->permissionRequired( 'makereview' );
 28+ return;
 29+ }
 30+
 31+ $this->setHeaders();
 32+
 33+ $this->target = $par ? $par : $wgRequest->getText( 'username', '' );
 34+
 35+ $wgOut->addWikiText( wfMsgNoTrans( 'makevalidate-header' ) );
 36+ $wgOut->addHtml( $this->makeSearchForm() );
 37+
 38+ if( $this->target != '' ) {
 39+ $wgOut->addHtml( wfElement( 'p', NULL, NULL ) );
 40+ $user = User::newFromName( $this->target );
 41+ if( is_object( $user ) && !is_null( $user ) ) {
 42+ global $wgVersion;
 43+ if( version_compare( $wgVersion, '1.9alpha' ) < 0 ) {
 44+ $user->loadFromDatabase();
 45+ } else {
 46+ $user->load();
 47+ }
 48+ # Valid username, check existence
 49+ if( $user->getID() ) {
 50+ $oldgroups = $user->getGroups();
 51+ if( $wgRequest->getCheck( 'dosearch' ) || !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ), 'makevalidate' ) ) {
 52+ # Exists, check editor & reviewer status
 53+ # We never just assigned reviewer status alone
 54+ if( in_array( 'editor', $user->mGroups ) && in_array( 'reviewer', $user->mGroups ) ) {
 55+ # Has a reviewer flag
 56+ $wgOut->addWikiText( wfMsg( 'makevalidate-iseditor', $user->getName() ) );
 57+ $wgOut->addWikiText( wfMsg( 'makevalidate-isvalidator', $user->getName() ) );
 58+ $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_REVOKE_REVOKE ) );
 59+ } else if( in_array( 'editor', $user->mGroups ) ) {
 60+ # Has a editor flag
 61+ $wgOut->addWikiText( wfMsg( 'makevalidate-iseditor', $user->getName() ) );
 62+ $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_REVOKE_GRANT ) );
 63+ } else if( in_array( 'reviewer', $user->mGroups ) ) {
 64+ # This shouldn't happen...
 65+ $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_GRANT_REVOKE ) );
 66+ } else {
 67+ # Not a reviewer; show the grant form
 68+ $wgOut->addHtml( $this->makeGrantForm( MW_MAKEVALIDATE_GRANT_GRANT ) );
 69+ }
 70+ } elseif( $wgRequest->getCheck( 'grant2' ) ) {
 71+ # Permission check
 72+ if( !$wgUser->isAllowed( 'makevalidate' ) ) {
 73+ $wgOut->permissionRequired( 'makevalidate' ); return;
 74+ }
 75+ # Grant the flag
 76+ if( !in_array( 'reviewer', $user->mGroups ) )
 77+ $user->addGroup( 'reviewer' );
 78+ # All reviewers are editors too
 79+ if( !in_array( 'editor', $user->mGroups ) )
 80+ $user->addGroup( 'editor' );
 81+ $this->addLogItem( 'rights', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups);
 82+ $wgOut->addWikiText( wfMsg( 'makevalidate-granted-r', $user->getName() ) );
 83+ } elseif( $wgRequest->getCheck( 'revoke2' ) ) {
 84+ # Permission check
 85+ if( !$wgUser->isAllowed( 'makevalidate' ) ) {
 86+ $wgOut->permissionRequired( 'makevalidate' ); return;
 87+ }
 88+ # Revoke the flag
 89+ if ( in_array( 'reviewer', $user->mGroups ) )
 90+ $user->removeGroup( 'reviewer' );
 91+ $this->addLogItem( 'rights', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
 92+ $wgOut->addWikiText( wfMsg( 'makevalidate-revoked-r', $user->getName() ) );
 93+ } elseif( $wgRequest->getCheck( 'grant1' ) ) {
 94+ # Grant the flag
 95+ if( !in_array( 'editor', $user->mGroups ) )
 96+ $user->addGroup( 'editor' );
 97+ $this->addLogItem( 'rights', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
 98+ $wgOut->addWikiText( wfMsg( 'makevalidate-granted-e', $user->getName() ) );
 99+ } elseif( $wgRequest->getCheck( 'revoke1' ) ) {
 100+ if( in_array( 'reviewer', $user->mGroups ) ) {
 101+ # Permission check
 102+ if( !$wgUser->isAllowed( 'makevalidate' ) ) {
 103+ $wgOut->permissionRequired( 'makevalidate' );
 104+ return;
 105+ }
 106+ $user->removeGroup( 'editor' );
 107+ # Reviewer flag falls of too
 108+ $user->removeGroup( 'reviewer' );
 109+ } else if( in_array( 'editor', $user->mGroups ) ) {
 110+ # Revoke the flag
 111+ $user->removeGroup( 'editor' );
 112+ }
 113+ $this->addLogItem( 'erevoke', $user, trim( $wgRequest->getText( 'comment' ) ), $oldgroups );
 114+ $wgOut->addWikiText( wfMsg( 'makevalidate-revoked-e', $user->getName() ) );
 115+ }
 116+ # Show log entries
 117+ $this->showLogEntries( $user );
 118+ } else {
 119+ # Doesn't exist
 120+ $wgOut->addWikiText( wfMsg( 'nosuchusershort', htmlspecialchars( $this->target ) ) );
 121+ }
 122+ } else {
 123+ # Invalid username
 124+ $wgOut->addWikiText( wfMsg( 'noname' ) );
 125+ }
 126+ }
 127+
 128+ }
 129+
 130+ /**
 131+ * Produce a form to allow for entering a username
 132+ * @return string
 133+ */
 134+ function makeSearchForm() {
 135+ $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
 136+ $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
 137+ $form .= wfElement( 'label', array( 'for' => 'username' ), wfMsg( 'makevalidate-username' ) ) . ' ';
 138+ $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'username', 'id' => 'username', 'value' => $this->target ) ) . ' ';
 139+ $form .= wfElement( 'input', array( 'type' => 'submit', 'name' => 'dosearch', 'value' => wfMsg( 'makevalidate-search' ) ) );
 140+ $form .= wfCloseElement( 'form' );
 141+ return $form;
 142+ }
 143+
 144+ /**
 145+ * Produce a form to allow granting or revocation of the flag
 146+ * @param $type Either MW_makevalidate_GRANT or MW_makevalidate_REVOKE
 147+ * where the trailing name refers to what's enabled
 148+ * @return string
 149+ */
 150+ function makeGrantForm( $type ) {
 151+ global $wgUser;
 152+ $thisTitle = Title::makeTitle( NS_SPECIAL, $this->getName() );
 153+ if( $type == MW_MAKEVALIDATE_GRANT_GRANT ) {
 154+ $grant1 = true; $revoke1 = false;
 155+ $grant2 = true; $revoke2 = false;
 156+ } else if ( $type == MW_MAKEVALIDATE_REVOKE_GRANT ) {
 157+ $grant1 = false; $revoke1 = true;
 158+ $grant2 = true; $revoke2 = false;
 159+ } else if ( $type == MW_MAKEVALIDATE_REVOKE_REVOKE ) {
 160+ $grant1 = false; $revoke1 = $wgUser->isAllowed('makevalidate');
 161+ $grant2 = false; $revoke2 = true;
 162+ } else {
 163+ // OK, this one should never happen
 164+ $grant1 = true; $revoke1 = $wgUser->isAllowed('makevalidate');
 165+ $grant2 = false; $revoke2 = true;
 166+ }
 167+
 168+ # Start the table
 169+ $form = wfOpenElement( 'form', array( 'method' => 'post', 'action' => $thisTitle->getLocalUrl() ) );
 170+ $form .= '<fieldset><legend>' . wfMsg('makevalidate-legend') . '</legend>';
 171+ $form .= wfOpenElement( 'table' ) . wfOpenElement( 'tr' );
 172+ # Grant/revoke buttons
 173+ $form .= wfElement( 'td', array( 'align' => 'right' ), wfMsg( 'makevalidate-change-e' ) );
 174+ $form .= wfOpenElement( 'td' );
 175+ foreach( array( 'grant1', 'revoke1' ) as $button ) {
 176+ $attribs = array( 'type' => 'submit', 'name' => $button, 'value' => wfMsg( 'makevalidate-' . $button ) );
 177+ if( !$$button )
 178+ $attribs['disabled'] = 'disabled';
 179+ $form .= wfElement( 'input', $attribs );
 180+ }
 181+ $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
 182+ // Check permissions
 183+ if ( $wgUser->isAllowed('makevalidate') ) {
 184+ $form .= wfElement( 'td', array( 'align' => 'right' ), wfMsg( 'makevalidate-change-r' ) );
 185+ $form .= wfOpenElement( 'td' );
 186+ foreach( array( 'grant2', 'revoke2' ) as $button ) {
 187+ $attribs = array( 'type' => 'submit', 'name' => $button, 'value' => wfMsg( 'makevalidate-' . $button ) );
 188+ if( !$$button )
 189+ $attribs['disabled'] = 'disabled';
 190+ $form .= wfElement( 'input', $attribs );
 191+ }
 192+ $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
 193+ }
 194+ # Comment field
 195+ $form .= wfOpenElement( 'td', array( 'align' => 'right' ) );
 196+ $form .= wfElement( 'label', array( 'for' => 'comment' ), wfMsg( 'makevalidate-comment' ) );
 197+ $form .= wfOpenElement( 'td' );
 198+ $form .= wfElement( 'input', array( 'type' => 'text', 'name' => 'comment', 'id' => 'comment', 'size' => 45 ) );
 199+ $form .= wfCloseElement( 'td' ) . wfCloseElement( 'tr' );
 200+ # End table
 201+ $form .= wfCloseElement( 'table' );
 202+ # Username
 203+ $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'username', 'value' => $this->target ) );
 204+ # Edit token
 205+ $form .= wfElement( 'input', array( 'type' => 'hidden', 'name' => 'token', 'value' => $wgUser->editToken( 'makevalidate' ) ) );
 206+ $form .= '</fieldset>';
 207+ $form .= wfCloseElement( 'form' );
 208+ return $form;
 209+ }
 210+
 211+ /**
 212+ * Add logging entries for the specified action
 213+ * @param $type Either grant or revoke
 214+ * @param $user User receiving the action
 215+ * @param $comment Comment for the log item
 216+ */
 217+ function addLogItem( $type, &$user, $comment = '', $oldgroups ) {
 218+ global $wgUser;
 219+
 220+ $log = new LogPage( 'rights' );
 221+ $targetPage = $user->getUserPage();
 222+ $newgroups = $user->getGroups();
 223+
 224+ $log->addEntry( $type, $targetPage, $comment,
 225+ array( implode( ', ',$oldgroups ), implode( ', ',$newgroups ) )
 226+ );
 227+ }
 228+
 229+ /**
 230+ * Show the bot status log entries for the specified user
 231+ * @param $user User to show the log for
 232+ */
 233+ function showLogEntries( &$user ) {
 234+ global $wgOut;
 235+ $title = $user->getUserPage();
 236+ $wgOut->addHtml( wfElement( 'h2', NULL, htmlspecialchars( LogPage::logName( 'rights' ) ) ) );
 237+ $logViewer = new LogViewer( new LogReader( new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'rights' ) ) ) );
 238+ $logViewer->showList( $wgOut );
 239+ }
 240+
 241+}
\ No newline at end of file
Index: trunk/extensions/FlaggedRevs/SpecialMakevalidate.php
@@ -36,7 +36,7 @@
3737 /**
3838 * Register the special page
3939 */
40 - extAddSpecialPage( dirname(__FILE__) . '/Makevalidate.body.php', 'Makevalidate', 'makevalidate' );
 40+ extAddSpecialPage( dirname(__FILE__) . '/Makevalidate_body.php', 'Makevalidate', 'makevalidate' );
4141
4242 /**
4343 * Populate the message cache and set up the auditing

Status & tagging log