52 $feedClasses = $config->get(
'FeedClasses' );
57 if ( !$config->get(
'Feed' ) ) {
61 if ( !isset( $feedClasses[$params[
'feedformat']] ) ) {
66 $endTime =
wfTimestamp( TS_MW, time() - (
int)$params[
'hours'] * 60 * 60 );
72 'siprop' =>
'general',
73 'list' =>
'watchlist',
74 'wlprop' =>
'title|user|comment|timestamp|ids|loginfo',
77 'wllimit' => min( 50, $this->
getConfig()->
get(
'FeedLimit' ) )
80 if ( $params[
'wlowner'] !==
null ) {
81 $fauxReqArr[
'wlowner'] = $params[
'wlowner'];
83 if ( $params[
'wltoken'] !==
null ) {
84 $fauxReqArr[
'wltoken'] = $params[
'wltoken'];
86 if ( $params[
'wlexcludeuser'] !==
null ) {
87 $fauxReqArr[
'wlexcludeuser'] = $params[
'wlexcludeuser'];
89 if ( $params[
'wlshow'] !==
null ) {
90 $fauxReqArr[
'wlshow'] = $params[
'wlshow'];
92 if ( $params[
'wltype'] !==
null ) {
93 $fauxReqArr[
'wltype'] = $params[
'wltype'];
98 if ( $params[
'linktosections'] ) {
99 $this->linkToSections =
true;
103 if ( $params[
'allrev'] ) {
104 $fauxReqArr[
'wlallrev'] =
'';
109 $module =
new ApiMain( $fauxReq );
112 $data = $module->getResult()->getResultData( [
'query',
'watchlist' ] );
114 foreach ( (array)$data as $key => $info ) {
115 if ( ApiResult::isMetadataKey( $key ) ) {
120 $feedItems[] = $feedItem;
124 $msg =
wfMessage(
'watchlist' )->inContentLanguage()->text();
126 $feedTitle = $this->
getConfig()->get(
'Sitename' ) .
' - ' . $msg .
127 ' [' . $this->
getConfig()->get(
'LanguageCode' ) .
']';
128 $feedUrl = SpecialPage::getTitleFor(
'Watchlist' )->getFullURL();
130 $feed =
new $feedClasses[$params[
'feedformat']] (
132 htmlspecialchars( $msg ),
137 }
catch ( Exception $e ) {
139 $this->
getMain()->setCacheMaxAge( 0 );
142 $feedTitle = $this->
getConfig()->get(
'Sitename' ) .
' - Error - ' .
143 wfMessage(
'watchlist' )->inContentLanguage()->text() .
144 ' [' . $this->
getConfig()->get(
'LanguageCode' ) .
']';
145 $feedUrl = SpecialPage::getTitleFor(
'Watchlist' )->getFullURL();
147 $feedFormat = $params[
'feedformat'] ??
'rss';
148 $msg =
wfMessage(
'watchlist' )->inContentLanguage()->escaped();
149 $feed =
new $feedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl );
152 foreach ( $e->getStatusValue()->getErrors() as $error ) {
156 $errorTitle = $this->
msg(
'api-feed-error-title', $msg->getApiCode() );
157 $errorText = $msg->text();
158 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
162 $errorCode =
'internal_api_error';
163 $errorTitle = $this->
msg(
'api-feed-error-title', $errorCode );
164 $errorText = $e->getMessage();
165 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
177 if ( !isset( $info[
'title'] ) ) {
182 $titleStr = $info[
'title'];
183 $title = Title::newFromText( $titleStr );
188 if ( isset( $info[
'pageid'] ) ) {
189 $title = Title::newFromID( $info[
'pageid'] );
190 $curidParam = [
'curid' => $info[
'pageid'] ];
196 if ( isset( $info[
'revid'] ) ) {
197 if ( $info[
'revid'] === 0 && isset( $info[
'logid'] ) ) {
198 $logTitle = Title::makeTitle(
NS_SPECIAL,
'Log' );
199 $titleUrl = $logTitle->getFullURL( [
'logid' => $info[
'logid'] ] );
201 $titleUrl =
$title->getFullURL( [
'diff' => $info[
'revid'] ] );
204 $titleUrl =
$title->getFullURL( $curidParam );
206 $comment = $info[
'comment'] ??
null;
212 if ( $this->linkToSections && $comment !==
null &&
213 preg_match(
'!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,
$matches )
215 $titleUrl .= MediaWikiServices::getInstance()->getParser()
216 ->guessSectionNameFromWikiText(
$matches[ 2 ] );
219 $timestamp = $info[
'timestamp'];
221 if ( isset( $info[
'user'] ) ) {
222 $user = $info[
'user'];
223 $completeText =
"$comment ($user)";
226 $completeText = (string)$comment;
229 return new FeedItem( $titleStr, $completeText, $titleUrl, $timestamp, $user );
233 if ( $this->watchlistModule ===
null ) {
234 $this->watchlistModule = $this->
getMain()->getModuleManager()->getModule(
'query' )
235 ->getModuleManager()->getModule(
'watchlist' );
242 $feedFormatNames = array_keys( $this->
getConfig()->
get(
'FeedClasses' ) );
254 'linktosections' =>
false,
258 'allrev' =>
'allrev',
259 'owner' =>
'wlowner',
260 'token' =>
'wltoken',
263 'excludeuser' =>
'wlexcludeuser',
267 foreach ( $copyParams as $from => $to ) {
268 $p = $wlparams[$from];
269 if ( !is_array( $p ) ) {
287 foreach ( $copyParams as $from => $to ) {
297 'action=feedwatchlist'
298 =>
'apihelp-feedwatchlist-example-default',
299 'action=feedwatchlist&allrev=&hours=6'
300 =>
'apihelp-feedwatchlist-example-all6hrs',
305 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.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
getMain()
Get the main module.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
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)
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.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
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.