MediaWiki  1.33.0
RecentChange.php
Go to the documentation of this file.
1 <?php
23 
69 class RecentChange implements Taggable {
70  // Constants for the rc_source field. Extensions may also have
71  // their own source constants.
72  const SRC_EDIT = 'mw.edit';
73  const SRC_NEW = 'mw.new';
74  const SRC_LOG = 'mw.log';
75  const SRC_EXTERNAL = 'mw.external'; // obsolete
76  const SRC_CATEGORIZE = 'mw.categorize';
77 
78  const PRC_UNPATROLLED = 0;
79  const PRC_PATROLLED = 1;
80  const PRC_AUTOPATROLLED = 2;
81 
85  const SEND_NONE = true;
86 
90  const SEND_FEED = false;
91 
92  public $mAttribs = [];
93  public $mExtra = [];
94 
98  public $mTitle = false;
99 
103  private $mPerformer = false;
104 
107 
111  public $counter = -1;
112 
116  private $tags = [];
117 
121  private static $changeTypes = [
122  'edit' => RC_EDIT,
123  'new' => RC_NEW,
124  'log' => RC_LOG,
125  'external' => RC_EXTERNAL,
126  'categorize' => RC_CATEGORIZE,
127  ];
128 
129  # Factory methods
130 
135  public static function newFromRow( $row ) {
136  $rc = new RecentChange;
137  $rc->loadFromRow( $row );
138 
139  return $rc;
140  }
141 
149  public static function parseToRCType( $type ) {
150  if ( is_array( $type ) ) {
151  $retval = [];
152  foreach ( $type as $t ) {
153  $retval[] = self::parseToRCType( $t );
154  }
155 
156  return $retval;
157  }
158 
159  if ( !array_key_exists( $type, self::$changeTypes ) ) {
160  throw new MWException( "Unknown type '$type'" );
161  }
162  return self::$changeTypes[$type];
163  }
164 
171  public static function parseFromRCType( $rcType ) {
172  return array_search( $rcType, self::$changeTypes, true ) ?: "$rcType";
173  }
174 
182  public static function getChangeTypes() {
183  return array_keys( self::$changeTypes );
184  }
185 
192  public static function newFromId( $rcid ) {
193  return self::newFromConds( [ 'rc_id' => $rcid ], __METHOD__ );
194  }
195 
205  public static function newFromConds(
206  $conds,
207  $fname = __METHOD__,
208  $dbType = DB_REPLICA
209  ) {
210  $db = wfGetDB( $dbType );
211  $rcQuery = self::getQueryInfo();
212  $row = $db->selectRow(
213  $rcQuery['tables'], $rcQuery['fields'], $conds, $fname, [], $rcQuery['joins']
214  );
215  if ( $row !== false ) {
216  return self::newFromRow( $row );
217  } else {
218  return null;
219  }
220  }
221 
228  public static function selectFields() {
230 
231  wfDeprecated( __METHOD__, '1.31' );
233  // If code is using this instead of self::getQueryInfo(), there's a
234  // decent chance it's going to try to directly access
235  // $row->rc_user or $row->rc_user_text and we can't give it
236  // useful values here once those aren't being used anymore.
237  throw new BadMethodCallException(
238  'Cannot use ' . __METHOD__
239  . ' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
240  );
241  }
242 
243  return [
244  'rc_id',
245  'rc_timestamp',
246  'rc_user',
247  'rc_user_text',
248  'rc_actor' => 'NULL',
249  'rc_namespace',
250  'rc_title',
251  'rc_minor',
252  'rc_bot',
253  'rc_new',
254  'rc_cur_id',
255  'rc_this_oldid',
256  'rc_last_oldid',
257  'rc_type',
258  'rc_source',
259  'rc_patrolled',
260  'rc_ip',
261  'rc_old_len',
262  'rc_new_len',
263  'rc_deleted',
264  'rc_logid',
265  'rc_log_type',
266  'rc_log_action',
267  'rc_params',
268  ] + CommentStore::getStore()->getFields( 'rc_comment' );
269  }
270 
280  public static function getQueryInfo() {
281  $commentQuery = CommentStore::getStore()->getJoin( 'rc_comment' );
282  $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
283  return [
284  'tables' => [ 'recentchanges' ] + $commentQuery['tables'] + $actorQuery['tables'],
285  'fields' => [
286  'rc_id',
287  'rc_timestamp',
288  'rc_namespace',
289  'rc_title',
290  'rc_minor',
291  'rc_bot',
292  'rc_new',
293  'rc_cur_id',
294  'rc_this_oldid',
295  'rc_last_oldid',
296  'rc_type',
297  'rc_source',
298  'rc_patrolled',
299  'rc_ip',
300  'rc_old_len',
301  'rc_new_len',
302  'rc_deleted',
303  'rc_logid',
304  'rc_log_type',
305  'rc_log_action',
306  'rc_params',
307  ] + $commentQuery['fields'] + $actorQuery['fields'],
308  'joins' => $commentQuery['joins'] + $actorQuery['joins'],
309  ];
310  }
311 
312  # Accessors
313 
317  public function setAttribs( $attribs ) {
318  $this->mAttribs = $attribs;
319  }
320 
324  public function setExtra( $extra ) {
325  $this->mExtra = $extra;
326  }
327 
331  public function &getTitle() {
332  if ( $this->mTitle === false ) {
333  $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
334  }
335 
336  return $this->mTitle;
337  }
338 
344  public function getPerformer() {
345  if ( $this->mPerformer === false ) {
346  if ( !empty( $this->mAttribs['rc_actor'] ) ) {
347  $this->mPerformer = User::newFromActorId( $this->mAttribs['rc_actor'] );
348  } elseif ( !empty( $this->mAttribs['rc_user'] ) ) {
349  $this->mPerformer = User::newFromId( $this->mAttribs['rc_user'] );
350  } elseif ( !empty( $this->mAttribs['rc_user_text'] ) ) {
351  $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false );
352  } else {
353  throw new MWException( 'RecentChange object lacks rc_actor, rc_user, and rc_user_text' );
354  }
355  }
356 
357  return $this->mPerformer;
358  }
359 
369  public function save( $send = self::SEND_FEED ) {
371 
372  if ( is_string( $send ) ) {
373  // Callers used to pass undocumented strings like 'noudp'
374  // or 'pleasedontudp' instead of self::SEND_NONE (true).
375  // @deprecated since 1.31 Use SEND_NONE instead.
376  $send = self::SEND_NONE;
377  }
378 
379  $dbw = wfGetDB( DB_MASTER );
380  if ( !is_array( $this->mExtra ) ) {
381  $this->mExtra = [];
382  }
383 
384  if ( !$wgPutIPinRC ) {
385  $this->mAttribs['rc_ip'] = '';
386  }
387 
388  # Strict mode fixups (not-NULL fields)
389  foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
390  $this->mAttribs["rc_$field"] = (int)$this->mAttribs["rc_$field"];
391  }
392  # ...more fixups (NULL fields)
393  foreach ( [ 'old_len', 'new_len' ] as $field ) {
394  $this->mAttribs["rc_$field"] = isset( $this->mAttribs["rc_$field"] )
395  ? (int)$this->mAttribs["rc_$field"]
396  : null;
397  }
398 
399  # If our database is strict about IP addresses, use NULL instead of an empty string
400  $strictIPs = in_array( $dbw->getType(), [ 'oracle', 'postgres' ] ); // legacy
401  if ( $strictIPs && $this->mAttribs['rc_ip'] == '' ) {
402  unset( $this->mAttribs['rc_ip'] );
403  }
404 
405  # Trim spaces on user supplied text
406  $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] );
407 
408  # Fixup database timestamps
409  $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] );
410 
411  # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
412  if ( $this->mAttribs['rc_cur_id'] == 0 ) {
413  unset( $this->mAttribs['rc_cur_id'] );
414  }
415 
416  $row = $this->mAttribs;
417 
418  # Convert mAttribs['rc_comment'] for CommentStore
419  $comment = $row['rc_comment'];
420  unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] );
421  $row += CommentStore::getStore()->insert( $dbw, 'rc_comment', $comment );
422 
423  # Convert mAttribs['rc_user'] etc for ActorMigration
425  $row['rc_user'] ?? null,
426  $row['rc_user_text'] ?? null,
427  $row['rc_actor'] ?? null
428  );
429  unset( $row['rc_user'], $row['rc_user_text'], $row['rc_actor'] );
430  $row += ActorMigration::newMigration()->getInsertValues( $dbw, 'rc_user', $user );
431 
432  # Don't reuse an existing rc_id for the new row, if one happens to be
433  # set for some reason.
434  unset( $row['rc_id'] );
435 
436  # Insert new row
437  $dbw->insert( 'recentchanges', $row, __METHOD__ );
438 
439  # Set the ID
440  $this->mAttribs['rc_id'] = $dbw->insertId();
441 
442  # Notify extensions
443  // Avoid PHP 7.1 warning from passing $this by reference
444  $rc = $this;
445  Hooks::run( 'RecentChange_save', [ &$rc ] );
446 
447  if ( count( $this->tags ) ) {
448  ChangeTags::addTags( $this->tags, $this->mAttribs['rc_id'],
449  $this->mAttribs['rc_this_oldid'], $this->mAttribs['rc_logid'], null, $this );
450  }
451 
452  if ( $send === self::SEND_FEED ) {
453  // Emit the change to external applications via RCFeeds.
454  $this->notifyRCFeeds();
455  }
456 
457  # E-mail notifications
458  if ( $wgUseEnotif || $wgShowUpdatedMarker ) {
459  $editor = $this->getPerformer();
460  $title = $this->getTitle();
461 
462  // Never send an RC notification email about categorization changes
463  if (
464  Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) &&
465  $this->mAttribs['rc_type'] != RC_CATEGORIZE
466  ) {
467  // @FIXME: This would be better as an extension hook
468  // Send emails or email jobs once this row is safely committed
469  $dbw->onTransactionCommitOrIdle(
470  function () use ( $editor, $title ) {
471  $enotif = new EmailNotification();
472  $enotif->notifyOnPageChange(
473  $editor,
474  $title,
475  $this->mAttribs['rc_timestamp'],
476  $this->mAttribs['rc_comment'],
477  $this->mAttribs['rc_minor'],
478  $this->mAttribs['rc_last_oldid'],
479  $this->mExtra['pageStatus']
480  );
481  },
482  __METHOD__
483  );
484  }
485  }
486 
487  // Update the cached list of active users
488  if ( $this->mAttribs['rc_user'] > 0 ) {
490  }
491  }
492 
497  public function notifyRCFeeds( array $feeds = null ) {
498  global $wgRCFeeds;
499  if ( $feeds === null ) {
500  $feeds = $wgRCFeeds;
501  }
502 
503  $performer = $this->getPerformer();
504 
505  foreach ( $feeds as $params ) {
506  $params += [
507  'omit_bots' => false,
508  'omit_anon' => false,
509  'omit_user' => false,
510  'omit_minor' => false,
511  'omit_patrolled' => false,
512  ];
513 
514  if (
515  ( $params['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
516  ( $params['omit_anon'] && $performer->isAnon() ) ||
517  ( $params['omit_user'] && !$performer->isAnon() ) ||
518  ( $params['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
519  ( $params['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) ||
520  $this->mAttribs['rc_type'] == RC_EXTERNAL
521  ) {
522  continue;
523  }
524 
525  $actionComment = $this->mExtra['actionCommentIRC'] ?? null;
526 
527  $feed = RCFeed::factory( $params );
528  $feed->notify( $this, $actionComment );
529  }
530  }
531 
540  public static function getEngine( $uri, $params = [] ) {
541  // TODO: Merge into RCFeed::factory().
542  global $wgRCEngines;
543  $scheme = parse_url( $uri, PHP_URL_SCHEME );
544  if ( !$scheme ) {
545  throw new MWException( "Invalid RCFeed uri: '$uri'" );
546  }
547  if ( !isset( $wgRCEngines[$scheme] ) ) {
548  throw new MWException( "Unknown RCFeedEngine scheme: '$scheme'" );
549  }
550  if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
551  return $wgRCEngines[$scheme];
552  }
553  return new $wgRCEngines[$scheme]( $params );
554  }
555 
565  public static function markPatrolled( $change, $auto = false, $tags = null ) {
566  global $wgUser;
567 
568  $change = $change instanceof RecentChange
569  ? $change
570  : self::newFromId( $change );
571 
572  if ( !$change instanceof RecentChange ) {
573  return null;
574  }
575 
576  return $change->doMarkPatrolled( $wgUser, $auto, $tags );
577  }
578 
590  public function doMarkPatrolled( User $user, $auto = false, $tags = null ) {
592 
593  // Fix up $tags so that the MarkPatrolled hook below always gets an array
594  if ( $tags === null ) {
595  $tags = [];
596  } elseif ( is_string( $tags ) ) {
597  $tags = [ $tags ];
598  }
599 
600  $errors = [];
601  // If recentchanges patrol is disabled, only new pages or new file versions
602  // can be patrolled, provided the appropriate config variable is set
603  if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) &&
604  ( !$wgUseFilePatrol || !( $this->getAttribute( 'rc_type' ) == RC_LOG &&
605  $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
606  $errors[] = [ 'rcpatroldisabled' ];
607  }
608  // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
609  $right = $auto ? 'autopatrol' : 'patrol';
610  $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
611  if ( !Hooks::run( 'MarkPatrolled',
612  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto, &$tags ] )
613  ) {
614  $errors[] = [ 'hookaborted' ];
615  }
616  // Users without the 'autopatrol' right can't patrol their
617  // own revisions
618  if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
619  && !$user->isAllowed( 'autopatrol' )
620  ) {
621  $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
622  }
623  if ( $errors ) {
624  return $errors;
625  }
626  // If the change was patrolled already, do nothing
627  if ( $this->getAttribute( 'rc_patrolled' ) ) {
628  return [];
629  }
630  // Actually set the 'patrolled' flag in RC
631  $this->reallyMarkPatrolled();
632  // Log this patrol event
633  PatrolLog::record( $this, $auto, $user, $tags );
634 
635  Hooks::run(
636  'MarkPatrolledComplete',
637  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
638  );
639 
640  return [];
641  }
642 
647  public function reallyMarkPatrolled() {
648  $dbw = wfGetDB( DB_MASTER );
649  $dbw->update(
650  'recentchanges',
651  [
652  'rc_patrolled' => self::PRC_PATROLLED
653  ],
654  [
655  'rc_id' => $this->getAttribute( 'rc_id' )
656  ],
657  __METHOD__
658  );
659  // Invalidate the page cache after the page has been patrolled
660  // to make sure that the Patrol link isn't visible any longer!
661  $this->getTitle()->invalidateCache();
662 
663  return $dbw->affectedRows();
664  }
665 
685  public static function notifyEdit(
686  $timestamp, $title, $minor, $user, $comment, $oldId, $lastTimestamp,
687  $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
688  $tags = []
689  ) {
690  $rc = new RecentChange;
691  $rc->mTitle = $title;
692  $rc->mPerformer = $user;
693  $rc->mAttribs = [
694  'rc_timestamp' => $timestamp,
695  'rc_namespace' => $title->getNamespace(),
696  'rc_title' => $title->getDBkey(),
697  'rc_type' => RC_EDIT,
698  'rc_source' => self::SRC_EDIT,
699  'rc_minor' => $minor ? 1 : 0,
700  'rc_cur_id' => $title->getArticleID(),
701  'rc_user' => $user->getId(),
702  'rc_user_text' => $user->getName(),
703  'rc_actor' => $user->getActorId(),
704  'rc_comment' => &$comment,
705  'rc_comment_text' => &$comment,
706  'rc_comment_data' => null,
707  'rc_this_oldid' => $newId,
708  'rc_last_oldid' => $oldId,
709  'rc_bot' => $bot ? 1 : 0,
710  'rc_ip' => self::checkIPAddress( $ip ),
711  'rc_patrolled' => intval( $patrol ),
712  'rc_new' => 0, # obsolete
713  'rc_old_len' => $oldSize,
714  'rc_new_len' => $newSize,
715  'rc_deleted' => 0,
716  'rc_logid' => 0,
717  'rc_log_type' => null,
718  'rc_log_action' => '',
719  'rc_params' => ''
720  ];
721 
722  $rc->mExtra = [
723  'prefixedDBkey' => $title->getPrefixedDBkey(),
724  'lastTimestamp' => $lastTimestamp,
725  'oldSize' => $oldSize,
726  'newSize' => $newSize,
727  'pageStatus' => 'changed'
728  ];
729 
731  function () use ( $rc, $tags ) {
732  $rc->addTags( $tags );
733  $rc->save();
734  },
736  wfGetDB( DB_MASTER )
737  );
738 
739  return $rc;
740  }
741 
759  public static function notifyNew(
760  $timestamp, $title, $minor, $user, $comment, $bot,
761  $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
762  ) {
763  $rc = new RecentChange;
764  $rc->mTitle = $title;
765  $rc->mPerformer = $user;
766  $rc->mAttribs = [
767  'rc_timestamp' => $timestamp,
768  'rc_namespace' => $title->getNamespace(),
769  'rc_title' => $title->getDBkey(),
770  'rc_type' => RC_NEW,
771  'rc_source' => self::SRC_NEW,
772  'rc_minor' => $minor ? 1 : 0,
773  'rc_cur_id' => $title->getArticleID(),
774  'rc_user' => $user->getId(),
775  'rc_user_text' => $user->getName(),
776  'rc_actor' => $user->getActorId(),
777  'rc_comment' => &$comment,
778  'rc_comment_text' => &$comment,
779  'rc_comment_data' => null,
780  'rc_this_oldid' => $newId,
781  'rc_last_oldid' => 0,
782  'rc_bot' => $bot ? 1 : 0,
783  'rc_ip' => self::checkIPAddress( $ip ),
784  'rc_patrolled' => intval( $patrol ),
785  'rc_new' => 1, # obsolete
786  'rc_old_len' => 0,
787  'rc_new_len' => $size,
788  'rc_deleted' => 0,
789  'rc_logid' => 0,
790  'rc_log_type' => null,
791  'rc_log_action' => '',
792  'rc_params' => ''
793  ];
794 
795  $rc->mExtra = [
796  'prefixedDBkey' => $title->getPrefixedDBkey(),
797  'lastTimestamp' => 0,
798  'oldSize' => 0,
799  'newSize' => $size,
800  'pageStatus' => 'created'
801  ];
802 
804  function () use ( $rc, $tags ) {
805  $rc->addTags( $tags );
806  $rc->save();
807  },
809  wfGetDB( DB_MASTER )
810  );
811 
812  return $rc;
813  }
814 
830  public static function notifyLog( $timestamp, $title, $user, $actionComment, $ip, $type,
831  $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
832  ) {
833  global $wgLogRestrictions;
834 
835  # Don't add private logs to RC!
836  if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
837  return false;
838  }
839  $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
840  $target, $logComment, $params, $newId, $actionCommentIRC );
841  $rc->save();
842 
843  return true;
844  }
845 
863  public static function newLogEntry( $timestamp, $title, $user, $actionComment, $ip,
864  $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
865  $revId = 0, $isPatrollable = false ) {
866  global $wgRequest;
867 
868  # # Get pageStatus for email notification
869  switch ( $type . '-' . $action ) {
870  case 'delete-delete':
871  case 'delete-delete_redir':
872  $pageStatus = 'deleted';
873  break;
874  case 'move-move':
875  case 'move-move_redir':
876  $pageStatus = 'moved';
877  break;
878  case 'delete-restore':
879  $pageStatus = 'restored';
880  break;
881  case 'upload-upload':
882  $pageStatus = 'created';
883  break;
884  case 'upload-overwrite':
885  default:
886  $pageStatus = 'changed';
887  break;
888  }
889 
890  // Allow unpatrolled status for patrollable log entries
891  $markPatrolled = $isPatrollable ? $user->isAllowed( 'autopatrol' ) : true;
892 
893  $rc = new RecentChange;
894  $rc->mTitle = $target;
895  $rc->mPerformer = $user;
896  $rc->mAttribs = [
897  'rc_timestamp' => $timestamp,
898  'rc_namespace' => $target->getNamespace(),
899  'rc_title' => $target->getDBkey(),
900  'rc_type' => RC_LOG,
901  'rc_source' => self::SRC_LOG,
902  'rc_minor' => 0,
903  'rc_cur_id' => $target->getArticleID(),
904  'rc_user' => $user->getId(),
905  'rc_user_text' => $user->getName(),
906  'rc_actor' => $user->getActorId(),
907  'rc_comment' => &$logComment,
908  'rc_comment_text' => &$logComment,
909  'rc_comment_data' => null,
910  'rc_this_oldid' => $revId,
911  'rc_last_oldid' => 0,
912  'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0,
913  'rc_ip' => self::checkIPAddress( $ip ),
914  'rc_patrolled' => $markPatrolled ? self::PRC_AUTOPATROLLED : self::PRC_UNPATROLLED,
915  'rc_new' => 0, # obsolete
916  'rc_old_len' => null,
917  'rc_new_len' => null,
918  'rc_deleted' => 0,
919  'rc_logid' => $newId,
920  'rc_log_type' => $type,
921  'rc_log_action' => $action,
922  'rc_params' => $params
923  ];
924 
925  $rc->mExtra = [
926  'prefixedDBkey' => $title->getPrefixedDBkey(),
927  'lastTimestamp' => 0,
928  'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
929  'pageStatus' => $pageStatus,
930  'actionCommentIRC' => $actionCommentIRC
931  ];
932 
933  return $rc;
934  }
935 
957  public static function newForCategorization(
958  $timestamp,
959  Title $categoryTitle,
960  User $user = null,
961  $comment,
962  Title $pageTitle,
963  $oldRevId,
964  $newRevId,
965  $lastTimestamp,
966  $bot,
967  $ip = '',
968  $deleted = 0,
969  $added = null
970  ) {
971  // Done in a backwards compatible way.
972  $params = [
973  'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
974  ];
975  if ( $added !== null ) {
976  $params['added'] = $added;
977  }
978 
979  $rc = new RecentChange;
980  $rc->mTitle = $categoryTitle;
981  $rc->mPerformer = $user;
982  $rc->mAttribs = [
983  'rc_timestamp' => $timestamp,
984  'rc_namespace' => $categoryTitle->getNamespace(),
985  'rc_title' => $categoryTitle->getDBkey(),
986  'rc_type' => RC_CATEGORIZE,
987  'rc_source' => self::SRC_CATEGORIZE,
988  'rc_minor' => 0,
989  'rc_cur_id' => $pageTitle->getArticleID(),
990  'rc_user' => $user ? $user->getId() : 0,
991  'rc_user_text' => $user ? $user->getName() : '',
992  'rc_actor' => $user ? $user->getActorId() : null,
993  'rc_comment' => &$comment,
994  'rc_comment_text' => &$comment,
995  'rc_comment_data' => null,
996  'rc_this_oldid' => $newRevId,
997  'rc_last_oldid' => $oldRevId,
998  'rc_bot' => $bot ? 1 : 0,
999  'rc_ip' => self::checkIPAddress( $ip ),
1000  'rc_patrolled' => self::PRC_AUTOPATROLLED, // Always patrolled, just like log entries
1001  'rc_new' => 0, # obsolete
1002  'rc_old_len' => null,
1003  'rc_new_len' => null,
1004  'rc_deleted' => $deleted,
1005  'rc_logid' => 0,
1006  'rc_log_type' => null,
1007  'rc_log_action' => '',
1008  'rc_params' => serialize( $params )
1009  ];
1010 
1011  $rc->mExtra = [
1012  'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
1013  'lastTimestamp' => $lastTimestamp,
1014  'oldSize' => 0,
1015  'newSize' => 0,
1016  'pageStatus' => 'changed'
1017  ];
1018 
1019  return $rc;
1020  }
1021 
1030  public function getParam( $name ) {
1031  $params = $this->parseParams();
1032  return $params[$name] ?? null;
1033  }
1034 
1040  public function loadFromRow( $row ) {
1041  $this->mAttribs = get_object_vars( $row );
1042  $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] );
1043  // rc_deleted MUST be set
1044  $this->mAttribs['rc_deleted'] = $row->rc_deleted;
1045 
1046  if ( isset( $this->mAttribs['rc_ip'] ) ) {
1047  // Clean up CIDRs for Postgres per T164898. ("127.0.0.1" casts to "127.0.0.1/32")
1048  $n = strpos( $this->mAttribs['rc_ip'], '/' );
1049  if ( $n !== false ) {
1050  $this->mAttribs['rc_ip'] = substr( $this->mAttribs['rc_ip'], 0, $n );
1051  }
1052  }
1053 
1054  $comment = CommentStore::getStore()
1055  // Legacy because $row may have come from self::selectFields()
1056  ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'rc_comment', $row, true )
1057  ->text;
1058  $this->mAttribs['rc_comment'] = &$comment;
1059  $this->mAttribs['rc_comment_text'] = &$comment;
1060  $this->mAttribs['rc_comment_data'] = null;
1061 
1063  $this->mAttribs['rc_user'] ?? null,
1064  $this->mAttribs['rc_user_text'] ?? null,
1065  $this->mAttribs['rc_actor'] ?? null
1066  );
1067  $this->mAttribs['rc_user'] = $user->getId();
1068  $this->mAttribs['rc_user_text'] = $user->getName();
1069  $this->mAttribs['rc_actor'] = $user->getActorId();
1070  }
1071 
1078  public function getAttribute( $name ) {
1079  if ( $name === 'rc_comment' ) {
1080  return CommentStore::getStore()
1081  ->getComment( 'rc_comment', $this->mAttribs, true )->text;
1082  }
1083 
1084  if ( $name === 'rc_user' || $name === 'rc_user_text' || $name === 'rc_actor' ) {
1086  $this->mAttribs['rc_user'] ?? null,
1087  $this->mAttribs['rc_user_text'] ?? null,
1088  $this->mAttribs['rc_actor'] ?? null
1089  );
1090  if ( $name === 'rc_user' ) {
1091  return $user->getId();
1092  }
1093  if ( $name === 'rc_user_text' ) {
1094  return $user->getName();
1095  }
1096  if ( $name === 'rc_actor' ) {
1097  return $user->getActorId();
1098  }
1099  }
1100 
1101  return $this->mAttribs[$name] ?? null;
1102  }
1103 
1107  public function getAttributes() {
1108  return $this->mAttribs;
1109  }
1110 
1117  public function diffLinkTrail( $forceCur ) {
1118  if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
1119  $trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) .
1120  "&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] );
1121  if ( $forceCur ) {
1122  $trail .= '&diff=0';
1123  } else {
1124  $trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] );
1125  }
1126  } else {
1127  $trail = '';
1128  }
1129 
1130  return $trail;
1131  }
1132 
1140  public function getCharacterDifference( $old = 0, $new = 0 ) {
1141  if ( $old === 0 ) {
1142  $old = $this->mAttribs['rc_old_len'];
1143  }
1144  if ( $new === 0 ) {
1145  $new = $this->mAttribs['rc_new_len'];
1146  }
1147  if ( $old === null || $new === null ) {
1148  return '';
1149  }
1150 
1151  return ChangesList::showCharacterDifference( $old, $new );
1152  }
1153 
1154  private static function checkIPAddress( $ip ) {
1155  global $wgRequest;
1156  if ( $ip ) {
1157  if ( !IP::isIPAddress( $ip ) ) {
1158  throw new MWException( "Attempt to write \"" . $ip .
1159  "\" as an IP address into recent changes" );
1160  }
1161  } else {
1162  $ip = $wgRequest->getIP();
1163  if ( !$ip ) {
1164  $ip = '';
1165  }
1166  }
1167 
1168  return $ip;
1169  }
1170 
1180  public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1181  global $wgRCMaxAge;
1182 
1183  return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1184  }
1185 
1193  public function parseParams() {
1194  $rcParams = $this->getAttribute( 'rc_params' );
1195 
1196  Wikimedia\suppressWarnings();
1197  $unserializedParams = unserialize( $rcParams );
1198  Wikimedia\restoreWarnings();
1199 
1200  return $unserializedParams;
1201  }
1202 
1211  public function addTags( $tags ) {
1212  if ( is_string( $tags ) ) {
1213  $this->tags[] = $tags;
1214  } else {
1215  $this->tags = array_merge( $tags, $this->tags );
1216  }
1217  }
1218 }
RecentChange\getCharacterDifference
getCharacterDifference( $old=0, $new=0)
Returns the change size (HTML).
Definition: RecentChange.php:1140
RecentChange\save
save( $send=self::SEND_FEED)
Writes the data in this object to the database.
Definition: RecentChange.php:369
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:280
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:609
RC_EXTERNAL
const RC_EXTERNAL
Definition: Defines.php:145
SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:287
RecentChange\$tags
array $tags
List of tags to apply.
Definition: RecentChange.php:116
RecentChange\setExtra
setExtra( $extra)
Definition: RecentChange.php:324
SpecialRecentChangesLinked
This is to display changes made to all articles linked in an article.
Definition: SpecialRecentchangeslinked.php:29
RecentChange\newForCategorization
static newForCategorization( $timestamp, Title $categoryTitle, User $user=null, $comment, Title $pageTitle, $oldRevId, $newRevId, $lastTimestamp, $bot, $ip='', $deleted=0, $added=null)
Constructs a RecentChange object for the given categorization This does not call save() on the object...
Definition: RecentChange.php:957
RecentChange\newFromConds
static newFromConds( $conds, $fname=__METHOD__, $dbType=DB_REPLICA)
Find the first recent change matching some specific conditions.
Definition: RecentChange.php:205
$wgShowUpdatedMarker
$wgShowUpdatedMarker
Show "Updated (since my last visit)" marker in RC view, watchlist and history view for watched pages ...
Definition: DefaultSettings.php:7018
captcha-old.count
count
Definition: captcha-old.py:249
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1648
RecentChange\getAttributes
getAttributes()
Definition: RecentChange.php:1107
PatrolLog\record
static record( $rc, $auto=false, User $user=null, $tags=null)
Record a log event for a change being patrolled.
Definition: PatrolLog.php:42
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:69
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
RecentChange\$mAttribs
$mAttribs
Definition: RecentChange.php:92
RC_LOG
const RC_LOG
Definition: Defines.php:144
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:2954
RecentChange\notifyLog
static notifyLog( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:830
RecentChange\getEngine
static getEngine( $uri, $params=[])
Definition: RecentChange.php:540
RecentChange\loadFromRow
loadFromRow( $row)
Initialises the members of this object from a mysql row object.
Definition: RecentChange.php:1040
RecentChange\getChangeTypes
static getChangeTypes()
Get an array of all change types.
Definition: RecentChange.php:182
RecentChange\reallyMarkPatrolled
reallyMarkPatrolled()
Mark this RecentChange patrolled, without error checking.
Definition: RecentChange.php:647
$params
$params
Definition: styleTest.css.php:44
RC_EDIT
const RC_EDIT
Definition: Defines.php:142
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
RecentChange\$counter
int $counter
Line number of recent change.
Definition: RecentChange.php:111
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:676
RecentChange\setAttribs
setAttribs( $attribs)
Definition: RecentChange.php:317
MediaWiki\ChangeTags\Taggable
Interface that defines how to tag objects.
Definition: Taggable.php:32
RecentChange\SRC_CATEGORIZE
const SRC_CATEGORIZE
Definition: RecentChange.php:76
RecentChange\parseToRCType
static parseToRCType( $type)
Parsing text to RC_* constants.
Definition: RecentChange.php:149
serialize
serialize()
Definition: ApiMessageTrait.php:134
$wgUseRCPatrol
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
Definition: DefaultSettings.php:6911
$wgUseNPPatrol
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
Definition: DefaultSettings.php:6927
RecentChange\SRC_LOG
const SRC_LOG
Definition: RecentChange.php:74
RecentChangesUpdateJob\newCacheUpdateJob
static newCacheUpdateJob()
Definition: RecentChangesUpdateJob.php:54
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
php
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
RecentChange\parseParams
parseParams()
Parses and returns the rc_params attribute.
Definition: RecentChange.php:1193
$wgPutIPinRC
$wgPutIPinRC
Log IP addresses in the recentchanges table; can be accessed only by extensions (e....
Definition: DefaultSettings.php:5745
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:970
MWException
MediaWiki exception.
Definition: MWException.php:26
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1078
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:994
RecentChange\$notificationtimestamp
$notificationtimestamp
Definition: RecentChange.php:106
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
in
null for the wiki Added in
Definition: hooks.txt:1588
$attribs
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:1985
RecentChange\notifyEdit
static notifyEdit( $timestamp, $title, $minor, $user, $comment, $oldId, $lastTimestamp, $bot, $ip='', $oldSize=0, $newSize=0, $newId=0, $patrol=0, $tags=[])
Makes an entry in the database corresponding to an edit.
Definition: RecentChange.php:685
$wgRCFeeds
$wgRCFeeds
Recentchanges items are periodically purged; entries older than this many seconds will go.
Definition: DefaultSettings.php:6878
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:135
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DeferredUpdates\POSTSEND
const POSTSEND
Definition: DeferredUpdates.php:64
RecentChange\SRC_EDIT
const SRC_EDIT
Definition: RecentChange.php:72
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
RecentChange\diffLinkTrail
diffLinkTrail( $forceCur)
Gets the end part of the diff URL associated with this object Blank if no diff link should be display...
Definition: RecentChange.php:1117
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
RecentChange\SRC_NEW
const SRC_NEW
Definition: RecentChange.php:73
array
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))
$editor
passed in as a query string parameter to the various URLs constructed here(i.e. $prevlink) $ldel you ll need to handle error etc yourself modifying $error and returning true will cause the contents of $error to be echoed at the top of the edit form as wikitext Return true without altering $error to allow the edit to proceed & $editor
Definition: hooks.txt:1290
$wgUseFilePatrol
$wgUseFilePatrol
Use file patrolling to check new files on Special:Newfiles.
Definition: DefaultSettings.php:6938
$auto
return true to allow those checks to and false if checking is done remove or add to the links of a group of changes in EnhancedChangesList Hook subscribers can return false to omit this line from recentchanges use this to change the tables headers change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped true if there is text before this autocomment $auto
Definition: hooks.txt:1476
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:123
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
RecentChange\PRC_PATROLLED
const PRC_PATROLLED
Definition: RecentChange.php:79
RecentChange\newFromId
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
Definition: RecentChange.php:192
RecentChange\doMarkPatrolled
doMarkPatrolled(User $user, $auto=false, $tags=null)
Mark this RecentChange as patrolled.
Definition: RecentChange.php:590
RecentChange\$mExtra
$mExtra
Definition: RecentChange.php:93
$wgLogRestrictions
$wgLogRestrictions
This restricts log access to those who have a certain right Users without this will not see it in the...
Definition: DefaultSettings.php:7700
$wgRCMaxAge
$wgRCMaxAge
Recentchanges items are periodically purged; entries older than this many seconds will go.
Definition: DefaultSettings.php:6787
ChangesList\showCharacterDifference
static showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
Definition: ChangesList.php:317
RC_NEW
const RC_NEW
Definition: Defines.php:143
RecentChange\markPatrolled
static markPatrolled( $change, $auto=false, $tags=null)
Mark a given change as patrolled.
Definition: RecentChange.php:565
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:80
message
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a message
Definition: hooks.txt:2154
RecentChange\addTags
addTags( $tags)
Tags to append to the recent change, and associated revision/log.
Definition: RecentChange.php:1211
RecentChange\getAttribute
getAttribute( $name)
Get an attribute value.
Definition: RecentChange.php:1078
$wgUseEnotif
$wgUseEnotif
Definition: Setup.php:437
RecentChange\checkIPAddress
static checkIPAddress( $ip)
Definition: RecentChange.php:1154
RecentChange\newLogEntry
static newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
Definition: RecentChange.php:863
unserialize
unserialize( $serialized)
Definition: ApiMessageTrait.php:142
Title
Represents a title within MediaWiki.
Definition: Title.php:40
RecentChange\selectFields
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object.
Definition: RecentChange.php:228
JobQueueGroup\singleton
static singleton( $domain=false)
Definition: JobQueueGroup.php:70
RecentChange\notifyNew
static notifyNew( $timestamp, $title, $minor, $user, $comment, $bot, $ip='', $size=0, $newId=0, $patrol=0, $tags=[])
Makes an entry in the database corresponding to page creation Note: the title object must be loaded w...
Definition: RecentChange.php:759
RecentChange\$mTitle
Title $mTitle
Definition: RecentChange.php:98
RecentChange\parseFromRCType
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
Definition: RecentChange.php:171
$wgRCEngines
$wgRCEngines
Used by RecentChange::getEngine to find the correct engine for a given URI scheme.
Definition: DefaultSettings.php:6885
RecentChange\PRC_UNPATROLLED
const PRC_UNPATROLLED
Definition: RecentChange.php:78
as
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
RCFeed\factory
static factory(array $params)
Definition: RCFeed.php:46
RecentChange\isInRCLifespan
static isInRCLifespan( $timestamp, $tolerance=0)
Check whether the given timestamp is new enough to have a RC row with a given tolerance as the recent...
Definition: RecentChange.php:1180
User\newFromActorId
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
Definition: User.php:624
error
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition: hooks.txt:2636
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:146
RecentChange\notifyRCFeeds
notifyRCFeeds(array $feeds=null)
Notify all the feeds about the change.
Definition: RecentChange.php:497
$t
$t
Definition: testCompression.php:69
RecentChange\getPerformer
getPerformer()
Get the User object of the person who performed this change.
Definition: RecentChange.php:344
EmailNotification
This module processes the email notifications when the current page is changed.
Definition: EmailNotification.php:48
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:728
RecentChange\getTitle
& getTitle()
Definition: RecentChange.php:331
CommentStore\getStore
static getStore()
Definition: CommentStore.php:130
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:118
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
RecentChange\$mPerformer
User $mPerformer
Definition: RecentChange.php:103
RecentChange\$changeTypes
static array $changeTypes
Array of change types.
Definition: RecentChange.php:121
RecentChange\getParam
getParam( $name)
Get a parameter value.
Definition: RecentChange.php:1030
RecentChange\$numberofWatchingusers
$numberofWatchingusers
Definition: RecentChange.php:105
ChangeTags\addTags
static addTags( $tags, $rc_id=null, $rev_id=null, $log_id=null, $params=null, RecentChange $rc=null)
Add tags to a change given its rc_id, rev_id and/or log_id.
Definition: ChangeTags.php:226
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:77
RecentChange\SRC_EXTERNAL
const SRC_EXTERNAL
Definition: RecentChange.php:75
User\isAllowed
isAllowed( $action='')
Internal mechanics of testing a permission.
Definition: User.php:3859
$type
$type
Definition: testCompression.php:48
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:8979