Index: trunk/extensions/CollabWatchlist/CollabWatchlist.body.php |
— | — | @@ -1 +0,0 @@ |
2 | | -<?php |
Index: trunk/extensions/CollabWatchlist/CollabWatchlist.php |
— | — | @@ -11,8 +11,8 @@ |
12 | 12 | |
13 | 13 | $wgExtensionCredits['specialpage'][] = array( |
14 | 14 | 'name' => 'CollabWatchlist', |
15 | | - 'author' =>'Florian Hackenberger', |
16 | | - 'url' => 'http://www.mediawiki.org/wiki/User:Flohack', |
| 15 | + 'author' =>'Florian Hackenberger', |
| 16 | + 'url' => 'http://www.mediawiki.org/wiki/User:Flohack', |
17 | 17 | 'description' => 'Provides collaborative watchlists based on categories', |
18 | 18 | 'descriptionmsg' => 'specialcollabwatchlist-desc', |
19 | 19 | 'version' => '0.9.0', |
— | — | @@ -25,7 +25,6 @@ |
26 | 26 | $wgExtensionMessagesFiles['CollabWatchlist'] = $wgDir . 'CollabWatchlist.i18n.php'; |
27 | 27 | $wgExtensionAliasesFiles['CollabWatchlist'] = $wgDir . 'CollabWatchlist.alias.php'; |
28 | 28 | |
29 | | -//$wgAutoloadClasses['CollabWatchlist'] = $wgDir . 'CollabWatchlist.body.php'; # Tell MediaWiki to load the extension body. |
30 | 29 | $wgAutoloadClasses['SpecialCollabWatchlist'] = $wgCollabWatchlistIncludes . 'SpecialCollabWatchlist.php'; |
31 | 30 | $wgAutoloadClasses['CollabWatchlistChangesList'] = $wgCollabWatchlistIncludes . 'CollabWatchlistChangesList.php'; |
32 | 31 | $wgAutoloadClasses['CategoryTreeManip'] = $wgCollabWatchlistIncludes . 'CategoryTreeManip.php'; |
— | — | @@ -36,7 +35,7 @@ |
37 | 36 | |
38 | 37 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'fnCollabWatchlistDbSchema'; |
39 | 38 | $wgHooks['GetPreferences'][] = 'fnCollabWatchlistPreferences'; |
40 | | - |
| 39 | + |
41 | 40 | function fnCollabWatchlistDbSchema() { |
42 | 41 | global $wgExtNewTables; |
43 | 42 | $wgSql = dirname(__FILE__) . '/sql/'; |
Index: trunk/extensions/CollabWatchlist/includes/SpecialCollabWatchlist.php |
— | — | @@ -3,12 +3,12 @@ |
4 | 4 | function __construct() { |
5 | 5 | parent::__construct( 'CollabWatchlist' ); |
6 | 6 | } |
7 | | - |
| 7 | + |
8 | 8 | function execute( $par ) { |
9 | 9 | global $wgUser, $wgOut, $wgLang, $wgRequest; |
10 | | - global $wgRCShowWatchingUsers, $wgEnotifWatchlist; |
| 10 | + global $wgRCShowWatchingUsers; |
11 | 11 | global $wgEnotifWatchlist; |
12 | | - |
| 12 | + |
13 | 13 | // Add feed links |
14 | 14 | $wlToken = $wgUser->getOption( 'watchlisttoken' ); |
15 | 15 | if (!$wlToken) { |
— | — | @@ -16,27 +16,27 @@ |
17 | 17 | $wgUser->setOption( 'watchlisttoken', $wlToken ); |
18 | 18 | $wgUser->saveSettings(); |
19 | 19 | } |
20 | | - |
21 | | - global $wgServer, $wgScriptPath, $wgFeedClasses; |
| 20 | + |
| 21 | + global $wgFeedClasses; |
22 | 22 | $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev', |
23 | 23 | 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken ); |
24 | 24 | $feedTemplate = wfScript('api').'?'; |
25 | | - |
| 25 | + |
26 | 26 | foreach( $wgFeedClasses as $format => $class ) { |
27 | 27 | $theseParams = $apiParams + array( 'feedformat' => $format ); |
28 | 28 | $url = $feedTemplate . wfArrayToCGI( $theseParams ); |
29 | 29 | $wgOut->addFeedLink( $format, $url ); |
30 | 30 | } |
31 | | - |
| 31 | + |
32 | 32 | $skin = $wgUser->getSkin(); |
33 | 33 | $specialTitle = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
34 | 34 | $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
35 | | - |
| 35 | + |
36 | 36 | # Anons don't get a watchlist |
37 | 37 | if( $wgUser->isAnon() ) { |
38 | 38 | $wgOut->setPageTitle( wfMsg( 'watchnologin' ) ); |
39 | 39 | $llink = $skin->linkKnown( |
40 | | - SpecialPage::getTitleFor( 'Userlogin' ), |
| 40 | + SpecialPage::getTitleFor( 'Userlogin' ), |
41 | 41 | wfMsgHtml( 'loginreqlink' ), |
42 | 42 | array(), |
43 | 43 | array( 'returnto' => $specialTitle->getPrefixedText() ) |
— | — | @@ -44,9 +44,9 @@ |
45 | 45 | $wgOut->addHTML( wfMsgWikiHtml( 'watchlistanontext', $llink ) ); |
46 | 46 | return; |
47 | 47 | } |
48 | | - |
| 48 | + |
49 | 49 | $wgOut->setPageTitle( wfMsg( 'collabwatchlist' ) ); |
50 | | - |
| 50 | + |
51 | 51 | $listIdsAndNames = CollabWatchlistChangesList::getCollabWatchlistIdAndName($wgUser->getId()); |
52 | 52 | $sub = wfMsgExt( |
53 | 53 | 'watchlistfor2', |
— | — | @@ -56,9 +56,9 @@ |
57 | 57 | ); |
58 | 58 | $sub .= '<br />' . CollabWatchlistEditor::buildTools( $listIdsAndNames, $wgUser->getSkin() ); |
59 | 59 | $wgOut->setSubtitle( $sub ); |
60 | | - |
| 60 | + |
61 | 61 | $uid = $wgUser->getId(); |
62 | | - |
| 62 | + |
63 | 63 | // The filter form has one checkbox for each tag, build an array |
64 | 64 | $postValues = $wgRequest->getValues(); |
65 | 65 | $tagFilter = array(); |
— | — | @@ -71,7 +71,7 @@ |
72 | 72 | if( empty($tagFilter) ) { |
73 | 73 | $tagFilter = explode('|', $wgRequest->getVal('filterTags')); |
74 | 74 | } |
75 | | - |
| 75 | + |
76 | 76 | $defaults = array( |
77 | 77 | /* float */ 'days' => floatval( $wgUser->getOption( 'watchlistdays' ) ), /* 3.0 or 0.5, watch further below */ |
78 | 78 | /* bool */ 'hideMinor' => (int)$wgUser->getBoolOption( 'watchlisthideminor' ), |
— | — | @@ -87,9 +87,9 @@ |
88 | 88 | /* ? */ 'invertTags'=> false, |
89 | 89 | /* ? */ 'filterTags'=> '', |
90 | 90 | ); |
91 | | - |
| 91 | + |
92 | 92 | extract($defaults); |
93 | | - |
| 93 | + |
94 | 94 | # Extract variables from the request, falling back to user preferences or |
95 | 95 | # other default values if these don't exist |
96 | 96 | $prefs['days'] = floatval( $wgUser->getOption( 'watchlistdays' ) ); |
— | — | @@ -102,7 +102,7 @@ |
103 | 103 | $prefs['hidepatrolled' ] = $wgUser->getBoolOption( 'watchlisthidepatrolled' ); |
104 | 104 | $prefs['invertTags' ] = $wgUser->getBoolOption( 'collabwatchlistinverttags' ); |
105 | 105 | $prefs['filterTags' ] = $wgUser->getOption( 'collabwatchlistfiltertags' ); |
106 | | - |
| 106 | + |
107 | 107 | # Get query variables |
108 | 108 | $days = $wgRequest->getVal( 'days' , $prefs['days'] ); |
109 | 109 | $hideMinor = $wgRequest->getBool( 'hideMinor', $prefs['hideminor'] ); |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | $hidePatrolled = $wgRequest->getBool( 'hidePatrolled' , $prefs['hidepatrolled'] ); |
116 | 116 | $filterTags = implode('|', $tagFilter); |
117 | 117 | $invertTags = $wgRequest->getBool( 'invertTags' , $prefs['invertTags'] ); |
118 | | - |
| 118 | + |
119 | 119 | # Get collabwatchlist value, if supplied, and prepare a WHERE fragment |
120 | 120 | $collabWatchlist = $wgRequest->getIntOrNull( 'collabwatchlist' ); |
121 | 121 | $invert = $wgRequest->getBool( 'invert' ); |
— | — | @@ -127,16 +127,16 @@ |
128 | 128 | if(array_key_exists($collabWatchlist, $listIdsAndNames)) { |
129 | 129 | $wgOut->addHTML( Xml::element('h2', null, $listIdsAndNames[$collabWatchlist]) ); |
130 | 130 | } |
131 | | - |
| 131 | + |
132 | 132 | if( ( $mode = CollabWatchlistEditor::getMode( $wgRequest, $par ) ) !== false ) { |
133 | 133 | $editor = new CollabWatchlistEditor(); |
134 | 134 | $editor->execute( $collabWatchlist, $listIdsAndNames, $wgOut, $wgRequest, $mode ); |
135 | 135 | return; |
136 | 136 | } |
137 | | - |
| 137 | + |
138 | 138 | $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
139 | 139 | $recentchanges = $dbr->tableName( 'recentchanges' ); |
140 | | - |
| 140 | + |
141 | 141 | $nitems = $dbr->selectField( 'collabwatchlistcategory', 'COUNT(*)', |
142 | 142 | $collabWatchlist == 0 ? array() : array('rl_id' => $collabWatchlist |
143 | 143 | ), __METHOD__ ); |
— | — | @@ -144,10 +144,10 @@ |
145 | 145 | $wgOut->addWikiMsg( 'nowatchlist' ); |
146 | 146 | return; |
147 | 147 | } |
148 | | - |
| 148 | + |
149 | 149 | // Dump everything here |
150 | 150 | $nondefaults = array(); |
151 | | - |
| 151 | + |
152 | 152 | wfAppendToArrayIfNotDefault( 'days' , $days , $defaults, $nondefaults); |
153 | 153 | wfAppendToArrayIfNotDefault( 'hideMinor', (int)$hideMinor, $defaults, $nondefaults ); |
154 | 154 | wfAppendToArrayIfNotDefault( 'hideBots' , (int)$hideBots , $defaults, $nondefaults); |
— | — | @@ -160,21 +160,21 @@ |
161 | 161 | wfAppendToArrayIfNotDefault( 'filterTags', $filterTags , $defaults, $nondefaults ); |
162 | 162 | wfAppendToArrayIfNotDefault( 'invertTags', $invertTags , $defaults, $nondefaults ); |
163 | 163 | wfAppendToArrayIfNotDefault( 'invert', $invert , $defaults, $nondefaults ); |
164 | | - |
| 164 | + |
165 | 165 | if( $days <= 0 ) { |
166 | 166 | $andcutoff = ''; |
167 | 167 | } else { |
168 | 168 | $andcutoff = "rc_timestamp > '".$dbr->timestamp( time() - intval( $days * 86400 ) )."'"; |
169 | 169 | } |
170 | | - |
| 170 | + |
171 | 171 | # If the watchlist is relatively short, it's simplest to zip |
172 | 172 | # down its entirety and then sort the results. |
173 | | - |
| 173 | + |
174 | 174 | # If it's relatively long, it may be worth our while to zip |
175 | 175 | # through the time-sorted page list checking for watched items. |
176 | | - |
| 176 | + |
177 | 177 | # Up estimate of watched items by 15% to compensate for talk pages... |
178 | | - |
| 178 | + |
179 | 179 | # Toggles |
180 | 180 | $andHideOwn = $hideOwn ? "rc_user != $uid" : ''; |
181 | 181 | $andHideBots = $hideBots ? "rc_bot = 0" : ''; |
— | — | @@ -183,7 +183,7 @@ |
184 | 184 | $andHideAnons = $hideAnons ? "rc_user != 0" : ''; |
185 | 185 | $andHideListUser = $hideListUser ? $this->wlGetFilterClauseListUser($collabWatchlist) : ''; |
186 | 186 | $andHidePatrolled = $wgUser->useRCPatrol() && $hidePatrolled ? "rc_patrolled != 1" : ''; |
187 | | - |
| 187 | + |
188 | 188 | # Toggle watchlist content (all recent edits or just the latest) |
189 | 189 | if( $wgUser->getOption( 'extendwatchlist' )) { |
190 | 190 | $andLatest=''; |
— | — | @@ -195,22 +195,22 @@ |
196 | 196 | $limitWatchlist = 0; |
197 | 197 | $usePage = true; |
198 | 198 | } |
199 | | - |
| 199 | + |
200 | 200 | # Show a message about slave lag, if applicable |
201 | 201 | if( ( $lag = $dbr->getLag() ) > 0 ) |
202 | 202 | $wgOut->showLagWarning( $lag ); |
203 | | - |
| 203 | + |
204 | 204 | # Create output form |
205 | 205 | $form = Xml::fieldset( wfMsg( 'watchlist-options' ), false, array( 'id' => 'mw-watchlist-options' ) ); |
206 | | - |
| 206 | + |
207 | 207 | # Show watchlist header |
208 | 208 | $form .= wfMsgExt( 'collabwatchlist-details', array( 'parseinline' ), $wgLang->formatNum( $nitems ) ); |
209 | | - |
| 209 | + |
210 | 210 | if( $wgUser->getOption( 'enotifwatchlistpages' ) && $wgEnotifWatchlist) { |
211 | 211 | $form .= wfMsgExt( 'wlheader-enotif', 'parse' ) . "\n"; |
212 | 212 | } |
213 | 213 | $form .= '<hr />'; |
214 | | - |
| 214 | + |
215 | 215 | $tables = array( 'recentchanges', 'categorylinks' ); |
216 | 216 | $fields = array( "{$recentchanges}.*" ); |
217 | 217 | $categoryClause = $this->wlGetFilterClauseForCollabWatchlistIds($collabWatchlist, 'cl_to', 'rc_cur_id'); |
— | — | @@ -223,7 +223,7 @@ |
224 | 224 | if( !empty($tagFilter) ) { |
225 | 225 | // The tag filter causes a query runtime of O(MxN), where M is relative to the number |
226 | 226 | // of recentchanges we select (from a table which is purged periodically, limited to 250) |
227 | | - // and N is relative the number of change_tag entries for a recentchange. Doing it |
| 227 | + // and N is relative the number of change_tag entries for a recentchange. Doing it |
228 | 228 | // the other way around (selecting from change_tag first, is probably slower, as the |
229 | 229 | // change_tag table is never purged. |
230 | 230 | // Using the tag_summary table for filtering is difficult, at least I have been unable to |
— | — | @@ -235,8 +235,8 @@ |
236 | 236 | } else { |
237 | 237 | $filter = 'NOT EXISTS '; |
238 | 238 | } |
239 | | - $filter .= '(select ct_rc_id from change_tag |
240 | | - JOIN collabwatchlistrevisiontag ON collabwatchlistrevisiontag.ct_id = change_tag.ct_id |
| 239 | + $filter .= '(select ct_rc_id from change_tag |
| 240 | + JOIN collabwatchlistrevisiontag ON collabwatchlistrevisiontag.ct_id = change_tag.ct_id |
241 | 241 | WHERE ct_rc_id = recentchanges.rc_id AND ct_tag '; |
242 | 242 | if( count($tagFilter) > 1 ) |
243 | 243 | $filter .= 'IN (' . $dbr->makeList($tagFilter) . '))'; |
— | — | @@ -257,23 +257,23 @@ |
258 | 258 | if( $andHideAnons ) $conds[] = $andHideAnons; |
259 | 259 | if( $andHideListUser ) $conds[] = $andHideListUser; |
260 | 260 | if( $andHidePatrolled ) $conds[] = $andHidePatrolled; |
261 | | - |
| 261 | + |
262 | 262 | $rollbacker = $wgUser->isAllowed('rollback'); |
263 | 263 | if ( $usePage || $rollbacker ) { |
264 | 264 | $tables[] = 'page'; |
265 | 265 | $join_conds['page'] = array('LEFT JOIN','rc_cur_id=page.page_id'); |
266 | | - if ($rollbacker) |
| 266 | + if ($rollbacker) |
267 | 267 | $fields[] = 'page_latest'; |
268 | 268 | } |
269 | | - |
| 269 | + |
270 | 270 | ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' ); |
271 | 271 | wfRunHooks('SpecialCollabWatchlistQuery', array(&$conds,&$tables,&$join_conds,&$fields) ); |
272 | | - |
| 272 | + |
273 | 273 | $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds ); |
274 | 274 | $numRows = $dbr->numRows( $res ); |
275 | | - |
| 275 | + |
276 | 276 | /* Start bottom header */ |
277 | | - |
| 277 | + |
278 | 278 | $wlInfo = ''; |
279 | 279 | if( $days >= 1 ) { |
280 | 280 | $wlInfo = wfMsgExt( 'rcnote', 'parseinline', |
— | — | @@ -289,11 +289,11 @@ |
290 | 290 | $wgLang->formatNum( round($days*24) ) |
291 | 291 | ) . '<br />'; |
292 | 292 | } |
293 | | - |
| 293 | + |
294 | 294 | $cutofflinks = "\n" . $this->wlCutoffLinks( $days, 'CollabWatchlist', $nondefaults ) . "<br />\n"; |
295 | | - |
| 295 | + |
296 | 296 | $thisTitle = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
297 | | - |
| 297 | + |
298 | 298 | # Spit out some control panel links |
299 | 299 | $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhideminor', 'hideMinor', $hideMinor ); |
300 | 300 | $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidebots', 'hideBots', $hideBots ); |
— | — | @@ -301,11 +301,11 @@ |
302 | 302 | $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhideliu', 'hideLiu', $hideLiu ); |
303 | 303 | $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidemine', 'hideOwn', $hideOwn ); |
304 | 304 | $links[] = $this->wlShowHideLink( $nondefaults, 'collabwatchlistshowhidelistusers', 'hideListUser', $hideListUser ); |
305 | | - |
| 305 | + |
306 | 306 | if( $wgUser->useRCPatrol() ) { |
307 | 307 | $links[] = $this->wlShowHideLink( $nondefaults, 'rcshowhidepatr', 'hidePatrolled', $hidePatrolled ); |
308 | 308 | } |
309 | | - |
| 309 | + |
310 | 310 | # Namespace filter and put the whole form together. |
311 | 311 | $form .= $wlInfo; |
312 | 312 | $form .= $cutofflinks; |
— | — | @@ -352,35 +352,35 @@ |
353 | 353 | $form .= Xml::closeElement( 'form' ); |
354 | 354 | $form .= Xml::closeElement( 'fieldset' ); |
355 | 355 | $wgOut->addHTML( $form ); |
356 | | - |
| 356 | + |
357 | 357 | # If there's nothing to show, stop here |
358 | 358 | if( $numRows == 0 ) { |
359 | 359 | $wgOut->addWikiMsg( 'watchnochange' ); |
360 | 360 | return; |
361 | 361 | } |
362 | | - |
| 362 | + |
363 | 363 | /* End bottom header */ |
364 | | - |
| 364 | + |
365 | 365 | /* Do link batch query */ |
366 | 366 | $linkBatch = new LinkBatch; |
367 | | - while ( $row = $dbr->fetchObject( $res ) ) { |
| 367 | + foreach ( $res as $row ) { |
368 | 368 | $userNameUnderscored = str_replace( ' ', '_', $row->rc_user_text ); |
369 | 369 | if ( $row->rc_user != 0 ) { |
370 | 370 | $linkBatch->add( NS_USER, $userNameUnderscored ); |
371 | 371 | } |
372 | 372 | $linkBatch->add( NS_USER_TALK, $userNameUnderscored ); |
373 | | - |
| 373 | + |
374 | 374 | $linkBatch->add( $row->rc_namespace, $row->rc_title ); |
375 | 375 | } |
376 | 376 | $linkBatch->execute(); |
377 | 377 | $dbr->dataSeek( $res, 0 ); |
378 | | - |
| 378 | + |
379 | 379 | $list = CollabWatchlistChangesList::newFromUser( $wgUser ); |
380 | 380 | $list->setWatchlistDivs(); |
381 | | - |
| 381 | + |
382 | 382 | $s = $list->beginRecentChangesList(); |
383 | 383 | $counter = 1; |
384 | | - while ( $obj = $dbr->fetchObject( $res ) ) { |
| 384 | + foreach ( $res as $obj ) { |
385 | 385 | # Make RC entry |
386 | 386 | $rc = RecentChange::newFromRow( $obj ); |
387 | 387 | $rc->counter = $counter++; |
— | — | @@ -396,7 +396,7 @@ |
397 | 397 | } else { |
398 | 398 | $rc->numberofWatchingusers = 0; |
399 | 399 | } |
400 | | - |
| 400 | + |
401 | 401 | $tags = $this->wlTagsForRevision($obj->rc_this_oldid, array($collabWatchlist), $invert); |
402 | 402 | // if( isset($tags) ) { |
403 | 403 | // // Filter recentchanges which contain unwanted tags |
— | — | @@ -411,71 +411,71 @@ |
412 | 412 | $attrs = $rc->getAttributes(); |
413 | 413 | $attrs['collabwatchlist_tags'] = $tags; |
414 | 414 | $rc->setAttribs($attrs); |
415 | | - |
| 415 | + |
416 | 416 | $s .= $list->recentChangesLine( $rc, false, $counter ); |
417 | 417 | } |
418 | 418 | $s .= $list->endRecentChangesList(); |
419 | | - |
| 419 | + |
420 | 420 | $dbr->freeResult( $res ); |
421 | 421 | $wgOut->addHTML( $s ); |
422 | 422 | } |
423 | | - |
| 423 | + |
424 | 424 | function wlShowHideLink( $options, $message, $name, $value ) { |
425 | 425 | global $wgUser; |
426 | | - |
| 426 | + |
427 | 427 | $showLinktext = wfMsgHtml( 'show' ); |
428 | 428 | $hideLinktext = wfMsgHtml( 'hide' ); |
429 | 429 | $title = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
430 | 430 | $skin = $wgUser->getSkin(); |
431 | | - |
| 431 | + |
432 | 432 | $label = $value ? $showLinktext : $hideLinktext; |
433 | 433 | $options[$name] = 1 - (int) $value; |
434 | | - |
| 434 | + |
435 | 435 | return wfMsgHtml( $message, $skin->linkKnown( $title, $label, array(), $options ) ); |
436 | 436 | } |
437 | | - |
438 | | - |
| 437 | + |
| 438 | + |
439 | 439 | function wlHoursLink( $h, $page, $options = array() ) { |
440 | 440 | global $wgUser, $wgLang, $wgContLang; |
441 | | - |
| 441 | + |
442 | 442 | $sk = $wgUser->getSkin(); |
443 | 443 | $title = Title::newFromText( $wgContLang->specialPage( $page ) ); |
444 | 444 | $options['days'] = ($h / 24.0); |
445 | | - |
| 445 | + |
446 | 446 | $s = $sk->linkKnown( |
447 | 447 | $title, |
448 | 448 | $wgLang->formatNum( $h ), |
449 | 449 | array(), |
450 | 450 | $options |
451 | 451 | ); |
452 | | - |
| 452 | + |
453 | 453 | return $s; |
454 | 454 | } |
455 | | - |
| 455 | + |
456 | 456 | function wlDaysLink( $d, $page, $options = array() ) { |
457 | 457 | global $wgUser, $wgLang, $wgContLang; |
458 | | - |
| 458 | + |
459 | 459 | $sk = $wgUser->getSkin(); |
460 | 460 | $title = Title::newFromText( $wgContLang->specialPage( $page ) ); |
461 | 461 | $options['days'] = $d; |
462 | 462 | $message = ($d ? $wgLang->formatNum( $d ) : wfMsgHtml( 'watchlistall2' ) ); |
463 | | - |
| 463 | + |
464 | 464 | $s = $sk->linkKnown( |
465 | 465 | $title, |
466 | 466 | $message, |
467 | 467 | array(), |
468 | 468 | $options |
469 | 469 | ); |
470 | | - |
| 470 | + |
471 | 471 | return $s; |
472 | 472 | } |
473 | | - |
| 473 | + |
474 | 474 | /** |
475 | 475 | * Returns html |
476 | 476 | */ |
477 | 477 | function wlCutoffLinks( $days, $page = 'CollabWatchlist', $options = array() ) { |
478 | 478 | global $wgLang; |
479 | | - |
| 479 | + |
480 | 480 | $hours = array( 1, 2, 6, 12 ); |
481 | 481 | $days = array( 1, 3, 7 ); |
482 | 482 | $i = 0; |
— | — | @@ -492,7 +492,7 @@ |
493 | 493 | $wgLang->pipeList( $days ), |
494 | 494 | $this->wlDaysLink( 0, $page, $options ) ); |
495 | 495 | } |
496 | | - |
| 496 | + |
497 | 497 | /** |
498 | 498 | * Count the number of items on a user's watchlist |
499 | 499 | * |
— | — | @@ -501,21 +501,21 @@ |
502 | 502 | */ |
503 | 503 | function wlCountItems( &$user, $talk = true ) { |
504 | 504 | $dbr = wfGetDB( DB_SLAVE, 'watchlist' ); |
505 | | - |
| 505 | + |
506 | 506 | # Fetch the raw count |
507 | | - $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', |
| 507 | + $res = $dbr->select( 'watchlist', 'COUNT(*) AS count', |
508 | 508 | array( 'wl_user' => $user->mId ), 'wlCountItems' ); |
509 | 509 | $row = $dbr->fetchObject( $res ); |
510 | 510 | $count = $row->count; |
511 | 511 | $dbr->freeResult( $res ); |
512 | | - |
| 512 | + |
513 | 513 | # Halve to remove talk pages if needed |
514 | 514 | if( !$talk ) |
515 | 515 | $count = floor( $count / 2 ); |
516 | | - |
| 516 | + |
517 | 517 | return( $count ); |
518 | 518 | } |
519 | | - |
| 519 | + |
520 | 520 | /** Returns an array of maps representing collab watchlist tags. The following fields are present |
521 | 521 | * in each map: |
522 | 522 | * - rl_id Id of the collaborative watchlist |
— | — | @@ -553,13 +553,12 @@ |
554 | 554 | ) |
555 | 555 | ); |
556 | 556 | $tags = array(); |
557 | | - while( $row = $res->fetchObject() ) { |
| 557 | + foreach( $res as $row ) { |
558 | 558 | $tags[] = get_object_vars( $row ); |
559 | 559 | } |
560 | | - $dbr->freeResult( $res ); |
561 | 560 | return $tags; |
562 | 561 | } |
563 | | - |
| 562 | + |
564 | 563 | function wlGetFilterClauseForCollabWatchlistIds($rl_ids, $catNameCol, $pageIdCol) { |
565 | 564 | $excludedCatPageIds = array(); |
566 | 565 | $includedCatPageIds = array(); |
— | — | @@ -573,7 +572,7 @@ |
574 | 573 | array( 'collabwatchlistcategory' => array('JOIN', 'collabwatchlist.rl_id = collabwatchlistcategory.rl_id'), |
575 | 574 | 'page' => array('JOIN', 'page.page_id = collabwatchlistcategory.cat_page_id') ) |
576 | 575 | ); |
577 | | - while( $row = $res->fetchObject() ) { |
| 576 | + foreach( $res as $row ) { |
578 | 577 | if($row->page_namespace == NS_CATEGORY) { |
579 | 578 | if($row->subtract) { |
580 | 579 | $excludedCatPageIds[$row->cat_page_id] = $row->page_title; |
— | — | @@ -584,8 +583,7 @@ |
585 | 584 | $includedPageIds[$row->cat_page_id] = $row->page_title; |
586 | 585 | } |
587 | 586 | } |
588 | | - $dbr->freeResult( $res ); |
589 | | - |
| 587 | + |
590 | 588 | if($includedCatPageIds) { |
591 | 589 | $catTree = new CategoryTreeManip(); |
592 | 590 | $catTree->initialiseFromCategoryNames(array_values($includedCatPageIds)); |
— | — | @@ -603,7 +601,7 @@ |
604 | 602 | } |
605 | 603 | return $collabWatchlistClause; |
606 | 604 | } |
607 | | - |
| 605 | + |
608 | 606 | function wlGetFilterClauseListUser($rl_id) { |
609 | 607 | $excludedUserIds = array(); |
610 | 608 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -612,17 +610,16 @@ |
613 | 611 | array('collabwatchlistuser.rl_id' => $rl_id) # Conditions |
614 | 612 | ); |
615 | 613 | $clause = ''; |
616 | | - while( $row = $res->fetchObject() ) { |
| 614 | + foreach( $res as $row ) { |
617 | 615 | $excludedUserIds[] = $row->user_id; |
618 | 616 | } |
619 | 617 | if($res->numRows() > 0) { |
620 | 618 | $clause = '( rc_user NOT IN ('; |
621 | 619 | $clause .= implode(',', $this->addQuotes($dbr, $excludedUserIds)) . ') )'; |
622 | 620 | } |
623 | | - $dbr->freeResult( $res ); |
624 | 621 | return $clause; |
625 | 622 | } |
626 | | - |
| 623 | + |
627 | 624 | public static function addQuotes($db, $strings) { |
628 | 625 | $result = array(); |
629 | 626 | foreach($strings as $string) { |
Index: trunk/extensions/CollabWatchlist/includes/CategoryTreeManip.php |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | * @author fhackenberger |
12 | 12 | */ |
13 | 13 | class CategoryTreeManip { |
14 | | - |
| 14 | + |
15 | 15 | var $root; |
16 | 16 | var $name; |
17 | 17 | var $id; |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | var $parents = array(); |
20 | 20 | var $enabled = true; |
21 | 21 | var $children = array(); |
22 | | - |
| 22 | + |
23 | 23 | /** |
24 | 24 | * Constructor |
25 | 25 | */ |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | } |
34 | 34 | $this->parents = $parents; |
35 | 35 | } |
36 | | - |
| 36 | + |
37 | 37 | private function addChildren($children) { |
38 | 38 | if(!is_array($children)) |
39 | 39 | throw new Exception('Argument must be an array'); |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | $this->children[$child->id] = $child; |
42 | 42 | } |
43 | 43 | } |
44 | | - |
| 44 | + |
45 | 45 | private function addParents($parents) { |
46 | 46 | if(!is_array($parents)) |
47 | 47 | throw new Exception('Argument must be an array'); |
— | — | @@ -48,18 +48,17 @@ |
49 | 49 | $this->parents[$parent->id] = $parent; |
50 | 50 | } |
51 | 51 | } |
52 | | - |
| 52 | + |
53 | 53 | /** Disable this category node and all subcategory nodes |
54 | 54 | * @return |
55 | 55 | */ |
56 | 56 | public function disable() { |
57 | 57 | $this->recursiveDisable(); |
58 | 58 | } |
59 | | - |
| 59 | + |
60 | 60 | /** Disable the given categories (by id) and all their subcategories |
61 | | - * |
| 61 | + * |
62 | 62 | * @param array $catPageIds The page ids of the categories to disable |
63 | | - * @return |
64 | 63 | */ |
65 | 64 | public function disableCategoryIds($catPageIds) { |
66 | 65 | foreach($catPageIds as $catId) { |
— | — | @@ -69,7 +68,7 @@ |
70 | 69 | } |
71 | 70 | } |
72 | 71 | } |
73 | | - |
| 72 | + |
74 | 73 | private function recursiveDisable($visitedNodeIds = array()) { |
75 | 74 | if(!$this->enabled || array_key_exists($this->id, $visitedNodeIds)) |
76 | 75 | return; # Break the recursion |
— | — | @@ -77,12 +76,12 @@ |
78 | 77 | $visitedNodeIds[] = $this->id; |
79 | 78 | foreach($this->children as $cat) { |
80 | 79 | $cat->recursiveDisable($visitedNodeIds); |
81 | | - } |
| 80 | + } |
82 | 81 | } |
83 | | - |
| 82 | + |
84 | 83 | /** Returns a list of enables category names, including |
85 | 84 | * all subcategories. |
86 | | - * |
| 85 | + * |
87 | 86 | * @return array An array of category names |
88 | 87 | */ |
89 | 88 | public function getEnabledCategoryNames() { |
— | — | @@ -93,16 +92,16 @@ |
94 | 93 | } |
95 | 94 | return $enabledCategories; |
96 | 95 | } |
97 | | - |
| 96 | + |
98 | 97 | /** Returns a map of enabled categories, including |
99 | 98 | * all subcategories. |
100 | | - * |
| 99 | + * |
101 | 100 | * @return array An array mapping from category page ids to CategoryTreeManip objects |
102 | 101 | */ |
103 | 102 | public function getEnabledNodeMap() { |
104 | 103 | return $this->root->recursiveGetEnabledNodeMap(); |
105 | 104 | } |
106 | | - |
| 105 | + |
107 | 106 | private function recursiveGetEnabledNodeMap(&$foundNodes = array()) { |
108 | 107 | if(isset($this->id)) { |
109 | 108 | if(!$this->enabled || array_key_exists($this->id, $foundNodes)) |
— | — | @@ -114,9 +113,9 @@ |
115 | 114 | } |
116 | 115 | return $foundNodes; |
117 | 116 | } |
118 | | - |
| 117 | + |
119 | 118 | /** Returns a CategoryTreeManip node, given a category page id |
120 | | - * |
| 119 | + * |
121 | 120 | * @param $catPageId The page id of the category to retrieve |
122 | 121 | * @return CategoryTreeManip The node |
123 | 122 | */ |
— | — | @@ -124,14 +123,14 @@ |
125 | 124 | if(array_key_exists($catPageId, $this->root->catPageIdToNode)) |
126 | 125 | return $this->root->catPageIdToNode[$catPageId]; |
127 | 126 | } |
128 | | - |
| 127 | + |
129 | 128 | private function addNode($node) { |
130 | 129 | $this->root->catPageIdToNode[$node->id] = $node; |
131 | 130 | } |
132 | | - |
| 131 | + |
133 | 132 | /** Build the category tree, given a list of category names. |
134 | 133 | * All categories and subcategories are enabled by default. |
135 | | - * |
| 134 | + * |
136 | 135 | * @param array $catNames An array of strings representing category names |
137 | 136 | * @return |
138 | 137 | */ |
— | — | @@ -147,7 +146,7 @@ |
148 | 147 | ); |
149 | 148 | $parentList = array(); |
150 | 149 | $childList = array(); |
151 | | - while( $row = $res->fetchObject() ) { |
| 150 | + foreach( $res as $row ) { |
152 | 151 | $parentList[$row->parName][] = array($row->childId, $row->childName); |
153 | 152 | if(array_key_exists($row->childId, $childList)) { |
154 | 153 | $childEntry = $childList[$row->childId]; |
— | — | @@ -156,8 +155,7 @@ |
157 | 156 | $childList[$row->childId] = array($row->childName, array($row->parName)); |
158 | 157 | } |
159 | 158 | } |
160 | | - $dbr->freeResult( $res ); |
161 | | - |
| 159 | + |
162 | 160 | if(!isset($parentNameToNode) && !empty($parentList)) { |
163 | 161 | // Fetch the page ids of the $catNames and add the parent categories if needed |
164 | 162 | $res = $dbr->select( array('page' ), # Tables |
— | — | @@ -165,7 +163,7 @@ |
166 | 164 | array('page_title' => array_keys($parentList)) # Conditions |
167 | 165 | ); |
168 | 166 | $parentNameToNode = array(); |
169 | | - while( $row = $res->fetchObject() ) { |
| 167 | + foreach( $res as $row ) { |
170 | 168 | $node = $this->getNodeForCatPageId($row->page_id); |
171 | 169 | if(!isset($node)) { |
172 | 170 | $node = new CategoryTreeManip($row->page_id, $row->page_title, $this->root); |
— | — | @@ -174,9 +172,8 @@ |
175 | 173 | } |
176 | 174 | $parentNameToNode[$row->page_title] = $node; |
177 | 175 | } |
178 | | - $dbr->freeResult( $res ); |
179 | 176 | } |
180 | | - |
| 177 | + |
181 | 178 | $newChildNameToNode = array(); |
182 | 179 | // Add the new child nodes |
183 | 180 | foreach($childList as $childPageId => $childInfo) { |
— | — | @@ -192,7 +189,7 @@ |
193 | 190 | $childNode->addParents(array($parent)); |
194 | 191 | } |
195 | 192 | } |
196 | | - |
| 193 | + |
197 | 194 | // Prepare for the next loop |
198 | 195 | $parentNameToNode = $newChildNameToNode; |
199 | 196 | $catNames = array_keys($parentNameToNode); |
Index: trunk/extensions/CollabWatchlist/includes/CollabWatchlistChangesList.php |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | class CollabWatchlistChangesList extends EnhancedChangesList { |
7 | 7 | protected $user; |
8 | 8 | protected $tagCheckboxIndex = 0; |
9 | | - |
| 9 | + |
10 | 10 | /** |
11 | 11 | * Collaborative Watchlist contructor |
12 | 12 | * @param User $user |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | parent::__construct($skin); |
17 | 17 | $this->user = $user; |
18 | 18 | } |
19 | | - |
| 19 | + |
20 | 20 | /** |
21 | 21 | * (non-PHPdoc) |
22 | 22 | * @see includes/EnhancedChangesList#beginRecentChangesList() |
— | — | @@ -25,13 +25,13 @@ |
26 | 26 | $gwlSpeciaPageTitle = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
27 | 27 | $result = Xml::openElement('form', array( |
28 | 28 | 'class' => 'mw-collaborative-watchlist-addtag-form', |
29 | | - 'method' => 'post', |
| 29 | + 'method' => 'post', |
30 | 30 | 'action' => $gwlSpeciaPageTitle->getLocalUrl( array( 'action' => 'setTags' )))); |
31 | 31 | $result .= Xml::input('redirTarget', false, $wgRequest->getFullRequestURL(), array('type' => 'hidden')); |
32 | 32 | $result .= parent::beginRecentChangesList(); |
33 | 33 | return $result; |
34 | 34 | } |
35 | | - |
| 35 | + |
36 | 36 | /** |
37 | 37 | * (non-PHPdoc) |
38 | 38 | * @see includes/EnhancedChangesList#endRecentChangesList() |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | $result .= Xml::closeElement('form'); |
52 | 52 | return $result; |
53 | 53 | } |
54 | | - |
| 54 | + |
55 | 55 | /** |
56 | 56 | * (non-PHPdoc) |
57 | 57 | * @see includes/EnhancedChangesList#insertBeforeRCFlags($r, $rcObj) |
— | — | @@ -62,18 +62,18 @@ |
63 | 63 | 'value' => ($rcObj->getTitle() . '|' . $rcObj->getAttribute('rc_this_oldid') . '|' . $rcObj->getAttribute('rc_id')))); |
64 | 64 | $this->tagCheckboxIndex++; |
65 | 65 | } |
66 | | - |
| 66 | + |
67 | 67 | /** |
68 | 68 | * (non-PHPdoc) |
69 | 69 | * @see includes/EnhancedChangesList#insertBeforeRCFlagsBlock($r, $block) |
70 | 70 | */ |
71 | 71 | protected function insertBeforeRCFlagsBlock( &$r, &$block ) { |
72 | 72 | $r .= Xml::element('input', array( |
73 | | - 'name' => 'collaborative-watchlist-addtag-placeholder', |
| 73 | + 'name' => 'collaborative-watchlist-addtag-placeholder', |
74 | 74 | 'type' => 'checkbox', |
75 | 75 | 'style' => 'visibility: hidden;')); |
76 | 76 | } |
77 | | - |
| 77 | + |
78 | 78 | /** |
79 | 79 | * (non-PHPdoc) |
80 | 80 | * @see includes/ChangesList#insertRollback($s, $rc) |
— | — | @@ -96,7 +96,7 @@ |
97 | 97 | } |
98 | 98 | } |
99 | 99 | } |
100 | | - |
| 100 | + |
101 | 101 | /** |
102 | 102 | * Fetch an appropriate changes list class for the specified user |
103 | 103 | * Some users might want to use an enhanced list format, for instance |
— | — | @@ -113,7 +113,7 @@ |
114 | 114 | return $list; |
115 | 115 | } |
116 | 116 | } |
117 | | - |
| 117 | + |
118 | 118 | /** |
119 | 119 | * (non-PHPdoc) |
120 | 120 | * @see includes/ChangesList#insertTags($s, $rc, $classes) |
— | — | @@ -125,7 +125,7 @@ |
126 | 126 | $s .= ' ' . $tagSummary; |
127 | 127 | } |
128 | 128 | } |
129 | | - |
| 129 | + |
130 | 130 | /** |
131 | 131 | * (non-PHPdoc) |
132 | 132 | * @see includes/EnhancedChangesList#insertHistLink($s, $rc, $title, $params, $sep) |
— | — | @@ -133,7 +133,7 @@ |
134 | 134 | protected function insertHistLink( &$s, &$rc, $title, $params = array(), $sep = NULL ) { |
135 | 135 | // No history |
136 | 136 | } |
137 | | - |
| 137 | + |
138 | 138 | /** |
139 | 139 | * (non-PHPdoc) |
140 | 140 | * @see includes/EnhancedChangesList#insertCurrAndLastLinks($s, $rc) |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | $s .= $rc->curlink; |
145 | 145 | $s .= ')'; |
146 | 146 | } |
147 | | - |
| 147 | + |
148 | 148 | /** |
149 | 149 | * (non-PHPdoc) |
150 | 150 | * @see includes/EnhancedChangesList#insertUserAndTalkLinks($s, $rc) |
— | — | @@ -151,16 +151,16 @@ |
152 | 152 | protected function insertUserAndTalkLinks( &$s, &$rc ) { |
153 | 153 | $s .= $rc->userlink; |
154 | 154 | } |
155 | | - |
| 155 | + |
156 | 156 | /** |
157 | | - * Insert the tags of the given change |
| 157 | + * Insert the tags of the given change |
158 | 158 | */ |
159 | 159 | private function formatReviewSummaryRow( $rc, $page ) { |
160 | 160 | global $wgRequest; |
161 | 161 | $s = ''; |
162 | 162 | if( !$rc ) |
163 | 163 | return $s; |
164 | | - |
| 164 | + |
165 | 165 | $attr = $rc->mAttribs; |
166 | 166 | $tagRows = $attr['collabwatchlist_tags']; |
167 | 167 | |
— | — | @@ -177,7 +177,7 @@ |
178 | 178 | ChangeTags::tagDescription( $tag ) |
179 | 179 | ); |
180 | 180 | $classes[] = Sanitizer::escapeClass( "mw-collabwatchlist-tag-$tag" ); |
181 | | - |
| 181 | + |
182 | 182 | /** Insert links to user page, user talk page and eventually a blocking link */ |
183 | 183 | $userLink = $this->skin->userLink( $tagRow['user_id'], $tagRow['user_name'] ); |
184 | 184 | $delTagTarget = CollabWatchlistEditor::getUnsetTagUrl( $wgRequest->getFullRequestURL(), $attr['rc_title'], $tagRow['rl_id'], $tag, $attr['rc_id'] ); |
— | — | @@ -188,10 +188,10 @@ |
189 | 189 | $markers = Xml::tags( 'span', array( 'class' => 'mw-collabwatchlist-tag-markers' ), $markers ); |
190 | 190 | return array( $markers, $classes ); |
191 | 191 | } |
192 | | - |
| 192 | + |
193 | 193 | /** Generate a form 'select' element for the collaborative watchlists and a 'select' element for choosing a tag. |
194 | 194 | * The tag selector reacts on the watchlist selector and displays the relevant tags only, if javascript is enabled. |
195 | | - * |
| 195 | + * |
196 | 196 | * @see #collabWatchlistSelector() |
197 | 197 | * @see #tagSelector() |
198 | 198 | * @param String $rlLabel The label for the collab watchlist select tag |
— | — | @@ -205,7 +205,7 @@ |
206 | 206 | $ret = self::collabWatchlistSelector($glWlIdAndName, $selected, $all, $element_name, $rlLabel, $rlElementId, $tagElementIdBase); |
207 | 207 | $ret .= ' '; |
208 | 208 | $ret .= self::tagSelector(array_keys($glWlIdAndName), $tagLabel); |
209 | | - // Make sure the correct tags for the default selection are set |
| 209 | + // Make sure the correct tags for the default selection are set |
210 | 210 | $ret .= Xml::element( 'script', |
211 | 211 | array( |
212 | 212 | 'type' => $wgJsMimeType, |
— | — | @@ -230,11 +230,11 @@ |
231 | 231 | * @return string |
232 | 232 | */ |
233 | 233 | public static function collabWatchlistSelector( $glWlIdAndName, $selected = '', $all = null, $element_name = 'collabwatchlist', $label = null, $element_id = 'collabwatchlist', $tagElementIdBase = null ) { |
234 | | - global $wgContLang, $wgScriptPath, $wgJsMimeType; |
| 234 | + global $wgScriptPath, $wgJsMimeType; |
235 | 235 | $ret = ''; |
236 | 236 | if(isset($tagElementIdBase)) { |
237 | 237 | $jsPath = "$wgScriptPath/extensions/CollabWatchlist/js"; |
238 | | - $ret .= Xml::element( 'script', |
| 238 | + $ret .= Xml::element( 'script', |
239 | 239 | array( |
240 | 240 | 'type' => $wgJsMimeType, |
241 | 241 | 'src' => "$jsPath/CollabWatchlist.js", |
— | — | @@ -260,7 +260,7 @@ |
261 | 261 | if( $index === 0 ) |
262 | 262 | $name = wfMsg( 'blankcollabwatchlist' ); |
263 | 263 | $options[] = Xml::option( $name, $index, $index === $selected, isset($tagElementIdBase) ? |
264 | | - array('onclick' => 'onCollabWatchlistSelection("' . $tagElementIdBase . '", this.value)') : |
| 264 | + array('onclick' => 'onCollabWatchlistSelection("' . $tagElementIdBase . '", this.value)') : |
265 | 265 | array() |
266 | 266 | ); |
267 | 267 | } |
— | — | @@ -279,10 +279,10 @@ |
280 | 280 | } |
281 | 281 | return $ret; |
282 | 282 | } |
283 | | - |
| 283 | + |
284 | 284 | /** |
285 | 285 | * Build a drop-down box for selecting a collaborative watchlist tag |
286 | | - * |
| 286 | + * |
287 | 287 | * @param array $rlIds A list of collaborative watchlist ids |
288 | 288 | * @param String $label The label for the select tag |
289 | 289 | * @param String $elemId The id of the select tag |
— | — | @@ -323,12 +323,12 @@ |
324 | 324 | 'name' => 'collabwatchlisttag-rl', |
325 | 325 | 'class' => 'mw-collaborative-watchlist-tag-selector')) . |
326 | 326 | Xml::closeElement('select'); |
327 | | - |
| 327 | + |
328 | 328 | return $ret; |
329 | 329 | } |
330 | | - |
| 330 | + |
331 | 331 | /** Returns an array mapping from collab watchlist tag names to information about the tag |
332 | | - * |
| 332 | + * |
333 | 333 | * The info is an array with the following keys: |
334 | 334 | * 'rt_description' The description of the tag |
335 | 335 | * 'rl_ids' An array of collab watchlist ids the tag belongs to |
— | — | @@ -346,17 +346,16 @@ |
347 | 347 | __METHOD__ |
348 | 348 | ); |
349 | 349 | $list = array(); |
350 | | - while( $row = $res->fetchObject() ) { |
| 350 | + foreach( $res as $row ) { |
351 | 351 | if(array_key_exists($row->rt_name, $list)) { |
352 | 352 | $list[$row->rt_name]['rl_ids'][] = $row->rl_id; |
353 | 353 | } else { |
354 | 354 | $list[$row->rt_name] = array('rt_description' => $row->rt_description, 'rl_ids' => array($row->rl_id)); |
355 | 355 | } |
356 | 356 | } |
357 | | - $dbr->freeResult( $res ); |
358 | 357 | return $list; |
359 | 358 | } |
360 | | - |
| 359 | + |
361 | 360 | //XXX Cache the result of this method in this class |
362 | 361 | /** Get an array mapping from collab watchlist id to its name, filtering by member type |
363 | 362 | * The method return only collab watchlist the given user is a member of, restricted by the allowed member types |
— | — | @@ -376,13 +375,12 @@ |
377 | 376 | # Join conditions |
378 | 377 | array( 'collabwatchlistuser' => array('JOIN', $wgDBprefix . 'collabwatchlist.rl_id = ' . $wgDBprefix . 'collabwatchlistuser.rl_id') ) |
379 | 378 | ); |
380 | | - while( $row = $res->fetchObject() ) { |
| 379 | + foreach( $res as $row ) { |
381 | 380 | $list[$row->rl_id] = $row->rl_name; |
382 | 381 | } |
383 | | - $dbr->freeResult( $res ); |
384 | 382 | return $list; |
385 | 383 | } |
386 | | - |
| 384 | + |
387 | 385 | //XXX Copied from HistoryPage, we should patch HistoryPage to export that functionality |
388 | 386 | // as a static function |
389 | 387 | /** |
— | — | @@ -393,7 +391,7 @@ |
394 | 392 | * @return String Undo Link |
395 | 393 | */ |
396 | 394 | public static function generateUndoLink($skin, $title, $revision, $undoAfterRevision) { |
397 | | - if( ! $revision instanceof Revision || ! $undoAfterRevision instanceof Revision || |
| 395 | + if( ! $revision instanceof Revision || ! $undoAfterRevision instanceof Revision || |
398 | 396 | ! $title instanceof Title || !$skin instanceof Skin ) |
399 | 397 | return null; |
400 | 398 | # Create undo tooltip for the first (=latest) line only |
Index: trunk/extensions/CollabWatchlist/includes/CollabWatchlistEditor.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | const USERS_EDIT_RAW = 7; |
24 | 24 | const NEW_LIST = 8; |
25 | 25 | const DELETE_LIST = 9; |
26 | | - |
| 26 | + |
27 | 27 | /** |
28 | 28 | * Main execution point |
29 | 29 | * |
— | — | @@ -267,14 +267,14 @@ |
268 | 268 | return $tokenOk; |
269 | 269 | return $this->checkPermissions( $user, $rlId, $memberTypes ); |
270 | 270 | } |
271 | | - |
| 271 | + |
272 | 272 | private function checkPermissions( $user, $rlId, $memberTypes = array(COLLABWATCHLISTUSER_OWNER) ) { |
273 | 273 | // Check permissions |
274 | 274 | $dbr = wfGetDB( DB_MASTER ); |
275 | 275 | $res = $dbr->select( 'collabwatchlistuser', |
276 | | - 'COUNT(*) AS count', |
| 276 | + 'COUNT(*) AS count', |
277 | 277 | array( 'rl_id' => $rlId, 'user_id' => $user->getId(), 'rlu_type' => $memberTypes ), |
278 | | - __METHOD__ |
| 278 | + __METHOD__ |
279 | 279 | ); |
280 | 280 | $row = $dbr->fetchObject( $res ); |
281 | 281 | return $row->count >= 1; |
— | — | @@ -311,7 +311,7 @@ |
312 | 312 | } |
313 | 313 | return array_unique( $titles ); |
314 | 314 | } |
315 | | - |
| 315 | + |
316 | 316 | private function extractTypeTypeTextAndUsername( $typeAndUsernameStr ) { |
317 | 317 | $type = COLLABWATCHLISTUSER_USER; |
318 | 318 | $typeText = COLLABWATCHLISTUSER_USER_TEXT; |
— | — | @@ -332,7 +332,7 @@ |
333 | 333 | } |
334 | 334 | return array($type, $typeText, $titleText); |
335 | 335 | } |
336 | | - |
| 336 | + |
337 | 337 | /** |
338 | 338 | * Extract a list of users from a blob of text, returning |
339 | 339 | * (prefixed) strings |
— | — | @@ -358,7 +358,7 @@ |
359 | 359 | } |
360 | 360 | return array_unique( $titles ); |
361 | 361 | } |
362 | | - |
| 362 | + |
363 | 363 | /** |
364 | 364 | * Extract a list of tags from a blob of text, returning |
365 | 365 | * (prefixed) strings |
— | — | @@ -425,7 +425,7 @@ |
426 | 426 | } |
427 | 427 | $output->addHTML( "</ul>\n" ); |
428 | 428 | } |
429 | | - |
| 429 | + |
430 | 430 | /** |
431 | 431 | * Print out a list of tags with description |
432 | 432 | * |
— | — | @@ -458,7 +458,7 @@ |
459 | 459 | $row = $dbr->fetchObject( $res ); |
460 | 460 | return $row->count; |
461 | 461 | } |
462 | | - |
| 462 | + |
463 | 463 | /** |
464 | 464 | * Count the number of users on a collaborative watchlist |
465 | 465 | * |
— | — | @@ -471,7 +471,7 @@ |
472 | 472 | $row = $dbr->fetchObject( $res ); |
473 | 473 | return $row->count; |
474 | 474 | } |
475 | | - |
| 475 | + |
476 | 476 | /** |
477 | 477 | * Count the number of tags on a collaborative watchlist |
478 | 478 | * |
— | — | @@ -484,7 +484,7 @@ |
485 | 485 | $row = $dbr->fetchObject( $res ); |
486 | 486 | return $row->count; |
487 | 487 | } |
488 | | - |
| 488 | + |
489 | 489 | /** |
490 | 490 | * Count the number of set edit tags on a collaborative watchlist |
491 | 491 | * |
— | — | @@ -519,16 +519,15 @@ |
520 | 520 | array( 'page' => array('JOIN', 'page.page_id = collabwatchlistcategory.cat_page_id') ) |
521 | 521 | ); |
522 | 522 | if( $res->numRows() > 0 ) { |
523 | | - while( $row = $res->fetchObject() ) { |
| 523 | + foreach( $res as $row ) { |
524 | 524 | $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
525 | 525 | if( $title instanceof Title && !$title->isTalkPage() ) |
526 | 526 | $list[] = $row->subtract ? '- ' . $title->getPrefixedText() : $title->getPrefixedText(); |
527 | 527 | } |
528 | | - $res->free(); |
529 | 528 | } |
530 | 529 | return $list; |
531 | 530 | } |
532 | | - |
| 531 | + |
533 | 532 | /** |
534 | 533 | * Prepare a list of users on a collaborative watchlist |
535 | 534 | * and return an array of (prefixed) strings |
— | — | @@ -550,15 +549,14 @@ |
551 | 550 | array( 'user' => array('JOIN', 'user.user_id = collabwatchlistuser.user_id') ) |
552 | 551 | ); |
553 | 552 | if( $res->numRows() > 0 ) { |
554 | | - while( $row = $res->fetchObject() ) { |
| 553 | + foreach( $res as $row ) { |
555 | 554 | $typeText = fnCollabWatchlistUserTypeToText($row->rlu_type); |
556 | 555 | $list[] = $typeText . ' ' . $row->user_name; |
557 | 556 | } |
558 | | - $res->free(); |
559 | 557 | } |
560 | 558 | return $list; |
561 | 559 | } |
562 | | - |
| 560 | + |
563 | 561 | /** |
564 | 562 | * Prepare a list of tags on a collaborative watchlist |
565 | 563 | * and return an array of tag names mapping to tag descriptions |
— | — | @@ -577,10 +575,9 @@ |
578 | 576 | ), __METHOD__ |
579 | 577 | ); |
580 | 578 | if( $res->numRows() > 0 ) { |
581 | | - while( $row = $res->fetchObject() ) { |
| 579 | + foreach( $res as $row ) { |
582 | 580 | $list[$row->rt_name] = $row->rt_description; |
583 | 581 | } |
584 | | - $res->free(); |
585 | 582 | } |
586 | 583 | return $list; |
587 | 584 | } |
— | — | @@ -596,7 +593,7 @@ |
597 | 594 | private function getWatchlistInfo( $rlId ) { |
598 | 595 | $titles = array(); |
599 | 596 | $dbr = wfGetDB( DB_MASTER ); |
600 | | - |
| 597 | + |
601 | 598 | $res = $dbr->select( |
602 | 599 | array('collabwatchlistcategory', 'page'), |
603 | 600 | array('page_title', 'page_namespace', 'page_id', 'page_len', 'page_is_redirect', 'subtract'), |
— | — | @@ -607,10 +604,10 @@ |
608 | 605 | # Join conditions |
609 | 606 | array( 'page' => array('JOIN', 'page.page_id = collabwatchlistcategory.cat_page_id') ) |
610 | 607 | ); |
611 | | - |
| 608 | + |
612 | 609 | if( $res && $dbr->numRows( $res ) > 0 ) { |
613 | 610 | $cache = LinkCache::singleton(); |
614 | | - while( $row = $dbr->fetchObject( $res ) ) { |
| 611 | + foreach( $res as $row ) { |
615 | 612 | $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title ); |
616 | 613 | if( $title instanceof Title ) { |
617 | 614 | // Update the link cache while we're at it |
— | — | @@ -645,7 +642,7 @@ |
646 | 643 | } |
647 | 644 | return $count; |
648 | 645 | } |
649 | | - |
| 646 | + |
650 | 647 | /** |
651 | 648 | * Show a message indicating the number of categories on the collaborative watchlist, |
652 | 649 | * and return this count for additional checking |
— | — | @@ -663,7 +660,7 @@ |
664 | 661 | } |
665 | 662 | return $count; |
666 | 663 | } |
667 | | - |
| 664 | + |
668 | 665 | /** |
669 | 666 | * Show a message indicating the number of set tags for edits on the collaborative watchlist, |
670 | 667 | * and return this count for additional checking |
— | — | @@ -681,7 +678,7 @@ |
682 | 679 | } |
683 | 680 | return $count; |
684 | 681 | } |
685 | | - |
| 682 | + |
686 | 683 | /** |
687 | 684 | * Show a message indicating the number of categories on the collaborative watchlist, |
688 | 685 | * and return this count for additional checking |
— | — | @@ -699,7 +696,7 @@ |
700 | 697 | } |
701 | 698 | return $count; |
702 | 699 | } |
703 | | - |
| 700 | + |
704 | 701 | /** |
705 | 702 | * Remove all categories from a collaborative watchlist |
706 | 703 | * |
— | — | @@ -744,7 +741,7 @@ |
745 | 742 | $dbw->insert( 'collabwatchlistcategory', $rows, __METHOD__, 'IGNORE' ); |
746 | 743 | return $added; |
747 | 744 | } |
748 | | - |
| 745 | + |
749 | 746 | /** |
750 | 747 | * Add a list of users to a collaborative watchlist |
751 | 748 | * |
— | — | @@ -772,7 +769,7 @@ |
773 | 770 | $dbw->insert( 'collabwatchlistuser', $rows, __METHOD__, 'IGNORE' ); |
774 | 771 | return $added; |
775 | 772 | } |
776 | | - |
| 773 | + |
777 | 774 | private function setTags( $titlesAndTagInfo, $tag, $userId, $rlId, $comment, $setPatrolled = false) { |
778 | 775 | //XXX Attach a hook to delete tags from the collabwatchlistrevisiontag table as soon as the actual tags are deleted from the change_tags table |
779 | 776 | $allowedTagsAndInfo = $this->getCollabWatchlistTags($rlId); |
— | — | @@ -792,7 +789,7 @@ |
793 | 790 | } |
794 | 791 | } |
795 | 792 | // Add the tagged revisions to the collaborative watchlist |
796 | | - $sql = 'INSERT IGNORE INTO collabwatchlistrevisiontag (ct_id, rl_id, user_id, rrt_comment) |
| 793 | + $sql = 'INSERT IGNORE INTO collabwatchlistrevisiontag (ct_id, rl_id, user_id, rrt_comment) |
797 | 794 | SELECT ct_id, ' . $dbw->strencode($rlId) . ',' . |
798 | 795 | $dbw->strencode($userId) . ',' . |
799 | 796 | $dbw->addQuotes($comment) . ' FROM change_tag WHERE ct_tag = ? AND ct_rc_id '; |
— | — | @@ -809,7 +806,7 @@ |
810 | 807 | return true; |
811 | 808 | } |
812 | 809 | } |
813 | | - |
| 810 | + |
814 | 811 | private function unsetTags( $titlesAndTagInfo, $tag, $userId, $rlId ) { |
815 | 812 | $dbw = wfGetDB( DB_MASTER ); |
816 | 813 | foreach( $titlesAndTagInfo as $title => $infos ) { |
— | — | @@ -820,8 +817,8 @@ |
821 | 818 | $rcIds[] = $info['rc_id']; |
822 | 819 | } |
823 | 820 | // Remove the tag from the collaborative watchlist |
824 | | - $sql = 'delete collabwatchlistrevisiontag from collabwatchlistrevisiontag JOIN change_tag |
825 | | - ON change_tag.ct_id = collabwatchlistrevisiontag.ct_id |
| 821 | + $sql = 'delete collabwatchlistrevisiontag from collabwatchlistrevisiontag JOIN change_tag |
| 822 | + ON change_tag.ct_id = collabwatchlistrevisiontag.ct_id |
826 | 823 | WHERE ct_tag = ? AND ct_rc_id '; |
827 | 824 | if( count($rcIds) > 1 ) { |
828 | 825 | $sql .= 'IN (' . $dbw->makeList($rcIds) . ')'; |
— | — | @@ -835,7 +832,7 @@ |
836 | 833 | $dbw->freePrepared($prepSql); |
837 | 834 | } |
838 | 835 | } |
839 | | - |
| 836 | + |
840 | 837 | /** |
841 | 838 | * Add a list of tags to a collaborative watchlist |
842 | 839 | * |
— | — | @@ -893,7 +890,7 @@ |
894 | 891 | } |
895 | 892 | } |
896 | 893 | } |
897 | | - |
| 894 | + |
898 | 895 | /** |
899 | 896 | * Remove a list of users from a collaborative watchlist |
900 | 897 | * |
— | — | @@ -922,7 +919,7 @@ |
923 | 920 | //XXX Check if we can simply rename the hook, or if we need to register it |
924 | 921 | //wfRunHooks('UnwatchArticleComplete',array(&$user,&$article)); |
925 | 922 | } |
926 | | - |
| 923 | + |
927 | 924 | /** |
928 | 925 | * Remove a list of tags from a collaborative watchlist |
929 | 926 | * |
— | — | @@ -970,7 +967,7 @@ |
971 | 968 | $output->addHTML( $form ); |
972 | 969 | } |
973 | 970 | } |
974 | | - |
| 971 | + |
975 | 972 | private function showNewListForm( $output ) { |
976 | 973 | global $wgUser; |
977 | 974 | $self = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
— | — | @@ -984,7 +981,7 @@ |
985 | 982 | $form .= '</fieldset></form>'; |
986 | 983 | $output->addHTML( $form ); |
987 | 984 | } |
988 | | - |
| 985 | + |
989 | 986 | private function showDeleteListForm( $output, $rlId ) { |
990 | 987 | global $wgUser; |
991 | 988 | $self = SpecialPage::getTitleFor( 'CollabWatchlist' ); |
— | — | @@ -1000,7 +997,7 @@ |
1001 | 998 | $form .= '</fieldset></form>'; |
1002 | 999 | $output->addHTML( $form ); |
1003 | 1000 | } |
1004 | | - |
| 1001 | + |
1005 | 1002 | private function createNewList($name) { |
1006 | 1003 | global $wgUser; |
1007 | 1004 | if( !isset($name) || empty($name) ) |
— | — | @@ -1014,7 +1011,7 @@ |
1015 | 1012 | 'rl_name' => $name, |
1016 | 1013 | 'rl_start' => wfTimestamp(TS_ISO_8601), |
1017 | 1014 | ), __METHOD__, 'IGNORE' ); |
1018 | | - |
| 1015 | + |
1019 | 1016 | $affected = $dbw->affectedRows(); |
1020 | 1017 | if( $affected ) { |
1021 | 1018 | $newid = $dbw->insertId(); |
— | — | @@ -1039,7 +1036,7 @@ |
1040 | 1037 | $dbw->rollback(); |
1041 | 1038 | } |
1042 | 1039 | } |
1043 | | - |
| 1040 | + |
1044 | 1041 | private function deleteList($rlId) { |
1045 | 1042 | if( !isset($rlId) || empty($rlId) ) |
1046 | 1043 | return; |
— | — | @@ -1188,7 +1185,7 @@ |
1189 | 1186 | $form .= '</fieldset></form>'; |
1190 | 1187 | $output->addHTML( $form ); |
1191 | 1188 | } |
1192 | | - |
| 1189 | + |
1193 | 1190 | /** |
1194 | 1191 | * Show a form for editing the tags of a collaborative watchlist in "raw" mode |
1195 | 1192 | * |
— | — | @@ -1218,7 +1215,7 @@ |
1219 | 1216 | $form .= '</fieldset></form>'; |
1220 | 1217 | $output->addHTML( $form ); |
1221 | 1218 | } |
1222 | | - |
| 1219 | + |
1223 | 1220 | /** |
1224 | 1221 | * Show a form for editing the users of a collaborative watchlist in "raw" mode |
1225 | 1222 | * |
— | — | @@ -1293,7 +1290,7 @@ |
1294 | 1291 | */ |
1295 | 1292 | public static function buildTools( $listIdsAndNames, $skin ) { |
1296 | 1293 | global $wgLang, $wgUser; |
1297 | | - $modes = array( 'view' => false, 'delete' => 'delete', 'edit' => 'edit', |
| 1294 | + $modes = array( 'view' => false, 'delete' => 'delete', 'edit' => 'edit', |
1298 | 1295 | 'rawCategories' => 'rawCategories', 'rawTags' => 'rawTags', |
1299 | 1296 | 'rawUsers' => 'rawUsers' ); |
1300 | 1297 | $r = ''; |
— | — | @@ -1323,9 +1320,9 @@ |
1324 | 1321 | } |
1325 | 1322 | return $r; |
1326 | 1323 | } |
1327 | | - |
| 1324 | + |
1328 | 1325 | /** Returns a URL for unsetting a specific tag on a specific edit on a given list |
1329 | | - * |
| 1326 | + * |
1330 | 1327 | * @param String $redirUrl The url to redirect after the tag was removed |
1331 | 1328 | * @param String $pageName The name of the page the tag is set on |
1332 | 1329 | * @param int $rlId The id of the collab watchlist |