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