MediaWiki  1.23.12
ApiFeedRecentChanges.php
Go to the documentation of this file.
1 <?php
28 
34  public function getCustomPrinter() {
35  return new ApiFormatFeedWrapper( $this->getMain() );
36  }
37 
42  public function execute() {
43  global $wgFeed, $wgFeedClasses;
44 
45  $this->params = $this->extractRequestParams();
46 
47  if ( !$wgFeed ) {
48  $this->dieUsage( 'Syndication feeds are not available', 'feed-unavailable' );
49  }
50 
51  if ( !isset( $wgFeedClasses[$this->params['feedformat']] ) ) {
52  $this->dieUsage( 'Invalid subscription feed type', 'feed-invalid' );
53  }
54 
55  $this->getMain()->setCacheMode( 'public' );
56  if ( !$this->getMain()->getParameter( 'smaxage' ) ) {
57  // bug 63249: This page gets hit a lot, cache at least 15 seconds.
58  $this->getMain()->setCacheMaxAge( 15 );
59  }
60 
61  $feedFormat = $this->params['feedformat'];
62  $specialClass = $this->params['target'] !== null
63  ? 'SpecialRecentchangeslinked'
64  : 'SpecialRecentchanges';
65 
66  $formatter = $this->getFeedObject( $feedFormat, $specialClass );
67 
68  // Everything is passed implicitly via $wgRequest… :(
69  // The row-getting functionality should maybe be factored out of ChangesListSpecialPage too…
70  $rc = new $specialClass();
71  $rows = $rc->getRows();
72 
73  $feedItems = $rows ? ChangesFeed::buildItems( $rows ) : array();
74 
75  ApiFormatFeedWrapper::setResult( $this->getResult(), $formatter, $feedItems );
76  }
77 
86  public function getFeedObject( $feedFormat, $specialClass ) {
87  if ( $specialClass === 'SpecialRecentchangeslinked' ) {
88  $title = Title::newFromText( $this->params['target'] );
89  if ( !$title ) {
90  $this->dieUsageMsg( array( 'invalidtitle', $this->params['target'] ) );
91  }
92 
93  $feed = new ChangesFeed( $feedFormat, false );
94  $feedObj = $feed->getFeedObject(
95  $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
96  ->inContentLanguage()->text(),
97  $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
98  SpecialPage::getTitleFor( 'Recentchangeslinked' )->getFullURL()
99  );
100  } else {
101  $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
102  $feedObj = $feed->getFeedObject(
103  $this->msg( 'recentchanges' )->inContentLanguage()->text(),
104  $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
105  SpecialPage::getTitleFor( 'Recentchanges' )->getFullURL()
106  );
107  }
108 
109  return $feedObj;
110  }
111 
112  public function getAllowedParams() {
113  global $wgFeedClasses, $wgAllowCategorizedRecentChanges, $wgFeedLimit;
114  $feedFormatNames = array_keys( $wgFeedClasses );
115 
116  $ret = array(
117  'feedformat' => array(
118  ApiBase::PARAM_DFLT => 'rss',
119  ApiBase::PARAM_TYPE => $feedFormatNames,
120  ),
121 
122  'namespace' => array(
123  ApiBase::PARAM_TYPE => 'namespace',
124  ),
125  'invert' => false,
126  'associated' => false,
127 
128  'days' => array(
129  ApiBase::PARAM_DFLT => 7,
130  ApiBase::PARAM_MIN => 1,
131  ApiBase::PARAM_TYPE => 'integer',
132  ),
133  'limit' => array(
134  ApiBase::PARAM_DFLT => 50,
135  ApiBase::PARAM_MIN => 1,
136  ApiBase::PARAM_MAX => $wgFeedLimit,
137  ApiBase::PARAM_TYPE => 'integer',
138  ),
139  'from' => array(
140  ApiBase::PARAM_TYPE => 'timestamp',
141  ),
142 
143  'hideminor' => false,
144  'hidebots' => false,
145  'hideanons' => false,
146  'hideliu' => false,
147  'hidepatrolled' => false,
148  'hidemyself' => false,
149 
150  'tagfilter' => array(
151  ApiBase::PARAM_TYPE => 'string',
152  ),
153 
154  'target' => array(
155  ApiBase::PARAM_TYPE => 'string',
156  ),
157  'showlinkedto' => false,
158  );
159 
160  if ( $wgAllowCategorizedRecentChanges ) {
161  $ret += array(
162  'categories' => array(
163  ApiBase::PARAM_TYPE => 'string',
164  ApiBase::PARAM_ISMULTI => true,
165  ),
166  'categories_any' => false,
167  );
168  }
169 
170  return $ret;
171  }
172 
173  public function getParamDescription() {
174  return array(
175  'feedformat' => 'The format of the feed',
176  'namespace' => 'Namespace to limit the results to',
177  'invert' => 'All namespaces but the selected one',
178  'associated' => 'Include associated (talk or main) namespace',
179  'days' => 'Days to limit the results to',
180  'limit' => 'Maximum number of results to return',
181  'from' => 'Show changes since then',
182  'hideminor' => 'Hide minor changes',
183  'hidebots' => 'Hide changes made by bots',
184  'hideanons' => 'Hide changes made by anonymous users',
185  'hideliu' => 'Hide changes made by registered users',
186  'hidepatrolled' => 'Hide patrolled changes',
187  'hidemyself' => 'Hide changes made by yourself',
188  'tagfilter' => 'Filter by tag',
189  'target' => 'Show only changes on pages linked from this page',
190  'showlinkedto' => 'Show changes on pages linked to the selected page instead',
191  'categories' => 'Show only changes on pages in all of these categories',
192  'categories_any' => 'Show only changes on pages in any of the categories instead',
193  );
194  }
195 
196  public function getDescription() {
197  return 'Returns a recent changes feed';
198  }
199 
200  public function getPossibleErrors() {
201  return array_merge( parent::getPossibleErrors(), array(
202  array( 'code' => 'feed-unavailable', 'info' => 'Syndication feeds are not available' ),
203  array( 'code' => 'feed-invalid', 'info' => 'Invalid subscription feed type' ),
204  ) );
205  }
206 
207  public function getExamples() {
208  return array(
209  'api.php?action=feedrecentchanges',
210  'api.php?action=feedrecentchanges&days=30'
211  );
212  }
213 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:175
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1933
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
ApiFeedRecentChanges\getCustomPrinter
getCustomPrinter()
This module uses a custom feed wrapper printer.
Definition: ApiFeedRecentChanges.php:34
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
ApiFeedRecentChanges\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiFeedRecentChanges.php:173
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiFeedRecentChanges\getFeedObject
getFeedObject( $feedFormat, $specialClass)
Return a ChannelFeed object.
Definition: ApiFeedRecentChanges.php:86
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:56
ApiFormatFeedWrapper
This printer is used to wrap an instance of the Feed class.
Definition: ApiFormatBase.php:348
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:52
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ChangesFeed
Feed to Special:RecentChanges and Special:RecentChangesLiked.
Definition: ChangesFeed.php:28
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ApiFeedRecentChanges\execute
execute()
Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked) as an RSS/Atom feed...
Definition: ApiFeedRecentChanges.php:42
ApiFeedRecentChanges\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiFeedRecentChanges.php:196
ApiBase\dieUsage
dieUsage( $description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
Definition: ApiBase.php:1363
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
ApiBase\getParameter
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
Definition: ApiBase.php:711
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiFeedRecentChanges
Recent changes feed.
Definition: ApiFeedRecentChanges.php:27
ApiFeedRecentChanges\getPossibleErrors
getPossibleErrors()
Returns a list of all possible errors returned by the module.
Definition: ApiFeedRecentChanges.php:200
ChangesFeed\buildItems
static buildItems( $rows)
Generate the feed items given a row from the database.
Definition: ChangesFeed.php:184
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:188
ApiFeedRecentChanges\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiFeedRecentChanges.php:112
ApiFeedRecentChanges\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiFeedRecentChanges.php:207
ApiFormatFeedWrapper\setResult
static setResult( $result, $feed, $feedItems)
Call this method to initialize output data.
Definition: ApiFormatBase.php:360