39 private $watchlistModule =
null;
40 private $linkToSections =
false;
55 parent::__construct( $main, $action );
56 $this->parser = $parser;
74 $feedClasses = $config->get( MainConfigNames::FeedClasses );
80 if ( !$config->get( MainConfigNames::Feed ) ) {
84 if ( !isset( $feedClasses[$params[
'feedformat']] ) ) {
89 $endTime =
wfTimestamp( TS_MW, time() - (
int)$params[
'hours'] * 60 * 60 );
95 'siprop' =>
'general',
96 'list' =>
'watchlist',
97 'wlprop' =>
'title|user|comment|timestamp|ids|loginfo',
100 'wllimit' => min( 50, $this->
getConfig()->
get( MainConfigNames::FeedLimit ) )
103 if ( $params[
'wlowner'] !==
null ) {
104 $fauxReqArr[
'wlowner'] = $params[
'wlowner'];
106 if ( $params[
'wltoken'] !==
null ) {
107 $fauxReqArr[
'wltoken'] = $params[
'wltoken'];
109 if ( $params[
'wlexcludeuser'] !==
null ) {
110 $fauxReqArr[
'wlexcludeuser'] = $params[
'wlexcludeuser'];
112 if ( $params[
'wlshow'] !==
null ) {
113 $fauxReqArr[
'wlshow'] = ParamValidator::implodeMultiValue( $params[
'wlshow'] );
115 if ( $params[
'wltype'] !==
null ) {
116 $fauxReqArr[
'wltype'] = ParamValidator::implodeMultiValue( $params[
'wltype'] );
121 if ( $params[
'linktosections'] ) {
122 $this->linkToSections =
true;
126 if ( $params[
'allrev'] ) {
127 $fauxReqArr[
'wlallrev'] =
'';
132 $module =
new ApiMain( $fauxReq );
135 $data = $module->getResult()->getResultData( [
'query',
'watchlist' ] );
136 foreach ( (array)$data as $key => $info ) {
137 if ( ApiResult::isMetadataKey( $key ) ) {
140 $feedItem = $this->createFeedItem( $info );
142 $feedItems[] = $feedItem;
146 $msg = $this->
msg(
'watchlist' )->inContentLanguage()->text();
148 $feedTitle = $this->
getConfig()->get( MainConfigNames::Sitename ) .
' - ' . $msg .
149 ' [' . $this->
getConfig()->get( MainConfigNames::LanguageCode ) .
']';
152 $feed =
new $feedClasses[$params[
'feedformat']] (
154 htmlspecialchars( $msg ),
159 }
catch ( Exception $e ) {
161 $this->
getMain()->setCacheMaxAge( 0 );
164 $feedTitle = $this->
getConfig()->get( MainConfigNames::Sitename ) .
' - Error - ' .
165 $this->
msg(
'watchlist' )->inContentLanguage()->text() .
166 ' [' . $this->
getConfig()->get( MainConfigNames::LanguageCode ) .
']';
169 $feedFormat = $params[
'feedformat'] ??
'rss';
170 $msg = $this->
msg(
'watchlist' )->inContentLanguage()->escaped();
171 $feed =
new $feedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl );
174 foreach ( $e->getStatusValue()->getErrors() as $error ) {
176 $msg = ApiMessage::create( $error )
178 $errorTitle = $this->
msg(
'api-feed-error-title', $msg->getApiCode() );
179 $errorText = $msg->text();
180 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
184 $errorCode =
'internal_api_error';
185 $errorTitle = $this->
msg(
'api-feed-error-title', $errorCode );
186 $errorText = $e->getMessage();
187 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
198 private function createFeedItem( $info ) {
199 if ( !isset( $info[
'title'] ) ) {
204 $titleStr = $info[
'title'];
205 $title = Title::newFromText( $titleStr );
210 if ( isset( $info[
'pageid'] ) ) {
211 $title = Title::newFromID( $info[
'pageid'] );
212 $curidParam = [
'curid' => $info[
'pageid'] ];
218 if ( isset( $info[
'revid'] ) ) {
219 if ( $info[
'revid'] === 0 && isset( $info[
'logid'] ) ) {
220 $logTitle = Title::makeTitle(
NS_SPECIAL,
'Log' );
221 $titleUrl = $logTitle->getFullURL( [
'logid' => $info[
'logid'] ] );
223 $titleUrl =
$title->getFullURL( [
'diff' => $info[
'revid'] ] );
226 $titleUrl =
$title->getFullURL( $curidParam );
228 $comment = $info[
'comment'] ??
null;
234 if ( $this->linkToSections && $comment !==
null &&
235 preg_match(
'!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,
$matches )
237 $titleUrl .= $this->parser->guessSectionNameFromWikiText(
$matches[ 2 ] );
240 $timestamp = $info[
'timestamp'];
242 if ( isset( $info[
'user'] ) ) {
243 $user = $info[
'user'];
244 $completeText =
"$comment ($user)";
247 $completeText = (string)$comment;
250 return new FeedItem( $titleStr, $completeText, $titleUrl, $timestamp, $user );
253 private function getWatchlistModule() {
254 $this->watchlistModule ??= $this->
getMain()->getModuleManager()->getModule(
'query' )
255 ->getModuleManager()->getModule(
'watchlist' );
257 return $this->watchlistModule;
261 $feedFormatNames = array_keys( $this->
getConfig()->
get( MainConfigNames::FeedClasses ) );
264 ParamValidator::PARAM_DEFAULT =>
'rss',
265 ParamValidator::PARAM_TYPE => $feedFormatNames
268 ParamValidator::PARAM_DEFAULT => 24,
269 ParamValidator::PARAM_TYPE =>
'integer',
270 IntegerDef::PARAM_MIN => 1,
271 IntegerDef::PARAM_MAX => 72,
273 'linktosections' =>
false,
277 'allrev' =>
'allrev',
278 'owner' =>
'wlowner',
279 'token' =>
'wltoken',
282 'excludeuser' =>
'wlexcludeuser',
286 $wlparams = $this->getWatchlistModule()->getAllowedParams( $flags );
287 foreach ( $copyParams as $from => $to ) {
288 $p = $wlparams[$from];
289 if ( !is_array( $p ) ) {
290 $p = [ ParamValidator::PARAM_DEFAULT => $p ];
295 if ( isset( $p[ParamValidator::PARAM_TYPE] ) && is_array( $p[ParamValidator::PARAM_TYPE] ) &&
298 foreach ( $p[ParamValidator::PARAM_TYPE] as $v ) {
307 foreach ( $copyParams as $to ) {
317 'action=feedwatchlist'
318 =>
'apihelp-feedwatchlist-example-default',
319 'action=feedwatchlist&allrev=&hours=6'
320 =>
'apihelp-feedwatchlist-example-all6hrs',
325 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.
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, or 'string' with PARAM_ISMULTI,...
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()
A class containing constants representing the names of configuration variables.
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,...