MediaWiki  REL1_23
ApiFeedRecentChanges.php
Go to the documentation of this file.
00001 <?php
00027 class ApiFeedRecentChanges extends ApiBase {
00028 
00034     public function getCustomPrinter() {
00035         return new ApiFormatFeedWrapper( $this->getMain() );
00036     }
00037 
00042     public function execute() {
00043         global $wgFeed, $wgFeedClasses;
00044 
00045         $this->params = $this->extractRequestParams();
00046 
00047         if ( !$wgFeed ) {
00048             $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
00049         }
00050 
00051         if ( !isset( $wgFeedClasses[$this->params['feedformat']] ) ) {
00052             $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
00053         }
00054 
00055         $this->getMain()->setCacheMode( 'public' );
00056         if ( !$this->getMain()->getParameter( 'smaxage' ) ) {
00057             // bug 63249: This page gets hit a lot, cache at least 15 seconds.
00058             $this->getMain()->setCacheMaxAge( 15 );
00059         }
00060 
00061         $feedFormat = $this->params['feedformat'];
00062         $specialClass = $this->params['target'] !== null
00063             ? 'SpecialRecentchangeslinked'
00064             : 'SpecialRecentchanges';
00065 
00066         $formatter = $this->getFeedObject( $feedFormat, $specialClass );
00067 
00068         // Everything is passed implicitly via $wgRequest… :(
00069         // The row-getting functionality should maybe be factored out of ChangesListSpecialPage too…
00070         $rc = new $specialClass();
00071         $rows = $rc->getRows();
00072 
00073         $feedItems = $rows ? ChangesFeed::buildItems( $rows ) : array();
00074 
00075         ApiFormatFeedWrapper::setResult( $this->getResult(), $formatter, $feedItems );
00076     }
00077 
00086     public function getFeedObject( $feedFormat, $specialClass ) {
00087         if ( $specialClass === 'SpecialRecentchangeslinked' ) {
00088             $title = Title::newFromText( $this->params['target'] );
00089             if ( !$title ) {
00090                 $this->dieUsageMsg( array( 'invalidtitle', $this->params['target'] ) );
00091             }
00092 
00093             $feed = new ChangesFeed( $feedFormat, false );
00094             $feedObj = $feed->getFeedObject(
00095                 $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
00096                     ->inContentLanguage()->text(),
00097                 $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
00098                 SpecialPage::getTitleFor( 'Recentchangeslinked' )->getFullURL()
00099             );
00100         } else {
00101             $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
00102             $feedObj = $feed->getFeedObject(
00103                 $this->msg( 'recentchanges' )->inContentLanguage()->text(),
00104                 $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
00105                 SpecialPage::getTitleFor( 'Recentchanges' )->getFullURL()
00106             );
00107         }
00108 
00109         return $feedObj;
00110     }
00111 
00112     public function getAllowedParams() {
00113         global $wgFeedClasses, $wgAllowCategorizedRecentChanges, $wgFeedLimit;
00114         $feedFormatNames = array_keys( $wgFeedClasses );
00115 
00116         $ret = array(
00117             'feedformat' => array(
00118                 ApiBase::PARAM_DFLT => 'rss',
00119                 ApiBase::PARAM_TYPE => $feedFormatNames,
00120             ),
00121 
00122             'namespace' => array(
00123                 ApiBase::PARAM_TYPE => 'namespace',
00124             ),
00125             'invert' => false,
00126             'associated' => false,
00127 
00128             'days' => array(
00129                 ApiBase::PARAM_DFLT => 7,
00130                 ApiBase::PARAM_MIN => 1,
00131                 ApiBase::PARAM_TYPE => 'integer',
00132             ),
00133             'limit' => array(
00134                 ApiBase::PARAM_DFLT => 50,
00135                 ApiBase::PARAM_MIN => 1,
00136                 ApiBase::PARAM_MAX => $wgFeedLimit,
00137                 ApiBase::PARAM_TYPE => 'integer',
00138             ),
00139             'from' => array(
00140                 ApiBase::PARAM_TYPE => 'timestamp',
00141             ),
00142 
00143             'hideminor' => false,
00144             'hidebots' => false,
00145             'hideanons' => false,
00146             'hideliu' => false,
00147             'hidepatrolled' => false,
00148             'hidemyself' => false,
00149 
00150             'tagfilter' => array(
00151                 ApiBase::PARAM_TYPE => 'string',
00152             ),
00153 
00154             'target' => array(
00155                 ApiBase::PARAM_TYPE => 'string',
00156             ),
00157             'showlinkedto' => false,
00158         );
00159 
00160         if ( $wgAllowCategorizedRecentChanges ) {
00161             $ret += array(
00162                 'categories' => array(
00163                     ApiBase::PARAM_TYPE => 'string',
00164                     ApiBase::PARAM_ISMULTI => true,
00165                 ),
00166                 'categories_any' => false,
00167             );
00168         }
00169 
00170         return $ret;
00171     }
00172 
00173     public function getParamDescription() {
00174         return array(
00175             'feedformat' => 'The format of the feed',
00176             'namespace' => 'Namespace to limit the results to',
00177             'invert' => 'All namespaces but the selected one',
00178             'associated' => 'Include associated (talk or main) namespace',
00179             'days' => 'Days to limit the results to',
00180             'limit' => 'Maximum number of results to return',
00181             'from' => 'Show changes since then',
00182             'hideminor' => 'Hide minor changes',
00183             'hidebots' => 'Hide changes made by bots',
00184             'hideanons' => 'Hide changes made by anonymous users',
00185             'hideliu' => 'Hide changes made by registered users',
00186             'hidepatrolled' => 'Hide patrolled changes',
00187             'hidemyself' => 'Hide changes made by yourself',
00188             'tagfilter' => 'Filter by tag',
00189             'target' => 'Show only changes on pages linked from this page',
00190             'showlinkedto' => 'Show changes on pages linked to the selected page instead',
00191             'categories' => 'Show only changes on pages in all of these categories',
00192             'categories_any' => 'Show only changes on pages in any of the categories instead',
00193         );
00194     }
00195 
00196     public function getDescription() {
00197         return 'Returns a recent changes feed';
00198     }
00199 
00200     public function getPossibleErrors() {
00201         return array_merge( parent::getPossibleErrors(), array(
00202             array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
00203             array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
00204         ) );
00205     }
00206 
00207     public function getExamples() {
00208         return array(
00209             'api.php?action=feedrecentchanges',
00210             'api.php?action=feedrecentchanges&days=30'
00211         );
00212     }
00213 }