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 @@ |
33 | 33 | # Load promotion UI |
34 | 34 | include_once('SpecialMakevalidate.php'); |
35 | 35 | # Load review UI |
36 | | -extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage.body.php', 'Revisionreview', 'Revisionreview' ); |
| 36 | +extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage_body.php', 'Revisionreview', 'Revisionreview' ); |
37 | 37 | # Load stableversions UI |
38 | | -extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage.body.php', 'Stableversions', 'Stableversions' ); |
| 38 | +extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage_body.php', 'Stableversions', 'Stableversions' ); |
39 | 39 | # Load unreviewed pages list |
40 | | -extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage.body.php', 'Unreviewedpages', 'UnreviewedPages' ); |
| 40 | +extAddSpecialPage( dirname(__FILE__) . '/FlaggedRevsPage_body.php', 'Unreviewedpages', 'UnreviewedPages' ); |
41 | 41 | |
42 | 42 | function efLoadReviewMessages() { |
43 | 43 | global $wgMessageCache, $RevisionreviewMessages, $wgOut, $wgJsMimeType; |
— | — | @@ -131,6 +131,7 @@ |
132 | 132 | $wgLogHeaders['review'] = 'review-logpagetext'; |
133 | 133 | $wgLogActions['review/approve'] = 'review-logentrygrant'; |
134 | 134 | $wgLogActions['review/unapprove'] = 'review-logentryrevoke'; |
| 135 | +$wgLogActions['rights/erevoke'] = 'rights-editor-revoke'; |
135 | 136 | |
136 | 137 | class FlaggedRevs { |
137 | 138 | |
— | — | @@ -174,6 +175,7 @@ |
175 | 176 | * @param int $id |
176 | 177 | * @param ParserOptions $options |
177 | 178 | * @param int $timeframe, when the revision was reviewed |
| 179 | + * @returns ParserOutput |
178 | 180 | * Get the HTML of a revision based on how it was during $timeframe |
179 | 181 | */ |
180 | 182 | public static function parseStableText( $title, $text, $id=NULL, $options ) { |
— | — | @@ -193,10 +195,10 @@ |
194 | 196 | |
195 | 197 | /** |
196 | 198 | * @param int $rev_id |
| 199 | + * @returns string |
197 | 200 | * Get the text of a stable version |
198 | 201 | */ |
199 | 202 | public static function getFlaggedRevText( $rev_id ) { |
200 | | - wfProfileIn( __METHOD__ ); |
201 | 203 | $db = wfGetDB( DB_SLAVE ); |
202 | 204 | // Get the text from the flagged revisions table |
203 | 205 | $result = $db->select( |
— | — | @@ -208,18 +210,16 @@ |
209 | 211 | if( $row = $db->fetchObject($result) ) { |
210 | 212 | return $row->fr_text; |
211 | 213 | } |
212 | | - wfProfileOut( __METHOD__ ); |
213 | 214 | |
214 | 215 | return NULL; |
215 | 216 | } |
216 | 217 | |
217 | 218 | /** |
218 | 219 | * @param int $rev_id |
219 | | - * Returns a revision row |
| 220 | + * @returns Revision |
220 | 221 | * Will not return if deleted |
221 | 222 | */ |
222 | 223 | public static function getFlaggedRev( $rev_id ) { |
223 | | - wfProfileIn( __METHOD__ ); |
224 | 224 | $db = wfGetDB( DB_SLAVE ); |
225 | 225 | // Skip deleted revisions |
226 | 226 | $result = $db->select( |
— | — | @@ -231,22 +231,20 @@ |
232 | 232 | if( $row = $db->fetchObject($result) ) { |
233 | 233 | return $row; |
234 | 234 | } |
235 | | - wfProfileOut( __METHOD__ ); |
236 | 235 | |
237 | 236 | return NULL; |
238 | 237 | } |
239 | 238 | |
240 | 239 | /** |
241 | 240 | * @param int $page_id |
| 241 | + * @returns Row |
242 | 242 | * Get rev ids of reviewed revs for a page |
243 | 243 | * Will include deleted revs here |
244 | 244 | */ |
245 | 245 | public static function getReviewedRevs( $page ) { |
246 | | - $rows = array(); |
247 | | - |
248 | | - wfProfileIn( __METHOD__ ); |
| 246 | + $rows = array(); |
| 247 | + |
249 | 248 | $db = wfGetDB( DB_SLAVE ); |
250 | | - |
251 | 249 | $result = $db->select('flaggedrevs', |
252 | 250 | array('fr_rev_id','fr_quality'), |
253 | 251 | array('fr_namespace' => $page->getNamespace(), 'fr_title' => $page->getDBkey() ), |
— | — | @@ -255,7 +253,6 @@ |
256 | 254 | while( $row = $db->fetchObject($result) ) { |
257 | 255 | $rows[$row->fr_rev_id] = $row->fr_quality; |
258 | 256 | } |
259 | | - wfProfileOut( __METHOD__ ); |
260 | 257 | |
261 | 258 | return $rows; |
262 | 259 | } |
— | — | @@ -263,15 +260,14 @@ |
264 | 261 | /** |
265 | 262 | * @param int $page_id |
266 | 263 | * @param int $from_rev |
| 264 | + * @returns int |
267 | 265 | * Get number of revs since a certain revision |
268 | 266 | */ |
269 | 267 | 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(*)', |
273 | 270 | array('rev_page' => $page_id, "rev_id > $from_rev"), |
274 | 271 | __METHOD__ ); |
275 | | - wfProfileOut( __METHOD__ ); |
276 | 272 | |
277 | 273 | return $count; |
278 | 274 | } |
— | — | @@ -284,7 +280,7 @@ |
285 | 281 | return null; |
286 | 282 | |
287 | 283 | $dbr = wfGetDB( DB_SLAVE ); |
288 | | - // Skip deleted revisions |
| 284 | + // Look for quality revision |
289 | 285 | $result = $dbr->select( |
290 | 286 | array('flaggedrevs', 'revision'), |
291 | 287 | array('fr_rev_id', 'fr_user', 'fr_timestamp', 'fr_comment', 'rev_timestamp'), |
— | — | @@ -292,7 +288,7 @@ |
293 | 289 | 'fr_rev_id = rev_id', 'rev_page' => $title->getArticleID(), 'rev_deleted = 0'), |
294 | 290 | __METHOD__, |
295 | 291 | 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... |
297 | 293 | if( !$row = $dbr->fetchObject($result) ) { |
298 | 294 | $result = $dbr->select( |
299 | 295 | array('flaggedrevs', 'revision'), |
— | — | @@ -318,7 +314,6 @@ |
319 | 315 | $flags[$tag] = 0; |
320 | 316 | } |
321 | 317 | |
322 | | - wfProfileIn( __METHOD__ ); |
323 | 318 | $db = wfGetDB( DB_SLAVE ); |
324 | 319 | // Grab all the tags for this revision |
325 | 320 | $result = $db->select('flaggedrevtags', |
— | — | @@ -329,16 +324,26 @@ |
330 | 325 | while ( $row = $db->fetchObject($result) ) { |
331 | 326 | $flags[$row->frt_dimension] = $row->frt_value; |
332 | 327 | } |
333 | | - wfProfileOut( __METHOD__ ); |
334 | | - |
335 | 328 | return $flags; |
336 | 329 | } |
337 | 330 | |
| 331 | + /** |
| 332 | + * @param int $title |
| 333 | + * @returns bool |
| 334 | + * Is $title the main page? |
| 335 | + */ |
338 | 336 | public static function isMainPage( $title ) { |
339 | 337 | $mp = Title::newMainPage(); |
340 | 338 | return ( $title->getNamespace()==$mp->getNamespace() && $title->getDBKey()==$mp->getDBKey() ); |
341 | 339 | } |
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 | + */ |
343 | 348 | public function addTagRatings( $flags, $prettyBox = false, $css='' ) { |
344 | 349 | global $wgFlaggedRevTags; |
345 | 350 | |
— | — | @@ -373,7 +378,14 @@ |
374 | 379 | |
375 | 380 | return $tag; |
376 | 381 | } |
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 | + */ |
378 | 390 | function prettyRatingBox( $tfrev, $flags, $revs_since, $simpleTag=false ) { |
379 | 391 | global $wgLang, $wgUser; |
380 | 392 | |
— | — | @@ -404,7 +416,12 @@ |
405 | 417 | |
406 | 418 | return $box; |
407 | 419 | } |
408 | | - |
| 420 | + |
| 421 | + /** |
| 422 | + * @param Row $row |
| 423 | + * @returns string |
| 424 | + * Generates revision review notes |
| 425 | + */ |
409 | 426 | public static function ReviewNotes( $row ) { |
410 | 427 | global $wgUser, $wgFlaggedRevComments; |
411 | 428 | |
— | — | @@ -422,7 +439,7 @@ |
423 | 440 | |
424 | 441 | /** |
425 | 442 | * @param Array $flags |
426 | | - * @output bool, is this revision at quality condition? |
| 443 | + * @returns bool, is this revision at quality condition? |
427 | 444 | */ |
428 | 445 | public static function isQuality( $flags ) { |
429 | 446 | global $wgFlaggedRevTags; |
— | — | @@ -435,7 +452,7 @@ |
436 | 453 | |
437 | 454 | /** |
438 | 455 | * @param Array $flags |
439 | | - * @output bool, is this revision at optimal condition? |
| 456 | + * @returns bool, is this revision at optimal condition? |
440 | 457 | */ |
441 | 458 | public static function isPristine( $flags ) { |
442 | 459 | global $wgFlaggedRevValues; |
— | — | @@ -448,7 +465,7 @@ |
449 | 466 | |
450 | 467 | /** |
451 | 468 | * @param Array $flags |
452 | | - * @output integer, lowest rating level |
| 469 | + * @returns integer, lowest rating level |
453 | 470 | */ |
454 | 471 | public static function getLCQuality( $flags ) { |
455 | 472 | global $wgFlaggedRevValues; |
— | — | @@ -462,6 +479,7 @@ |
463 | 480 | |
464 | 481 | /** |
465 | 482 | * @param Article $article |
| 483 | + * @returns ParserOutput |
466 | 484 | * Get the page cache for the top stable revision of an article |
467 | 485 | */ |
468 | 486 | public static function getPageCache( $article ) { |
— | — | @@ -775,38 +793,38 @@ |
776 | 794 | $now = time(); |
777 | 795 | $usercreation = wfTimestamp(TS_UNIX,$user->mRegistration); |
778 | 796 | $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 ) ) |
781 | 799 | return true; |
782 | 800 | // 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') ); |
797 | 816 | |
798 | | - if( $removed===false ) { |
799 | | - $newGroups = $groups ; |
800 | | - array_push( $newGroups, 'editor'); |
| 817 | + if( $removed===false ) { |
| 818 | + $newGroups = $groups ; |
| 819 | + array_push( $newGroups, 'editor'); |
801 | 820 | |
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) ) ); |
806 | 825 | |
807 | | - $user->addGroup('editor'); |
808 | | - } |
| 826 | + $user->addGroup('editor'); |
809 | 827 | } |
810 | | - return true; |
| 828 | + return true; |
811 | 829 | } |
812 | 830 | } |
813 | 831 | |
— | — | @@ -1394,10 +1412,6 @@ |
1395 | 1413 | |
1396 | 1414 | } |
1397 | 1415 | |
1398 | | -function makeGroupNameList( $ids ) { |
1399 | | - return implode( ', ', $ids ); |
1400 | | -} |
1401 | | - |
1402 | 1416 | // Our class instances |
1403 | 1417 | $flaggedRevsModifier = new FlaggedArticle(); |
1404 | 1418 | // Main hooks, overrides pages content, adds tags, sets tabs and permalink |
Index: trunk/extensions/FlaggedRevs/FlaggedRevsPage.i18n.php |
— | — | @@ -111,6 +111,8 @@ |
112 | 112 | 'viewunreviewed' => 'List unreviewed content pages', |
113 | 113 | 'included-nonquality' => 'Show only reviewed pages not marked as quality.', |
114 | 114 | 'unreviewed-list' => 'This page lists articles that have not yet been reviewed.', |
| 115 | + |
| 116 | + 'rights-editor-revoke' => 'removed editor status from [[$1]]', |
115 | 117 | ); |
116 | 118 | |
117 | 119 | // 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 @@ |
37 | 37 | /** |
38 | 38 | * Register the special page |
39 | 39 | */ |
40 | | - extAddSpecialPage( dirname(__FILE__) . '/Makevalidate.body.php', 'Makevalidate', 'makevalidate' ); |
| 40 | + extAddSpecialPage( dirname(__FILE__) . '/Makevalidate_body.php', 'Makevalidate', 'makevalidate' ); |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Populate the message cache and set up the auditing |