5use Wikimedia\Assert\Assert;
63 $this->loadBalancer = $loadBalancer;
72 Hooks::run(
'WatchedItemQueryServiceExtensions', [ &$this->
extensions, $this ] );
74 return $this->extensions;
82 return $this->loadBalancer->getConnectionRef(
DB_REPLICA, [
'watchlist' ] );
86 if ( !$this->commentStore ) {
89 return $this->commentStore;
139 'includeFields' => [],
140 'namespaceIds' => [],
142 'allRevisions' =>
false,
143 'usedInGenerator' =>
false
149 '$options[\'rcTypes\']',
150 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
153 !isset(
$options[
'dir'] ) || in_array(
$options[
'dir'], [ self::DIR_OLDER, self::DIR_NEWER ] ),
155 'must be DIR_OLDER or DIR_NEWER'
158 !isset(
$options[
'start'] ) && !isset(
$options[
'end'] ) && $startFrom ===
null
161 'must be provided when providing the "start" or "end" options or the $startFrom parameter'
165 '$options[\'startFrom\']',
166 'must not be provided, use $startFrom instead'
169 !isset( $startFrom ) || ( is_array( $startFrom ) && count( $startFrom ) === 2 ),
171 'must be a two-element array'
173 if ( array_key_exists(
'watchlistOwner',
$options ) ) {
174 Assert::parameterType(
177 '$options[\'watchlistOwner\']'
180 isset(
$options[
'watchlistOwnerToken'] ),
181 '$options[\'watchlistOwnerToken\']',
182 'must be provided when providing watchlistOwner option'
194 if ( $startFrom !==
null ) {
199 $extension->modifyWatchedItemsWithRCInfoQuery(
218 $limit = isset( $dbOptions[
'LIMIT'] ) ? $dbOptions[
'LIMIT'] : INF;
221 foreach (
$res as $row ) {
222 if ( --$limit <= 0 ) {
223 $startFrom = [ $row->rc_timestamp, $row->rc_id ];
230 new TitleValue( (
int)$row->rc_namespace, $row->rc_title ),
231 $row->wl_notificationtimestamp
238 $extension->modifyWatchedItemsWithRCInfo(
$user,
$options, $db, $items,
$res, $startFrom );
264 if (
$user->isAnon() ) {
270 $options += [
'namespaceIds' => [] ];
273 !isset(
$options[
'sort'] ) || in_array(
$options[
'sort'], [ self::SORT_ASC, self::SORT_DESC ] ),
274 '$options[\'sort\']',
275 'must be SORT_ASC or SORT_DESC'
278 !isset(
$options[
'filter'] ) || in_array(
279 $options[
'filter'], [ self::FILTER_CHANGED, self::FILTER_NOT_CHANGED ]
281 '$options[\'filter\']',
282 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
287 '$options[\'sort\']',
288 'must be provided if any of "from", "until", "startFrom" options is provided'
298 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
305 foreach (
$res as $row ) {
309 new TitleValue( (
int)$row->wl_namespace, $row->wl_title ),
310 $row->wl_notificationtimestamp
314 return $watchedItems;
320 $allFields = get_object_vars( $row );
321 $rcKeys = array_filter(
322 array_keys( $allFields ),
324 return substr( $key, 0, 3 ) ===
'rc_';
327 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
331 $tables = [
'recentchanges',
'watchlist' ];
335 if ( in_array( self::INCLUDE_COMMENT,
$options[
'includeFields'] ) ) {
349 'wl_notificationtimestamp'
357 if (
$options[
'usedInGenerator'] ) {
359 $rcIdFields = [
'rc_this_oldid' ];
361 $rcIdFields = [
'rc_cur_id' ];
364 $fields = array_merge( $fields, $rcIdFields );
366 if ( in_array( self::INCLUDE_FLAGS,
$options[
'includeFields'] ) ) {
367 $fields = array_merge( $fields, [
'rc_type',
'rc_minor',
'rc_bot' ] );
369 if ( in_array( self::INCLUDE_USER,
$options[
'includeFields'] ) ) {
370 $fields[] =
'rc_user_text';
372 if ( in_array( self::INCLUDE_USER_ID,
$options[
'includeFields'] ) ) {
373 $fields[] =
'rc_user';
375 if ( in_array( self::INCLUDE_COMMENT,
$options[
'includeFields'] ) ) {
378 if ( in_array( self::INCLUDE_PATROL_INFO,
$options[
'includeFields'] ) ) {
379 $fields = array_merge( $fields, [
'rc_patrolled',
'rc_log_type' ] );
381 if ( in_array( self::INCLUDE_SIZES,
$options[
'includeFields'] ) ) {
382 $fields = array_merge( $fields, [
'rc_old_len',
'rc_new_len' ] );
384 if ( in_array( self::INCLUDE_LOG_INFO,
$options[
'includeFields'] ) ) {
385 $fields = array_merge( $fields, [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ] );
397 $conds = [
'wl_user' => $watchlistOwnerId ];
401 [
'rc_this_oldid=page_latest',
'rc_type=' .
RC_LOG ],
407 $conds[
'wl_namespace'] = array_map(
'intval',
$options[
'namespaceIds'] );
410 if ( array_key_exists(
'rcTypes',
$options ) ) {
411 $conds[
'rc_type'] = array_map(
'intval',
$options[
'rcTypes'] );
414 $conds = array_merge(
422 if ( $db->
getType() ===
'mysql' ) {
424 $conds[] =
'rc_timestamp > ' . $db->
addQuotes(
'' );
431 if ( $deletedPageLogCond ) {
432 $conds[] = $deletedPageLogCond;
439 if ( array_key_exists(
'watchlistOwner',
$options ) ) {
441 $watchlistOwner =
$options[
'watchlistOwner'];
442 $ownersToken = $watchlistOwner->getOption(
'watchlisttoken' );
443 $token =
$options[
'watchlistOwnerToken'];
444 if ( $ownersToken ==
'' || !hash_equals( $ownersToken, $token ) ) {
447 return $watchlistOwner->getId();
449 return $user->getId();
455 if ( in_array( self::FILTER_MINOR,
$options[
'filters'] ) ) {
456 $conds[] =
'rc_minor != 0';
457 } elseif ( in_array( self::FILTER_NOT_MINOR,
$options[
'filters'] ) ) {
458 $conds[] =
'rc_minor = 0';
461 if ( in_array( self::FILTER_BOT,
$options[
'filters'] ) ) {
462 $conds[] =
'rc_bot != 0';
463 } elseif ( in_array( self::FILTER_NOT_BOT,
$options[
'filters'] ) ) {
464 $conds[] =
'rc_bot = 0';
467 if ( in_array( self::FILTER_ANON,
$options[
'filters'] ) ) {
468 $conds[] =
'rc_user = 0';
469 } elseif ( in_array( self::FILTER_NOT_ANON,
$options[
'filters'] ) ) {
470 $conds[] =
'rc_user != 0';
473 if (
$user->useRCPatrol() ||
$user->useNPPatrol() ) {
476 if ( in_array( self::FILTER_PATROLLED,
$options[
'filters'] ) ) {
477 $conds[] =
'rc_patrolled != 0';
478 } elseif ( in_array( self::FILTER_NOT_PATROLLED,
$options[
'filters'] ) ) {
479 $conds[] =
'rc_patrolled = 0';
483 if ( in_array( self::FILTER_UNREAD,
$options[
'filters'] ) ) {
484 $conds[] =
'rc_timestamp >= wl_notificationtimestamp';
485 } elseif ( in_array( self::FILTER_NOT_UNREAD,
$options[
'filters'] ) ) {
487 $conds[] =
'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
501 $after =
$options[
'dir'] === self::DIR_OLDER ?
'<=' :
'>=';
502 $conds[] =
'rc_timestamp ' . $after .
' ' .
506 $before =
$options[
'dir'] === self::DIR_OLDER ?
'>=' :
'<=';
507 $conds[] =
'rc_timestamp ' . $before .
' ' .
515 if ( !array_key_exists(
'onlyByUser',
$options ) && !array_key_exists(
'notByUser',
$options ) ) {
521 if ( array_key_exists(
'onlyByUser',
$options ) ) {
522 $conds[
'rc_user_text'] =
$options[
'onlyByUser'];
523 } elseif ( array_key_exists(
'notByUser',
$options ) ) {
529 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
531 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
535 $conds[] = $db->
bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask";
545 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
547 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
553 $db->
bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
560 $op =
$options[
'dir'] === self::DIR_OLDER ?
'<' :
'>';
561 list( $rcTimestamp, $rcId ) = $startFrom;
566 "rc_timestamp $op $rcTimestamp",
569 "rc_timestamp = $rcTimestamp",
580 $conds = [
'wl_user' =>
$user->getId() ];
582 $conds[
'wl_namespace'] = array_map(
'intval',
$options[
'namespaceIds'] );
584 if ( isset(
$options[
'filter'] ) ) {
586 if ( $filter === self::FILTER_CHANGED ) {
587 $conds[] =
'wl_notificationtimestamp IS NOT NULL';
589 $conds[] =
'wl_notificationtimestamp IS NULL';
594 $op =
$options[
'sort'] === self::SORT_ASC ?
'>' :
'<';
598 $op =
$options[
'sort'] === self::SORT_ASC ?
'<' :
'>';
601 if ( isset(
$options[
'startFrom'] ) ) {
602 $op =
$options[
'sort'] === self::SORT_ASC ?
'>' :
'<';
637 if ( array_key_exists(
'dir',
$options ) ) {
639 $dbOptions[
'ORDER BY'] = [
'rc_timestamp' .
$sort,
'rc_id' .
$sort ];
642 if ( array_key_exists(
'limit',
$options ) ) {
643 $dbOptions[
'LIMIT'] = (int)
$options[
'limit'] + 1;
651 if ( array_key_exists(
'sort',
$options ) ) {
652 $dbOptions[
'ORDER BY'] = [
653 "wl_namespace {$options['sort']}",
654 "wl_title {$options['sort']}"
656 if ( count(
$options[
'namespaceIds'] ) === 1 ) {
657 $dbOptions[
'ORDER BY'] =
"wl_title {$options['sort']}";
660 if ( array_key_exists(
'limit',
$options ) ) {
661 $dbOptions[
'LIMIT'] = (int)
$options[
'limit'];
668 'watchlist' => [
'INNER JOIN',
670 'wl_namespace=rc_namespace',
676 $joinConds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
678 if ( in_array( self::INCLUDE_COMMENT,
$options[
'includeFields'] ) ) {
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static newWithMessage(ApiBase $module=null, $msg, $code=null, $data=null, $httpCode=0)
Represents a page (or page fragment) title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getWatchedItemsForUser(User $user, array $options=[])
For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser.
CommentStore null $commentStore
getExtraDeletedPageLogEntryRelatedCond(IDatabase $db, User $user)
WatchedItemQueryServiceExtension[] null $extensions
getUserRelatedConds(IDatabase $db, User $user, array $options)
const INCLUDE_PATROL_INFO
getWatchedItemsWithRCInfoQueryDbOptions(array $options)
getWatchedItemsWithRCInfoQueryFilterConds(User $user, array $options)
getWatchedItemsWithRCInfoQueryTables(array $options)
getWatchedItemsWithRCInfoQueryFields(array $options)
getWatchedItemsWithRCInfoQueryConds(IDatabase $db, User $user, array $options)
getWatchedItemsForUserQueryConds(IDatabase $db, User $user, array $options)
getFromUntilTargetConds(IDatabase $db, LinkTarget $target, $op)
Creates a query condition part for getting only items before or after the given link target (while or...
LoadBalancer $loadBalancer
__construct(LoadBalancer $loadBalancer)
getStartEndConds(IDatabase $db, array $options)
const FILTER_NOT_PATROLLED
getWatchlistOwnerId(User $user, array $options)
getWatchedItemsWithRecentChangeInfo(User $user, array $options=[], &$startFrom=null)
getWatchedItemsWithRCInfoQueryJoinConds(array $options)
getWatchedItemsForUserQueryDbOptions(array $options)
getRecentChangeFieldsFromRow(stdClass $row)
getStartFromConds(IDatabase $db, array $options, array $startFrom)
Representation of a pair of user and title for watchlist entries.
The ContentHandler facility adds support for arbitrary content types on wiki instead of relying on wikitext for everything It was introduced in MediaWiki Each kind of and so on Built in content types as usual *javascript user provided javascript code *json simple implementation for use by extensions
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
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 & $options
processing should stop and the error should be shown to the user * false
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
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