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