MediaWiki  1.32.0
RecentChange.php
Go to the documentation of this file.
1 <?php
68 class RecentChange {
69  // Constants for the rc_source field. Extensions may also have
70  // their own source constants.
71  const SRC_EDIT = 'mw.edit';
72  const SRC_NEW = 'mw.new';
73  const SRC_LOG = 'mw.log';
74  const SRC_EXTERNAL = 'mw.external'; // obsolete
75  const SRC_CATEGORIZE = 'mw.categorize';
76 
77  const PRC_UNPATROLLED = 0;
78  const PRC_PATROLLED = 1;
79  const PRC_AUTOPATROLLED = 2;
80 
84  const SEND_NONE = true;
85 
89  const SEND_FEED = false;
90 
91  public $mAttribs = [];
92  public $mExtra = [];
93 
97  public $mTitle = false;
98 
102  private $mPerformer = false;
103 
106 
110  public $counter = -1;
111 
115  private $tags = [];
116 
120  private static $changeTypes = [
121  'edit' => RC_EDIT,
122  'new' => RC_NEW,
123  'log' => RC_LOG,
124  'external' => RC_EXTERNAL,
125  'categorize' => RC_CATEGORIZE,
126  ];
127 
128  # Factory methods
129 
134  public static function newFromRow( $row ) {
135  $rc = new RecentChange;
136  $rc->loadFromRow( $row );
137 
138  return $rc;
139  }
140 
148  public static function parseToRCType( $type ) {
149  if ( is_array( $type ) ) {
150  $retval = [];
151  foreach ( $type as $t ) {
153  }
154 
155  return $retval;
156  }
157 
158  if ( !array_key_exists( $type, self::$changeTypes ) ) {
159  throw new MWException( "Unknown type '$type'" );
160  }
161  return self::$changeTypes[$type];
162  }
163 
170  public static function parseFromRCType( $rcType ) {
171  return array_search( $rcType, self::$changeTypes, true ) ?: "$rcType";
172  }
173 
181  public static function getChangeTypes() {
182  return array_keys( self::$changeTypes );
183  }
184 
191  public static function newFromId( $rcid ) {
192  return self::newFromConds( [ 'rc_id' => $rcid ], __METHOD__ );
193  }
194 
204  public static function newFromConds(
205  $conds,
206  $fname = __METHOD__,
207  $dbType = DB_REPLICA
208  ) {
209  $db = wfGetDB( $dbType );
210  $rcQuery = self::getQueryInfo();
211  $row = $db->selectRow(
212  $rcQuery['tables'], $rcQuery['fields'], $conds, $fname, [], $rcQuery['joins']
213  );
214  if ( $row !== false ) {
215  return self::newFromRow( $row );
216  } else {
217  return null;
218  }
219  }
220 
227  public static function selectFields() {
229 
230  wfDeprecated( __METHOD__, '1.31' );
232  // If code is using this instead of self::getQueryInfo(), there's a
233  // decent chance it's going to try to directly access
234  // $row->rc_user or $row->rc_user_text and we can't give it
235  // useful values here once those aren't being used anymore.
236  throw new BadMethodCallException(
237  'Cannot use ' . __METHOD__
238  . ' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
239  );
240  }
241 
242  return [
243  'rc_id',
244  'rc_timestamp',
245  'rc_user',
246  'rc_user_text',
247  'rc_actor' => 'NULL',
248  'rc_namespace',
249  'rc_title',
250  'rc_minor',
251  'rc_bot',
252  'rc_new',
253  'rc_cur_id',
254  'rc_this_oldid',
255  'rc_last_oldid',
256  'rc_type',
257  'rc_source',
258  'rc_patrolled',
259  'rc_ip',
260  'rc_old_len',
261  'rc_new_len',
262  'rc_deleted',
263  'rc_logid',
264  'rc_log_type',
265  'rc_log_action',
266  'rc_params',
267  ] + CommentStore::getStore()->getFields( 'rc_comment' );
268  }
269 
279  public static function getQueryInfo() {
280  $commentQuery = CommentStore::getStore()->getJoin( 'rc_comment' );
281  $actorQuery = ActorMigration::newMigration()->getJoin( 'rc_user' );
282  return [
283  'tables' => [ 'recentchanges' ] + $commentQuery['tables'] + $actorQuery['tables'],
284  'fields' => [
285  'rc_id',
286  'rc_timestamp',
287  'rc_namespace',
288  'rc_title',
289  'rc_minor',
290  'rc_bot',
291  'rc_new',
292  'rc_cur_id',
293  'rc_this_oldid',
294  'rc_last_oldid',
295  'rc_type',
296  'rc_source',
297  'rc_patrolled',
298  'rc_ip',
299  'rc_old_len',
300  'rc_new_len',
301  'rc_deleted',
302  'rc_logid',
303  'rc_log_type',
304  'rc_log_action',
305  'rc_params',
306  ] + $commentQuery['fields'] + $actorQuery['fields'],
307  'joins' => $commentQuery['joins'] + $actorQuery['joins'],
308  ];
309  }
310 
311  # Accessors
312 
316  public function setAttribs( $attribs ) {
317  $this->mAttribs = $attribs;
318  }
319 
323  public function setExtra( $extra ) {
324  $this->mExtra = $extra;
325  }
326 
330  public function &getTitle() {
331  if ( $this->mTitle === false ) {
332  $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
333  }
334 
335  return $this->mTitle;
336  }
337 
343  public function getPerformer() {
344  if ( $this->mPerformer === false ) {
345  if ( !empty( $this->mAttribs['rc_actor'] ) ) {
346  $this->mPerformer = User::newFromActorId( $this->mAttribs['rc_actor'] );
347  } elseif ( !empty( $this->mAttribs['rc_user'] ) ) {
348  $this->mPerformer = User::newFromId( $this->mAttribs['rc_user'] );
349  } elseif ( !empty( $this->mAttribs['rc_user_text'] ) ) {
350  $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false );
351  } else {
352  throw new MWException( 'RecentChange object lacks rc_actor, rc_user, and rc_user_text' );
353  }
354  }
355 
356  return $this->mPerformer;
357  }
358 
368  public function save( $send = self::SEND_FEED ) {
370 
371  if ( is_string( $send ) ) {
372  // Callers used to pass undocumented strings like 'noudp'
373  // or 'pleasedontudp' instead of self::SEND_NONE (true).
374  // @deprecated since 1.31 Use SEND_NONE instead.
375  $send = self::SEND_NONE;
376  }
377 
378  $dbw = wfGetDB( DB_MASTER );
379  if ( !is_array( $this->mExtra ) ) {
380  $this->mExtra = [];
381  }
382 
383  if ( !$wgPutIPinRC ) {
384  $this->mAttribs['rc_ip'] = '';
385  }
386 
387  # Strict mode fixups (not-NULL fields)
388  foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
389  $this->mAttribs["rc_$field"] = (int)$this->mAttribs["rc_$field"];
390  }
391  # ...more fixups (NULL fields)
392  foreach ( [ 'old_len', 'new_len' ] as $field ) {
393  $this->mAttribs["rc_$field"] = isset( $this->mAttribs["rc_$field"] )
394  ? (int)$this->mAttribs["rc_$field"]
395  : null;
396  }
397 
398  # If our database is strict about IP addresses, use NULL instead of an empty string
399  $strictIPs = in_array( $dbw->getType(), [ 'oracle', 'postgres' ] ); // legacy
400  if ( $strictIPs && $this->mAttribs['rc_ip'] == '' ) {
401  unset( $this->mAttribs['rc_ip'] );
402  }
403 
404  # Trim spaces on user supplied text
405  $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] );
406 
407  # Fixup database timestamps
408  $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] );
409 
410  # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
411  if ( $this->mAttribs['rc_cur_id'] == 0 ) {
412  unset( $this->mAttribs['rc_cur_id'] );
413  }
414 
415  $row = $this->mAttribs;
416 
417  # Convert mAttribs['rc_comment'] for CommentStore
418  $comment = $row['rc_comment'];
419  unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] );
420  $row += CommentStore::getStore()->insert( $dbw, 'rc_comment', $comment );
421 
422  # Convert mAttribs['rc_user'] etc for ActorMigration
424  $row['rc_user'] ?? null,
425  $row['rc_user_text'] ?? null,
426  $row['rc_actor'] ?? null
427  );
428  unset( $row['rc_user'], $row['rc_user_text'], $row['rc_actor'] );
429  $row += ActorMigration::newMigration()->getInsertValues( $dbw, 'rc_user', $user );
430 
431  # Don't reuse an existing rc_id for the new row, if one happens to be
432  # set for some reason.
433  unset( $row['rc_id'] );
434 
435  # Insert new row
436  $dbw->insert( 'recentchanges', $row, __METHOD__ );
437 
438  # Set the ID
439  $this->mAttribs['rc_id'] = $dbw->insertId();
440 
441  # Notify extensions
442  // Avoid PHP 7.1 warning from passing $this by reference
443  $rc = $this;
444  Hooks::run( 'RecentChange_save', [ &$rc ] );
445 
446  if ( count( $this->tags ) ) {
447  ChangeTags::addTags( $this->tags, $this->mAttribs['rc_id'],
448  $this->mAttribs['rc_this_oldid'], $this->mAttribs['rc_logid'], null, $this );
449  }
450 
451  if ( $send === self::SEND_FEED ) {
452  // Emit the change to external applications via RCFeeds.
453  $this->notifyRCFeeds();
454  }
455 
456  # E-mail notifications
457  if ( $wgUseEnotif || $wgShowUpdatedMarker ) {
458  $editor = $this->getPerformer();
459  $title = $this->getTitle();
460 
461  // Never send an RC notification email about categorization changes
462  if (
463  Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) &&
464  $this->mAttribs['rc_type'] != RC_CATEGORIZE
465  ) {
466  // @FIXME: This would be better as an extension hook
467  // Send emails or email jobs once this row is safely committed
468  $dbw->onTransactionCommitOrIdle(
469  function () use ( $editor, $title ) {
470  $enotif = new EmailNotification();
471  $enotif->notifyOnPageChange(
472  $editor,
473  $title,
474  $this->mAttribs['rc_timestamp'],
475  $this->mAttribs['rc_comment'],
476  $this->mAttribs['rc_minor'],
477  $this->mAttribs['rc_last_oldid'],
478  $this->mExtra['pageStatus']
479  );
480  },
481  __METHOD__
482  );
483  }
484  }
485 
486  // Update the cached list of active users
487  if ( $this->mAttribs['rc_user'] > 0 ) {
489  }
490  }
491 
496  public function notifyRCFeeds( array $feeds = null ) {
497  global $wgRCFeeds;
498  if ( $feeds === null ) {
499  $feeds = $wgRCFeeds;
500  }
501 
502  $performer = $this->getPerformer();
503 
504  foreach ( $feeds as $params ) {
505  $params += [
506  'omit_bots' => false,
507  'omit_anon' => false,
508  'omit_user' => false,
509  'omit_minor' => false,
510  'omit_patrolled' => false,
511  ];
512 
513  if (
514  ( $params['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
515  ( $params['omit_anon'] && $performer->isAnon() ) ||
516  ( $params['omit_user'] && !$performer->isAnon() ) ||
517  ( $params['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
518  ( $params['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) ||
519  $this->mAttribs['rc_type'] == RC_EXTERNAL
520  ) {
521  continue;
522  }
523 
524  $actionComment = $this->mExtra['actionCommentIRC'] ?? null;
525 
526  $feed = RCFeed::factory( $params );
527  $feed->notify( $this, $actionComment );
528  }
529  }
530 
539  public static function getEngine( $uri, $params = [] ) {
540  // TODO: Merge into RCFeed::factory().
541  global $wgRCEngines;
542  $scheme = parse_url( $uri, PHP_URL_SCHEME );
543  if ( !$scheme ) {
544  throw new MWException( "Invalid RCFeed uri: '$uri'" );
545  }
546  if ( !isset( $wgRCEngines[$scheme] ) ) {
547  throw new MWException( "Unknown RCFeedEngine scheme: '$scheme'" );
548  }
549  if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
550  return $wgRCEngines[$scheme];
551  }
552  return new $wgRCEngines[$scheme]( $params );
553  }
554 
564  public static function markPatrolled( $change, $auto = false, $tags = null ) {
565  global $wgUser;
566 
567  $change = $change instanceof RecentChange
568  ? $change
569  : self::newFromId( $change );
570 
571  if ( !$change instanceof RecentChange ) {
572  return null;
573  }
574 
575  return $change->doMarkPatrolled( $wgUser, $auto, $tags );
576  }
577 
589  public function doMarkPatrolled( User $user, $auto = false, $tags = null ) {
591 
592  $errors = [];
593  // If recentchanges patrol is disabled, only new pages or new file versions
594  // can be patrolled, provided the appropriate config variable is set
595  if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) &&
596  ( !$wgUseFilePatrol || !( $this->getAttribute( 'rc_type' ) == RC_LOG &&
597  $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
598  $errors[] = [ 'rcpatroldisabled' ];
599  }
600  // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
601  $right = $auto ? 'autopatrol' : 'patrol';
602  $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
603  if ( !Hooks::run( 'MarkPatrolled',
604  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
605  ) {
606  $errors[] = [ 'hookaborted' ];
607  }
608  // Users without the 'autopatrol' right can't patrol their
609  // own revisions
610  if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
611  && !$user->isAllowed( 'autopatrol' )
612  ) {
613  $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
614  }
615  if ( $errors ) {
616  return $errors;
617  }
618  // If the change was patrolled already, do nothing
619  if ( $this->getAttribute( 'rc_patrolled' ) ) {
620  return [];
621  }
622  // Actually set the 'patrolled' flag in RC
623  $this->reallyMarkPatrolled();
624  // Log this patrol event
625  PatrolLog::record( $this, $auto, $user, $tags );
626 
627  Hooks::run(
628  'MarkPatrolledComplete',
629  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
630  );
631 
632  return [];
633  }
634 
639  public function reallyMarkPatrolled() {
640  $dbw = wfGetDB( DB_MASTER );
641  $dbw->update(
642  'recentchanges',
643  [
644  'rc_patrolled' => self::PRC_PATROLLED
645  ],
646  [
647  'rc_id' => $this->getAttribute( 'rc_id' )
648  ],
649  __METHOD__
650  );
651  // Invalidate the page cache after the page has been patrolled
652  // to make sure that the Patrol link isn't visible any longer!
653  $this->getTitle()->invalidateCache();
654 
655  return $dbw->affectedRows();
656  }
657 
677  public static function notifyEdit(
678  $timestamp, $title, $minor, $user, $comment, $oldId, $lastTimestamp,
679  $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
680  $tags = []
681  ) {
682  $rc = new RecentChange;
683  $rc->mTitle = $title;
684  $rc->mPerformer = $user;
685  $rc->mAttribs = [
686  'rc_timestamp' => $timestamp,
687  'rc_namespace' => $title->getNamespace(),
688  'rc_title' => $title->getDBkey(),
689  'rc_type' => RC_EDIT,
690  'rc_source' => self::SRC_EDIT,
691  'rc_minor' => $minor ? 1 : 0,
692  'rc_cur_id' => $title->getArticleID(),
693  'rc_user' => $user->getId(),
694  'rc_user_text' => $user->getName(),
695  'rc_actor' => $user->getActorId(),
696  'rc_comment' => &$comment,
697  'rc_comment_text' => &$comment,
698  'rc_comment_data' => null,
699  'rc_this_oldid' => $newId,
700  'rc_last_oldid' => $oldId,
701  'rc_bot' => $bot ? 1 : 0,
702  'rc_ip' => self::checkIPAddress( $ip ),
703  'rc_patrolled' => intval( $patrol ),
704  'rc_new' => 0, # obsolete
705  'rc_old_len' => $oldSize,
706  'rc_new_len' => $newSize,
707  'rc_deleted' => 0,
708  'rc_logid' => 0,
709  'rc_log_type' => null,
710  'rc_log_action' => '',
711  'rc_params' => ''
712  ];
713 
714  $rc->mExtra = [
715  'prefixedDBkey' => $title->getPrefixedDBkey(),
716  'lastTimestamp' => $lastTimestamp,
717  'oldSize' => $oldSize,
718  'newSize' => $newSize,
719  'pageStatus' => 'changed'
720  ];
721 
723  function () use ( $rc, $tags ) {
724  $rc->addTags( $tags );
725  $rc->save();
726  },
728  wfGetDB( DB_MASTER )
729  );
730 
731  return $rc;
732  }
733 
751  public static function notifyNew(
752  $timestamp, $title, $minor, $user, $comment, $bot,
753  $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
754  ) {
755  $rc = new RecentChange;
756  $rc->mTitle = $title;
757  $rc->mPerformer = $user;
758  $rc->mAttribs = [
759  'rc_timestamp' => $timestamp,
760  'rc_namespace' => $title->getNamespace(),
761  'rc_title' => $title->getDBkey(),
762  'rc_type' => RC_NEW,
763  'rc_source' => self::SRC_NEW,
764  'rc_minor' => $minor ? 1 : 0,
765  'rc_cur_id' => $title->getArticleID(),
766  'rc_user' => $user->getId(),
767  'rc_user_text' => $user->getName(),
768  'rc_actor' => $user->getActorId(),
769  'rc_comment' => &$comment,
770  'rc_comment_text' => &$comment,
771  'rc_comment_data' => null,
772  'rc_this_oldid' => $newId,
773  'rc_last_oldid' => 0,
774  'rc_bot' => $bot ? 1 : 0,
775  'rc_ip' => self::checkIPAddress( $ip ),
776  'rc_patrolled' => intval( $patrol ),
777  'rc_new' => 1, # obsolete
778  'rc_old_len' => 0,
779  'rc_new_len' => $size,
780  'rc_deleted' => 0,
781  'rc_logid' => 0,
782  'rc_log_type' => null,
783  'rc_log_action' => '',
784  'rc_params' => ''
785  ];
786 
787  $rc->mExtra = [
788  'prefixedDBkey' => $title->getPrefixedDBkey(),
789  'lastTimestamp' => 0,
790  'oldSize' => 0,
791  'newSize' => $size,
792  'pageStatus' => 'created'
793  ];
794 
796  function () use ( $rc, $tags ) {
797  $rc->addTags( $tags );
798  $rc->save();
799  },
801  wfGetDB( DB_MASTER )
802  );
803 
804  return $rc;
805  }
806 
822  public static function notifyLog( $timestamp, $title, $user, $actionComment, $ip, $type,
823  $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
824  ) {
825  global $wgLogRestrictions;
826 
827  # Don't add private logs to RC!
828  if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
829  return false;
830  }
831  $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
832  $target, $logComment, $params, $newId, $actionCommentIRC );
833  $rc->save();
834 
835  return true;
836  }
837 
855  public static function newLogEntry( $timestamp, $title, $user, $actionComment, $ip,
856  $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
857  $revId = 0, $isPatrollable = false ) {
858  global $wgRequest;
859 
860  # # Get pageStatus for email notification
861  switch ( $type . '-' . $action ) {
862  case 'delete-delete':
863  case 'delete-delete_redir':
864  $pageStatus = 'deleted';
865  break;
866  case 'move-move':
867  case 'move-move_redir':
868  $pageStatus = 'moved';
869  break;
870  case 'delete-restore':
871  $pageStatus = 'restored';
872  break;
873  case 'upload-upload':
874  $pageStatus = 'created';
875  break;
876  case 'upload-overwrite':
877  default:
878  $pageStatus = 'changed';
879  break;
880  }
881 
882  // Allow unpatrolled status for patrollable log entries
883  $markPatrolled = $isPatrollable ? $user->isAllowed( 'autopatrol' ) : true;
884 
885  $rc = new RecentChange;
886  $rc->mTitle = $target;
887  $rc->mPerformer = $user;
888  $rc->mAttribs = [
889  'rc_timestamp' => $timestamp,
890  'rc_namespace' => $target->getNamespace(),
891  'rc_title' => $target->getDBkey(),
892  'rc_type' => RC_LOG,
893  'rc_source' => self::SRC_LOG,
894  'rc_minor' => 0,
895  'rc_cur_id' => $target->getArticleID(),
896  'rc_user' => $user->getId(),
897  'rc_user_text' => $user->getName(),
898  'rc_actor' => $user->getActorId(),
899  'rc_comment' => &$logComment,
900  'rc_comment_text' => &$logComment,
901  'rc_comment_data' => null,
902  'rc_this_oldid' => $revId,
903  'rc_last_oldid' => 0,
904  'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0,
905  'rc_ip' => self::checkIPAddress( $ip ),
906  'rc_patrolled' => $markPatrolled ? self::PRC_AUTOPATROLLED : self::PRC_UNPATROLLED,
907  'rc_new' => 0, # obsolete
908  'rc_old_len' => null,
909  'rc_new_len' => null,
910  'rc_deleted' => 0,
911  'rc_logid' => $newId,
912  'rc_log_type' => $type,
913  'rc_log_action' => $action,
914  'rc_params' => $params
915  ];
916 
917  $rc->mExtra = [
918  'prefixedDBkey' => $title->getPrefixedDBkey(),
919  'lastTimestamp' => 0,
920  'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
921  'pageStatus' => $pageStatus,
922  'actionCommentIRC' => $actionCommentIRC
923  ];
924 
925  return $rc;
926  }
927 
949  public static function newForCategorization(
950  $timestamp,
951  Title $categoryTitle,
952  User $user = null,
953  $comment,
954  Title $pageTitle,
955  $oldRevId,
956  $newRevId,
957  $lastTimestamp,
958  $bot,
959  $ip = '',
960  $deleted = 0,
961  $added = null
962  ) {
963  // Done in a backwards compatible way.
964  $params = [
965  'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
966  ];
967  if ( $added !== null ) {
968  $params['added'] = $added;
969  }
970 
971  $rc = new RecentChange;
972  $rc->mTitle = $categoryTitle;
973  $rc->mPerformer = $user;
974  $rc->mAttribs = [
975  'rc_timestamp' => $timestamp,
976  'rc_namespace' => $categoryTitle->getNamespace(),
977  'rc_title' => $categoryTitle->getDBkey(),
978  'rc_type' => RC_CATEGORIZE,
979  'rc_source' => self::SRC_CATEGORIZE,
980  'rc_minor' => 0,
981  'rc_cur_id' => $pageTitle->getArticleID(),
982  'rc_user' => $user ? $user->getId() : 0,
983  'rc_user_text' => $user ? $user->getName() : '',
984  'rc_actor' => $user ? $user->getActorId() : null,
985  'rc_comment' => &$comment,
986  'rc_comment_text' => &$comment,
987  'rc_comment_data' => null,
988  'rc_this_oldid' => $newRevId,
989  'rc_last_oldid' => $oldRevId,
990  'rc_bot' => $bot ? 1 : 0,
991  'rc_ip' => self::checkIPAddress( $ip ),
992  'rc_patrolled' => self::PRC_AUTOPATROLLED, // Always patrolled, just like log entries
993  'rc_new' => 0, # obsolete
994  'rc_old_len' => null,
995  'rc_new_len' => null,
996  'rc_deleted' => $deleted,
997  'rc_logid' => 0,
998  'rc_log_type' => null,
999  'rc_log_action' => '',
1000  'rc_params' => serialize( $params )
1001  ];
1002 
1003  $rc->mExtra = [
1004  'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
1005  'lastTimestamp' => $lastTimestamp,
1006  'oldSize' => 0,
1007  'newSize' => 0,
1008  'pageStatus' => 'changed'
1009  ];
1010 
1011  return $rc;
1012  }
1013 
1022  public function getParam( $name ) {
1023  $params = $this->parseParams();
1024  return $params[$name] ?? null;
1025  }
1026 
1032  public function loadFromRow( $row ) {
1033  $this->mAttribs = get_object_vars( $row );
1034  $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] );
1035  // rc_deleted MUST be set
1036  $this->mAttribs['rc_deleted'] = $row->rc_deleted;
1037 
1038  if ( isset( $this->mAttribs['rc_ip'] ) ) {
1039  // Clean up CIDRs for Postgres per T164898. ("127.0.0.1" casts to "127.0.0.1/32")
1040  $n = strpos( $this->mAttribs['rc_ip'], '/' );
1041  if ( $n !== false ) {
1042  $this->mAttribs['rc_ip'] = substr( $this->mAttribs['rc_ip'], 0, $n );
1043  }
1044  }
1045 
1046  $comment = CommentStore::getStore()
1047  // Legacy because $row may have come from self::selectFields()
1048  ->getCommentLegacy( wfGetDB( DB_REPLICA ), 'rc_comment', $row, true )
1049  ->text;
1050  $this->mAttribs['rc_comment'] = &$comment;
1051  $this->mAttribs['rc_comment_text'] = &$comment;
1052  $this->mAttribs['rc_comment_data'] = null;
1053 
1055  $this->mAttribs['rc_user'] ?? null,
1056  $this->mAttribs['rc_user_text'] ?? null,
1057  $this->mAttribs['rc_actor'] ?? null
1058  );
1059  $this->mAttribs['rc_user'] = $user->getId();
1060  $this->mAttribs['rc_user_text'] = $user->getName();
1061  $this->mAttribs['rc_actor'] = $user->getActorId();
1062  }
1063 
1070  public function getAttribute( $name ) {
1071  if ( $name === 'rc_comment' ) {
1072  return CommentStore::getStore()
1073  ->getComment( 'rc_comment', $this->mAttribs, true )->text;
1074  }
1075 
1076  if ( $name === 'rc_user' || $name === 'rc_user_text' || $name === 'rc_actor' ) {
1078  $this->mAttribs['rc_user'] ?? null,
1079  $this->mAttribs['rc_user_text'] ?? null,
1080  $this->mAttribs['rc_actor'] ?? null
1081  );
1082  if ( $name === 'rc_user' ) {
1083  return $user->getId();
1084  }
1085  if ( $name === 'rc_user_text' ) {
1086  return $user->getName();
1087  }
1088  if ( $name === 'rc_actor' ) {
1089  return $user->getActorId();
1090  }
1091  }
1092 
1093  return $this->mAttribs[$name] ?? null;
1094  }
1095 
1099  public function getAttributes() {
1100  return $this->mAttribs;
1101  }
1102 
1109  public function diffLinkTrail( $forceCur ) {
1110  if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
1111  $trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) .
1112  "&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] );
1113  if ( $forceCur ) {
1114  $trail .= '&diff=0';
1115  } else {
1116  $trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] );
1117  }
1118  } else {
1119  $trail = '';
1120  }
1121 
1122  return $trail;
1123  }
1124 
1132  public function getCharacterDifference( $old = 0, $new = 0 ) {
1133  if ( $old === 0 ) {
1134  $old = $this->mAttribs['rc_old_len'];
1135  }
1136  if ( $new === 0 ) {
1137  $new = $this->mAttribs['rc_new_len'];
1138  }
1139  if ( $old === null || $new === null ) {
1140  return '';
1141  }
1142 
1143  return ChangesList::showCharacterDifference( $old, $new );
1144  }
1145 
1146  private static function checkIPAddress( $ip ) {
1147  global $wgRequest;
1148  if ( $ip ) {
1149  if ( !IP::isIPAddress( $ip ) ) {
1150  throw new MWException( "Attempt to write \"" . $ip .
1151  "\" as an IP address into recent changes" );
1152  }
1153  } else {
1154  $ip = $wgRequest->getIP();
1155  if ( !$ip ) {
1156  $ip = '';
1157  }
1158  }
1159 
1160  return $ip;
1161  }
1162 
1172  public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1173  global $wgRCMaxAge;
1174 
1175  return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1176  }
1177 
1185  public function parseParams() {
1186  $rcParams = $this->getAttribute( 'rc_params' );
1187 
1188  Wikimedia\suppressWarnings();
1189  $unserializedParams = unserialize( $rcParams );
1190  Wikimedia\restoreWarnings();
1191 
1192  return $unserializedParams;
1193  }
1194 
1203  public function addTags( $tags ) {
1204  if ( is_string( $tags ) ) {
1205  $this->tags[] = $tags;
1206  } else {
1207  $this->tags = array_merge( $tags, $this->tags );
1208  }
1209  }
1210 }
RecentChange\getCharacterDifference
getCharacterDifference( $old=0, $new=0)
Returns the change size (HTML).
Definition: RecentChange.php:1132
RecentChange\save
save( $send=self::SEND_FEED)
Writes the data in this object to the database.
Definition: RecentChange.php:368
RecentChange\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new recentchanges object.
Definition: RecentChange.php:279
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:244
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:615
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:115
RecentChange\setExtra
setExtra( $extra)
Definition: RecentChange.php:323
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:949
RecentChange\newFromConds
static newFromConds( $conds, $fname=__METHOD__, $dbType=DB_REPLICA)
Find the first recent change matching some specific conditions.
Definition: RecentChange.php:204
$wgShowUpdatedMarker
$wgShowUpdatedMarker
Show "Updated (since my last visit)" marker in RC view, watchlist and history view for watched pages ...
Definition: DefaultSettings.php:7040
captcha-old.count
count
Definition: captcha-old.py:249
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1682
RecentChange\getAttributes
getAttributes()
Definition: RecentChange.php:1099
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:68
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1954
RecentChange\$mAttribs
$mAttribs
Definition: RecentChange.php:91
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:3562
RecentChange\notifyLog
static notifyLog( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:822
RecentChange\getEngine
static getEngine( $uri, $params=[])
Definition: RecentChange.php:539
RecentChange\loadFromRow
loadFromRow( $row)
Initialises the members of this object from a mysql row object.
Definition: RecentChange.php:1032
RecentChange\getChangeTypes
static getChangeTypes()
Get an array of all change types.
Definition: RecentChange.php:181
RecentChange\reallyMarkPatrolled
reallyMarkPatrolled()
Mark this RecentChange patrolled, without error checking.
Definition: RecentChange.php:639
$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:592
RecentChange\$counter
int $counter
Line number of recent change.
Definition: RecentChange.php:110
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:682
RecentChange\setAttribs
setAttribs( $attribs)
Definition: RecentChange.php:316
RecentChange\SRC_CATEGORIZE
const SRC_CATEGORIZE
Definition: RecentChange.php:75
RecentChange\parseToRCType
static parseToRCType( $type)
Parsing text to RC_* constants.
Definition: RecentChange.php:148
serialize
serialize()
Definition: ApiMessageTrait.php:131
$wgUseRCPatrol
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
Definition: DefaultSettings.php:6933
$wgUseNPPatrol
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
Definition: DefaultSettings.php:6949
RecentChange\SRC_LOG
const SRC_LOG
Definition: RecentChange.php:73
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:1185
$wgPutIPinRC
$wgPutIPinRC
Log IP addresses in the recentchanges table; can be accessed only by extensions (e....
Definition: DefaultSettings.php:5770
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:951
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:964
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:127
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1118
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:974
RecentChange\$notificationtimestamp
$notificationtimestamp
Definition: RecentChange.php:105
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
in
null for the wiki Added in
Definition: hooks.txt:1627
$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:2036
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:677
$wgRCFeeds
$wgRCFeeds
Recentchanges items are periodically purged; entries older than this many seconds will go.
Definition: DefaultSettings.php:6900
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:134
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:71
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:545
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:1109
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:72
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:1329
$wgUseFilePatrol
$wgUseFilePatrol
Use file patrolling to check new files on Special:Newfiles.
Definition: DefaultSettings.php:6960
$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:1515
$fname
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
Definition: Setup.php:121
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
RecentChange\PRC_PATROLLED
const PRC_PATROLLED
Definition: RecentChange.php:78
RecentChange\newFromId
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
Definition: RecentChange.php:191
RecentChange\doMarkPatrolled
doMarkPatrolled(User $user, $auto=false, $tags=null)
Mark this RecentChange as patrolled.
Definition: RecentChange.php:589
RecentChange\$mExtra
$mExtra
Definition: RecentChange.php:92
$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:7734
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:244
$wgRCMaxAge
$wgRCMaxAge
Recentchanges items are periodically purged; entries older than this many seconds will go.
Definition: DefaultSettings.php:6809
ChangesList\showCharacterDifference
static showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
Definition: ChangesList.php:316
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:564
RecentChange\PRC_AUTOPATROLLED
const PRC_AUTOPATROLLED
Definition: RecentChange.php:79
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:2205
RecentChange\addTags
addTags( $tags)
Tags to append to the recent change, and associated revision/log.
Definition: RecentChange.php:1203
RecentChange\getAttribute
getAttribute( $name)
Get an attribute value.
Definition: RecentChange.php:1070
$wgUseEnotif
$wgUseEnotif
Definition: Setup.php:440
RecentChange\checkIPAddress
static checkIPAddress( $ip)
Definition: RecentChange.php:1146
RecentChange\newLogEntry
static newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
Definition: RecentChange.php:855
unserialize
unserialize( $serialized)
Definition: ApiMessageTrait.php:139
Title
Represents a title within MediaWiki.
Definition: Title.php:39
RecentChange\selectFields
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object.
Definition: RecentChange.php:227
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:751
RecentChange\$mTitle
Title $mTitle
Definition: RecentChange.php:97
RecentChange\parseFromRCType
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
Definition: RecentChange.php:170
$wgRCEngines
$wgRCEngines
Used by RecentChange::getEngine to find the correct engine for a given URI scheme.
Definition: DefaultSettings.php:6907
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:69
RecentChange\PRC_UNPATROLLED
const PRC_UNPATROLLED
Definition: RecentChange.php:77
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:1172
User\newFromActorId
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
Definition: User.php:630
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:2675
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:496
$t
$t
Definition: testCompression.php:69
RecentChange\getPerformer
getPerformer()
Get the User object of the person who performed this change.
Definition: RecentChange.php:343
EmailNotification
This module processes the email notifications when the current page is changed.
Definition: EmailNotification.php:49
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:747
RecentChange\getTitle
& getTitle()
Definition: RecentChange.php:330
CommentStore\getStore
static getStore()
Definition: CommentStore.php:125
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:47
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:102
RecentChange\$changeTypes
static array $changeTypes
Array of change types.
Definition: RecentChange.php:120
RecentChange\getParam
getParam( $name)
Get a parameter value.
Definition: RecentChange.php:1022
RecentChange\$numberofWatchingusers
$numberofWatchingusers
Definition: RecentChange.php:104
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:224
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:74
User\isAllowed
isAllowed( $action='')
Internal mechanics of testing a permission.
Definition: User.php:3857
$type
$type
Definition: testCompression.php:48
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:9006