r65341 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65340‎ | r65341 | r65342 >
Date:21:11, 20 April 2010
Author:siebrand
Status:deferred
Tags:
Comment:
stylize.php, trailing whitespace removed
Modified paths:
  • /trunk/extensions/CategoryFeed/CategoryFeed.i18n.php (modified) (history)
  • /trunk/extensions/CategoryFeed/CategoryFeed.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CategoryFeed/CategoryFeed.i18n.php
@@ -1,6 +1,6 @@
22 <?php
33 /* Internationalization file for CategoryFeed extension
4 -*/
 4+ */
55
66 $messages = array();
77
Index: trunk/extensions/CategoryFeed/CategoryFeed.php
@@ -4,19 +4,19 @@
55 *
66 * Copyright (C) 2005 Gabriel Wicke <wicke@wikidev.net>
77 * http://wikidev.net
8 - *
 8+ *
99 * uses bits from recentchanges feeds
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * 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
1414 * (at your option) any later version.
15 - *
 15+ *
1616 * This program is distributed in the hope that it will be useful,
1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1919 * GNU General Public License for more details.
20 - *
 20+ *
2121 * You should have received a copy of the GNU General Public License along
2222 * with this program; if not, write to the Free Software Foundation, Inc.,
2323 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -35,17 +35,17 @@
3636 'url' => 'http://wikidev.net',
3737 );
3838
39 -$dir = dirname(__FILE__) . '/';
 39+$dir = dirname( __FILE__ ) . '/';
4040 $wgExtensionMessagesFiles['catfeed'] = $dir . 'Categoryfeed.i18n.php';
4141
42 -if( $wgCategoryMagicGallery )
43 - require_once('ImageGallery.php');
 42+if ( $wgCategoryMagicGallery )
 43+ require_once( 'ImageGallery.php' );
4444
4545 function setupCatRSSExtension() {
46 -
4746 global $IP;
 47+
4848 require_once( "$IP/includes/CategoryPage.php" );
49 - require_once("Feed.php");
 49+ require_once( "Feed.php" );
5050 wfLoadExtensionMessages( 'catfeed' );
5151 global $wgHooks;
5252
@@ -53,13 +53,12 @@
5454 global $wgParser;
5555 $wgParser->setHook( "catnews", "viewCatNewslist" );
5656
57 -
5857 class CategoryByDate extends CategoryPage {
5958 /**
6059 * Feed for recently-added members of a category based on cl_timestamp
6160 * Uses bits of the recentchanges feeds (caching and formatting)
6261 */
63 -
 62+
6463 var $mLimit = 50;
6564 var $mDatelevel = 2;
6665
@@ -68,8 +67,8 @@
6968 $this->mTitle = $title;
7069 $this->mFeedFormat = $wgRequest->getVal( 'feed', '' );
7170 $this->mTitleStrings = array();
72 - if ( is_array($tarray) ) {
73 - foreach($tarray as $title) {
 71+ if ( is_array( $tarray ) ) {
 72+ foreach ( $tarray as $title ) {
7473 $this->mTitleStrings[] = $title->getDBkey();
7574 }
7675 } else {
@@ -84,7 +83,7 @@
8584 function getData() {
8685 $fname = __CLASS__ . '::' . __FUNCTION__;
8786 $this->mMaxTimeStamp = 0;
88 -
 87+
8988 $dbr = wfGetDB( DB_SLAVE );
9089 $set = implode( ',', array_map(
9190 array( &$dbr, 'addQuotes' ),
@@ -94,12 +93,12 @@
9594 array( 'cur_title', 'cur_namespace', 'cur_text', 'cur_user_text', 'cl_sortkey', 'cl_timestamp' ),
9695 array( 'cl_from = cur_id',
9796 'cl_to IN (' . $set . ')',
98 - 'cur_is_redirect' => 0),
 97+ 'cur_is_redirect' => 0 ),
9998 $fname,
10099 array( 'ORDER BY' => 'cl_timestamp DESC, cl_sortkey ASC',
101 - 'LIMIT' => $this->mLimit ));
 100+ 'LIMIT' => $this->mLimit ) );
102101 $rows = array();
103 - while( $row = $dbr->fetchObject ( $res ) ) {
 102+ while ( $row = $dbr->fetchObject ( $res ) ) {
104103 $rows[] = $row;
105104 if ( $row->cl_timestamp > $this->mMaxTimeStamp ) {
106105 $this->mMaxTimeStamp = $row->cl_timestamp;
@@ -111,17 +110,17 @@
112111 # strip images, links, tags
113112 function formatSummary ( $text ) {
114113 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;
119118
120119 $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
124123 "/\[http:\/\/[^\s]+\s*(.*?)\]/" => "\$1", # external links
125 - "/\[\[(".$imgprefix."|Image|Media):[^\]]*\]\]/i" => "", # images, plus int. prefix
 124+ "/\[\[(" . $imgprefix . "|Image|Media):[^\]]*\]\]/i" => "", # images, plus int. prefix
126125 "/<br([^>]{1,60})>/i" => "\n", # break
127126 "/{{([^}]+)}}/s" => "", # templates
128127 "/<table[^>]{0,660}>(.{1,1200})<\/table>/si" => "", # short tables are removed
@@ -139,31 +138,29 @@
140139 "/(\n\s*)+/" => "\n" # many newlines
141140 );
142141
143 - $text = preg_replace( array_keys($rules), array_values($rules), $text);
144 -
 142+ $text = preg_replace( array_keys( $rules ), array_values( $rules ), $text );
 143+
145144 # only return the first few chars for now
146145 $shorttext = $wgContLang->truncate( trim( $text ), 145 );
147146 return htmlspecialchars( $shorttext );
148147 }
149 -
150 - function setLimit($limit) {
151 - $this->mLimit=$limit;
 148+
 149+ function setLimit( $limit ) {
 150+ $this->mLimit = $limit;
152151 }
153 -
154 - function setDatelevel($datelevel) {
155 - $this->mDatelevel=$datelevel;
156 - }
157152
 153+ function setDatelevel( $datelevel ) {
 154+ $this->mDatelevel = $datelevel;
 155+ }
158156 }
159157
160158 class CategoryByDateFeed extends CategoryByDate {
161 -
162159 function view() {
163160 global $wgRequest;
164161 global $messageMemc, $wgDBname;
165162 global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode;
166163
167 - if( !isset( $wgFeedClasses[$this->mFeedFormat] ) ) {
 164+ if ( !isset( $wgFeedClasses[$this->mFeedFormat] ) ) {
168165 wfHttpError( 500, "Internal Server Error", "Unsupported feed type." );
169166 return false;
170167 }
@@ -172,16 +169,16 @@
173170 $feedTitle,
174171 htmlspecialchars( wfMsgForContent( 'catfeedsummary' ) ),
175172 $wgTitle->getFullUrl() );
176 -
 173+
177174 $pagekey = md5( $this->mTitle->getDBkey() );
178175 $timekey = "$wgDBname:catfeed:$pagekey:$this->mFeedFormat:limit:{$this->mLimit}:timestamp";
179176 $key = "$wgDBname:catfeed:$pagekey:$this->mFeedFormat:limit:{$this->mLimit}";
180177 $cachedFeed = false;
181 - $adddeltimestamp = $wgDBname.':Category:'.$pagekey.':adddeltimestamp';
182 -
 178+ $adddeltimestamp = $wgDBname . ':Category:' . $pagekey . ':adddeltimestamp';
 179+
183180 $catLastAddDel = $messageMemc->get( $adddeltimestamp );
184181
185 - if( $feedLastmod = $messageMemc->get( $timekey )
 182+ if ( $feedLastmod = $messageMemc->get( $timekey )
186183 and $catLastAddDel <= $feedLastmod ) {
187184 wfDebug( "CatFeed: loading feed from cache ($key; $feedLastmod; $catLastAddDel )...\n" );
188185 $cachedFeed = $messageMemc->get( $key );
@@ -189,7 +186,7 @@
190187 wfDebug( "CatFeed: cached feed timestamp check failed ($feedLastmod; $catLastAddDel) timekey: $timekey; adddel: $adddeltimestamp \n" );
191188
192189 }
193 - if( is_string( $cachedFeed ) ) {
 190+ if ( is_string( $cachedFeed ) ) {
194191 wfDebug( "CatFeed: Outputting cached feed\n" );
195192 $this->feed->httpHeaders();
196193 echo $cachedFeed;
@@ -211,7 +208,7 @@
212209 global $wgSitename, $wgFeedClasses, $wgContLanguageCode;
213210
214211 $this->feed->outHeader();
215 - foreach( $rows as $row ) {
 212+ foreach ( $rows as $row ) {
216213 $title = Title::makeTitle( $row->cur_namespace, $row->cur_title );
217214 $item = new FeedItem(
218215 $title->getPrefixedText(),
@@ -219,17 +216,15 @@
220217 $title->getFullURL(),
221218 $row->cl_timestamp,
222219 $row->cur_user_text,
223 - '' #$talkpage->getFullURL()
 220+ '' # $talkpage->getFullURL()
224221 );
225222 $this->feed->outItem( $item );
226223 }
227224 $this->feed->outFooter();
228225 }
229 -
230226 }
231227
232228 class CategoryByDateNewslist extends CategoryByDate {
233 -
234229 function formatRows( $rows ) {
235230 # format members of a category as 'news list' within a page
236231 # useful for portals, probably wikinews etc
@@ -238,84 +233,83 @@
239234 $skin = &$wgUser->getSkin();
240235 $list = '';
241236 $ts = $closedl = $date = $oldns = $oldtitle = '';
242 - foreach( $rows as $row ) {
 237+ foreach ( $rows as $row ) {
243238 # 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 ) {
245240 $oldns = $row->cur_namespace;
246241 $oldtitle = $row->cur_title;
247242 $title = Title::makeTitle( $row->cur_namespace, $row->cur_title );
248243 $ts = $row->cl_timestamp;
249244 $newdate = $wgLang->date( wfTimestamp( TS_MW, $ts ) );
250 - if( $date != $newdate ) {
 245+ if ( $date != $newdate ) {
251246 $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>";
253248 $closedl = '</dl>';
254249 }
255 - $list .= '<dt>' . $skin->makeKnownLinkObj($title) .
 250+ $list .= '<dt>' . $skin->makeKnownLinkObj( $title ) .
256251 ' <span style="font-size: 0.76em;font-weight:normal;">' .
257252 $wgLang->time( wfTimestamp( TS_MW, $ts ) ) . '</span></dt><dd> ' .
258 - $this->formatSummary( $row->cur_text ).'</dd>';
 253+ $this->formatSummary( $row->cur_text ) . '</dd>';
259254 }
260255 }
261256 return $list . $closedl;
262257 }
263258 }
264 -
265259 }
266260
267261 function viewCatFeed( &$CategoryPage ) {
268262 global $wgRequest;
269 - $catfeed = new CategoryByDateFeed($CategoryPage->mTitle);
 263+ $catfeed = new CategoryByDateFeed( $CategoryPage->mTitle );
270264 # nothing to do,CategoryPage::view continues
271 - if(!$wgRequest->getBool('feed',false)) return true;
272 -
 265+ if ( !$wgRequest->getBool( 'feed', false ) ) return true;
 266+
273267 # else continue
274268 $catfeed->view();
275269 # stop CategoryPage::view from continuing
276270 return false;
277271 }
 272+
278273 function viewCatNewslist( $input ) {
279274 $text = '';
280 -
 275+
281276 # Defaults
282277 #
283 - # Number of headlines to be shown
284 - $limit=50;
 278+ # Number of headlines to be shown
 279+ $limit = 50;
285280 # Header level to be used for dates
286 - $datelevel=2;
287 -
 281+ $datelevel = 2;
 282+
288283 # 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" );
291286
292 - $iptitles = split("\n",trim($input));
 287+ $iptitles = split( "\n", trim( $input ) );
293288 $dbtitles = array();
294 -
 289+
295290 # Add only valid title objects
296291 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" ) {
299294 $dbtitles[] = $addtitle;
300295 }
301296 }
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 );
308303 $text .= $catnews->view();
309304 }
310 -
 305+
311306 return $text;
312307 }
313308
314 -function getCatOption(&$value,&$input,$name) {
 309+function getCatOption( &$value, &$input, $name ) {
315310
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];
318313 # 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+ }
321316 }
322 -

Status & tagging log