48 parent::__construct( $main, $action );
67 $feedClasses = $config->get(
'FeedClasses' );
73 if ( !$config->get(
'Feed' ) ) {
77 if ( !isset( $feedClasses[$params[
'feedformat']] ) ) {
82 $endTime =
wfTimestamp( TS_MW, time() - (
int)$params[
'hours'] * 60 * 60 );
88 'siprop' =>
'general',
89 'list' =>
'watchlist',
90 'wlprop' =>
'title|user|comment|timestamp|ids|loginfo',
93 'wllimit' => min( 50, $this->
getConfig()->
get(
'FeedLimit' ) )
96 if ( $params[
'wlowner'] !==
null ) {
97 $fauxReqArr[
'wlowner'] = $params[
'wlowner'];
99 if ( $params[
'wltoken'] !==
null ) {
100 $fauxReqArr[
'wltoken'] = $params[
'wltoken'];
102 if ( $params[
'wlexcludeuser'] !==
null ) {
103 $fauxReqArr[
'wlexcludeuser'] = $params[
'wlexcludeuser'];
105 if ( $params[
'wlshow'] !==
null ) {
106 $fauxReqArr[
'wlshow'] = $params[
'wlshow'];
108 if ( $params[
'wltype'] !==
null ) {
109 $fauxReqArr[
'wltype'] = $params[
'wltype'];
114 if ( $params[
'linktosections'] ) {
115 $this->linkToSections =
true;
119 if ( $params[
'allrev'] ) {
120 $fauxReqArr[
'wlallrev'] =
'';
125 $module =
new ApiMain( $fauxReq );
128 $data = $module->getResult()->getResultData( [
'query',
'watchlist' ] );
129 foreach ( (array)$data as $key => $info ) {
130 if ( ApiResult::isMetadataKey( $key ) ) {
135 $feedItems[] = $feedItem;
139 $msg =
wfMessage(
'watchlist' )->inContentLanguage()->text();
141 $feedTitle = $this->
getConfig()->get(
'Sitename' ) .
' - ' . $msg .
142 ' [' . $this->
getConfig()->get(
'LanguageCode' ) .
']';
145 $feed =
new $feedClasses[$params[
'feedformat']] (
147 htmlspecialchars( $msg ),
152 }
catch ( Exception $e ) {
154 $this->
getMain()->setCacheMaxAge( 0 );
157 $feedTitle = $this->
getConfig()->get(
'Sitename' ) .
' - Error - ' .
158 wfMessage(
'watchlist' )->inContentLanguage()->text() .
159 ' [' . $this->
getConfig()->get(
'LanguageCode' ) .
']';
162 $feedFormat = $params[
'feedformat'] ??
'rss';
163 $msg =
wfMessage(
'watchlist' )->inContentLanguage()->escaped();
164 $feed =
new $feedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl );
167 foreach ( $e->getStatusValue()->getErrors() as $error ) {
169 $msg = ApiMessage::create( $error )
171 $errorTitle = $this->
msg(
'api-feed-error-title', $msg->getApiCode() );
172 $errorText = $msg->text();
173 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
177 $errorCode =
'internal_api_error';
178 $errorTitle = $this->
msg(
'api-feed-error-title', $errorCode );
179 $errorText = $e->getMessage();
180 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
192 if ( !isset( $info[
'title'] ) ) {
197 $titleStr = $info[
'title'];
198 $title = Title::newFromText( $titleStr );
203 if ( isset( $info[
'pageid'] ) ) {
204 $title = Title::newFromID( $info[
'pageid'] );
205 $curidParam = [
'curid' => $info[
'pageid'] ];
211 if ( isset( $info[
'revid'] ) ) {
212 if ( $info[
'revid'] === 0 && isset( $info[
'logid'] ) ) {
213 $logTitle = Title::makeTitle(
NS_SPECIAL,
'Log' );
214 $titleUrl = $logTitle->getFullURL( [
'logid' => $info[
'logid'] ] );
216 $titleUrl =
$title->getFullURL( [
'diff' => $info[
'revid'] ] );
219 $titleUrl =
$title->getFullURL( $curidParam );
221 $comment = $info[
'comment'] ??
null;
227 if ( $this->linkToSections && $comment !==
null &&
228 preg_match(
'!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,
$matches )
230 $titleUrl .= $this->parser->guessSectionNameFromWikiText(
$matches[ 2 ] );
233 $timestamp = $info[
'timestamp'];
235 if ( isset( $info[
'user'] ) ) {
236 $user = $info[
'user'];
237 $completeText =
"$comment ($user)";
240 $completeText = (string)$comment;
243 return new FeedItem( $titleStr, $completeText, $titleUrl, $timestamp, $user );
247 if ( $this->watchlistModule ===
null ) {
248 $this->watchlistModule = $this->
getMain()->getModuleManager()->getModule(
'query' )
249 ->getModuleManager()->getModule(
'watchlist' );
256 $feedFormatNames = array_keys( $this->
getConfig()->
get(
'FeedClasses' ) );
268 'linktosections' =>
false,
272 'allrev' =>
'allrev',
273 'owner' =>
'wlowner',
274 'token' =>
'wltoken',
277 'excludeuser' =>
'wlexcludeuser',
282 foreach ( $copyParams as $from => $to ) {
283 $p = $wlparams[$from];
284 if ( !is_array( $p ) ) {
302 foreach ( $copyParams as $from => $to ) {
312 'action=feedwatchlist'
313 =>
'apihelp-feedwatchlist-example-default',
314 'action=feedwatchlist&allrev=&hours=6'
315 =>
'apihelp-feedwatchlist-example-all6hrs',
320 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Watchlist_feed';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getMain()
Get the main module.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
This action allows users to get their watchlist items in RSS/Atom formats.
getAllowedParams( $flags=0)
__construct(ApiMain $main, $action, Parser $parser)
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
getCustomPrinter()
This module uses a custom feed wrapper printer.
execute()
Make a nested call to the API to request watchlist items in the last $hours.
This is the main API class, used for both external and internal processing.
Exception used to abort API execution with an error.
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
WebRequest clone which takes values from a provided array.
A base class for outputting syndication feeds (e.g.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
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,...