r106767 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106766‎ | r106767 | r106768 >
Date:08:02, 20 December 2011
Author:maxsem
Status:ok
Tags:
Comment:
API module fixes: language selection, examples
Modified paths:
  • /trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FeaturedFeeds/ApiFeaturedFeeds.php
@@ -23,7 +23,11 @@
2424 $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
2525 }
2626
27 - $feeds = FeaturedFeeds::getFeeds( false );
 27+ $language = isset( $params['language'] ) ? $params['language'] : false;
 28+ if ( $language !== false && !Language::isValidCode( $language ) ) {
 29+ $this->dieUsage( 'Invalid language code', 'language-invalid' );
 30+ }
 31+ $feeds = FeaturedFeeds::getFeeds( $language );
2832 $ourFeed = $feeds[$params['channel']];
2933
3034 $feedClass = new $wgFeedClasses[$params['feedformat']] (
@@ -49,6 +53,9 @@
5054 ApiBase::PARAM_TYPE => $availableFeeds,
5155 ApiBase::PARAM_REQUIRED => true,
5256 ),
 57+ 'language' => array(
 58+ ApiBase::PARAM_TYPE => 'string',
 59+ )
5360 );
5461 }
5562
@@ -56,6 +63,7 @@
5764 return array(
5865 'feedformat' => 'The format of the feed',
5966 'channel' => 'Feed channel',
 67+ 'language' => 'Feed language code. Ignored by some feeds.'
6068 );
6169 }
6270
@@ -70,12 +78,28 @@
7179 }
7280
7381 public function getExamples() {
74 - return array(
75 - 'api.php?action=featuredfeed&channel=featured', //@todo
76 - );
 82+ global $wgVersion;
 83+ // attempt to find a valid channel name
 84+ // if none available, just use an example value
 85+ $availableFeeds = array_keys( FeaturedFeeds::getFeeds( false ) );
 86+ $channel = reset( $availableFeeds );
 87+ if ( !$channel ) {
 88+ $channel = 'featured';
 89+ }
 90+
 91+ if ( version_compare( $wgVersion, '1.19alpha', '>=' ) ) {
 92+ return array(
 93+ "api.php?action=featuredfeed&channel=$channel" => "Retrieve feed for channel `$channel'",
 94+ );
 95+ } else {
 96+ return array(
 97+ "Retrieve feed for channel `$channel'",
 98+ " api.php?action=featuredfeed&channel=$channel",
 99+ );
 100+ }
77101 }
78102
79103 public function getVersion() {
80104 return __CLASS__ . ': $Id$';
81105 }
82 -}
\ No newline at end of file
 106+}

Status & tagging log