http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83804
Revision: 83804 Author: bawolff Date: 2011-03-13 03:06:31 +0000 (Sun, 13 Mar 2011) Log Message: ----------- Various fixes: *Make this a non-includable special page. A special page calling $wgOut->disable, and then outputting an xml document should not be transcludable. Bad things happen. *Move the $wgFeedClasses setup into the setup file. It shouldn't only sometimes be loaded. *Remove the $parser->transformMsg calls. They're unnessary (you're not going to put {{MAGICWORDS}} into url params) and probably a bad idea. *Change/fix the way it handles category url parameter. Do &category=cat1|cat2|cat3 instead of &category[]=cat1&category[]=cat2 since the former seems more mediawiki style. Also make it do stuff with the parameter, don't just extract and throw away *Make it output an empty xml document if there are no results. This seems more sane than just outputting a random string, since this is meant to be read by computers who won't understand what the string "no results" means. (Although its unclear if this makes an invalid xml sitemap, but its going to happen from time to time so we have to do something). This also fixes some php warnings. Kill the noresults message as no longer used. *Make one of the errors an exception since it should really never never happen (Only could happen if the hardcoded fallback category is not a valid title, which is fairly impossible.) Kills badfeed message. Modified Paths: -------------- trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.i18n.php trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php Modified: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.i18n.php =================================================================== --- trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.i18n.php 2011-03-13 00:34:54 UTC (rev 83803) +++ trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.i18n.php 2011-03-13 03:06:31 UTC (rev 83804) @@ -19,9 +19,7 @@ 'googlenewssitemap_categorymap' => '', # Default empty. List of categories to map to keywords. Do not translate. 'googlenewssitemap_toomanycats' => 'Error: Too many categories!', 'googlenewssitemap_toofewcats' => 'Error: Too few categories!', - 'googlenewssitemap_noresults' => 'Error: No results!', 'googlenewssitemap_noincludecats' => 'Error: You need to include at least one category, or specify a namespace!', - 'googlenewssitemap_badfeedobject' => '$feed is not an object.', ); /** Message documentation (Message documentation) Modified: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php =================================================================== --- trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php 2011-03-13 00:34:54 UTC (rev 83803) +++ trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap.php 2011-03-13 03:06:31 UTC (rev 83804) @@ -68,3 +68,5 @@ $wgAutoloadClasses['FeedSMItem'] = $dir . 'FeedSMItem.php'; $wgAutoloadClasses['SitemapFeed'] = $dir . 'SitemapFeed.php'; $wgSpecialPages['GoogleNewsSitemap'] = 'GoogleNewsSitemap'; +$wgFeedClasses['sitemap'] = 'SitemapFeed'; + Modified: trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php =================================================================== --- trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php 2011-03-13 00:34:54 UTC (rev 83803) +++ trunk/extensions/GoogleNewsSitemap/GoogleNewsSitemap_body.php 2011-03-13 03:06:31 UTC (rev 83804) @@ -26,7 +26,7 @@ * suppresserrors = bool ; default = false **/ -class GoogleNewsSitemap extends IncludableSpecialPage { +class GoogleNewsSitemap extends SpecialPage { /** * FIXME: Some of this might need a config eventually * @var string @@ -91,8 +91,6 @@ } - $wgFeedClasses['sitemap'] = 'SitemapFeed' ; - $feed = new $wgFeedClasses[ $this->params['feed'] ]( $wgSitename, $wgSitename . ' ' . $this->params['feed'] . ' feed', @@ -103,18 +101,6 @@ $res = $this->doQuery(); - // FIXME: figure out how to fail with no results gracefully - if ( $res->numRows( $res ) == 0 ) { - $feed->outFooter(); - if ( false == $this->params['suppressErrors'] ) { - $wgOut->disable(); - echo htmlspecialchars( wfMsg( 'googlenewssitemap_noresults' ) ); - return; - } else { - return ''; - } - } - $feed->outHeader(); foreach ( $res as $row ) { $title = Title::makeTitle( $row->page_namespace, $row->page_title ); @@ -271,13 +257,16 @@ global $wgRequest; $this->params = array(); - $parser = new Parser; - $poptions = new ParserOptions; - $category = $wgRequest->getArray( 'category', 'Published' ); - // $title = Title::newFromText( $parser->transformMsg( $category, $poptions ) ); - // if ( is_object( $title ) ){ - // $this->categories[] = $title; - // } + + $category = $wgRequest->getText( 'category', 'Published' ); + $category = explode( "|", $category ); + foreach ( $category as $catName ) { + $catTitle = Title::newFromText( $catName, NS_CATEGORY ); + if ( $catTitle ) { + $this->categories[] = $catTitle; + } + } + // FIXME:notcats // $this->notCategories[] = $wgRequest->getArray('notcategory'); $this->params['nameSpace'] = $wgContLang->getNsIndex( $wgRequest->getVal( 'namespace', 0 ) ); @@ -300,15 +289,16 @@ $this->params['catCount'] = count( $this->categories ); $this->params['notCatCount'] = count( $this->notCategories ); $totalCatCount = $this->params['catCount'] + $this->params['notCatCount']; - if ( ( $this->params['catCount'] < 1 && !$this->params['nameSpace'] ) || ( $totalCatCount < $this->wgDPlminCategories ) ) { - $parser = new Parser; - $poptions = new ParserOptions; - $feed = Title::newFromText( $parser->transformMsg( 'Published', $poptions ) ); + + if ( ( $this->params['catCount'] < 1 && !$this->params['nameSpace'] ) + || ( $totalCatCount < $this->wgDPlminCategories ) ) + { + $feed = Title::newFromText( 'Published', NS_CATEGORY ); if ( is_object( $feed ) ) { $this->categories[] = $feed; $this->params['catCount'] = count( $this->categories ); } else { - $this->params['error'] = htmlspecialchars( wfMsg( 'googlenewssitemap_badfeedobject' ) ); + throw new MWException( "Default fallback category is not a valid title!" ); } } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs