MediaWiki  master
ContribsPager.php
Go to the documentation of this file.
1 <?php
30 
32 
36  private $messages;
37 
41  private $target;
42 
47  private $contribs;
48 
52  private $namespace = '';
53 
57  private $tagFilter;
58 
62  private $nsInvert;
63 
68  private $associated;
69 
73  private $deletedOnly;
74 
78  private $topOnly;
79 
83  private $newOnly;
84 
88  private $hideMinor;
89 
90  private $preventClickjacking = false;
91 
93  private $mDbSecondary;
94 
98  private $mParentLens;
99 
104 
105  public function __construct( IContextSource $context, array $options ) {
106  // Set ->target and ->contribs before calling parent::__construct() so
107  // parent can call $this->getIndexField() and get the right result. Set
108  // the rest too just to keep things simple.
109  $this->target = $options['target'] ?? '';
110  $this->contribs = $options['contribs'] ?? 'users';
111  $this->namespace = $options['namespace'] ?? '';
112  $this->tagFilter = $options['tagfilter'] ?? false;
113  $this->nsInvert = $options['nsInvert'] ?? false;
114  $this->associated = $options['associated'] ?? false;
115 
116  $this->deletedOnly = !empty( $options['deletedOnly'] );
117  $this->topOnly = !empty( $options['topOnly'] );
118  $this->newOnly = !empty( $options['newOnly'] );
119  $this->hideMinor = !empty( $options['hideMinor'] );
120 
121  parent::__construct( $context );
122 
123  $msgs = [
124  'diff',
125  'hist',
126  'pipe-separator',
127  'uctop'
128  ];
129 
130  foreach ( $msgs as $msg ) {
131  $this->messages[$msg] = $this->msg( $msg )->escaped();
132  }
133 
134  // Date filtering: use timestamp if available
135  $startTimestamp = '';
136  $endTimestamp = '';
137  if ( $options['start'] ) {
138  $startTimestamp = $options['start'] . ' 00:00:00';
139  }
140  if ( $options['end'] ) {
141  $endTimestamp = $options['end'] . ' 23:59:59';
142  }
143  $this->getDateRangeCond( $startTimestamp, $endTimestamp );
144 
145  // Most of this code will use the 'contributions' group DB, which can map to replica DBs
146  // with extra user based indexes or partioning by user. The additional metadata
147  // queries should use a regular replica DB since the lookup pattern is not all by user.
148  $this->mDbSecondary = wfGetDB( DB_REPLICA ); // any random replica DB
149  $this->mDb = wfGetDB( DB_REPLICA, 'contributions' );
150  $this->templateParser = new TemplateParser();
151  }
152 
153  function getDefaultQuery() {
154  $query = parent::getDefaultQuery();
155  $query['target'] = $this->target;
156 
157  return $query;
158  }
159 
167  function getNavigationBar() {
168  return Html::rawElement( 'p', [ 'class' => 'mw-pager-navigation-bar' ],
169  parent::getNavigationBar()
170  );
171  }
172 
182  function reallyDoQuery( $offset, $limit, $order ) {
183  list( $tables, $fields, $conds, $fname, $options, $join_conds ) = $this->buildQueryInfo(
184  $offset,
185  $limit,
186  $order
187  );
188 
189  /*
190  * This hook will allow extensions to add in additional queries, so they can get their data
191  * in My Contributions as well. Extensions should append their results to the $data array.
192  *
193  * Extension queries have to implement the navbar requirement as well. They should
194  * - have a column aliased as $pager->getIndexField()
195  * - have LIMIT set
196  * - have a WHERE-clause that compares the $pager->getIndexField()-equivalent column to the offset
197  * - have the ORDER BY specified based upon the details provided by the navbar
198  *
199  * See includes/Pager.php buildQueryInfo() method on how to build LIMIT, WHERE & ORDER BY
200  *
201  * &$data: an array of results of all contribs queries
202  * $pager: the ContribsPager object hooked into
203  * $offset: see phpdoc above
204  * $limit: see phpdoc above
205  * $descending: see phpdoc above
206  */
207  $data = [ $this->mDb->select(
208  $tables, $fields, $conds, $fname, $options, $join_conds
209  ) ];
210  Hooks::run(
211  'ContribsPager::reallyDoQuery',
212  [ &$data, $this, $offset, $limit, $order ]
213  );
214 
215  $result = [];
216 
217  // loop all results and collect them in an array
218  foreach ( $data as $query ) {
219  foreach ( $query as $i => $row ) {
220  // use index column as key, allowing us to easily sort in PHP
221  $result[$row->{$this->getIndexField()} . "-$i"] = $row;
222  }
223  }
224 
225  // sort results
226  if ( $order === self::QUERY_ASCENDING ) {
227  ksort( $result );
228  } else {
229  krsort( $result );
230  }
231 
232  // enforce limit
233  $result = array_slice( $result, 0, $limit );
234 
235  // get rid of array keys
236  $result = array_values( $result );
237 
238  return new FakeResultWrapper( $result );
239  }
240 
250  private function getTargetTable() {
251  if ( $this->contribs == 'newbie' ) {
252  return 'revision';
253  }
254 
255  $user = User::newFromName( $this->target, false );
256  $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
257  if ( $ipRangeConds ) {
258  return 'ip_changes';
259  } else {
260  $conds = ActorMigration::newMigration()->getWhere( $this->mDb, 'rev_user', $user );
261  if ( isset( $conds['orconds']['actor'] ) ) {
262  // @todo: This will need changing when revision_actor_temp goes away
263  return 'revision_actor_temp';
264  }
265  }
266 
267  return 'revision';
268  }
269 
270  function getQueryInfo() {
271  $revQuery = Revision::getQueryInfo( [ 'page', 'user' ] );
272  $queryInfo = [
273  'tables' => $revQuery['tables'],
274  'fields' => array_merge( $revQuery['fields'], [ 'page_is_new' ] ),
275  'conds' => [],
276  'options' => [],
277  'join_conds' => $revQuery['joins'],
278  ];
279 
280  // WARNING: Keep this in sync with getTargetTable()!
281 
282  if ( $this->contribs == 'newbie' ) {
283  $max = $this->mDb->selectField( 'user', 'max(user_id)', '', __METHOD__ );
284  $queryInfo['conds'][] = $revQuery['fields']['rev_user'] . ' >' . (int)( $max - $max / 100 );
285  # ignore local groups with the bot right
286  # @todo FIXME: Global groups may have 'bot' rights
287  $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
288  if ( count( $groupsWithBotPermission ) ) {
289  $queryInfo['tables'][] = 'user_groups';
290  $queryInfo['conds'][] = 'ug_group IS NULL';
291  $queryInfo['join_conds']['user_groups'] = [
292  'LEFT JOIN', [
293  'ug_user = ' . $revQuery['fields']['rev_user'],
294  'ug_group' => $groupsWithBotPermission,
295  'ug_expiry IS NULL OR ug_expiry >= ' .
296  $this->mDb->addQuotes( $this->mDb->timestamp() )
297  ]
298  ];
299  }
300  // (T140537) Disallow looking too far in the past for 'newbies' queries. If the user requested
301  // a timestamp offset far in the past such that there are no edits by users with user_ids in
302  // the range, we would end up scanning all revisions from that offset until start of time.
303  $queryInfo['conds'][] = 'rev_timestamp > ' .
304  $this->mDb->addQuotes( $this->mDb->timestamp( wfTimestamp() - 30 * 24 * 60 * 60 ) );
305  } else {
306  $user = User::newFromName( $this->target, false );
307  $ipRangeConds = $user->isAnon() ? $this->getIpRangeConds( $this->mDb, $this->target ) : null;
308  if ( $ipRangeConds ) {
309  $queryInfo['tables'][] = 'ip_changes';
310  $queryInfo['join_conds']['ip_changes'] = [
311  'LEFT JOIN', [ 'ipc_rev_id = rev_id' ]
312  ];
313  $queryInfo['conds'][] = $ipRangeConds;
314  } else {
315  // tables and joins are already handled by Revision::getQueryInfo()
316  $conds = ActorMigration::newMigration()->getWhere( $this->mDb, 'rev_user', $user );
317  $queryInfo['conds'][] = $conds['conds'];
318  // Force the appropriate index to avoid bad query plans (T189026)
319  if ( isset( $conds['orconds']['actor'] ) ) {
320  // @todo: This will need changing when revision_actor_temp goes away
321  $queryInfo['options']['USE INDEX']['temp_rev_user'] = 'actor_timestamp';
322  } else {
323  $queryInfo['options']['USE INDEX']['revision'] =
324  isset( $conds['orconds']['userid'] ) ? 'user_timestamp' : 'usertext_timestamp';
325  }
326  }
327  }
328 
329  if ( $this->deletedOnly ) {
330  $queryInfo['conds'][] = 'rev_deleted != 0';
331  }
332 
333  if ( $this->topOnly ) {
334  $queryInfo['conds'][] = 'rev_id = page_latest';
335  }
336 
337  if ( $this->newOnly ) {
338  $queryInfo['conds'][] = 'rev_parent_id = 0';
339  }
340 
341  if ( $this->hideMinor ) {
342  $queryInfo['conds'][] = 'rev_minor_edit = 0';
343  }
344 
345  $user = $this->getUser();
346  $queryInfo['conds'] = array_merge( $queryInfo['conds'], $this->getNamespaceCond() );
347 
348  // Paranoia: avoid brute force searches (T19342)
349  if ( !$user->isAllowed( 'deletedhistory' ) ) {
350  $queryInfo['conds'][] = $this->mDb->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0';
351  } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) {
352  $queryInfo['conds'][] = $this->mDb->bitAnd( 'rev_deleted', Revision::SUPPRESSED_USER ) .
353  ' != ' . Revision::SUPPRESSED_USER;
354  }
355 
356  // $this->getIndexField() must be in the result rows, as reallyDoQuery() tries to access it.
357  $indexField = $this->getIndexField();
358  if ( $indexField !== 'rev_timestamp' ) {
359  $queryInfo['fields'][] = $indexField;
360  }
361 
363  $queryInfo['tables'],
364  $queryInfo['fields'],
365  $queryInfo['conds'],
366  $queryInfo['join_conds'],
367  $queryInfo['options'],
368  $this->tagFilter
369  );
370 
371  // Avoid PHP 7.1 warning from passing $this by reference
372  $pager = $this;
373  Hooks::run( 'ContribsPager::getQueryInfo', [ &$pager, &$queryInfo ] );
374 
375  return $queryInfo;
376  }
377 
378  function getNamespaceCond() {
379  if ( $this->namespace !== '' ) {
380  $selectedNS = $this->mDb->addQuotes( $this->namespace );
381  $eq_op = $this->nsInvert ? '!=' : '=';
382  $bool_op = $this->nsInvert ? 'AND' : 'OR';
383 
384  if ( !$this->associated ) {
385  return [ "page_namespace $eq_op $selectedNS" ];
386  }
387 
388  $associatedNS = $this->mDb->addQuotes(
389  MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociated( $this->namespace )
390  );
391 
392  return [
393  "page_namespace $eq_op $selectedNS " .
394  $bool_op .
395  " page_namespace $eq_op $associatedNS"
396  ];
397  }
398 
399  return [];
400  }
401 
408  private function getIpRangeConds( $db, $ip ) {
409  // First make sure it is a valid range and they are not outside the CIDR limit
410  if ( !$this->isQueryableRange( $ip ) ) {
411  return false;
412  }
413 
414  list( $start, $end ) = IP::parseRange( $ip );
415 
416  return 'ipc_hex BETWEEN ' . $db->addQuotes( $start ) . ' AND ' . $db->addQuotes( $end );
417  }
418 
426  public function isQueryableRange( $ipRange ) {
427  $limits = $this->getConfig()->get( 'RangeContributionsCIDRLimit' );
428 
429  $bits = IP::parseCIDR( $ipRange )[1];
430  if (
431  ( $bits === false ) ||
432  ( IP::isIPv4( $ipRange ) && $bits < $limits['IPv4'] ) ||
433  ( IP::isIPv6( $ipRange ) && $bits < $limits['IPv6'] )
434  ) {
435  return false;
436  }
437 
438  return true;
439  }
440 
444  public function getIndexField() {
445  // The returned column is used for sorting and continuation, so we need to
446  // make sure to use the right denormalized column depending on which table is
447  // being targeted by the query to avoid bad query plans.
448  // See T200259, T204669, T220991, and T221380.
449  $target = $this->getTargetTable();
450  switch ( $target ) {
451  case 'revision':
452  return 'rev_timestamp';
453  case 'ip_changes':
454  return 'ipc_rev_timestamp';
455  case 'revision_actor_temp':
456  return 'revactor_timestamp';
457  default:
458  wfWarn(
459  __METHOD__ . ": Unknown value '$target' from " . static::class . '::getTargetTable()', 0
460  );
461  return 'rev_timestamp';
462  }
463  }
464 
468  public function getTagFilter() {
469  return $this->tagFilter;
470  }
471 
475  public function getContribs() {
476  return $this->contribs;
477  }
478 
482  public function getTarget() {
483  return $this->target;
484  }
485 
489  public function isNewOnly() {
490  return $this->newOnly;
491  }
492 
496  public function getNamespace() {
497  return $this->namespace;
498  }
499 
503  protected function getExtraSortFields() {
504  // The returned columns are used for sorting, so we need to make sure
505  // to use the right denormalized column depending on which table is
506  // being targeted by the query to avoid bad query plans.
507  // See T200259, T204669, T220991, and T221380.
508  $target = $this->getTargetTable();
509  switch ( $target ) {
510  case 'revision':
511  return [ 'rev_id' ];
512  case 'ip_changes':
513  return [ 'ipc_rev_id' ];
514  case 'revision_actor_temp':
515  return [ 'revactor_rev' ];
516  default:
517  wfWarn(
518  __METHOD__ . ": Unknown value '$target' from " . static::class . '::getTargetTable()', 0
519  );
520  return [ 'rev_id' ];
521  }
522  }
523 
524  protected function doBatchLookups() {
525  # Do a link batch query
526  $this->mResult->seek( 0 );
527  $parentRevIds = [];
528  $this->mParentLens = [];
529  $batch = new LinkBatch();
530  $isIpRange = $this->isQueryableRange( $this->target );
531  # Give some pointers to make (last) links
532  foreach ( $this->mResult as $row ) {
533  if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
534  $parentRevIds[] = $row->rev_parent_id;
535  }
536  if ( isset( $row->rev_id ) ) {
537  $this->mParentLens[$row->rev_id] = $row->rev_len;
538  if ( $this->contribs === 'newbie' ) { // multiple users
539  $batch->add( NS_USER, $row->user_name );
540  $batch->add( NS_USER_TALK, $row->user_name );
541  } elseif ( $isIpRange ) {
542  // If this is an IP range, batch the IP's talk page
543  $batch->add( NS_USER_TALK, $row->rev_user_text );
544  }
545  $batch->add( $row->page_namespace, $row->page_title );
546  }
547  }
548  # Fetch rev_len for revisions not already scanned above
549  $this->mParentLens += Revision::getParentLengths(
550  $this->mDbSecondary,
551  array_diff( $parentRevIds, array_keys( $this->mParentLens ) )
552  );
553  $batch->execute();
554  $this->mResult->seek( 0 );
555  }
556 
560  protected function getStartBody() {
561  return "<ul class=\"mw-contributions-list\">\n";
562  }
563 
567  protected function getEndBody() {
568  return "</ul>\n";
569  }
570 
579  public function tryToCreateValidRevision( $row, $title = null ) {
580  /*
581  * There may be more than just revision rows. To make sure that we'll only be processing
582  * revisions here, let's _try_ to build a revision out of our row (without displaying
583  * notices though) and then trying to grab data from the built object. If we succeed,
584  * we're definitely dealing with revision data and we may proceed, if not, we'll leave it
585  * to extensions to subscribe to the hook to parse the row.
586  */
587  Wikimedia\suppressWarnings();
588  try {
589  $rev = new Revision( $row, 0, $title );
590  $validRevision = (bool)$rev->getId();
591  } catch ( Exception $e ) {
592  $validRevision = false;
593  }
594  Wikimedia\restoreWarnings();
595  return $validRevision ? $rev : null;
596  }
597 
610  function formatRow( $row ) {
611  $ret = '';
612  $classes = [];
613  $attribs = [];
614 
615  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
616 
617  $page = null;
618  // Create a title for the revision if possible
619  // Rows from the hook may not include title information
620  if ( isset( $row->page_namespace ) && isset( $row->page_title ) ) {
621  $page = Title::newFromRow( $row );
622  }
623  $rev = $this->tryToCreateValidRevision( $row, $page );
624  if ( $rev ) {
625  $attribs['data-mw-revid'] = $rev->getId();
626 
627  $link = $linkRenderer->makeLink(
628  $page,
629  $page->getPrefixedText(),
630  [ 'class' => 'mw-contributions-title' ],
631  $page->isRedirect() ? [ 'redirect' => 'no' ] : []
632  );
633  # Mark current revisions
634  $topmarktext = '';
635  $user = $this->getUser();
636 
637  if ( $row->rev_id === $row->page_latest ) {
638  $topmarktext .= '<span class="mw-uctop">' . $this->messages['uctop'] . '</span>';
639  $classes[] = 'mw-contributions-current';
640  # Add rollback link
641  if ( !$row->page_is_new && $page->quickUserCan( 'rollback', $user )
642  && $page->quickUserCan( 'edit', $user )
643  ) {
644  $this->preventClickjacking();
645  $topmarktext .= ' ' . Linker::generateRollback( $rev, $this->getContext() );
646  }
647  }
648  # Is there a visible previous revision?
649  if ( $rev->userCan( Revision::DELETED_TEXT, $user ) && $rev->getParentId() !== 0 ) {
650  $difftext = $linkRenderer->makeKnownLink(
651  $page,
652  new HtmlArmor( $this->messages['diff'] ),
653  [ 'class' => 'mw-changeslist-diff' ],
654  [
655  'diff' => 'prev',
656  'oldid' => $row->rev_id
657  ]
658  );
659  } else {
660  $difftext = $this->messages['diff'];
661  }
662  $histlink = $linkRenderer->makeKnownLink(
663  $page,
664  new HtmlArmor( $this->messages['hist'] ),
665  [ 'class' => 'mw-changeslist-history' ],
666  [ 'action' => 'history' ]
667  );
668 
669  if ( $row->rev_parent_id === null ) {
670  // For some reason rev_parent_id isn't populated for this row.
671  // Its rumoured this is true on wikipedia for some revisions (T36922).
672  // Next best thing is to have the total number of bytes.
673  $chardiff = ' <span class="mw-changeslist-separator"></span> ';
674  $chardiff .= Linker::formatRevisionSize( $row->rev_len );
675  $chardiff .= ' <span class="mw-changeslist-separator"></span> ';
676  } else {
677  $parentLen = 0;
678  if ( isset( $this->mParentLens[$row->rev_parent_id] ) ) {
679  $parentLen = $this->mParentLens[$row->rev_parent_id];
680  }
681 
682  $chardiff = ' <span class="mw-changeslist-separator"></span> ';
684  $parentLen,
685  $row->rev_len,
686  $this->getContext()
687  );
688  $chardiff .= ' <span class="mw-changeslist-separator"></span> ';
689  }
690 
691  $lang = $this->getLanguage();
692  $comment = $lang->getDirMark() . Linker::revComment( $rev, false, true, false );
693  $d = ChangesList::revDateLink( $rev, $user, $lang, $page );
694 
695  # Show user names for /newbies as there may be different users.
696  # Note that only unprivileged users have rows with hidden user names excluded.
697  # When querying for an IP range, we want to always show user and user talk links.
698  $userlink = '';
699  if ( ( $this->contribs == 'newbie' && !$rev->isDeleted( Revision::DELETED_USER ) )
700  || $this->isQueryableRange( $this->target ) ) {
701  $userlink = ' <span class="mw-changeslist-separator"></span> '
702  . $lang->getDirMark()
703  . Linker::userLink( $rev->getUser(), $rev->getUserText() );
704  $userlink .= ' ' . $this->msg( 'parentheses' )->rawParams(
705  Linker::userTalkLink( $rev->getUser(), $rev->getUserText() ) )->escaped() . ' ';
706  }
707 
708  $flags = [];
709  if ( $rev->getParentId() === 0 ) {
710  $flags[] = ChangesList::flag( 'newpage' );
711  }
712 
713  if ( $rev->isMinor() ) {
714  $flags[] = ChangesList::flag( 'minor' );
715  }
716 
717  $del = Linker::getRevDeleteLink( $user, $rev, $page );
718  if ( $del !== '' ) {
719  $del .= ' ';
720  }
721 
722  // While it might be tempting to use a list here
723  // this would result in clutter and slows down navigating the content
724  // in assistive technology.
725  // See https://phabricator.wikimedia.org/T205581#4734812
726  $diffHistLinks = Html::rawElement( 'span',
727  [ 'class' => 'mw-changeslist-links' ],
728  // The spans are needed to ensure the dividing '|' elements are not
729  // themselves styled as links.
730  Html::rawElement( 'span', [], $difftext ) .
731  ' ' . // Space needed for separating two words.
732  Html::rawElement( 'span', [], $histlink )
733  );
734 
735  # Tags, if any.
736  list( $tagSummary, $newClasses ) = ChangeTags::formatSummaryRow(
737  $row->ts_tags,
738  'contributions',
739  $this->getContext()
740  );
741  $classes = array_merge( $classes, $newClasses );
742 
743  Hooks::run( 'SpecialContributions::formatRow::flags', [ $this->getContext(), $row, &$flags ] );
744 
745  $templateParams = [
746  'del' => $del,
747  'timestamp' => $d,
748  'diffHistLinks' => $diffHistLinks,
749  'charDifference' => $chardiff,
750  'flags' => $flags,
751  'articleLink' => $link,
752  'userlink' => $userlink,
753  'logText' => $comment,
754  'topmarktext' => $topmarktext,
755  'tagSummary' => $tagSummary,
756  ];
757 
758  # Denote if username is redacted for this edit
759  if ( $rev->isDeleted( Revision::DELETED_USER ) ) {
760  $templateParams['rev-deleted-user-contribs'] =
761  $this->msg( 'rev-deleted-user-contribs' )->escaped();
762  }
763 
764  $ret = $this->templateParser->processTemplate(
765  'SpecialContributionsLine',
766  $templateParams
767  );
768  }
769 
770  // Let extensions add data
771  Hooks::run( 'ContributionsLineEnding', [ $this, &$ret, $row, &$classes, &$attribs ] );
772  $attribs = array_filter( $attribs,
773  [ Sanitizer::class, 'isReservedDataAttribute' ],
774  ARRAY_FILTER_USE_KEY
775  );
776 
777  // TODO: Handle exceptions in the catch block above. Do any extensions rely on
778  // receiving empty rows?
779 
780  if ( $classes === [] && $attribs === [] && $ret === '' ) {
781  wfDebug( "Dropping Special:Contribution row that could not be formatted\n" );
782  return "<!-- Could not format Special:Contribution row. -->\n";
783  }
784  $attribs['class'] = $classes;
785 
786  // FIXME: The signature of the ContributionsLineEnding hook makes it
787  // very awkward to move this LI wrapper into the template.
788  return Html::rawElement( 'li', $attribs, $ret ) . "\n";
789  }
790 
795  function getSqlComment() {
796  if ( $this->namespace || $this->deletedOnly ) {
797  // potentially slow, see CR r58153
798  return 'contributions page filtered for namespace or RevisionDeleted edits';
799  } else {
800  return 'contributions page unfiltered';
801  }
802  }
803 
804  protected function preventClickjacking() {
805  $this->preventClickjacking = true;
806  }
807 
811  public function getPreventClickjacking() {
813  }
814 
821  public static function processDateFilter( array $opts ) {
822  $start = $opts['start'] ?? '';
823  $end = $opts['end'] ?? '';
824  $year = $opts['year'] ?? '';
825  $month = $opts['month'] ?? '';
826 
827  if ( $start !== '' && $end !== '' && $start > $end ) {
828  $temp = $start;
829  $start = $end;
830  $end = $temp;
831  }
832 
833  // If year/month legacy filtering options are set, convert them to display the new stamp
834  if ( $year !== '' || $month !== '' ) {
835  // Reuse getDateCond logic, but subtract a day because
836  // the endpoints of our date range appear inclusive
837  // but the internal end offsets are always exclusive
838  $legacyTimestamp = ReverseChronologicalPager::getOffsetDate( $year, $month );
839  $legacyDateTime = new DateTime( $legacyTimestamp->getTimestamp( TS_ISO_8601 ) );
840  $legacyDateTime = $legacyDateTime->modify( '-1 day' );
841 
842  // Clear the new timestamp range options if used and
843  // replace with the converted legacy timestamp
844  $start = '';
845  $end = $legacyDateTime->format( 'Y-m-d' );
846  }
847 
848  $opts['start'] = $start;
849  $opts['end'] = $end;
850 
851  return $opts;
852  }
853 }
static modifyDisplayQuery(&$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag='')
Applies all tags-related changes to a query.
Definition: ChangeTags.php:732
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
Definition: deferred.txt:11
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1585
isQueryableRange( $ipRange)
Is the given IP a range and within the CIDR limit?
bool $deletedOnly
Set to true to show only deleted revisions.
static processDateFilter(array $opts)
Set up date filter options, given request data.
static parseRange( $range)
Given a string range in a number of formats, return the start and end of the range in hexadecimal...
Definition: IP.php:500
static formatRevisionSize( $size)
Definition: Linker.php:1597
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 noclasses & $ret
Definition: hooks.txt:1982
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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 noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1982
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2159
bool $hideMinor
Set to true to hide edits marked as minor by the user.
if(!isset( $args[0])) $lang
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
bool $associated
Set to true to show both the subject and talk namespace, no matter which got selected.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:538
string $contribs
Set to "newbie" to list contributions from the most recent 1% registered users.
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 MediaWikiServices
Definition: injection.txt:23
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:519
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1812
bool $nsInvert
Set to true to invert the namespace selection.
IContextSource $context
tryToCreateValidRevision( $row, $title=null)
Check whether the revision associated is valid for formatting.
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
Definition: hooks.txt:979
__construct(IContextSource $context, array $options)
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1980
$batch
Definition: linkcache.txt:23
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3051
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error messages
Definition: hooks.txt:1287
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:34
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static newMigration()
Static constructor.
static flag( $flag, IContextSource $context=null)
Make an "<abbr>" element for a given change flag.
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
Definition: User.php:4915
reallyDoQuery( $offset, $limit, $order)
This method basically executes the exact same code as the parent class, though with a hook added...
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
getDateRangeCond( $startStamp, $endStamp)
Set and return a date range condition using timestamps provided by the user.
string $target
User name, or a string describing an IP address range.
getContext()
Get the base IContextSource object.
static revDateLink(Revision $rev, User $user, Language $lang, $title=null)
Render the date and time of a revision in the current user language based on whether the user is able...
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
Definition: hooks.txt:1982
getTargetTable()
Return the table targeted for ordering and continuation.
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 noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1982
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
string false $tagFilter
Name of tag to filter, or false to ignore tags.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:511
formatRow( $row)
Generates each row in the contributions list.
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1766
TemplateParser $templateParser
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
Definition: distributors.txt:9
static showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
getSqlComment()
Overwrite Pager function and return a helpful comment.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings, LocalSettings).
Definition: Setup.php:123
string int $namespace
A single namespace number, or an empty string for all namespaces.
const DELETED_TEXT
Definition: Revision.php:46
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:900
buildQueryInfo( $offset, $limit, $order)
Build variables to use by the database wrapper.
const SUPPRESSED_USER
Definition: Revision.php:50
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
Definition: injection.txt:35
static isIPv6( $ip)
Given a string, determine if it as valid IP in IPv6 only.
Definition: IP.php:88
static getRevDeleteLink(User $user, Revision $rev, LinkTarget $title)
Get a revision-deletion link, or disabled link, or nothing, depending on user permissions & the setti...
Definition: Linker.php:2111
const DELETED_USER
Definition: Revision.php:48
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
Definition: maintenance.txt:52
static userTalkLink( $userId, $userText)
Definition: Linker.php:1036
Overloads the relevant methods of the real ResultsWrapper so it doesn&#39;t go anywhere near an actual da...
getNavigationBar()
Wrap the navigation bar in a p element with identifying class.
static getOffsetDate( $year, $month, $day=-1)
Core logic of determining the mOffset timestamp such that we can get all items with a timestamp up to...
string [] $messages
Local cache for escaped messages.
$revQuery
static isIPv4( $ip)
Given a string, determine if it as valid IP in IPv4 only.
Definition: IP.php:99
static formatSummaryRow( $tags, $page, IContextSource $context=null)
Creates HTML for the given tags.
Definition: ChangeTags.php:93
static revComment(Revision $rev, $local=false, $isPublic=false, $useParentheses=true)
Wrap and format the given revision&#39;s comment block, if the current user is allowed to view it...
Definition: Linker.php:1572
const DB_REPLICA
Definition: defines.php:25
Pager for filtering by a range of dates.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:594
static parseCIDR( $range)
Convert a network specification in CIDR notation to an integer network and a number of bits...
Definition: IP.php:457
const NS_USER_TALK
Definition: Defines.php:63
bool $topOnly
Set to true to show only latest (a.k.a.
getIpRangeConds( $db, $ip)
Get SQL conditions for an IP range, if applicable.
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
IDatabase $mDbSecondary
bool $newOnly
Set to true to show only new pages.