45 private $watchlistModule =
null;
47 private $linkToSections =
false;
56 parent::__construct( $main, $action );
57 $this->parserFactory = $parserFactory;
85 if ( !isset( $feedClasses[$params[
'feedformat']] ) ) {
90 $endTime =
wfTimestamp( TS_MW, time() - (
int)$params[
'hours'] * 60 * 60 );
96 'siprop' =>
'general',
97 'list' =>
'watchlist',
98 'wlprop' =>
'title|user|comment|timestamp|ids|loginfo',
104 if ( $params[
'wlowner'] !==
null ) {
105 $fauxReqArr[
'wlowner'] = $params[
'wlowner'];
107 if ( $params[
'wltoken'] !==
null ) {
108 $fauxReqArr[
'wltoken'] = $params[
'wltoken'];
110 if ( $params[
'wlexcludeuser'] !==
null ) {
111 $fauxReqArr[
'wlexcludeuser'] = $params[
'wlexcludeuser'];
113 if ( $params[
'wlshow'] !==
null ) {
114 $fauxReqArr[
'wlshow'] = ParamValidator::implodeMultiValue( $params[
'wlshow'] );
116 if ( $params[
'wltype'] !==
null ) {
117 $fauxReqArr[
'wltype'] = ParamValidator::implodeMultiValue( $params[
'wltype'] );
122 if ( $params[
'linktosections'] ) {
123 $this->linkToSections =
true;
127 if ( $params[
'allrev'] ) {
128 $fauxReqArr[
'wlallrev'] =
'';
133 $module =
new ApiMain( $fauxReq );
136 $data = $module->getResult()->getResultData( [
'query',
'watchlist' ] );
137 foreach ( (array)$data as $key => $info ) {
141 $feedItem = $this->createFeedItem( $info );
143 $feedItems[] = $feedItem;
147 $msg = $this->
msg(
'watchlist' )->inContentLanguage()->text();
153 $feed =
new $feedClasses[$params[
'feedformat']] (
155 htmlspecialchars( $msg ),
160 }
catch ( Exception $e ) {
162 $this->
getMain()->setCacheMaxAge( 0 );
166 $this->
msg(
'watchlist' )->inContentLanguage()->text() .
170 $feedFormat = $params[
'feedformat'] ??
'rss';
171 $msg = $this->
msg(
'watchlist' )->inContentLanguage()->escaped();
172 $feed =
new $feedClasses[$feedFormat] ( $feedTitle, $msg, $feedUrl );
175 foreach ( $e->getStatusValue()->getMessages() as $msg ) {
179 $errorTitle = $this->
msg(
'api-feed-error-title', $msg->getApiCode() );
180 $errorText = $msg->text();
181 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
185 $errorCode =
'internal_api_error';
186 $errorTitle = $this->
msg(
'api-feed-error-title', $errorCode );
187 $errorText = $e->getMessage();
188 $feedItems[] =
new FeedItem( $errorTitle, $errorText,
'',
'',
'' );
199 private function createFeedItem( $info ) {
200 if ( !isset( $info[
'title'] ) ) {
205 $titleStr = $info[
'title'];
206 $title = Title::newFromText( $titleStr );
208 if ( !$title || $title->isExternal() ) {
211 if ( isset( $info[
'pageid'] ) ) {
212 $title = Title::newFromID( $info[
'pageid'] );
213 $curidParam = [
'curid' => $info[
'pageid'] ];
215 if ( !$title || $title->isExternal() ) {
219 if ( isset( $info[
'revid'] ) ) {
220 if ( $info[
'revid'] === 0 && isset( $info[
'logid'] ) ) {
221 $logTitle = Title::makeTitle(
NS_SPECIAL,
'Log' );
222 $titleUrl = $logTitle->getFullURL( [
'logid' => $info[
'logid'] ] );
224 $titleUrl = $title->getFullURL( [
'diff' => $info[
'revid'] ] );
227 $titleUrl = $title->getFullURL( $curidParam );
229 $comment = $info[
'comment'] ??
null;
235 if ( $this->linkToSections && $comment !==
null &&
236 preg_match(
'!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment,
$matches )
238 $titleUrl .= $this->parserFactory->getMainInstance()->guessSectionNameFromWikiText(
$matches[ 2 ] );
241 $timestamp = $info[
'timestamp'];
243 if ( isset( $info[
'user'] ) ) {
244 $user = $info[
'user'];
245 $completeText =
"$comment ($user)";
248 $completeText = (string)$comment;
251 return new FeedItem( $titleStr, $completeText, $titleUrl, $timestamp, $user );
254 private function getWatchlistModule() {
255 $this->watchlistModule ??= $this->
getMain()->getModuleManager()->getModule(
'query' )
256 ->getModuleManager()->getModule(
'watchlist' );
258 return $this->watchlistModule;
265 ParamValidator::PARAM_DEFAULT =>
'rss',
266 ParamValidator::PARAM_TYPE => $feedFormatNames
269 ParamValidator::PARAM_DEFAULT => 24,
270 ParamValidator::PARAM_TYPE =>
'integer',
271 IntegerDef::PARAM_MIN => 1,
272 IntegerDef::PARAM_MAX => 72,
274 'linktosections' =>
false,
278 'allrev' =>
'allrev',
279 'owner' =>
'wlowner',
280 'token' =>
'wltoken',
283 '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 ) {
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';
325class_alias( ApiFeedWatchlist::class,
'ApiFeedWatchlist' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
This is the main API class, used for both external and internal processing.
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.
const FeedClasses
Name constant for the FeedClasses setting, for use with Config::get()
const Feed
Name constant for the Feed setting, for use with Config::get()
const Sitename
Name constant for the Sitename setting, for use with Config::get()
const LanguageCode
Name constant for the LanguageCode setting, for use with Config::get()
const FeedLimit
Name constant for the FeedLimit setting, for use with Config::get()
Parent class for all special pages.
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,...