62 return $this->loadBalancer->getConnectionRef(
DB_REPLICA, [
'watchlist' ] );
112 'includeFields' => [],
113 'namespaceIds' => [],
115 'allRevisions' =>
false,
116 'usedInGenerator' =>
false
122 '$options[\'rcTypes\']',
123 'must be an array containing only: RC_EDIT, RC_NEW, RC_LOG, RC_EXTERNAL and/or RC_CATEGORIZE'
126 !isset(
$options[
'dir'] ) || in_array(
$options[
'dir'], [ self::DIR_OLDER, self::DIR_NEWER ] ),
128 'must be DIR_OLDER or DIR_NEWER'
134 'must be provided when providing any of options: start, end, startFrom'
138 || ( is_array(
$options[
'startFrom'] ) && count(
$options[
'startFrom'] ) === 2 ),
139 '$options[\'startFrom\']',
140 'must be a two-element array'
142 if ( array_key_exists(
'watchlistOwner',
$options ) ) {
143 Assert::parameterType(
146 '$options[\'watchlistOwner\']'
149 isset(
$options[
'watchlistOwnerToken'] ),
150 '$options[\'watchlistOwnerToken\']',
151 'must be provided when providing watchlistOwner option'
155 $tables = [
'recentchanges',
'watchlist' ];
177 foreach (
$res as $row ) {
181 new TitleValue( (
int)$row->rc_namespace, $row->rc_title ),
182 $row->wl_notificationtimestamp
217 $options += [
'namespaceIds' => [] ];
220 !isset(
$options[
'sort'] ) || in_array(
$options[
'sort'], [ self::SORT_ASC, self::SORT_DESC ] ),
221 '$options[\'sort\']',
222 'must be SORT_ASC or SORT_DESC'
225 !isset(
$options[
'filter'] ) || in_array(
226 $options[
'filter'], [ self::FILTER_CHANGED, self::FILTER_NOT_CHANGED ]
228 '$options[\'filter\']',
229 'must be FILTER_CHANGED or FILTER_NOT_CHANGED'
234 '$options[\'sort\']',
235 'must be provided if any of "from", "until", "startFrom" options is provided'
245 [
'wl_namespace',
'wl_title',
'wl_notificationtimestamp' ],
252 foreach (
$res as $row ) {
256 new TitleValue( (
int)$row->wl_namespace, $row->wl_title ),
257 $row->wl_notificationtimestamp
261 return $watchedItems;
267 $allFields = get_object_vars( $row );
268 $rcKeys = array_filter(
269 array_keys( $allFields ),
271 return substr( $key, 0, 3 ) ===
'rc_';
274 return array_intersect_key( $allFields, array_flip( $rcKeys ) );
285 'wl_notificationtimestamp'
293 if ( $options[
'usedInGenerator'] ) {
294 if ( $options[
'allRevisions'] ) {
295 $rcIdFields = [
'rc_this_oldid' ];
297 $rcIdFields = [
'rc_cur_id' ];
300 $fields = array_merge( $fields, $rcIdFields );
302 if ( in_array( self::INCLUDE_FLAGS, $options[
'includeFields'] ) ) {
303 $fields = array_merge( $fields, [
'rc_type',
'rc_minor',
'rc_bot' ] );
305 if ( in_array( self::INCLUDE_USER, $options[
'includeFields'] ) ) {
306 $fields[] =
'rc_user_text';
308 if ( in_array( self::INCLUDE_USER_ID, $options[
'includeFields'] ) ) {
309 $fields[] =
'rc_user';
311 if ( in_array( self::INCLUDE_COMMENT, $options[
'includeFields'] ) ) {
312 $fields[] =
'rc_comment';
314 if ( in_array( self::INCLUDE_PATROL_INFO, $options[
'includeFields'] ) ) {
315 $fields = array_merge( $fields, [
'rc_patrolled',
'rc_log_type' ] );
317 if ( in_array( self::INCLUDE_SIZES, $options[
'includeFields'] ) ) {
318 $fields = array_merge( $fields, [
'rc_old_len',
'rc_new_len' ] );
320 if ( in_array( self::INCLUDE_LOG_INFO, $options[
'includeFields'] ) ) {
321 $fields = array_merge( $fields, [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ] );
333 $conds = [
'wl_user' => $watchlistOwnerId ];
335 if ( !$options[
'allRevisions'] ) {
337 [
'rc_this_oldid=page_latest',
'rc_type=' .
RC_LOG ],
342 if ( $options[
'namespaceIds'] ) {
343 $conds[
'wl_namespace'] = array_map(
'intval', $options[
'namespaceIds'] );
346 if ( array_key_exists(
'rcTypes', $options ) ) {
347 $conds[
'rc_type'] = array_map(
'intval', $options[
'rcTypes'] );
350 $conds = array_merge(
357 if ( !isset( $options[
'start'] ) && !isset( $options[
'end'] ) ) {
358 if ( $db->
getType() ===
'mysql' ) {
360 $conds[] =
"rc_timestamp > ''";
367 if ( $deletedPageLogCond ) {
368 $conds[] = $deletedPageLogCond;
371 if ( array_key_exists(
'startFrom', $options ) ) {
379 if ( array_key_exists(
'watchlistOwner', $options ) ) {
381 $watchlistOwner = $options[
'watchlistOwner'];
382 $ownersToken = $watchlistOwner->getOption(
'watchlisttoken' );
383 $token = $options[
'watchlistOwnerToken'];
384 if ( $ownersToken ==
'' || !hash_equals( $ownersToken, $token ) ) {
386 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences',
390 return $watchlistOwner->getId();
392 return $user->
getId();
398 if ( in_array( self::FILTER_MINOR, $options[
'filters'] ) ) {
399 $conds[] =
'rc_minor != 0';
400 } elseif ( in_array( self::FILTER_NOT_MINOR, $options[
'filters'] ) ) {
401 $conds[] =
'rc_minor = 0';
404 if ( in_array( self::FILTER_BOT, $options[
'filters'] ) ) {
405 $conds[] =
'rc_bot != 0';
406 } elseif ( in_array( self::FILTER_NOT_BOT, $options[
'filters'] ) ) {
407 $conds[] =
'rc_bot = 0';
410 if ( in_array( self::FILTER_ANON, $options[
'filters'] ) ) {
411 $conds[] =
'rc_user = 0';
412 } elseif ( in_array( self::FILTER_NOT_ANON, $options[
'filters'] ) ) {
413 $conds[] =
'rc_user != 0';
419 if ( in_array( self::FILTER_PATROLLED, $options[
'filters'] ) ) {
420 $conds[] =
'rc_patrolled != 0';
421 } elseif ( in_array( self::FILTER_NOT_PATROLLED, $options[
'filters'] ) ) {
422 $conds[] =
'rc_patrolled = 0';
426 if ( in_array( self::FILTER_UNREAD, $options[
'filters'] ) ) {
427 $conds[] =
'rc_timestamp >= wl_notificationtimestamp';
428 } elseif ( in_array( self::FILTER_NOT_UNREAD, $options[
'filters'] ) ) {
430 $conds[] =
'wl_notificationtimestamp IS NULL OR rc_timestamp < wl_notificationtimestamp';
437 if ( !isset( $options[
'start'] ) && ! isset( $options[
'end'] ) ) {
443 if ( isset( $options[
'start'] ) ) {
444 $after = $options[
'dir'] === self::DIR_OLDER ?
'<=' :
'>=';
445 $conds[] =
'rc_timestamp ' . $after .
' ' .
448 if ( isset( $options[
'end'] ) ) {
449 $before = $options[
'dir'] === self::DIR_OLDER ?
'>=' :
'<=';
450 $conds[] =
'rc_timestamp ' . $before .
' ' .
458 if ( !array_key_exists(
'onlyByUser', $options ) && !array_key_exists(
'notByUser', $options ) ) {
464 if ( array_key_exists(
'onlyByUser', $options ) ) {
465 $conds[
'rc_user_text'] = $options[
'onlyByUser'];
466 } elseif ( array_key_exists(
'notByUser', $options ) ) {
467 $conds[] =
'rc_user_text != ' . $db->
addQuotes( $options[
'notByUser'] );
472 if ( !$user->
isAllowed(
'deletedhistory' ) ) {
474 } elseif ( !$user->
isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
478 $conds[] = $db->
bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask";
488 if ( !$user->
isAllowed(
'deletedhistory' ) ) {
490 } elseif ( !$user->
isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
496 $db->
bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
503 $op = $options[
'dir'] === self::DIR_OLDER ?
'<' :
'>';
504 list( $rcTimestamp, $rcId ) = $options[
'startFrom'];
509 "rc_timestamp $op $rcTimestamp",
512 "rc_timestamp = $rcTimestamp",
523 $conds = [
'wl_user' => $user->
getId() ];
524 if ( $options[
'namespaceIds'] ) {
525 $conds[
'wl_namespace'] = array_map(
'intval', $options[
'namespaceIds'] );
527 if ( isset( $options[
'filter'] ) ) {
528 $filter = $options[
'filter'];
529 if ( $filter === self::FILTER_CHANGED ) {
530 $conds[] =
'wl_notificationtimestamp IS NOT NULL';
532 $conds[] =
'wl_notificationtimestamp IS NULL';
536 if ( isset( $options[
'from'] ) ) {
537 $op = $options[
'sort'] === self::SORT_ASC ?
'>' :
'<';
540 if ( isset( $options[
'until'] ) ) {
541 $op = $options[
'sort'] === self::SORT_ASC ?
'<' :
'>';
544 if ( isset( $options[
'startFrom'] ) ) {
545 $op = $options[
'sort'] === self::SORT_ASC ?
'>' :
'<';
580 if ( array_key_exists(
'dir', $options ) ) {
581 $sort = $options[
'dir'] === self::DIR_OLDER ?
' DESC' :
'';
582 $dbOptions[
'ORDER BY'] = [
'rc_timestamp' .
$sort,
'rc_id' .
$sort ];
585 if ( array_key_exists(
'limit', $options ) ) {
586 $dbOptions[
'LIMIT'] = (int)$options[
'limit'];
594 if ( array_key_exists(
'sort', $options ) ) {
595 $dbOptions[
'ORDER BY'] = [
596 "wl_namespace {$options['sort']}",
597 "wl_title {$options['sort']}"
599 if ( count( $options[
'namespaceIds'] ) === 1 ) {
600 $dbOptions[
'ORDER BY'] =
"wl_title {$options['sort']}";
603 if ( array_key_exists(
'limit', $options ) ) {
604 $dbOptions[
'LIMIT'] = (int)$options[
'limit'];
611 'watchlist' => [
'INNER JOIN',
613 'wl_namespace=rc_namespace',
618 if ( !$options[
'allRevisions'] ) {
619 $joinConds[
'page'] = [
'LEFT JOIN',
'rc_cur_id=page_id' ];
getWatchedItemsWithRCInfoQueryFields(array $options)
getUserRelatedConds(IDatabase $db, User $user, array $options)
getWatchedItemsForUserQueryConds(IDatabase $db, User $user, array $options)
getWatchedItemsWithRecentChangeInfo(User $user, array $options=[])
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
the array() calling protocol came about after MediaWiki 1.4rc1.
getWatchedItemsForUser(User $user, array $options=[])
For simple listing of user's watchlist items, see WatchedItemStore::getWatchedItemsForUser.
getWatchedItemsForUserQueryDbOptions(array $options)
getWatchedItemsWithRCInfoQueryConds(IDatabase $db, User $user, array $options)
processing should stop and the error should be shown to the user * false
getFromUntilTargetConds(IDatabase $db, LinkTarget $target, $op)
Creates a query condition part for getting only items before or after the given link target (while or...
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getStartEndConds(IDatabase $db, array $options)
isAllowedAny()
Check if user is allowed to access a feature / make an action.
LoadBalancer $loadBalancer
getWatchedItemsWithRCInfoQueryDbOptions(array $options)
Represents a page (or page fragment) title within MediaWiki.
getWatchedItemsWithRCInfoQueryJoinConds(array $options)
bitAnd($fieldLeft, $fieldRight)
getExtraDeletedPageLogEntryRelatedCond(IDatabase $db, User $user)
timestamp($ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
getType()
Get the type of the DBMS, as it appears in $wgDBtype.
const INCLUDE_PATROL_INFO
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist & $tables
makeList($a, $mode=self::LIST_COMMA)
Makes an encoded list of strings from an array.
isAllowed($action= '')
Internal mechanics of testing a permission.
isAnon()
Get whether the user is anonymous.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
getWatchedItemsWithRCInfoQueryFilterConds(User $user, array $options)
const FILTER_NOT_PATROLLED
Representation of a pair of user and title for watchlist entries.
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
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
useRCPatrol()
Check whether to enable recent changes patrol features for this user.
getStartFromConds(IDatabase $db, array $options)
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
getWatchlistOwnerId(User $user, array $options)
getRecentChangeFieldsFromRow(stdClass $row)
getId()
Get the user's ID.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
useNPPatrol()
Check whether to enable new pages patrol features for this user.
addQuotes($s)
Adds quotes and backslashes.
__construct(LoadBalancer $loadBalancer)
Basic database interface for live and lazy-loaded relation database handles.
This exception will be thrown when dieUsage is called to stop module execution.