MediaWiki  1.29.1
ApiFeedRecentChanges.php
Go to the documentation of this file.
1 <?php
28 
29  private $params;
30 
36  public function getCustomPrinter() {
37  return new ApiFormatFeedWrapper( $this->getMain() );
38  }
39 
44  public function execute() {
45  $config = $this->getConfig();
46 
47  $this->params = $this->extractRequestParams();
48 
49  if ( !$config->get( 'Feed' ) ) {
50  $this->dieWithError( 'feed-unavailable' );
51  }
52 
53  $feedClasses = $config->get( 'FeedClasses' );
54  if ( !isset( $feedClasses[$this->params['feedformat']] ) ) {
55  $this->dieWithError( 'feed-invalid' );
56  }
57 
58  $this->getMain()->setCacheMode( 'public' );
59  if ( !$this->getMain()->getParameter( 'smaxage' ) ) {
60  // T65249: This page gets hit a lot, cache at least 15 seconds.
61  $this->getMain()->setCacheMaxAge( 15 );
62  }
63 
64  $feedFormat = $this->params['feedformat'];
65  $specialClass = $this->params['target'] !== null
66  ? 'SpecialRecentchangeslinked'
67  : 'SpecialRecentchanges';
68 
69  $formatter = $this->getFeedObject( $feedFormat, $specialClass );
70 
71  // Parameters are passed via the request in the context… :(
72  $context = new DerivativeContext( $this );
73  $context->setRequest( new DerivativeRequest(
74  $this->getRequest(),
75  $this->params,
76  $this->getRequest()->wasPosted()
77  ) );
78 
79  // The row-getting functionality should be factored out of ChangesListSpecialPage too…
80  $rc = new $specialClass();
81  $rc->setContext( $context );
82  $rows = $rc->getRows();
83 
84  $feedItems = $rows ? ChangesFeed::buildItems( $rows ) : [];
85 
86  ApiFormatFeedWrapper::setResult( $this->getResult(), $formatter, $feedItems );
87  }
88 
97  public function getFeedObject( $feedFormat, $specialClass ) {
98  if ( $specialClass === 'SpecialRecentchangeslinked' ) {
99  $title = Title::newFromText( $this->params['target'] );
100  if ( !$title ) {
101  $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $this->params['target'] ) ] );
102  }
103 
104  $feed = new ChangesFeed( $feedFormat, false );
105  $feedObj = $feed->getFeedObject(
106  $this->msg( 'recentchangeslinked-title', $title->getPrefixedText() )
107  ->inContentLanguage()->text(),
108  $this->msg( 'recentchangeslinked-feed' )->inContentLanguage()->text(),
109  SpecialPage::getTitleFor( 'Recentchangeslinked' )->getFullURL()
110  );
111  } else {
112  $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
113  $feedObj = $feed->getFeedObject(
114  $this->msg( 'recentchanges' )->inContentLanguage()->text(),
115  $this->msg( 'recentchanges-feed-description' )->inContentLanguage()->text(),
116  SpecialPage::getTitleFor( 'Recentchanges' )->getFullURL()
117  );
118  }
119 
120  return $feedObj;
121  }
122 
123  public function getAllowedParams() {
124  $config = $this->getConfig();
125  $feedFormatNames = array_keys( $config->get( 'FeedClasses' ) );
126 
127  $ret = [
128  'feedformat' => [
129  ApiBase::PARAM_DFLT => 'rss',
130  ApiBase::PARAM_TYPE => $feedFormatNames,
131  ],
132 
133  'namespace' => [
134  ApiBase::PARAM_TYPE => 'namespace',
135  ],
136  'invert' => false,
137  'associated' => false,
138 
139  'days' => [
140  ApiBase::PARAM_DFLT => 7,
141  ApiBase::PARAM_MIN => 1,
142  ApiBase::PARAM_TYPE => 'integer',
143  ],
144  'limit' => [
145  ApiBase::PARAM_DFLT => 50,
146  ApiBase::PARAM_MIN => 1,
147  ApiBase::PARAM_MAX => $config->get( 'FeedLimit' ),
148  ApiBase::PARAM_TYPE => 'integer',
149  ],
150  'from' => [
151  ApiBase::PARAM_TYPE => 'timestamp',
152  ],
153 
154  'hideminor' => false,
155  'hidebots' => false,
156  'hideanons' => false,
157  'hideliu' => false,
158  'hidepatrolled' => false,
159  'hidemyself' => false,
160  'hidecategorization' => false,
161 
162  'tagfilter' => [
163  ApiBase::PARAM_TYPE => 'string',
164  ],
165 
166  'target' => [
167  ApiBase::PARAM_TYPE => 'string',
168  ],
169  'showlinkedto' => false,
170  ];
171 
172  if ( $config->get( 'AllowCategorizedRecentChanges' ) ) {
173  $ret += [
174  'categories' => [
175  ApiBase::PARAM_TYPE => 'string',
176  ApiBase::PARAM_ISMULTI => true,
177  ],
178  'categories_any' => false,
179  ];
180  }
181 
182  return $ret;
183  }
184 
185  protected function getExamplesMessages() {
186  return [
187  'action=feedrecentchanges'
188  => 'apihelp-feedrecentchanges-example-simple',
189  'action=feedrecentchanges&days=30'
190  => 'apihelp-feedrecentchanges-example-30days',
191  ];
192  }
193 }
DerivativeRequest
Similar to FauxRequest, but only fakes URL parameters and method (POST or GET) and use the base reque...
Definition: DerivativeRequest.php:34
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:34
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
ApiFeedRecentChanges\$params
$params
Definition: ApiFeedRecentChanges.php:29
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:265
ContextSource\msg
msg()
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:187
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\dieWithError
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition: ApiBase.php:1796
ApiBase\PARAM_TYPE
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition: ApiBase.php:91
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:610
ApiFeedRecentChanges\getCustomPrinter
getCustomPrinter()
This module uses a custom feed wrapper printer.
Definition: ApiFeedRecentChanges.php:36
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:82
ContextSource\getRequest
getRequest()
Get the WebRequest object.
Definition: ContextSource.php:78
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:41
ApiFeedRecentChanges\getFeedObject
getFeedObject( $feedFormat, $specialClass)
Return a ChannelFeed object.
Definition: ApiFeedRecentChanges.php:97
ApiBase\PARAM_MIN
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:103
DerivativeContext
An IContextSource implementation which will inherit context from another source but allow individual ...
Definition: DerivativeContext.php:31
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
ApiFormatFeedWrapper
This printer is used to wrap an instance of the Feed class.
Definition: ApiFormatFeedWrapper.php:31
ApiBase\PARAM_MAX
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
Definition: ApiBase.php:94
ChangesFeed
Feed to Special:RecentChanges and Special:RecentChangesLiked.
Definition: ChangesFeed.php:30
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:718
ApiFeedRecentChanges\execute
execute()
Format the rows (generated by SpecialRecentchanges or SpecialRecentchangeslinked) as an RSS/Atom feed...
Definition: ApiFeedRecentChanges.php:44
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1657
$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:1956
ApiFeedRecentChanges\getExamplesMessages
getExamplesMessages()
Returns usage examples for this module.
Definition: ApiFeedRecentChanges.php:185
ApiBase\PARAM_DFLT
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition: ApiBase.php:52
ApiBase\getParameter
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
Definition: ApiBase.php:742
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition: ApiBase.php:55
ApiFeedRecentChanges
Recent changes feed.
Definition: ApiFeedRecentChanges.php:27
ChangesFeed\buildItems
static buildItems( $rows)
Generate the feed items given a row from the database.
Definition: ChangesFeed.php:186
ApiBase\getMain
getMain()
Get the main module.
Definition: ApiBase.php:506
ApiFeedRecentChanges\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiFeedRecentChanges.php:123
ApiFormatFeedWrapper\setResult
static setResult( $result, $feed, $feedItems)
Call this method to initialize output data.
Definition: ApiFormatFeedWrapper.php:43