Index: trunk/extensions/CategoryFeed/CategoryFeed.i18n.php |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /* Internationalization file for CategoryFeed extension |
4 | | -*/ |
| 4 | + */ |
5 | 5 | |
6 | 6 | $messages = array(); |
7 | 7 | |
Index: trunk/extensions/CategoryFeed/CategoryFeed.php |
— | — | @@ -4,19 +4,19 @@ |
5 | 5 | * |
6 | 6 | * Copyright (C) 2005 Gabriel Wicke <wicke@wikidev.net> |
7 | 7 | * http://wikidev.net |
8 | | - * |
| 8 | + * |
9 | 9 | * uses bits from recentchanges feeds |
10 | 10 | * |
11 | 11 | * This program is free software; you can redistribute it and/or modify |
12 | 12 | * it under the terms of the GNU General Public License as published by |
13 | | - * the Free Software Foundation; either version 2 of the License, or |
| 13 | + * the Free Software Foundation; either version 2 of the License, or |
14 | 14 | * (at your option) any later version. |
15 | | - * |
| 15 | + * |
16 | 16 | * This program is distributed in the hope that it will be useful, |
17 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | 19 | * GNU General Public License for more details. |
20 | | - * |
| 20 | + * |
21 | 21 | * You should have received a copy of the GNU General Public License along |
22 | 22 | * with this program; if not, write to the Free Software Foundation, Inc., |
23 | 23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
— | — | @@ -35,17 +35,17 @@ |
36 | 36 | 'url' => 'http://wikidev.net', |
37 | 37 | ); |
38 | 38 | |
39 | | -$dir = dirname(__FILE__) . '/'; |
| 39 | +$dir = dirname( __FILE__ ) . '/'; |
40 | 40 | $wgExtensionMessagesFiles['catfeed'] = $dir . 'Categoryfeed.i18n.php'; |
41 | 41 | |
42 | | -if( $wgCategoryMagicGallery ) |
43 | | - require_once('ImageGallery.php'); |
| 42 | +if ( $wgCategoryMagicGallery ) |
| 43 | + require_once( 'ImageGallery.php' ); |
44 | 44 | |
45 | 45 | function setupCatRSSExtension() { |
46 | | - |
47 | 46 | global $IP; |
| 47 | + |
48 | 48 | require_once( "$IP/includes/CategoryPage.php" ); |
49 | | - require_once("Feed.php"); |
| 49 | + require_once( "Feed.php" ); |
50 | 50 | wfLoadExtensionMessages( 'catfeed' ); |
51 | 51 | global $wgHooks; |
52 | 52 | |
— | — | @@ -53,13 +53,12 @@ |
54 | 54 | global $wgParser; |
55 | 55 | $wgParser->setHook( "catnews", "viewCatNewslist" ); |
56 | 56 | |
57 | | - |
58 | 57 | class CategoryByDate extends CategoryPage { |
59 | 58 | /** |
60 | 59 | * Feed for recently-added members of a category based on cl_timestamp |
61 | 60 | * Uses bits of the recentchanges feeds (caching and formatting) |
62 | 61 | */ |
63 | | - |
| 62 | + |
64 | 63 | var $mLimit = 50; |
65 | 64 | var $mDatelevel = 2; |
66 | 65 | |
— | — | @@ -68,8 +67,8 @@ |
69 | 68 | $this->mTitle = $title; |
70 | 69 | $this->mFeedFormat = $wgRequest->getVal( 'feed', '' ); |
71 | 70 | $this->mTitleStrings = array(); |
72 | | - if ( is_array($tarray) ) { |
73 | | - foreach($tarray as $title) { |
| 71 | + if ( is_array( $tarray ) ) { |
| 72 | + foreach ( $tarray as $title ) { |
74 | 73 | $this->mTitleStrings[] = $title->getDBkey(); |
75 | 74 | } |
76 | 75 | } else { |
— | — | @@ -84,7 +83,7 @@ |
85 | 84 | function getData() { |
86 | 85 | $fname = __CLASS__ . '::' . __FUNCTION__; |
87 | 86 | $this->mMaxTimeStamp = 0; |
88 | | - |
| 87 | + |
89 | 88 | $dbr = wfGetDB( DB_SLAVE ); |
90 | 89 | $set = implode( ',', array_map( |
91 | 90 | array( &$dbr, 'addQuotes' ), |
— | — | @@ -94,12 +93,12 @@ |
95 | 94 | array( 'cur_title', 'cur_namespace', 'cur_text', 'cur_user_text', 'cl_sortkey', 'cl_timestamp' ), |
96 | 95 | array( 'cl_from = cur_id', |
97 | 96 | 'cl_to IN (' . $set . ')', |
98 | | - 'cur_is_redirect' => 0), |
| 97 | + 'cur_is_redirect' => 0 ), |
99 | 98 | $fname, |
100 | 99 | array( 'ORDER BY' => 'cl_timestamp DESC, cl_sortkey ASC', |
101 | | - 'LIMIT' => $this->mLimit )); |
| 100 | + 'LIMIT' => $this->mLimit ) ); |
102 | 101 | $rows = array(); |
103 | | - while( $row = $dbr->fetchObject ( $res ) ) { |
| 102 | + while ( $row = $dbr->fetchObject ( $res ) ) { |
104 | 103 | $rows[] = $row; |
105 | 104 | if ( $row->cl_timestamp > $this->mMaxTimeStamp ) { |
106 | 105 | $this->mMaxTimeStamp = $row->cl_timestamp; |
— | — | @@ -111,17 +110,17 @@ |
112 | 111 | # strip images, links, tags |
113 | 112 | function formatSummary ( $text ) { |
114 | 113 | global $wgContLang; |
115 | | - $prefixes = array_keys($wgContLang->getLanguageNames()); |
116 | | - $prefixes[] = $wgContLang->getNsText(NS_CATEGORY); |
117 | | - $imgprefix = $wgContLang->getNsText(NS_IMAGE); |
118 | | - $text = "\n".$text; |
| 114 | + $prefixes = array_keys( $wgContLang->getLanguageNames() ); |
| 115 | + $prefixes[] = $wgContLang->getNsText( NS_CATEGORY ); |
| 116 | + $imgprefix = $wgContLang->getNsText( NS_IMAGE ); |
| 117 | + $text = "\n" . $text; |
119 | 118 | |
120 | 119 | $rules = array( |
121 | | - "/\[\[(".implode('|',$prefixes)."):[^\]]*\]\]/i" => "", # interwiki links, cat links |
122 | | - "/\[\[(?!".$imgprefix.")([^\[\]]+)\|([^[\]\|]*)\]\]/" => "\$2", # piped links |
123 | | - "/\[\[(?!".$imgprefix.")([^\[\]]+)\]\]/i" => "\$1", # links |
| 120 | + "/\[\[(" . implode( '|', $prefixes ) . "):[^\]]*\]\]/i" => "", # interwiki links, cat links |
| 121 | + "/\[\[(?!" . $imgprefix . ")([^\[\]]+)\|([^[\]\|]*)\]\]/" => "\$2", # piped links |
| 122 | + "/\[\[(?!" . $imgprefix . ")([^\[\]]+)\]\]/i" => "\$1", # links |
124 | 123 | "/\[http:\/\/[^\s]+\s*(.*?)\]/" => "\$1", # external links |
125 | | - "/\[\[(".$imgprefix."|Image|Media):[^\]]*\]\]/i" => "", # images, plus int. prefix |
| 124 | + "/\[\[(" . $imgprefix . "|Image|Media):[^\]]*\]\]/i" => "", # images, plus int. prefix |
126 | 125 | "/<br([^>]{1,60})>/i" => "\n", # break |
127 | 126 | "/{{([^}]+)}}/s" => "", # templates |
128 | 127 | "/<table[^>]{0,660}>(.{1,1200})<\/table>/si" => "", # short tables are removed |
— | — | @@ -139,31 +138,29 @@ |
140 | 139 | "/(\n\s*)+/" => "\n" # many newlines |
141 | 140 | ); |
142 | 141 | |
143 | | - $text = preg_replace( array_keys($rules), array_values($rules), $text); |
144 | | - |
| 142 | + $text = preg_replace( array_keys( $rules ), array_values( $rules ), $text ); |
| 143 | + |
145 | 144 | # only return the first few chars for now |
146 | 145 | $shorttext = $wgContLang->truncate( trim( $text ), 145 ); |
147 | 146 | return htmlspecialchars( $shorttext ); |
148 | 147 | } |
149 | | - |
150 | | - function setLimit($limit) { |
151 | | - $this->mLimit=$limit; |
| 148 | + |
| 149 | + function setLimit( $limit ) { |
| 150 | + $this->mLimit = $limit; |
152 | 151 | } |
153 | | - |
154 | | - function setDatelevel($datelevel) { |
155 | | - $this->mDatelevel=$datelevel; |
156 | | - } |
157 | 152 | |
| 153 | + function setDatelevel( $datelevel ) { |
| 154 | + $this->mDatelevel = $datelevel; |
| 155 | + } |
158 | 156 | } |
159 | 157 | |
160 | 158 | class CategoryByDateFeed extends CategoryByDate { |
161 | | - |
162 | 159 | function view() { |
163 | 160 | global $wgRequest; |
164 | 161 | global $messageMemc, $wgDBname; |
165 | 162 | global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode; |
166 | 163 | |
167 | | - if( !isset( $wgFeedClasses[$this->mFeedFormat] ) ) { |
| 164 | + if ( !isset( $wgFeedClasses[$this->mFeedFormat] ) ) { |
168 | 165 | wfHttpError( 500, "Internal Server Error", "Unsupported feed type." ); |
169 | 166 | return false; |
170 | 167 | } |
— | — | @@ -172,16 +169,16 @@ |
173 | 170 | $feedTitle, |
174 | 171 | htmlspecialchars( wfMsgForContent( 'catfeedsummary' ) ), |
175 | 172 | $wgTitle->getFullUrl() ); |
176 | | - |
| 173 | + |
177 | 174 | $pagekey = md5( $this->mTitle->getDBkey() ); |
178 | 175 | $timekey = "$wgDBname:catfeed:$pagekey:$this->mFeedFormat:limit:{$this->mLimit}:timestamp"; |
179 | 176 | $key = "$wgDBname:catfeed:$pagekey:$this->mFeedFormat:limit:{$this->mLimit}"; |
180 | 177 | $cachedFeed = false; |
181 | | - $adddeltimestamp = $wgDBname.':Category:'.$pagekey.':adddeltimestamp'; |
182 | | - |
| 178 | + $adddeltimestamp = $wgDBname . ':Category:' . $pagekey . ':adddeltimestamp'; |
| 179 | + |
183 | 180 | $catLastAddDel = $messageMemc->get( $adddeltimestamp ); |
184 | 181 | |
185 | | - if( $feedLastmod = $messageMemc->get( $timekey ) |
| 182 | + if ( $feedLastmod = $messageMemc->get( $timekey ) |
186 | 183 | and $catLastAddDel <= $feedLastmod ) { |
187 | 184 | wfDebug( "CatFeed: loading feed from cache ($key; $feedLastmod; $catLastAddDel )...\n" ); |
188 | 185 | $cachedFeed = $messageMemc->get( $key ); |
— | — | @@ -189,7 +186,7 @@ |
190 | 187 | wfDebug( "CatFeed: cached feed timestamp check failed ($feedLastmod; $catLastAddDel) timekey: $timekey; adddel: $adddeltimestamp \n" ); |
191 | 188 | |
192 | 189 | } |
193 | | - if( is_string( $cachedFeed ) ) { |
| 190 | + if ( is_string( $cachedFeed ) ) { |
194 | 191 | wfDebug( "CatFeed: Outputting cached feed\n" ); |
195 | 192 | $this->feed->httpHeaders(); |
196 | 193 | echo $cachedFeed; |
— | — | @@ -211,7 +208,7 @@ |
212 | 209 | global $wgSitename, $wgFeedClasses, $wgContLanguageCode; |
213 | 210 | |
214 | 211 | $this->feed->outHeader(); |
215 | | - foreach( $rows as $row ) { |
| 212 | + foreach ( $rows as $row ) { |
216 | 213 | $title = Title::makeTitle( $row->cur_namespace, $row->cur_title ); |
217 | 214 | $item = new FeedItem( |
218 | 215 | $title->getPrefixedText(), |
— | — | @@ -219,17 +216,15 @@ |
220 | 217 | $title->getFullURL(), |
221 | 218 | $row->cl_timestamp, |
222 | 219 | $row->cur_user_text, |
223 | | - '' #$talkpage->getFullURL() |
| 220 | + '' # $talkpage->getFullURL() |
224 | 221 | ); |
225 | 222 | $this->feed->outItem( $item ); |
226 | 223 | } |
227 | 224 | $this->feed->outFooter(); |
228 | 225 | } |
229 | | - |
230 | 226 | } |
231 | 227 | |
232 | 228 | class CategoryByDateNewslist extends CategoryByDate { |
233 | | - |
234 | 229 | function formatRows( $rows ) { |
235 | 230 | # format members of a category as 'news list' within a page |
236 | 231 | # useful for portals, probably wikinews etc |
— | — | @@ -238,84 +233,83 @@ |
239 | 234 | $skin = &$wgUser->getSkin(); |
240 | 235 | $list = ''; |
241 | 236 | $ts = $closedl = $date = $oldns = $oldtitle = ''; |
242 | | - foreach( $rows as $row ) { |
| 237 | + foreach ( $rows as $row ) { |
243 | 238 | # check for duplicates, cheaper than in the db |
244 | | - if($row->cur_namespace != $oldns or $row->cur_title != $oldtitle) { |
| 239 | + if ( $row->cur_namespace != $oldns or $row->cur_title != $oldtitle ) { |
245 | 240 | $oldns = $row->cur_namespace; |
246 | 241 | $oldtitle = $row->cur_title; |
247 | 242 | $title = Title::makeTitle( $row->cur_namespace, $row->cur_title ); |
248 | 243 | $ts = $row->cl_timestamp; |
249 | 244 | $newdate = $wgLang->date( wfTimestamp( TS_MW, $ts ) ); |
250 | | - if( $date != $newdate ) { |
| 245 | + if ( $date != $newdate ) { |
251 | 246 | $date = $newdate; |
252 | | - $list .= "$closedl\n<h{$this->mDatelevel}> ".$date." </h{$this->mDatelevel}>\n<dl>"; |
| 247 | + $list .= "$closedl\n<h{$this->mDatelevel}> " . $date . " </h{$this->mDatelevel}>\n<dl>"; |
253 | 248 | $closedl = '</dl>'; |
254 | 249 | } |
255 | | - $list .= '<dt>' . $skin->makeKnownLinkObj($title) . |
| 250 | + $list .= '<dt>' . $skin->makeKnownLinkObj( $title ) . |
256 | 251 | ' <span style="font-size: 0.76em;font-weight:normal;">' . |
257 | 252 | $wgLang->time( wfTimestamp( TS_MW, $ts ) ) . '</span></dt><dd> ' . |
258 | | - $this->formatSummary( $row->cur_text ).'</dd>'; |
| 253 | + $this->formatSummary( $row->cur_text ) . '</dd>'; |
259 | 254 | } |
260 | 255 | } |
261 | 256 | return $list . $closedl; |
262 | 257 | } |
263 | 258 | } |
264 | | - |
265 | 259 | } |
266 | 260 | |
267 | 261 | function viewCatFeed( &$CategoryPage ) { |
268 | 262 | global $wgRequest; |
269 | | - $catfeed = new CategoryByDateFeed($CategoryPage->mTitle); |
| 263 | + $catfeed = new CategoryByDateFeed( $CategoryPage->mTitle ); |
270 | 264 | # nothing to do,CategoryPage::view continues |
271 | | - if(!$wgRequest->getBool('feed',false)) return true; |
272 | | - |
| 265 | + if ( !$wgRequest->getBool( 'feed', false ) ) return true; |
| 266 | + |
273 | 267 | # else continue |
274 | 268 | $catfeed->view(); |
275 | 269 | # stop CategoryPage::view from continuing |
276 | 270 | return false; |
277 | 271 | } |
| 272 | + |
278 | 273 | function viewCatNewslist( $input ) { |
279 | 274 | $text = ''; |
280 | | - |
| 275 | + |
281 | 276 | # Defaults |
282 | 277 | # |
283 | | - # Number of headlines to be shown |
284 | | - $limit=50; |
| 278 | + # Number of headlines to be shown |
| 279 | + $limit = 50; |
285 | 280 | # Header level to be used for dates |
286 | | - $datelevel=2; |
287 | | - |
| 281 | + $datelevel = 2; |
| 282 | + |
288 | 283 | # Extract possible options from input |
289 | | - getCatOption($limit,$input,"limit"); |
290 | | - getCatOption($datelevel,$input,"datelevel"); |
| 284 | + getCatOption( $limit, $input, "limit" ); |
| 285 | + getCatOption( $datelevel, $input, "datelevel" ); |
291 | 286 | |
292 | | - $iptitles = split("\n",trim($input)); |
| 287 | + $iptitles = split( "\n", trim( $input ) ); |
293 | 288 | $dbtitles = array(); |
294 | | - |
| 289 | + |
295 | 290 | # Add only valid title objects |
296 | 291 | foreach ( $iptitles as $title ) { |
297 | | - $addtitle = Title::newFromURL($title); |
298 | | - if(get_class($addtitle)=="title") { |
| 292 | + $addtitle = Title::newFromURL( $title ); |
| 293 | + if ( get_class( $addtitle ) == "title" ) { |
299 | 294 | $dbtitles[] = $addtitle; |
300 | 295 | } |
301 | 296 | } |
302 | | - # search for 5 categories max for now |
303 | | - $dbtitles = array_slice($dbtitles, 0, 4); |
304 | | - if(count($dbtitles)>0) { |
305 | | - $catnews = new CategoryByDateNewslist($dbtitles[0], $dbtitles); |
306 | | - $catnews->setLimit($limit); |
307 | | - $catnews->setDatelevel($datelevel); |
| 297 | + # search for 5 categories max for now |
| 298 | + $dbtitles = array_slice( $dbtitles, 0, 4 ); |
| 299 | + if ( count( $dbtitles ) > 0 ) { |
| 300 | + $catnews = new CategoryByDateNewslist( $dbtitles[0], $dbtitles ); |
| 301 | + $catnews->setLimit( $limit ); |
| 302 | + $catnews->setDatelevel( $datelevel ); |
308 | 303 | $text .= $catnews->view(); |
309 | 304 | } |
310 | | - |
| 305 | + |
311 | 306 | return $text; |
312 | 307 | } |
313 | 308 | |
314 | | -function getCatOption(&$value,&$input,$name) { |
| 309 | +function getCatOption( &$value, &$input, $name ) { |
315 | 310 | |
316 | | - if(preg_match("/$name\s*=\s*(\d+)/mi",$input,$matches)) { |
317 | | - $value=$matches[1]; |
| 311 | + if ( preg_match( "/$name\s*=\s*(\d+)/mi", $input, $matches ) ) { |
| 312 | + $value = $matches[1]; |
318 | 313 | # Extract from input |
319 | | - $input=preg_replace("/$name\s*=\s*\d+/mi","",$input); |
320 | | - } |
| 314 | + $input = preg_replace( "/$name\s*=\s*\d+/mi", "", $input ); |
| 315 | + } |
321 | 316 | } |
322 | | - |