MediaWiki  1.30.0
RecentChange.php
Go to the documentation of this file.
1 <?php
67 class RecentChange {
68  // Constants for the rc_source field. Extensions may also have
69  // their own source constants.
70  const SRC_EDIT = 'mw.edit';
71  const SRC_NEW = 'mw.new';
72  const SRC_LOG = 'mw.log';
73  const SRC_EXTERNAL = 'mw.external'; // obsolete
74  const SRC_CATEGORIZE = 'mw.categorize';
75 
76  public $mAttribs = [];
77  public $mExtra = [];
78 
82  public $mTitle = false;
83 
87  private $mPerformer = false;
88 
91 
95  public $counter = -1;
96 
100  private $tags = [];
101 
105  private static $changeTypes = [
106  'edit' => RC_EDIT,
107  'new' => RC_NEW,
108  'log' => RC_LOG,
109  'external' => RC_EXTERNAL,
110  'categorize' => RC_CATEGORIZE,
111  ];
112 
113  # Factory methods
114 
119  public static function newFromRow( $row ) {
120  $rc = new RecentChange;
121  $rc->loadFromRow( $row );
122 
123  return $rc;
124  }
125 
133  public static function parseToRCType( $type ) {
134  if ( is_array( $type ) ) {
135  $retval = [];
136  foreach ( $type as $t ) {
138  }
139 
140  return $retval;
141  }
142 
143  if ( !array_key_exists( $type, self::$changeTypes ) ) {
144  throw new MWException( "Unknown type '$type'" );
145  }
146  return self::$changeTypes[$type];
147  }
148 
155  public static function parseFromRCType( $rcType ) {
156  return array_search( $rcType, self::$changeTypes, true ) ?: "$rcType";
157  }
158 
166  public static function getChangeTypes() {
167  return array_keys( self::$changeTypes );
168  }
169 
176  public static function newFromId( $rcid ) {
177  return self::newFromConds( [ 'rc_id' => $rcid ], __METHOD__ );
178  }
179 
189  public static function newFromConds(
190  $conds,
191  $fname = __METHOD__,
192  $dbType = DB_REPLICA
193  ) {
194  $db = wfGetDB( $dbType );
195  $row = $db->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
196  if ( $row !== false ) {
197  return self::newFromRow( $row );
198  } else {
199  return null;
200  }
201  }
202 
210  public static function selectFields() {
211  return [
212  'rc_id',
213  'rc_timestamp',
214  'rc_user',
215  'rc_user_text',
216  'rc_namespace',
217  'rc_title',
218  'rc_minor',
219  'rc_bot',
220  'rc_new',
221  'rc_cur_id',
222  'rc_this_oldid',
223  'rc_last_oldid',
224  'rc_type',
225  'rc_source',
226  'rc_patrolled',
227  'rc_ip',
228  'rc_old_len',
229  'rc_new_len',
230  'rc_deleted',
231  'rc_logid',
232  'rc_log_type',
233  'rc_log_action',
234  'rc_params',
235  ] + CommentStore::newKey( 'rc_comment' )->getFields();
236  }
237 
238  # Accessors
239 
243  public function setAttribs( $attribs ) {
244  $this->mAttribs = $attribs;
245  }
246 
250  public function setExtra( $extra ) {
251  $this->mExtra = $extra;
252  }
253 
257  public function &getTitle() {
258  if ( $this->mTitle === false ) {
259  $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
260  }
261 
262  return $this->mTitle;
263  }
264 
270  public function getPerformer() {
271  if ( $this->mPerformer === false ) {
272  if ( $this->mAttribs['rc_user'] ) {
273  $this->mPerformer = User::newFromId( $this->mAttribs['rc_user'] );
274  } else {
275  $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false );
276  }
277  }
278 
279  return $this->mPerformer;
280  }
281 
286  public function save( $noudp = false ) {
288 
289  $dbw = wfGetDB( DB_MASTER );
290  if ( !is_array( $this->mExtra ) ) {
291  $this->mExtra = [];
292  }
293 
294  if ( !$wgPutIPinRC ) {
295  $this->mAttribs['rc_ip'] = '';
296  }
297 
298  # Strict mode fixups (not-NULL fields)
299  foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
300  $this->mAttribs["rc_$field"] = (int)$this->mAttribs["rc_$field"];
301  }
302  # ...more fixups (NULL fields)
303  foreach ( [ 'old_len', 'new_len' ] as $field ) {
304  $this->mAttribs["rc_$field"] = isset( $this->mAttribs["rc_$field"] )
305  ? (int)$this->mAttribs["rc_$field"]
306  : null;
307  }
308 
309  # If our database is strict about IP addresses, use NULL instead of an empty string
310  $strictIPs = in_array( $dbw->getType(), [ 'oracle', 'postgres' ] ); // legacy
311  if ( $strictIPs && $this->mAttribs['rc_ip'] == '' ) {
312  unset( $this->mAttribs['rc_ip'] );
313  }
314 
315  # Trim spaces on user supplied text
316  $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] );
317 
318  # Fixup database timestamps
319  $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] );
320 
321  # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
322  if ( $this->mAttribs['rc_cur_id'] == 0 ) {
323  unset( $this->mAttribs['rc_cur_id'] );
324  }
325 
326  # Convert mAttribs['rc_comment'] for CommentStore
327  $row = $this->mAttribs;
328  $comment = $row['rc_comment'];
329  unset( $row['rc_comment'], $row['rc_comment_text'], $row['rc_comment_data'] );
330  $row += CommentStore::newKey( 'rc_comment' )->insert( $dbw, $comment );
331 
332  # Don't reuse an existing rc_id for the new row, if one happens to be
333  # set for some reason.
334  unset( $row['rc_id'] );
335 
336  # Insert new row
337  $dbw->insert( 'recentchanges', $row, __METHOD__ );
338 
339  # Set the ID
340  $this->mAttribs['rc_id'] = $dbw->insertId();
341 
342  # Notify extensions
343  // Avoid PHP 7.1 warning from passing $this by reference
344  $rc = $this;
345  Hooks::run( 'RecentChange_save', [ &$rc ] );
346 
347  if ( count( $this->tags ) ) {
348  ChangeTags::addTags( $this->tags, $this->mAttribs['rc_id'],
349  $this->mAttribs['rc_this_oldid'], $this->mAttribs['rc_logid'], null, $this );
350  }
351 
352  # Notify external application via UDP
353  if ( !$noudp ) {
354  $this->notifyRCFeeds();
355  }
356 
357  # E-mail notifications
358  if ( $wgUseEnotif || $wgShowUpdatedMarker ) {
359  $editor = $this->getPerformer();
360  $title = $this->getTitle();
361 
362  // Never send an RC notification email about categorization changes
363  if (
364  Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) &&
365  $this->mAttribs['rc_type'] != RC_CATEGORIZE
366  ) {
367  // @FIXME: This would be better as an extension hook
368  // Send emails or email jobs once this row is safely committed
369  $dbw->onTransactionIdle(
370  function () use ( $editor, $title ) {
371  $enotif = new EmailNotification();
372  $enotif->notifyOnPageChange(
373  $editor,
374  $title,
375  $this->mAttribs['rc_timestamp'],
376  $this->mAttribs['rc_comment'],
377  $this->mAttribs['rc_minor'],
378  $this->mAttribs['rc_last_oldid'],
379  $this->mExtra['pageStatus']
380  );
381  },
382  __METHOD__
383  );
384  }
385  }
386 
387  // Update the cached list of active users
388  if ( $this->mAttribs['rc_user'] > 0 ) {
390  }
391  }
392 
397  public function notifyRCFeeds( array $feeds = null ) {
399  if ( $feeds === null ) {
400  $feeds = $wgRCFeeds;
401  }
402 
403  $performer = $this->getPerformer();
404 
405  foreach ( $feeds as $params ) {
406  $params += [
407  'omit_bots' => false,
408  'omit_anon' => false,
409  'omit_user' => false,
410  'omit_minor' => false,
411  'omit_patrolled' => false,
412  ];
413 
414  if (
415  ( $params['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
416  ( $params['omit_anon'] && $performer->isAnon() ) ||
417  ( $params['omit_user'] && !$performer->isAnon() ) ||
418  ( $params['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
419  ( $params['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) ||
420  $this->mAttribs['rc_type'] == RC_EXTERNAL
421  ) {
422  continue;
423  }
424 
425  if ( isset( $this->mExtra['actionCommentIRC'] ) ) {
426  $actionComment = $this->mExtra['actionCommentIRC'];
427  } else {
428  $actionComment = null;
429  }
430 
431  $feed = RCFeed::factory( $params );
432  $feed->notify( $this, $actionComment );
433  }
434  }
435 
444  public static function getEngine( $uri, $params = [] ) {
445  // TODO: Merge into RCFeed::factory().
447  $scheme = parse_url( $uri, PHP_URL_SCHEME );
448  if ( !$scheme ) {
449  throw new MWException( "Invalid RCFeed uri: '$uri'" );
450  }
451  if ( !isset( $wgRCEngines[$scheme] ) ) {
452  throw new MWException( "Unknown RCFeedEngine scheme: '$scheme'" );
453  }
454  if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
455  return $wgRCEngines[$scheme];
456  }
457  return new $wgRCEngines[$scheme]( $params );
458  }
459 
469  public static function markPatrolled( $change, $auto = false, $tags = null ) {
470  global $wgUser;
471 
472  $change = $change instanceof RecentChange
473  ? $change
474  : self::newFromId( $change );
475 
476  if ( !$change instanceof RecentChange ) {
477  return null;
478  }
479 
480  return $change->doMarkPatrolled( $wgUser, $auto, $tags );
481  }
482 
494  public function doMarkPatrolled( User $user, $auto = false, $tags = null ) {
496 
497  $errors = [];
498  // If recentchanges patrol is disabled, only new pages or new file versions
499  // can be patrolled, provided the appropriate config variable is set
500  if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) &&
501  ( !$wgUseFilePatrol || !( $this->getAttribute( 'rc_type' ) == RC_LOG &&
502  $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
503  $errors[] = [ 'rcpatroldisabled' ];
504  }
505  // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
506  $right = $auto ? 'autopatrol' : 'patrol';
507  $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
508  if ( !Hooks::run( 'MarkPatrolled',
509  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
510  ) {
511  $errors[] = [ 'hookaborted' ];
512  }
513  // Users without the 'autopatrol' right can't patrol their
514  // own revisions
515  if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
516  && !$user->isAllowed( 'autopatrol' )
517  ) {
518  $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
519  }
520  if ( $errors ) {
521  return $errors;
522  }
523  // If the change was patrolled already, do nothing
524  if ( $this->getAttribute( 'rc_patrolled' ) ) {
525  return [];
526  }
527  // Actually set the 'patrolled' flag in RC
528  $this->reallyMarkPatrolled();
529  // Log this patrol event
530  PatrolLog::record( $this, $auto, $user, $tags );
531 
532  Hooks::run(
533  'MarkPatrolledComplete',
534  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
535  );
536 
537  return [];
538  }
539 
544  public function reallyMarkPatrolled() {
545  $dbw = wfGetDB( DB_MASTER );
546  $dbw->update(
547  'recentchanges',
548  [
549  'rc_patrolled' => 1
550  ],
551  [
552  'rc_id' => $this->getAttribute( 'rc_id' )
553  ],
554  __METHOD__
555  );
556  // Invalidate the page cache after the page has been patrolled
557  // to make sure that the Patrol link isn't visible any longer!
558  $this->getTitle()->invalidateCache();
559 
560  return $dbw->affectedRows();
561  }
562 
582  public static function notifyEdit(
583  $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp,
584  $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
585  $tags = []
586  ) {
587  $rc = new RecentChange;
588  $rc->mTitle = $title;
589  $rc->mPerformer = $user;
590  $rc->mAttribs = [
591  'rc_timestamp' => $timestamp,
592  'rc_namespace' => $title->getNamespace(),
593  'rc_title' => $title->getDBkey(),
594  'rc_type' => RC_EDIT,
595  'rc_source' => self::SRC_EDIT,
596  'rc_minor' => $minor ? 1 : 0,
597  'rc_cur_id' => $title->getArticleID(),
598  'rc_user' => $user->getId(),
599  'rc_user_text' => $user->getName(),
600  'rc_comment' => &$comment,
601  'rc_comment_text' => &$comment,
602  'rc_comment_data' => null,
603  'rc_this_oldid' => $newId,
604  'rc_last_oldid' => $oldId,
605  'rc_bot' => $bot ? 1 : 0,
606  'rc_ip' => self::checkIPAddress( $ip ),
607  'rc_patrolled' => intval( $patrol ),
608  'rc_new' => 0, # obsolete
609  'rc_old_len' => $oldSize,
610  'rc_new_len' => $newSize,
611  'rc_deleted' => 0,
612  'rc_logid' => 0,
613  'rc_log_type' => null,
614  'rc_log_action' => '',
615  'rc_params' => ''
616  ];
617 
618  $rc->mExtra = [
619  'prefixedDBkey' => $title->getPrefixedDBkey(),
620  'lastTimestamp' => $lastTimestamp,
621  'oldSize' => $oldSize,
622  'newSize' => $newSize,
623  'pageStatus' => 'changed'
624  ];
625 
627  function () use ( $rc, $tags ) {
628  $rc->addTags( $tags );
629  $rc->save();
630  if ( $rc->mAttribs['rc_patrolled'] ) {
631  PatrolLog::record( $rc, true, $rc->getPerformer() );
632  }
633  },
635  wfGetDB( DB_MASTER )
636  );
637 
638  return $rc;
639  }
640 
658  public static function notifyNew(
659  $timestamp, &$title, $minor, &$user, $comment, $bot,
660  $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
661  ) {
662  $rc = new RecentChange;
663  $rc->mTitle = $title;
664  $rc->mPerformer = $user;
665  $rc->mAttribs = [
666  'rc_timestamp' => $timestamp,
667  'rc_namespace' => $title->getNamespace(),
668  'rc_title' => $title->getDBkey(),
669  'rc_type' => RC_NEW,
670  'rc_source' => self::SRC_NEW,
671  'rc_minor' => $minor ? 1 : 0,
672  'rc_cur_id' => $title->getArticleID(),
673  'rc_user' => $user->getId(),
674  'rc_user_text' => $user->getName(),
675  'rc_comment' => &$comment,
676  'rc_comment_text' => &$comment,
677  'rc_comment_data' => null,
678  'rc_this_oldid' => $newId,
679  'rc_last_oldid' => 0,
680  'rc_bot' => $bot ? 1 : 0,
681  'rc_ip' => self::checkIPAddress( $ip ),
682  'rc_patrolled' => intval( $patrol ),
683  'rc_new' => 1, # obsolete
684  'rc_old_len' => 0,
685  'rc_new_len' => $size,
686  'rc_deleted' => 0,
687  'rc_logid' => 0,
688  'rc_log_type' => null,
689  'rc_log_action' => '',
690  'rc_params' => ''
691  ];
692 
693  $rc->mExtra = [
694  'prefixedDBkey' => $title->getPrefixedDBkey(),
695  'lastTimestamp' => 0,
696  'oldSize' => 0,
697  'newSize' => $size,
698  'pageStatus' => 'created'
699  ];
700 
702  function () use ( $rc, $tags ) {
703  $rc->addTags( $tags );
704  $rc->save();
705  if ( $rc->mAttribs['rc_patrolled'] ) {
706  PatrolLog::record( $rc, true, $rc->getPerformer() );
707  }
708  },
710  wfGetDB( DB_MASTER )
711  );
712 
713  return $rc;
714  }
715 
731  public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
732  $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
733  ) {
735 
736  # Don't add private logs to RC!
737  if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
738  return false;
739  }
740  $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
741  $target, $logComment, $params, $newId, $actionCommentIRC );
742  $rc->save();
743 
744  return true;
745  }
746 
764  public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
765  $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
766  $revId = 0, $isPatrollable = false ) {
768 
769  # # Get pageStatus for email notification
770  switch ( $type . '-' . $action ) {
771  case 'delete-delete':
772  case 'delete-delete_redir':
773  $pageStatus = 'deleted';
774  break;
775  case 'move-move':
776  case 'move-move_redir':
777  $pageStatus = 'moved';
778  break;
779  case 'delete-restore':
780  $pageStatus = 'restored';
781  break;
782  case 'upload-upload':
783  $pageStatus = 'created';
784  break;
785  case 'upload-overwrite':
786  default:
787  $pageStatus = 'changed';
788  break;
789  }
790 
791  // Allow unpatrolled status for patrollable log entries
792  $markPatrolled = $isPatrollable ? $user->isAllowed( 'autopatrol' ) : true;
793 
794  $rc = new RecentChange;
795  $rc->mTitle = $target;
796  $rc->mPerformer = $user;
797  $rc->mAttribs = [
798  'rc_timestamp' => $timestamp,
799  'rc_namespace' => $target->getNamespace(),
800  'rc_title' => $target->getDBkey(),
801  'rc_type' => RC_LOG,
802  'rc_source' => self::SRC_LOG,
803  'rc_minor' => 0,
804  'rc_cur_id' => $target->getArticleID(),
805  'rc_user' => $user->getId(),
806  'rc_user_text' => $user->getName(),
807  'rc_comment' => &$logComment,
808  'rc_comment_text' => &$logComment,
809  'rc_comment_data' => null,
810  'rc_this_oldid' => $revId,
811  'rc_last_oldid' => 0,
812  'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0,
813  'rc_ip' => self::checkIPAddress( $ip ),
814  'rc_patrolled' => $markPatrolled ? 1 : 0,
815  'rc_new' => 0, # obsolete
816  'rc_old_len' => null,
817  'rc_new_len' => null,
818  'rc_deleted' => 0,
819  'rc_logid' => $newId,
820  'rc_log_type' => $type,
821  'rc_log_action' => $action,
822  'rc_params' => $params
823  ];
824 
825  $rc->mExtra = [
826  'prefixedDBkey' => $title->getPrefixedDBkey(),
827  'lastTimestamp' => 0,
828  'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
829  'pageStatus' => $pageStatus,
830  'actionCommentIRC' => $actionCommentIRC
831  ];
832 
833  return $rc;
834  }
835 
857  public static function newForCategorization(
858  $timestamp,
859  Title $categoryTitle,
860  User $user = null,
861  $comment,
862  Title $pageTitle,
863  $oldRevId,
864  $newRevId,
865  $lastTimestamp,
866  $bot,
867  $ip = '',
868  $deleted = 0,
869  $added = null
870  ) {
871  // Done in a backwards compatible way.
872  $params = [
873  'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
874  ];
875  if ( $added !== null ) {
876  $params['added'] = $added;
877  }
878 
879  $rc = new RecentChange;
880  $rc->mTitle = $categoryTitle;
881  $rc->mPerformer = $user;
882  $rc->mAttribs = [
883  'rc_timestamp' => $timestamp,
884  'rc_namespace' => $categoryTitle->getNamespace(),
885  'rc_title' => $categoryTitle->getDBkey(),
886  'rc_type' => RC_CATEGORIZE,
887  'rc_source' => self::SRC_CATEGORIZE,
888  'rc_minor' => 0,
889  'rc_cur_id' => $pageTitle->getArticleID(),
890  'rc_user' => $user ? $user->getId() : 0,
891  'rc_user_text' => $user ? $user->getName() : '',
892  'rc_comment' => &$comment,
893  'rc_comment_text' => &$comment,
894  'rc_comment_data' => null,
895  'rc_this_oldid' => $newRevId,
896  'rc_last_oldid' => $oldRevId,
897  'rc_bot' => $bot ? 1 : 0,
898  'rc_ip' => self::checkIPAddress( $ip ),
899  'rc_patrolled' => 1, // Always patrolled, just like log entries
900  'rc_new' => 0, # obsolete
901  'rc_old_len' => null,
902  'rc_new_len' => null,
903  'rc_deleted' => $deleted,
904  'rc_logid' => 0,
905  'rc_log_type' => null,
906  'rc_log_action' => '',
907  'rc_params' => serialize( $params )
908  ];
909 
910  $rc->mExtra = [
911  'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
912  'lastTimestamp' => $lastTimestamp,
913  'oldSize' => 0,
914  'newSize' => 0,
915  'pageStatus' => 'changed'
916  ];
917 
918  return $rc;
919  }
920 
929  public function getParam( $name ) {
930  $params = $this->parseParams();
931  return isset( $params[$name] ) ? $params[$name] : null;
932  }
933 
939  public function loadFromRow( $row ) {
940  $this->mAttribs = get_object_vars( $row );
941  $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] );
942  // rc_deleted MUST be set
943  $this->mAttribs['rc_deleted'] = $row->rc_deleted;
944 
945  if ( isset( $this->mAttribs['rc_ip'] ) ) {
946  // Clean up CIDRs for Postgres per T164898. ("127.0.0.1" casts to "127.0.0.1/32")
947  $n = strpos( $this->mAttribs['rc_ip'], '/' );
948  if ( $n !== false ) {
949  $this->mAttribs['rc_ip'] = substr( $this->mAttribs['rc_ip'], 0, $n );
950  }
951  }
952 
953  $comment = CommentStore::newKey( 'rc_comment' )
954  // Legacy because $row probably came from self::selectFields()
955  ->getCommentLegacy( wfGetDB( DB_REPLICA ), $row, true )->text;
956  $this->mAttribs['rc_comment'] = &$comment;
957  $this->mAttribs['rc_comment_text'] = &$comment;
958  $this->mAttribs['rc_comment_data'] = null;
959  }
960 
967  public function getAttribute( $name ) {
968  if ( $name === 'rc_comment' ) {
969  return CommentStore::newKey( 'rc_comment' )->getComment( $this->mAttribs, true )->text;
970  }
971  return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
972  }
973 
977  public function getAttributes() {
978  return $this->mAttribs;
979  }
980 
987  public function diffLinkTrail( $forceCur ) {
988  if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
989  $trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) .
990  "&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] );
991  if ( $forceCur ) {
992  $trail .= '&diff=0';
993  } else {
994  $trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] );
995  }
996  } else {
997  $trail = '';
998  }
999 
1000  return $trail;
1001  }
1002 
1010  public function getCharacterDifference( $old = 0, $new = 0 ) {
1011  if ( $old === 0 ) {
1012  $old = $this->mAttribs['rc_old_len'];
1013  }
1014  if ( $new === 0 ) {
1015  $new = $this->mAttribs['rc_new_len'];
1016  }
1017  if ( $old === null || $new === null ) {
1018  return '';
1019  }
1020 
1021  return ChangesList::showCharacterDifference( $old, $new );
1022  }
1023 
1024  private static function checkIPAddress( $ip ) {
1026  if ( $ip ) {
1027  if ( !IP::isIPAddress( $ip ) ) {
1028  throw new MWException( "Attempt to write \"" . $ip .
1029  "\" as an IP address into recent changes" );
1030  }
1031  } else {
1032  $ip = $wgRequest->getIP();
1033  if ( !$ip ) {
1034  $ip = '';
1035  }
1036  }
1037 
1038  return $ip;
1039  }
1040 
1050  public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1052 
1053  return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1054  }
1055 
1063  public function parseParams() {
1064  $rcParams = $this->getAttribute( 'rc_params' );
1065 
1066  MediaWiki\suppressWarnings();
1067  $unserializedParams = unserialize( $rcParams );
1068  MediaWiki\restoreWarnings();
1069 
1070  return $unserializedParams;
1071  }
1072 
1081  public function addTags( $tags ) {
1082  if ( is_string( $tags ) ) {
1083  $this->tags[] = $tags;
1084  } else {
1085  $this->tags = array_merge( $tags, $this->tags );
1086  }
1087  }
1088 }
RecentChange\getCharacterDifference
getCharacterDifference( $old=0, $new=0)
Returns the change size (HTML).
Definition: RecentChange.php:1010
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:658
$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
$wgUser
$wgUser
Definition: Setup.php:809
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:573
RC_EXTERNAL
const RC_EXTERNAL
Definition: Defines.php:146
RecentChange\$tags
array $tags
List of tags to apply.
Definition: RecentChange.php:100
RecentChange\setExtra
setExtra( $extra)
Definition: RecentChange.php:250
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:857
RecentChange\newFromConds
static newFromConds( $conds, $fname=__METHOD__, $dbType=DB_REPLICA)
Find the first recent change matching some specific conditions.
Definition: RecentChange.php:189
$wgShowUpdatedMarker
$wgShowUpdatedMarker
Show "Updated (since my last visit)" marker in RC view, watchlist and history view for watched pages ...
Definition: DefaultSettings.php:6925
captcha-old.count
count
Definition: captcha-old.py:249
Title\getPrefixedDBkey
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1538
RecentChange\getAttributes
getAttributes()
Definition: RecentChange.php:977
PatrolLog\record
static record( $rc, $auto=false, User $user=null, $tags=null)
Record a log event for a change being patrolled.
Definition: PatrolLog.php:41
RecentChange
Utility class for creating new RC entries.
Definition: RecentChange.php:67
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2040
RecentChange\$mAttribs
$mAttribs
Definition: RecentChange.php:76
RC_LOG
const RC_LOG
Definition: Defines.php:145
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
Title\getArticleID
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3331
RecentChange\getEngine
static getEngine( $uri, $params=[])
Definition: RecentChange.php:444
$fname
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition: Setup.php:36
unserialize
unserialize( $serialized)
Definition: ApiMessage.php:185
RecentChange\loadFromRow
loadFromRow( $row)
Initialises the members of this object from a mysql row object.
Definition: RecentChange.php:939
RecentChange\getChangeTypes
static getChangeTypes()
Get an array of all change types.
Definition: RecentChange.php:166
RecentChange\reallyMarkPatrolled
reallyMarkPatrolled()
Mark this RecentChange patrolled, without error checking.
Definition: RecentChange.php:544
$params
$params
Definition: styleTest.css.php:40
RC_EDIT
const RC_EDIT
Definition: Defines.php:143
serialize
serialize()
Definition: ApiMessage.php:177
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:550
RecentChange\$counter
int $counter
Line number of recent change.
Definition: RecentChange.php:95
RecentChange\setAttribs
setAttribs( $attribs)
Definition: RecentChange.php:243
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:582
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
RecentChange\SRC_CATEGORIZE
const SRC_CATEGORIZE
Definition: RecentChange.php:74
RecentChange\parseToRCType
static parseToRCType( $type)
Parsing text to RC_* constants.
Definition: RecentChange.php:133
CommentStore\newKey
static newKey( $key)
Static constructor for easier chaining.
Definition: CommentStore.php:114
$wgUseRCPatrol
$wgUseRCPatrol
Use RC Patrolling to check for vandalism (from recent changes and watchlists) New pages and new files...
Definition: DefaultSettings.php:6801
$wgUseNPPatrol
$wgUseNPPatrol
Use new page patrolling to check new pages on Special:Newpages.
Definition: DefaultSettings.php:6833
RecentChange\SRC_LOG
const SRC_LOG
Definition: RecentChange.php:72
RecentChangesUpdateJob\newCacheUpdateJob
static newCacheUpdateJob()
Definition: RecentChangesUpdateJob.php:54
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:1063
$wgPutIPinRC
$wgPutIPinRC
Log IP addresses in the recentchanges table; can be accessed only by extensions (e....
Definition: DefaultSettings.php:5757
DeferredUpdates\addCallableUpdate
static addCallableUpdate( $callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
Definition: DeferredUpdates.php:111
Title\getDBkey
getDBkey()
Get the main part with underscores.
Definition: Title.php:955
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:932
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:121
Title\getNamespace
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:978
RecentChange\$notificationtimestamp
$notificationtimestamp
Definition: RecentChange.php:90
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2856
in
null for the wiki Added in
Definition: hooks.txt:1581
$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:1965
$wgRCFeeds
$wgRCFeeds
Recentchanges items are periodically purged; entries older than this many seconds will go.
Definition: DefaultSettings.php:6772
RecentChange\newFromRow
static newFromRow( $row)
Definition: RecentChange.php:119
RecentChange\notifyLog
static notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='')
Definition: RecentChange.php:731
DeferredUpdates\POSTSEND
const POSTSEND
Definition: DeferredUpdates.php:61
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 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:2133
RecentChange\SRC_EDIT
const SRC_EDIT
Definition: RecentChange.php:70
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:529
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
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:987
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:71
$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:1265
$wgUseFilePatrol
$wgUseFilePatrol
Use file patrolling to check new files on Special:Newfiles.
Definition: DefaultSettings.php:6840
$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:1472
RecentChange\newFromId
static newFromId( $rcid)
Obtain the recent change with a given rc_id value.
Definition: RecentChange.php:176
RecentChange\doMarkPatrolled
doMarkPatrolled(User $user, $auto=false, $tags=null)
Mark this RecentChange as patrolled.
Definition: RecentChange.php:494
RecentChange\$mExtra
$mExtra
Definition: RecentChange.php:77
$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:7592
$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:6681
ChangesList\showCharacterDifference
static showCharacterDifference( $old, $new, IContextSource $context=null)
Show formatted char difference.
Definition: ChangesList.php:289
RC_NEW
const RC_NEW
Definition: Defines.php:144
RecentChange\markPatrolled
static markPatrolled( $change, $auto=false, $tags=null)
Mark a given change as patrolled.
Definition: RecentChange.php:469
RecentChange\addTags
addTags( $tags)
Tags to append to the recent change, and associated revision/log.
Definition: RecentChange.php:1081
RecentChange\getAttribute
getAttribute( $name)
Get an attribute value.
Definition: RecentChange.php:967
$wgUseEnotif
$wgUseEnotif
Definition: Setup.php:368
RecentChange\checkIPAddress
static checkIPAddress( $ip)
Definition: RecentChange.php:1024
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:210
RecentChange\$mTitle
Title $mTitle
Definition: RecentChange.php:82
RecentChange\parseFromRCType
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.
Definition: RecentChange.php:155
$wgRCEngines
$wgRCEngines
Used by RecentChange::getEngine to find the correct engine for a given URI scheme.
Definition: DefaultSettings.php:6779
RecentChange\newLogEntry
static newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC='', $revId=0, $isPatrollable=false)
Definition: RecentChange.php:764
JobQueueGroup\singleton
static singleton( $wiki=false)
Definition: JobQueueGroup.php:72
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:1050
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:2581
RC_CATEGORIZE
const RC_CATEGORIZE
Definition: Defines.php:147
RecentChange\notifyRCFeeds
notifyRCFeeds(array $feeds=null)
Notify all the feeds about the change.
Definition: RecentChange.php:397
$t
$t
Definition: testCompression.php:67
RecentChange\getPerformer
getPerformer()
Get the User object of the person who performed this change.
Definition: RecentChange.php:270
EmailNotification
This module processes the email notifications when the current page is changed.
Definition: EmailNotification.php:49
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:662
RecentChange\save
save( $noudp=false)
Writes the data in this object to the database.
Definition: RecentChange.php:286
RecentChange\getTitle
& getTitle()
Definition: RecentChange.php:257
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
RecentChange\$mPerformer
User $mPerformer
Definition: RecentChange.php:87
RecentChange\$changeTypes
static array $changeTypes
Array of change types.
Definition: RecentChange.php:105
RecentChange\getParam
getParam( $name)
Get a parameter value.
Definition: RecentChange.php:929
RecentChange\$numberofWatchingusers
$numberofWatchingusers
Definition: RecentChange.php:89
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:163
IP\isIPAddress
static isIPAddress( $ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:77
array
the array() calling protocol came about after MediaWiki 1.4rc1.
RecentChange\SRC_EXTERNAL
const SRC_EXTERNAL
Definition: RecentChange.php:73
User\isAllowed
isAllowed( $action='')
Internal mechanics of testing a permission.
Definition: User.php:3565
$type
$type
Definition: testCompression.php:48