5use Wikimedia\Assert\Assert;
77 $this->loadBalancer = $loadBalancer;
78 $this->commentStore = $commentStore;
79 $this->actorMigration = $actorMigration;
80 $this->watchedItemStore = $watchedItemStore;
89 Hooks::run(
'WatchedItemQueryServiceExtensions', [ &$this->
extensions, $this ] );
91 return $this->extensions;
98 return $this->loadBalancer->getConnectionRef(
DB_REPLICA, [
'watchlist' ] );
148 'includeFields' => [],
149 'namespaceIds' => [],
151 'allRevisions' =>
false,
152 'usedInGenerator' =>
false
158 '$options[\'rcTypes\']',
159 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
162 !isset(
$options[
'dir'] ) || in_array(
$options[
'dir'], [ self::DIR_OLDER, self::DIR_NEWER ] ),
164 'must be DIR_OLDER or DIR_NEWER'
167 !isset(
$options[
'start'] ) && !isset(
$options[
'end'] ) && $startFrom ===
null
170 'must be provided when providing the "start" or "end" options or the $startFrom parameter'
174 '$options[\'startFrom\']',
175 'must not be provided, use $startFrom instead'
178 !isset( $startFrom ) || ( is_array( $startFrom ) && count( $startFrom ) === 2 ),
180 'must be a two-element array'
182 if ( array_key_exists(
'watchlistOwner',
$options ) ) {
183 Assert::parameterType(
186 '$options[\'watchlistOwner\']'
189 isset(
$options[
'watchlistOwnerToken'] ),
190 '$options[\'watchlistOwnerToken\']',
191 'must be provided when providing watchlistOwner option'
203 if ( $startFrom !==
null ) {
208 $extension->modifyWatchedItemsWithRCInfoQuery(
227 $limit = $dbOptions[
'LIMIT'] ?? INF;
230 foreach (
$res as $row ) {
231 if ( --$limit <= 0 ) {
232 $startFrom = [ $row->rc_timestamp, $row->rc_id ];
236 $target =
new TitleValue( (
int)$row->rc_namespace, $row->rc_title );
241 $this->watchedItemStore->getLatestNotificationTimestamp(
242 $row->wl_notificationtimestamp,
$user, $target
250 $extension->modifyWatchedItemsWithRCInfo(
$user,
$options, $db, $items,
$res, $startFrom );
276 if (
$user->isAnon() ) {
282 $options += [
'namespaceIds' => [] ];
285 !isset(
$options[
'sort'] ) || in_array(
$options[
'sort'], [ self::SORT_ASC, self::SORT_DESC ] ),
286 '$options[\'sort\']',
287 'must be SORT_ASC or SORT_DESC'
290 !isset(
$options[
'filter'] ) || in_array(
291 $options[
'filter'], [ self::FILTER_CHANGED, self::FILTER_NOT_CHANGED ]
293 '$options[\'filter\']',
294 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
299 '$options[\'sort\']',
300 'must be provided if any of "from", "until", "startFrom" options is provided'
310 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
317 foreach (
$res as $row ) {
318 $target =
new TitleValue( (
int)$row->wl_namespace, $row->wl_title );
323 $this->watchedItemStore->getLatestNotificationTimestamp(
324 $row->wl_notificationtimestamp,
$user, $target
329 return $watchedItems;
335 $allFields = get_object_vars( $row );
336 $rcKeys = array_filter(
337 array_keys( $allFields ),
339 return substr( $key, 0, 3 ) ===
'rc_';
342 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
346 $tables = [
'recentchanges',
'watchlist' ];
350 if ( in_array( self::INCLUDE_COMMENT,
$options[
'includeFields'] ) ) {
351 $tables += $this->commentStore->getJoin(
'rc_comment' )[
'tables'];
353 if ( in_array( self::INCLUDE_USER,
$options[
'includeFields'] ) ||
354 in_array( self::INCLUDE_USER_ID,
$options[
'includeFields'] ) ||
355 in_array( self::FILTER_ANON,
$options[
'filters'] ) ||
356 in_array( self::FILTER_NOT_ANON,
$options[
'filters'] ) ||
357 array_key_exists(
'onlyByUser',
$options ) || array_key_exists(
'notByUser',
$options )
359 $tables += $this->actorMigration->getJoin(
'rc_user' )[
'tables'];
372 'wl_notificationtimestamp'
380 if (
$options[
'usedInGenerator'] ) {
382 $rcIdFields = [
'rc_this_oldid' ];
384 $rcIdFields = [
'rc_cur_id' ];
387 $fields = array_merge( $fields, $rcIdFields );
389 if ( in_array( self::INCLUDE_FLAGS,
$options[
'includeFields'] ) ) {
390 $fields = array_merge( $fields, [
'rc_type',
'rc_minor',
'rc_bot' ] );
392 if ( in_array( self::INCLUDE_USER,
$options[
'includeFields'] ) ) {
393 $fields[
'rc_user_text'] = $this->actorMigration->getJoin(
'rc_user' )[
'fields'][
'rc_user_text'];
395 if ( in_array( self::INCLUDE_USER_ID,
$options[
'includeFields'] ) ) {
396 $fields[
'rc_user'] = $this->actorMigration->getJoin(
'rc_user' )[
'fields'][
'rc_user'];
398 if ( in_array( self::INCLUDE_COMMENT,
$options[
'includeFields'] ) ) {
399 $fields += $this->commentStore->getJoin(
'rc_comment' )[
'fields'];
401 if ( in_array( self::INCLUDE_PATROL_INFO,
$options[
'includeFields'] ) ) {
402 $fields = array_merge( $fields, [
'rc_patrolled',
'rc_log_type' ] );
404 if ( in_array( self::INCLUDE_SIZES,
$options[
'includeFields'] ) ) {
405 $fields = array_merge( $fields, [
'rc_old_len',
'rc_new_len' ] );
407 if ( in_array( self::INCLUDE_LOG_INFO,
$options[
'includeFields'] ) ) {
408 $fields = array_merge( $fields, [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ] );
410 if ( in_array( self::INCLUDE_TAGS,
$options[
'includeFields'] ) ) {
424 $conds = [
'wl_user' => $watchlistOwnerId ];
428 [
'rc_this_oldid=page_latest',
'rc_type=' .
RC_LOG ],
434 $conds[
'wl_namespace'] = array_map(
'intval',
$options[
'namespaceIds'] );
437 if ( array_key_exists(
'rcTypes',
$options ) ) {
438 $conds[
'rc_type'] = array_map(
'intval',
$options[
'rcTypes'] );
441 $conds = array_merge(
450 $conds[] =
'rc_timestamp > ' . $db->
addQuotes(
'' );
456 if ( $deletedPageLogCond ) {
457 $conds[] = $deletedPageLogCond;
464 if ( array_key_exists(
'watchlistOwner',
$options ) ) {
466 $watchlistOwner =
$options[
'watchlistOwner'];
467 $ownersToken = $watchlistOwner->getOption(
'watchlisttoken' );
468 $token =
$options[
'watchlistOwnerToken'];
469 if ( $ownersToken ==
'' || !hash_equals( $ownersToken, $token ) ) {
472 return $watchlistOwner->getId();
474 return $user->getId();
480 if ( in_array( self::FILTER_MINOR,
$options[
'filters'] ) ) {
481 $conds[] =
'rc_minor != 0';
482 } elseif ( in_array( self::FILTER_NOT_MINOR,
$options[
'filters'] ) ) {
483 $conds[] =
'rc_minor = 0';
486 if ( in_array( self::FILTER_BOT,
$options[
'filters'] ) ) {
487 $conds[] =
'rc_bot != 0';
488 } elseif ( in_array( self::FILTER_NOT_BOT,
$options[
'filters'] ) ) {
489 $conds[] =
'rc_bot = 0';
492 if ( in_array( self::FILTER_ANON,
$options[
'filters'] ) ) {
493 $conds[] = $this->actorMigration->isAnon(
494 $this->actorMigration->getJoin(
'rc_user' )[
'fields'][
'rc_user']
496 } elseif ( in_array( self::FILTER_NOT_ANON,
$options[
'filters'] ) ) {
497 $conds[] = $this->actorMigration->isNotAnon(
498 $this->actorMigration->getJoin(
'rc_user' )[
'fields'][
'rc_user']
502 if (
$user->useRCPatrol() ||
$user->useNPPatrol() ) {
505 if ( in_array( self::FILTER_PATROLLED,
$options[
'filters'] ) ) {
506 $conds[] =
'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED;
507 } elseif ( in_array( self::FILTER_NOT_PATROLLED,
$options[
'filters'] ) ) {
508 $conds[
'rc_patrolled'] = RecentChange::PRC_UNPATROLLED;
511 if ( in_array( self::FILTER_AUTOPATROLLED,
$options[
'filters'] ) ) {
512 $conds[
'rc_patrolled'] = RecentChange::PRC_AUTOPATROLLED;
513 } elseif ( in_array( self::FILTER_NOT_AUTOPATROLLED,
$options[
'filters'] ) ) {
514 $conds[] =
'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED;
518 if ( in_array( self::FILTER_UNREAD,
$options[
'filters'] ) ) {
519 $conds[] =
'rc_timestamp >= wl_notificationtimestamp';
520 } elseif ( in_array( self::FILTER_NOT_UNREAD,
$options[
'filters'] ) ) {
522 $conds[] =
'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
536 $after =
$options[
'dir'] === self::DIR_OLDER ?
'<=' :
'>=';
537 $conds[] =
'rc_timestamp ' . $after .
' ' .
541 $before =
$options[
'dir'] === self::DIR_OLDER ?
'>=' :
'<=';
542 $conds[] =
'rc_timestamp ' . $before .
' ' .
550 if ( !array_key_exists(
'onlyByUser',
$options ) && !array_key_exists(
'notByUser',
$options ) ) {
556 if ( array_key_exists(
'onlyByUser',
$options ) ) {
558 $conds[] = $this->actorMigration->getWhere( $db,
'rc_user', $byUser )[
'conds'];
559 } elseif ( array_key_exists(
'notByUser',
$options ) ) {
561 $conds[] =
'NOT(' . $this->actorMigration->getWhere( $db,
'rc_user', $byUser )[
'conds'] .
')';
566 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
568 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
572 $conds[] = $db->
bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask";
582 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
584 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
590 $db->
bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
597 $op =
$options[
'dir'] === self::DIR_OLDER ?
'<' :
'>';
598 list( $rcTimestamp, $rcId ) = $startFrom;
603 "rc_timestamp $op $rcTimestamp",
606 "rc_timestamp = $rcTimestamp",
617 $conds = [
'wl_user' =>
$user->getId() ];
619 $conds[
'wl_namespace'] = array_map(
'intval',
$options[
'namespaceIds'] );
621 if ( isset(
$options[
'filter'] ) ) {
623 if (
$filter === self::FILTER_CHANGED ) {
624 $conds[] =
'wl_notificationtimestamp IS NOT NULL';
626 $conds[] =
'wl_notificationtimestamp IS NULL';
631 $op =
$options[
'sort'] === self::SORT_ASC ?
'>' :
'<';
635 $op =
$options[
'sort'] === self::SORT_ASC ?
'<' :
'>';
638 if ( isset(
$options[
'startFrom'] ) ) {
639 $op =
$options[
'sort'] === self::SORT_ASC ?
'>' :
'<';
674 if ( array_key_exists(
'dir',
$options ) ) {
676 $dbOptions[
'ORDER BY'] = [
'rc_timestamp' .
$sort,
'rc_id' .
$sort ];
679 if ( array_key_exists(
'limit',
$options ) ) {
680 $dbOptions[
'LIMIT'] = (int)
$options[
'limit'] + 1;
688 if ( array_key_exists(
'sort',
$options ) ) {
689 $dbOptions[
'ORDER BY'] = [
690 "wl_namespace {$options['sort']}",
691 "wl_title {$options['sort']}"
693 if ( count(
$options[
'namespaceIds'] ) === 1 ) {
694 $dbOptions[
'ORDER BY'] =
"wl_title {$options['sort']}";
697 if ( array_key_exists(
'limit',
$options ) ) {
698 $dbOptions[
'LIMIT'] = (int)
$options[
'limit'];
705 'watchlist' => [
'JOIN',
707 'wl_namespace=rc_namespace',
713 $joinConds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
715 if ( in_array( self::INCLUDE_COMMENT,
$options[
'includeFields'] ) ) {
716 $joinConds += $this->commentStore->getJoin(
'rc_comment' )[
'joins'];
718 if ( in_array( self::INCLUDE_USER,
$options[
'includeFields'] ) ||
719 in_array( self::INCLUDE_USER_ID,
$options[
'includeFields'] ) ||
720 in_array( self::FILTER_ANON,
$options[
'filters'] ) ||
721 in_array( self::FILTER_NOT_ANON,
$options[
'filters'] ) ||
722 array_key_exists(
'onlyByUser',
$options ) || array_key_exists(
'notByUser',
$options )
724 $joinConds += $this->actorMigration->getJoin(
'rc_user' )[
'joins'];
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This class handles the logic for the actor table migration.
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,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
getWatchedItemsForUser(User $user, array $options=[])
For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser.
const INCLUDE_AUTOPATROL_INFO
const FILTER_NOT_AUTOPATROLLED
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)
WatchedItemStoreInterface $watchedItemStore
getWatchedItemsForUserQueryConds(IDatabase $db, User $user, array $options)
const FILTER_AUTOPATROLLED
getFromUntilTargetConds(IDatabase $db, LinkTarget $target, $op)
Creates a query condition part for getting only items before or after the given link target (while or...
__construct(LoadBalancer $loadBalancer, CommentStore $commentStore, ActorMigration $actorMigration, WatchedItemStoreInterface $watchedItemStore)
LoadBalancer $loadBalancer
getStartEndConds(IDatabase $db, array $options)
ActorMigration $actorMigration
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)
CommentStore $commentStore
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
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
this hook is for auditing only 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
return true to allow those checks to and false if checking is done & $user
processing should stop and the error should be shown to the user * false
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))