http://www.mediawiki.org/wiki/Special:Code/MediaWiki/65341
Revision: 65341 Author: siebrand Date: 2010-04-20 21:11:00 +0000 (Tue, 20 Apr 2010) Log Message: ----------- stylize.php, trailing whitespace removed Modified Paths: -------------- trunk/extensions/CategoryFeed/CategoryFeed.i18n.php trunk/extensions/CategoryFeed/CategoryFeed.php Modified: trunk/extensions/CategoryFeed/CategoryFeed.i18n.php =================================================================== --- trunk/extensions/CategoryFeed/CategoryFeed.i18n.php 2010-04-20 21:03:48 UTC (rev 65340) +++ trunk/extensions/CategoryFeed/CategoryFeed.i18n.php 2010-04-20 21:11:00 UTC (rev 65341) @@ -1,6 +1,6 @@ <?php /* Internationalization file for CategoryFeed extension -*/ + */ $messages = array(); Modified: trunk/extensions/CategoryFeed/CategoryFeed.php =================================================================== --- trunk/extensions/CategoryFeed/CategoryFeed.php 2010-04-20 21:03:48 UTC (rev 65340) +++ trunk/extensions/CategoryFeed/CategoryFeed.php 2010-04-20 21:11:00 UTC (rev 65341) @@ -4,19 +4,19 @@ * * Copyright (C) 2005 Gabriel Wicke <wi...@wikidev.net> * http://wikidev.net - * + * * uses bits from recentchanges feeds * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -35,17 +35,17 @@ 'url' => 'http://wikidev.net', ); -$dir = dirname(__FILE__) . '/'; +$dir = dirname( __FILE__ ) . '/'; $wgExtensionMessagesFiles['catfeed'] = $dir . 'Categoryfeed.i18n.php'; -if( $wgCategoryMagicGallery ) - require_once('ImageGallery.php'); +if ( $wgCategoryMagicGallery ) + require_once( 'ImageGallery.php' ); function setupCatRSSExtension() { - global $IP; + require_once( "$IP/includes/CategoryPage.php" ); - require_once("Feed.php"); + require_once( "Feed.php" ); wfLoadExtensionMessages( 'catfeed' ); global $wgHooks; @@ -53,13 +53,12 @@ global $wgParser; $wgParser->setHook( "catnews", "viewCatNewslist" ); - class CategoryByDate extends CategoryPage { /** * Feed for recently-added members of a category based on cl_timestamp * Uses bits of the recentchanges feeds (caching and formatting) */ - + var $mLimit = 50; var $mDatelevel = 2; @@ -68,8 +67,8 @@ $this->mTitle = $title; $this->mFeedFormat = $wgRequest->getVal( 'feed', '' ); $this->mTitleStrings = array(); - if ( is_array($tarray) ) { - foreach($tarray as $title) { + if ( is_array( $tarray ) ) { + foreach ( $tarray as $title ) { $this->mTitleStrings[] = $title->getDBkey(); } } else { @@ -84,7 +83,7 @@ function getData() { $fname = __CLASS__ . '::' . __FUNCTION__; $this->mMaxTimeStamp = 0; - + $dbr = wfGetDB( DB_SLAVE ); $set = implode( ',', array_map( array( &$dbr, 'addQuotes' ), @@ -94,12 +93,12 @@ array( 'cur_title', 'cur_namespace', 'cur_text', 'cur_user_text', 'cl_sortkey', 'cl_timestamp' ), array( 'cl_from = cur_id', 'cl_to IN (' . $set . ')', - 'cur_is_redirect' => 0), + 'cur_is_redirect' => 0 ), $fname, array( 'ORDER BY' => 'cl_timestamp DESC, cl_sortkey ASC', - 'LIMIT' => $this->mLimit )); + 'LIMIT' => $this->mLimit ) ); $rows = array(); - while( $row = $dbr->fetchObject ( $res ) ) { + while ( $row = $dbr->fetchObject ( $res ) ) { $rows[] = $row; if ( $row->cl_timestamp > $this->mMaxTimeStamp ) { $this->mMaxTimeStamp = $row->cl_timestamp; @@ -111,17 +110,17 @@ # strip images, links, tags function formatSummary ( $text ) { global $wgContLang; - $prefixes = array_keys($wgContLang->getLanguageNames()); - $prefixes[] = $wgContLang->getNsText(NS_CATEGORY); - $imgprefix = $wgContLang->getNsText(NS_IMAGE); - $text = "\n".$text; + $prefixes = array_keys( $wgContLang->getLanguageNames() ); + $prefixes[] = $wgContLang->getNsText( NS_CATEGORY ); + $imgprefix = $wgContLang->getNsText( NS_IMAGE ); + $text = "\n" . $text; $rules = array( - "/\[\[(".implode('|',$prefixes)."):[^\]]*\]\]/i" => "", # interwiki links, cat links - "/\[\[(?!".$imgprefix.")([^\[\]]+)\|([^[\]\|]*)\]\]/" => "\$2", # piped links - "/\[\[(?!".$imgprefix.")([^\[\]]+)\]\]/i" => "\$1", # links + "/\[\[(" . implode( '|', $prefixes ) . "):[^\]]*\]\]/i" => "", # interwiki links, cat links + "/\[\[(?!" . $imgprefix . ")([^\[\]]+)\|([^[\]\|]*)\]\]/" => "\$2", # piped links + "/\[\[(?!" . $imgprefix . ")([^\[\]]+)\]\]/i" => "\$1", # links "/\[http:\/\/[^\s]+\s*(.*?)\]/" => "\$1", # external links - "/\[\[(".$imgprefix."|Image|Media):[^\]]*\]\]/i" => "", # images, plus int. prefix + "/\[\[(" . $imgprefix . "|Image|Media):[^\]]*\]\]/i" => "", # images, plus int. prefix "/<br([^>]{1,60})>/i" => "\n", # break "/{{([^}]+)}}/s" => "", # templates "/<table[^>]{0,660}>(.{1,1200})<\/table>/si" => "", # short tables are removed @@ -139,31 +138,29 @@ "/(\n\s*)+/" => "\n" # many newlines ); - $text = preg_replace( array_keys($rules), array_values($rules), $text); - + $text = preg_replace( array_keys( $rules ), array_values( $rules ), $text ); + # only return the first few chars for now $shorttext = $wgContLang->truncate( trim( $text ), 145 ); return htmlspecialchars( $shorttext ); } - - function setLimit($limit) { - $this->mLimit=$limit; + + function setLimit( $limit ) { + $this->mLimit = $limit; } - - function setDatelevel($datelevel) { - $this->mDatelevel=$datelevel; - } + function setDatelevel( $datelevel ) { + $this->mDatelevel = $datelevel; + } } class CategoryByDateFeed extends CategoryByDate { - function view() { global $wgRequest; global $messageMemc, $wgDBname; global $wgFeedClasses, $wgTitle, $wgSitename, $wgContLanguageCode; - if( !isset( $wgFeedClasses[$this->mFeedFormat] ) ) { + if ( !isset( $wgFeedClasses[$this->mFeedFormat] ) ) { wfHttpError( 500, "Internal Server Error", "Unsupported feed type." ); return false; } @@ -172,16 +169,16 @@ $feedTitle, htmlspecialchars( wfMsgForContent( 'catfeedsummary' ) ), $wgTitle->getFullUrl() ); - + $pagekey = md5( $this->mTitle->getDBkey() ); $timekey = "$wgDBname:catfeed:$pagekey:$this->mFeedFormat:limit:{$this->mLimit}:timestamp"; $key = "$wgDBname:catfeed:$pagekey:$this->mFeedFormat:limit:{$this->mLimit}"; $cachedFeed = false; - $adddeltimestamp = $wgDBname.':Category:'.$pagekey.':adddeltimestamp'; - + $adddeltimestamp = $wgDBname . ':Category:' . $pagekey . ':adddeltimestamp'; + $catLastAddDel = $messageMemc->get( $adddeltimestamp ); - if( $feedLastmod = $messageMemc->get( $timekey ) + if ( $feedLastmod = $messageMemc->get( $timekey ) and $catLastAddDel <= $feedLastmod ) { wfDebug( "CatFeed: loading feed from cache ($key; $feedLastmod; $catLastAddDel )...\n" ); $cachedFeed = $messageMemc->get( $key ); @@ -189,7 +186,7 @@ wfDebug( "CatFeed: cached feed timestamp check failed ($feedLastmod; $catLastAddDel) timekey: $timekey; adddel: $adddeltimestamp \n" ); } - if( is_string( $cachedFeed ) ) { + if ( is_string( $cachedFeed ) ) { wfDebug( "CatFeed: Outputting cached feed\n" ); $this->feed->httpHeaders(); echo $cachedFeed; @@ -211,7 +208,7 @@ global $wgSitename, $wgFeedClasses, $wgContLanguageCode; $this->feed->outHeader(); - foreach( $rows as $row ) { + foreach ( $rows as $row ) { $title = Title::makeTitle( $row->cur_namespace, $row->cur_title ); $item = new FeedItem( $title->getPrefixedText(), @@ -219,17 +216,15 @@ $title->getFullURL(), $row->cl_timestamp, $row->cur_user_text, - '' #$talkpage->getFullURL() + '' # $talkpage->getFullURL() ); $this->feed->outItem( $item ); } $this->feed->outFooter(); } - } class CategoryByDateNewslist extends CategoryByDate { - function formatRows( $rows ) { # format members of a category as 'news list' within a page # useful for portals, probably wikinews etc @@ -238,84 +233,83 @@ $skin = &$wgUser->getSkin(); $list = ''; $ts = $closedl = $date = $oldns = $oldtitle = ''; - foreach( $rows as $row ) { + foreach ( $rows as $row ) { # check for duplicates, cheaper than in the db - if($row->cur_namespace != $oldns or $row->cur_title != $oldtitle) { + if ( $row->cur_namespace != $oldns or $row->cur_title != $oldtitle ) { $oldns = $row->cur_namespace; $oldtitle = $row->cur_title; $title = Title::makeTitle( $row->cur_namespace, $row->cur_title ); $ts = $row->cl_timestamp; $newdate = $wgLang->date( wfTimestamp( TS_MW, $ts ) ); - if( $date != $newdate ) { + if ( $date != $newdate ) { $date = $newdate; - $list .= "$closedl\n<h{$this->mDatelevel}> ".$date." </h{$this->mDatelevel}>\n<dl>"; + $list .= "$closedl\n<h{$this->mDatelevel}> " . $date . " </h{$this->mDatelevel}>\n<dl>"; $closedl = '</dl>'; } - $list .= '<dt>' . $skin->makeKnownLinkObj($title) . + $list .= '<dt>' . $skin->makeKnownLinkObj( $title ) . ' <span style="font-size: 0.76em;font-weight:normal;">' . $wgLang->time( wfTimestamp( TS_MW, $ts ) ) . '</span></dt><dd> ' . - $this->formatSummary( $row->cur_text ).'</dd>'; + $this->formatSummary( $row->cur_text ) . '</dd>'; } } return $list . $closedl; } } - } function viewCatFeed( &$CategoryPage ) { global $wgRequest; - $catfeed = new CategoryByDateFeed($CategoryPage->mTitle); + $catfeed = new CategoryByDateFeed( $CategoryPage->mTitle ); # nothing to do,CategoryPage::view continues - if(!$wgRequest->getBool('feed',false)) return true; - + if ( !$wgRequest->getBool( 'feed', false ) ) return true; + # else continue $catfeed->view(); # stop CategoryPage::view from continuing return false; } + function viewCatNewslist( $input ) { $text = ''; - + # Defaults # - # Number of headlines to be shown - $limit=50; + # Number of headlines to be shown + $limit = 50; # Header level to be used for dates - $datelevel=2; - + $datelevel = 2; + # Extract possible options from input - getCatOption($limit,$input,"limit"); - getCatOption($datelevel,$input,"datelevel"); + getCatOption( $limit, $input, "limit" ); + getCatOption( $datelevel, $input, "datelevel" ); - $iptitles = split("\n",trim($input)); + $iptitles = split( "\n", trim( $input ) ); $dbtitles = array(); - + # Add only valid title objects foreach ( $iptitles as $title ) { - $addtitle = Title::newFromURL($title); - if(get_class($addtitle)=="title") { + $addtitle = Title::newFromURL( $title ); + if ( get_class( $addtitle ) == "title" ) { $dbtitles[] = $addtitle; } } - # search for 5 categories max for now - $dbtitles = array_slice($dbtitles, 0, 4); - if(count($dbtitles)>0) { - $catnews = new CategoryByDateNewslist($dbtitles[0], $dbtitles); - $catnews->setLimit($limit); - $catnews->setDatelevel($datelevel); + # search for 5 categories max for now + $dbtitles = array_slice( $dbtitles, 0, 4 ); + if ( count( $dbtitles ) > 0 ) { + $catnews = new CategoryByDateNewslist( $dbtitles[0], $dbtitles ); + $catnews->setLimit( $limit ); + $catnews->setDatelevel( $datelevel ); $text .= $catnews->view(); } - + return $text; } -function getCatOption(&$value,&$input,$name) { +function getCatOption( &$value, &$input, $name ) { - if(preg_match("/$name\s*=\s*(\d+)/mi",$input,$matches)) { - $value=$matches[1]; + if ( preg_match( "/$name\s*=\s*(\d+)/mi", $input, $matches ) ) { + $value = $matches[1]; # Extract from input - $input=preg_replace("/$name\s*=\s*\d+/mi","",$input); - } + $input = preg_replace( "/$name\s*=\s*\d+/mi", "", $input ); + } } - _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs