* Wrap the result as an RSS/Atom feed.
*/
public function execute() {
- global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgSitename, $wgLanguageCode;
-
+ $config = $this->getConfig();
+ $feedClasses = $config->get( 'FeedClasses' );
try {
$params = $this->extractRequestParams();
- if ( !$wgFeed ) {
+ if ( !$config->get( 'Feed' ) ) {
$this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
}
- if ( !isset( $wgFeedClasses[$params['feedformat']] ) ) {
+ if ( !isset( $feedClasses[$params['feedformat']] ) ) {
$this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
}
'wlprop' => 'title|user|comment|timestamp|ids',
'wldir' => 'older', // reverse order - from newest to oldest
'wlend' => $endTime, // stop at this time
- 'wllimit' => min( 50, $wgFeedLimit )
+ 'wllimit' => min( 50, $this->getConfig()->get( 'FeedLimit' ) )
);
if ( $params['wlowner'] !== null ) {
$feedItems = array();
foreach ( (array)$data['query']['watchlist'] as $info ) {
- $feedItems[] = $this->createFeedItem( $info );
+ $feedItem = $this->createFeedItem( $info );
+ if ( $feedItem ) {
+ $feedItems[] = $feedItem;
+ }
}
$msg = wfMessage( 'watchlist' )->inContentLanguage()->text();
- $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
+ $feedTitle = $this->getConfig()->get( 'Sitename' ) . ' - ' . $msg . ' [' . $this->getConfig()->get( 'LanguageCode' ) . ']';
$feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL();
- $feed = new $wgFeedClasses[$params['feedformat']] (
+ $feed = new $feedClasses[$params['feedformat']] (
$feedTitle,
htmlspecialchars( $msg ),
$feedUrl
$this->getMain()->setCacheMaxAge( 0 );
// @todo FIXME: Localise brackets
- $feedTitle = $wgSitename . ' - Error - ' .
+ $feedTitle = $this->getConfig()->get( 'Sitename' ) . ' - Error - ' .
wfMessage( 'watchlist' )->inContentLanguage()->text() .
- ' [' . $wgLanguageCode . ']';
+ ' [' . $this->getConfig()->get( 'LanguageCode' ) . ']';
$feedUrl = SpecialPage::getTitleFor( 'Watchlist' )->getFullURL();
$feedFormat = isset( $params['feedformat'] ) ? $params['feedformat'] : 'rss';
$msg = wfMessage( 'watchlist' )->inContentLanguage()->escaped();
- $feed = new $wgFeedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl );
+ $feed = new $feedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl );
if ( $e instanceof UsageException ) {
$errorCode = $e->getCodeString();
private function createFeedItem( $info ) {
$titleStr = $info['title'];
$title = Title::newFromText( $titleStr );
+ $curidParam = array();
+ if ( !$title || $title->isExternal() ) {
+ // Probably a formerly-valid title that's now conflicting with an
+ // interwiki prefix or the like.
+ if ( isset( $info['pageid'] ) ) {
+ $title = Title::newFromId( $info['pageid'] );
+ $curidParam = array( 'curid' => $info['pageid'] );
+ }
+ if ( !$title || $title->isExternal() ) {
+ return null;
+ }
+ }
if ( isset( $info['revid'] ) ) {
$titleUrl = $title->getFullURL( array( 'diff' => $info['revid'] ) );
} else {
- $titleUrl = $title->getFullURL();
+ $titleUrl = $title->getFullURL( $curidParam );
}
$comment = isset( $info['comment'] ) ? $info['comment'] : null;
}
public function getAllowedParams( $flags = 0 ) {
- global $wgFeedClasses;
- $feedFormatNames = array_keys( $wgFeedClasses );
+ $feedFormatNames = array_keys( $this->getConfig()->get( 'FeedClasses' ) );
$ret = array(
'feedformat' => array(
ApiBase::PARAM_DFLT => 'rss',
),
'linktosections' => false,
);
+
+ $copyParams = array(
+ 'allrev' => 'allrev',
+ 'owner' => 'wlowner',
+ 'token' => 'wltoken',
+ 'show' => 'wlshow',
+ 'type' => 'wltype',
+ 'excludeuser' => 'wlexcludeuser',
+ );
if ( $flags ) {
$wlparams = $this->getWatchlistModule()->getAllowedParams( $flags );
- $ret['allrev'] = $wlparams['allrev'];
- $ret['wlowner'] = $wlparams['owner'];
- $ret['wltoken'] = $wlparams['token'];
- $ret['wlshow'] = $wlparams['show'];
- $ret['wltype'] = $wlparams['type'];
- $ret['wlexcludeuser'] = $wlparams['excludeuser'];
+ foreach ( $copyParams as $from => $to ) {
+ $p = $wlparams[$from];
+ if ( !is_array( $p ) ) {
+ $p = array( ApiBase::PARAM_DFLT => $p );
+ }
+ if ( !isset( $p[ApiBase::PARAM_HELP_MSG] ) ) {
+ $p[ApiBase::PARAM_HELP_MSG] = "apihelp-query+watchlist-param-$from";
+ }
+ $ret[$to] = $p;
+ }
} else {
- $ret['allrev'] = null;
- $ret['wlowner'] = null;
- $ret['wltoken'] = null;
- $ret['wlshow'] = null;
- $ret['wltype'] = null;
- $ret['wlexcludeuser'] = null;
+ foreach ( $copyParams as $from => $to ) {
+ $ret[$to] = null;
+ }
}
return $ret;
}
- public function getParamDescription() {
- $wldescr = $this->getWatchlistModule()->getParamDescription();
-
- return array(
- 'feedformat' => 'The format of the feed',
- 'hours' => 'List pages modified within this many hours from now',
- 'linktosections' => 'Link directly to changed sections if possible',
- 'allrev' => $wldescr['allrev'],
- 'wlowner' => $wldescr['owner'],
- 'wltoken' => $wldescr['token'],
- 'wlshow' => $wldescr['show'],
- 'wltype' => $wldescr['type'],
- 'wlexcludeuser' => $wldescr['excludeuser'],
- );
- }
-
- public function getDescription() {
- return 'Returns a watchlist feed.';
- }
-
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(), array(
- array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
- array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
- ) );
- }
-
- public function getExamples() {
+ protected function getExamplesMessages() {
return array(
- 'api.php?action=feedwatchlist',
- 'api.php?action=feedwatchlist&allrev=&hours=6'
+ 'action=feedwatchlist'
+ => 'apihelp-feedwatchlist-example-default',
+ 'action=feedwatchlist&allrev=&hours=6'
+ => 'apihelp-feedwatchlist-example-all6hrs',
);
}