MediaWiki  1.28.0
RecentChange.php
Go to the documentation of this file.
1 <?php
63 class RecentChange {
64  // Constants for the rc_source field. Extensions may also have
65  // their own source constants.
66  const SRC_EDIT = 'mw.edit';
67  const SRC_NEW = 'mw.new';
68  const SRC_LOG = 'mw.log';
69  const SRC_EXTERNAL = 'mw.external'; // obsolete
70  const SRC_CATEGORIZE = 'mw.categorize';
71 
72  public $mAttribs = [];
73  public $mExtra = [];
74 
78  public $mTitle = false;
79 
83  private $mPerformer = false;
84 
85  public $numberofWatchingusers = 0; # Dummy to prevent error message in SpecialRecentChangesLinked
87 
91  public $counter = -1;
92 
96  private $tags = [];
97 
101  private static $changeTypes = [
102  'edit' => RC_EDIT,
103  'new' => RC_NEW,
104  'log' => RC_LOG,
105  'external' => RC_EXTERNAL,
106  'categorize' => RC_CATEGORIZE,
107  ];
108 
109  # Factory methods
110 
115  public static function newFromRow( $row ) {
116  $rc = new RecentChange;
117  $rc->loadFromRow( $row );
118 
119  return $rc;
120  }
121 
129  public static function parseToRCType( $type ) {
130  if ( is_array( $type ) ) {
131  $retval = [];
132  foreach ( $type as $t ) {
134  }
135 
136  return $retval;
137  }
138 
139  if ( !array_key_exists( $type, self::$changeTypes ) ) {
140  throw new MWException( "Unknown type '$type'" );
141  }
142  return self::$changeTypes[$type];
143  }
144 
151  public static function parseFromRCType( $rcType ) {
152  return array_search( $rcType, self::$changeTypes, true ) ?: "$rcType";
153  }
154 
162  public static function getChangeTypes() {
163  return array_keys( self::$changeTypes );
164  }
165 
172  public static function newFromId( $rcid ) {
173  return self::newFromConds( [ 'rc_id' => $rcid ], __METHOD__ );
174  }
175 
185  public static function newFromConds(
186  $conds,
187  $fname = __METHOD__,
188  $dbType = DB_REPLICA
189  ) {
190  $db = wfGetDB( $dbType );
191  $row = $db->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
192  if ( $row !== false ) {
193  return self::newFromRow( $row );
194  } else {
195  return null;
196  }
197  }
198 
204  public static function selectFields() {
205  return [
206  'rc_id',
207  'rc_timestamp',
208  'rc_user',
209  'rc_user_text',
210  'rc_namespace',
211  'rc_title',
212  'rc_comment',
213  'rc_minor',
214  'rc_bot',
215  'rc_new',
216  'rc_cur_id',
217  'rc_this_oldid',
218  'rc_last_oldid',
219  'rc_type',
220  'rc_source',
221  'rc_patrolled',
222  'rc_ip',
223  'rc_old_len',
224  'rc_new_len',
225  'rc_deleted',
226  'rc_logid',
227  'rc_log_type',
228  'rc_log_action',
229  'rc_params',
230  ];
231  }
232 
233  # Accessors
234 
238  public function setAttribs( $attribs ) {
239  $this->mAttribs = $attribs;
240  }
241 
245  public function setExtra( $extra ) {
246  $this->mExtra = $extra;
247  }
248 
252  public function &getTitle() {
253  if ( $this->mTitle === false ) {
254  $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
255  }
256 
257  return $this->mTitle;
258  }
259 
265  public function getPerformer() {
266  if ( $this->mPerformer === false ) {
267  if ( $this->mAttribs['rc_user'] ) {
268  $this->mPerformer = User::newFromId( $this->mAttribs['rc_user'] );
269  } else {
270  $this->mPerformer = User::newFromName( $this->mAttribs['rc_user_text'], false );
271  }
272  }
273 
274  return $this->mPerformer;
275  }
276 
281  public function save( $noudp = false ) {
282  global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
283 
284  $dbw = wfGetDB( DB_MASTER );
285  if ( !is_array( $this->mExtra ) ) {
286  $this->mExtra = [];
287  }
288 
289  if ( !$wgPutIPinRC ) {
290  $this->mAttribs['rc_ip'] = '';
291  }
292 
293  # Strict mode fixups (not-NULL fields)
294  foreach ( [ 'minor', 'bot', 'new', 'patrolled', 'deleted' ] as $field ) {
295  $this->mAttribs["rc_$field"] = (int)$this->mAttribs["rc_$field"];
296  }
297  # ...more fixups (NULL fields)
298  foreach ( [ 'old_len', 'new_len' ] as $field ) {
299  $this->mAttribs["rc_$field"] = isset( $this->mAttribs["rc_$field"] )
300  ? (int)$this->mAttribs["rc_$field"]
301  : null;
302  }
303 
304  # If our database is strict about IP addresses, use NULL instead of an empty string
305  $strictIPs = in_array( $dbw->getType(), [ 'oracle', 'postgres' ] ); // legacy
306  if ( $strictIPs && $this->mAttribs['rc_ip'] == '' ) {
307  unset( $this->mAttribs['rc_ip'] );
308  }
309 
310  # Trim spaces on user supplied text
311  $this->mAttribs['rc_comment'] = trim( $this->mAttribs['rc_comment'] );
312 
313  # Make sure summary is truncated (whole multibyte characters)
314  $this->mAttribs['rc_comment'] = $wgContLang->truncate( $this->mAttribs['rc_comment'], 255 );
315 
316  # Fixup database timestamps
317  $this->mAttribs['rc_timestamp'] = $dbw->timestamp( $this->mAttribs['rc_timestamp'] );
318  $this->mAttribs['rc_id'] = $dbw->nextSequenceValue( 'recentchanges_rc_id_seq' );
319 
320  # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
321  if ( $this->mAttribs['rc_cur_id'] == 0 ) {
322  unset( $this->mAttribs['rc_cur_id'] );
323  }
324 
325  # Insert new row
326  $dbw->insert( 'recentchanges', $this->mAttribs, __METHOD__ );
327 
328  # Set the ID
329  $this->mAttribs['rc_id'] = $dbw->insertId();
330 
331  # Notify extensions
332  Hooks::run( 'RecentChange_save', [ &$this ] );
333 
334  if ( count( $this->tags ) ) {
335  ChangeTags::addTags( $this->tags, $this->mAttribs['rc_id'],
336  $this->mAttribs['rc_this_oldid'], $this->mAttribs['rc_logid'], null, $this );
337  }
338 
339  # Notify external application via UDP
340  if ( !$noudp ) {
341  $this->notifyRCFeeds();
342  }
343 
344  # E-mail notifications
345  if ( $wgUseEnotif || $wgShowUpdatedMarker ) {
346  $editor = $this->getPerformer();
347  $title = $this->getTitle();
348 
349  // Never send an RC notification email about categorization changes
350  if (
351  $this->mAttribs['rc_type'] != RC_CATEGORIZE &&
352  Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] )
353  ) {
354  // @FIXME: This would be better as an extension hook
355  // Send emails or email jobs once this row is safely committed
356  $dbw->onTransactionIdle(
357  function () use ( $editor, $title ) {
358  $enotif = new EmailNotification();
359  $enotif->notifyOnPageChange(
360  $editor,
361  $title,
362  $this->mAttribs['rc_timestamp'],
363  $this->mAttribs['rc_comment'],
364  $this->mAttribs['rc_minor'],
365  $this->mAttribs['rc_last_oldid'],
366  $this->mExtra['pageStatus']
367  );
368  },
369  __METHOD__
370  );
371  }
372  }
373 
374  // Update the cached list of active users
375  if ( $this->mAttribs['rc_user'] > 0 ) {
377  }
378  }
379 
384  public function notifyRCFeeds( array $feeds = null ) {
385  global $wgRCFeeds;
386  if ( $feeds === null ) {
387  $feeds = $wgRCFeeds;
388  }
389 
390  $performer = $this->getPerformer();
391 
392  foreach ( $feeds as $feed ) {
393  $feed += [
394  'omit_bots' => false,
395  'omit_anon' => false,
396  'omit_user' => false,
397  'omit_minor' => false,
398  'omit_patrolled' => false,
399  ];
400 
401  if (
402  ( $feed['omit_bots'] && $this->mAttribs['rc_bot'] ) ||
403  ( $feed['omit_anon'] && $performer->isAnon() ) ||
404  ( $feed['omit_user'] && !$performer->isAnon() ) ||
405  ( $feed['omit_minor'] && $this->mAttribs['rc_minor'] ) ||
406  ( $feed['omit_patrolled'] && $this->mAttribs['rc_patrolled'] ) ||
407  $this->mAttribs['rc_type'] == RC_EXTERNAL
408  ) {
409  continue;
410  }
411 
412  $engine = self::getEngine( $feed['uri'] );
413 
414  if ( isset( $this->mExtra['actionCommentIRC'] ) ) {
415  $actionComment = $this->mExtra['actionCommentIRC'];
416  } else {
417  $actionComment = null;
418  }
419 
421  $formatter = is_object( $feed['formatter'] ) ? $feed['formatter'] : new $feed['formatter']();
422  $line = $formatter->getLine( $feed, $this, $actionComment );
423  if ( !$line ) {
424  // T109544
425  // If a feed formatter returns null, this will otherwise cause an
426  // error in at least RedisPubSubFeedEngine.
427  // Not sure where/how this should best be handled.
428  continue;
429  }
430 
431  $engine->send( $feed, $line );
432  }
433  }
434 
442  public static function getEngine( $uri ) {
443  global $wgRCEngines;
444 
445  $scheme = parse_url( $uri, PHP_URL_SCHEME );
446  if ( !$scheme ) {
447  throw new MWException( __FUNCTION__ . ": Invalid stream logger URI: '$uri'" );
448  }
449 
450  if ( !isset( $wgRCEngines[$scheme] ) ) {
451  throw new MWException( __FUNCTION__ . ": Unknown stream logger URI scheme: $scheme" );
452  }
453 
454  return new $wgRCEngines[$scheme];
455  }
456 
466  public static function markPatrolled( $change, $auto = false, $tags = null ) {
467  global $wgUser;
468 
469  $change = $change instanceof RecentChange
470  ? $change
471  : RecentChange::newFromId( $change );
472 
473  if ( !$change instanceof RecentChange ) {
474  return null;
475  }
476 
477  return $change->doMarkPatrolled( $wgUser, $auto, $tags );
478  }
479 
491  public function doMarkPatrolled( User $user, $auto = false, $tags = null ) {
492  global $wgUseRCPatrol, $wgUseNPPatrol, $wgUseFilePatrol;
493 
494  $errors = [];
495  // If recentchanges patrol is disabled, only new pages or new file versions
496  // can be patrolled, provided the appropriate config variable is set
497  if ( !$wgUseRCPatrol && ( !$wgUseNPPatrol || $this->getAttribute( 'rc_type' ) != RC_NEW ) &&
498  ( !$wgUseFilePatrol || !( $this->getAttribute( 'rc_type' ) == RC_LOG &&
499  $this->getAttribute( 'rc_log_type' ) == 'upload' ) ) ) {
500  $errors[] = [ 'rcpatroldisabled' ];
501  }
502  // Automatic patrol needs "autopatrol", ordinary patrol needs "patrol"
503  $right = $auto ? 'autopatrol' : 'patrol';
504  $errors = array_merge( $errors, $this->getTitle()->getUserPermissionsErrors( $right, $user ) );
505  if ( !Hooks::run( 'MarkPatrolled',
506  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ] )
507  ) {
508  $errors[] = [ 'hookaborted' ];
509  }
510  // Users without the 'autopatrol' right can't patrol their
511  // own revisions
512  if ( $user->getName() === $this->getAttribute( 'rc_user_text' )
513  && !$user->isAllowed( 'autopatrol' )
514  ) {
515  $errors[] = [ 'markedaspatrollederror-noautopatrol' ];
516  }
517  if ( $errors ) {
518  return $errors;
519  }
520  // If the change was patrolled already, do nothing
521  if ( $this->getAttribute( 'rc_patrolled' ) ) {
522  return [];
523  }
524  // Actually set the 'patrolled' flag in RC
525  $this->reallyMarkPatrolled();
526  // Log this patrol event
527  PatrolLog::record( $this, $auto, $user, $tags );
528 
529  Hooks::run(
530  'MarkPatrolledComplete',
531  [ $this->getAttribute( 'rc_id' ), &$user, false, $auto ]
532  );
533 
534  return [];
535  }
536 
541  public function reallyMarkPatrolled() {
542  $dbw = wfGetDB( DB_MASTER );
543  $dbw->update(
544  'recentchanges',
545  [
546  'rc_patrolled' => 1
547  ],
548  [
549  'rc_id' => $this->getAttribute( 'rc_id' )
550  ],
551  __METHOD__
552  );
553  // Invalidate the page cache after the page has been patrolled
554  // to make sure that the Patrol link isn't visible any longer!
555  $this->getTitle()->invalidateCache();
556 
557  return $dbw->affectedRows();
558  }
559 
579  public static function notifyEdit(
580  $timestamp, &$title, $minor, &$user, $comment, $oldId, $lastTimestamp,
581  $bot, $ip = '', $oldSize = 0, $newSize = 0, $newId = 0, $patrol = 0,
582  $tags = []
583  ) {
584  $rc = new RecentChange;
585  $rc->mTitle = $title;
586  $rc->mPerformer = $user;
587  $rc->mAttribs = [
588  'rc_timestamp' => $timestamp,
589  'rc_namespace' => $title->getNamespace(),
590  'rc_title' => $title->getDBkey(),
591  'rc_type' => RC_EDIT,
592  'rc_source' => self::SRC_EDIT,
593  'rc_minor' => $minor ? 1 : 0,
594  'rc_cur_id' => $title->getArticleID(),
595  'rc_user' => $user->getId(),
596  'rc_user_text' => $user->getName(),
597  'rc_comment' => $comment,
598  'rc_this_oldid' => $newId,
599  'rc_last_oldid' => $oldId,
600  'rc_bot' => $bot ? 1 : 0,
601  'rc_ip' => self::checkIPAddress( $ip ),
602  'rc_patrolled' => intval( $patrol ),
603  'rc_new' => 0, # obsolete
604  'rc_old_len' => $oldSize,
605  'rc_new_len' => $newSize,
606  'rc_deleted' => 0,
607  'rc_logid' => 0,
608  'rc_log_type' => null,
609  'rc_log_action' => '',
610  'rc_params' => ''
611  ];
612 
613  $rc->mExtra = [
614  'prefixedDBkey' => $title->getPrefixedDBkey(),
615  'lastTimestamp' => $lastTimestamp,
616  'oldSize' => $oldSize,
617  'newSize' => $newSize,
618  'pageStatus' => 'changed'
619  ];
620 
622  function () use ( $rc, $tags ) {
623  $rc->addTags( $tags );
624  $rc->save();
625  if ( $rc->mAttribs['rc_patrolled'] ) {
626  PatrolLog::record( $rc, true, $rc->getPerformer() );
627  }
628  },
630  wfGetDB( DB_MASTER )
631  );
632 
633  return $rc;
634  }
635 
653  public static function notifyNew(
654  $timestamp, &$title, $minor, &$user, $comment, $bot,
655  $ip = '', $size = 0, $newId = 0, $patrol = 0, $tags = []
656  ) {
657  $rc = new RecentChange;
658  $rc->mTitle = $title;
659  $rc->mPerformer = $user;
660  $rc->mAttribs = [
661  'rc_timestamp' => $timestamp,
662  'rc_namespace' => $title->getNamespace(),
663  'rc_title' => $title->getDBkey(),
664  'rc_type' => RC_NEW,
665  'rc_source' => self::SRC_NEW,
666  'rc_minor' => $minor ? 1 : 0,
667  'rc_cur_id' => $title->getArticleID(),
668  'rc_user' => $user->getId(),
669  'rc_user_text' => $user->getName(),
670  'rc_comment' => $comment,
671  'rc_this_oldid' => $newId,
672  'rc_last_oldid' => 0,
673  'rc_bot' => $bot ? 1 : 0,
674  'rc_ip' => self::checkIPAddress( $ip ),
675  'rc_patrolled' => intval( $patrol ),
676  'rc_new' => 1, # obsolete
677  'rc_old_len' => 0,
678  'rc_new_len' => $size,
679  'rc_deleted' => 0,
680  'rc_logid' => 0,
681  'rc_log_type' => null,
682  'rc_log_action' => '',
683  'rc_params' => ''
684  ];
685 
686  $rc->mExtra = [
687  'prefixedDBkey' => $title->getPrefixedDBkey(),
688  'lastTimestamp' => 0,
689  'oldSize' => 0,
690  'newSize' => $size,
691  'pageStatus' => 'created'
692  ];
693 
695  function () use ( $rc, $tags ) {
696  $rc->addTags( $tags );
697  $rc->save();
698  if ( $rc->mAttribs['rc_patrolled'] ) {
699  PatrolLog::record( $rc, true, $rc->getPerformer() );
700  }
701  },
703  wfGetDB( DB_MASTER )
704  );
705 
706  return $rc;
707  }
708 
724  public static function notifyLog( $timestamp, &$title, &$user, $actionComment, $ip, $type,
725  $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = ''
726  ) {
727  global $wgLogRestrictions;
728 
729  # Don't add private logs to RC!
730  if ( isset( $wgLogRestrictions[$type] ) && $wgLogRestrictions[$type] != '*' ) {
731  return false;
732  }
733  $rc = self::newLogEntry( $timestamp, $title, $user, $actionComment, $ip, $type, $action,
734  $target, $logComment, $params, $newId, $actionCommentIRC );
735  $rc->save();
736 
737  return true;
738  }
739 
757  public static function newLogEntry( $timestamp, &$title, &$user, $actionComment, $ip,
758  $type, $action, $target, $logComment, $params, $newId = 0, $actionCommentIRC = '',
759  $revId = 0, $isPatrollable = false ) {
761 
762  # # Get pageStatus for email notification
763  switch ( $type . '-' . $action ) {
764  case 'delete-delete':
765  case 'delete-delete_redir':
766  $pageStatus = 'deleted';
767  break;
768  case 'move-move':
769  case 'move-move_redir':
770  $pageStatus = 'moved';
771  break;
772  case 'delete-restore':
773  $pageStatus = 'restored';
774  break;
775  case 'upload-upload':
776  $pageStatus = 'created';
777  break;
778  case 'upload-overwrite':
779  default:
780  $pageStatus = 'changed';
781  break;
782  }
783 
784  // Allow unpatrolled status for patrollable log entries
785  $markPatrolled = $isPatrollable ? $user->isAllowed( 'autopatrol' ) : true;
786 
787  $rc = new RecentChange;
788  $rc->mTitle = $target;
789  $rc->mPerformer = $user;
790  $rc->mAttribs = [
791  'rc_timestamp' => $timestamp,
792  'rc_namespace' => $target->getNamespace(),
793  'rc_title' => $target->getDBkey(),
794  'rc_type' => RC_LOG,
795  'rc_source' => self::SRC_LOG,
796  'rc_minor' => 0,
797  'rc_cur_id' => $target->getArticleID(),
798  'rc_user' => $user->getId(),
799  'rc_user_text' => $user->getName(),
800  'rc_comment' => $logComment,
801  'rc_this_oldid' => $revId,
802  'rc_last_oldid' => 0,
803  'rc_bot' => $user->isAllowed( 'bot' ) ? (int)$wgRequest->getBool( 'bot', true ) : 0,
804  'rc_ip' => self::checkIPAddress( $ip ),
805  'rc_patrolled' => $markPatrolled ? 1 : 0,
806  'rc_new' => 0, # obsolete
807  'rc_old_len' => null,
808  'rc_new_len' => null,
809  'rc_deleted' => 0,
810  'rc_logid' => $newId,
811  'rc_log_type' => $type,
812  'rc_log_action' => $action,
813  'rc_params' => $params
814  ];
815 
816  $rc->mExtra = [
817  'prefixedDBkey' => $title->getPrefixedDBkey(),
818  'lastTimestamp' => 0,
819  'actionComment' => $actionComment, // the comment appended to the action, passed from LogPage
820  'pageStatus' => $pageStatus,
821  'actionCommentIRC' => $actionCommentIRC
822  ];
823 
824  return $rc;
825  }
826 
847  public static function newForCategorization(
848  $timestamp,
849  Title $categoryTitle,
850  User $user = null,
851  $comment,
852  Title $pageTitle,
853  $oldRevId,
854  $newRevId,
855  $lastTimestamp,
856  $bot,
857  $ip = '',
858  $deleted = 0
859  ) {
860  $rc = new RecentChange;
861  $rc->mTitle = $categoryTitle;
862  $rc->mPerformer = $user;
863  $rc->mAttribs = [
864  'rc_timestamp' => $timestamp,
865  'rc_namespace' => $categoryTitle->getNamespace(),
866  'rc_title' => $categoryTitle->getDBkey(),
867  'rc_type' => RC_CATEGORIZE,
868  'rc_source' => self::SRC_CATEGORIZE,
869  'rc_minor' => 0,
870  'rc_cur_id' => $pageTitle->getArticleID(),
871  'rc_user' => $user ? $user->getId() : 0,
872  'rc_user_text' => $user ? $user->getName() : '',
873  'rc_comment' => $comment,
874  'rc_this_oldid' => $newRevId,
875  'rc_last_oldid' => $oldRevId,
876  'rc_bot' => $bot ? 1 : 0,
877  'rc_ip' => self::checkIPAddress( $ip ),
878  'rc_patrolled' => 1, // Always patrolled, just like log entries
879  'rc_new' => 0, # obsolete
880  'rc_old_len' => null,
881  'rc_new_len' => null,
882  'rc_deleted' => $deleted,
883  'rc_logid' => 0,
884  'rc_log_type' => null,
885  'rc_log_action' => '',
886  'rc_params' => serialize( [
887  'hidden-cat' => WikiCategoryPage::factory( $categoryTitle )->isHidden()
888  ] )
889  ];
890 
891  $rc->mExtra = [
892  'prefixedDBkey' => $categoryTitle->getPrefixedDBkey(),
893  'lastTimestamp' => $lastTimestamp,
894  'oldSize' => 0,
895  'newSize' => 0,
896  'pageStatus' => 'changed'
897  ];
898 
899  return $rc;
900  }
901 
910  public function getParam( $name ) {
911  $params = $this->parseParams();
912  return isset( $params[$name] ) ? $params[$name] : null;
913  }
914 
920  public function loadFromRow( $row ) {
921  $this->mAttribs = get_object_vars( $row );
922  $this->mAttribs['rc_timestamp'] = wfTimestamp( TS_MW, $this->mAttribs['rc_timestamp'] );
923  $this->mAttribs['rc_deleted'] = $row->rc_deleted; // MUST be set
924  }
925 
932  public function getAttribute( $name ) {
933  return isset( $this->mAttribs[$name] ) ? $this->mAttribs[$name] : null;
934  }
935 
939  public function getAttributes() {
940  return $this->mAttribs;
941  }
942 
949  public function diffLinkTrail( $forceCur ) {
950  if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
951  $trail = "curid=" . (int)( $this->mAttribs['rc_cur_id'] ) .
952  "&oldid=" . (int)( $this->mAttribs['rc_last_oldid'] );
953  if ( $forceCur ) {
954  $trail .= '&diff=0';
955  } else {
956  $trail .= '&diff=' . (int)( $this->mAttribs['rc_this_oldid'] );
957  }
958  } else {
959  $trail = '';
960  }
961 
962  return $trail;
963  }
964 
972  public function getCharacterDifference( $old = 0, $new = 0 ) {
973  if ( $old === 0 ) {
974  $old = $this->mAttribs['rc_old_len'];
975  }
976  if ( $new === 0 ) {
977  $new = $this->mAttribs['rc_new_len'];
978  }
979  if ( $old === null || $new === null ) {
980  return '';
981  }
982 
983  return ChangesList::showCharacterDifference( $old, $new );
984  }
985 
986  private static function checkIPAddress( $ip ) {
988  if ( $ip ) {
989  if ( !IP::isIPAddress( $ip ) ) {
990  throw new MWException( "Attempt to write \"" . $ip .
991  "\" as an IP address into recent changes" );
992  }
993  } else {
994  $ip = $wgRequest->getIP();
995  if ( !$ip ) {
996  $ip = '';
997  }
998  }
999 
1000  return $ip;
1001  }
1002 
1012  public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
1013  global $wgRCMaxAge;
1014 
1015  return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
1016  }
1017 
1025  public function parseParams() {
1026  $rcParams = $this->getAttribute( 'rc_params' );
1027 
1028  MediaWiki\suppressWarnings();
1029  $unserializedParams = unserialize( $rcParams );
1030  MediaWiki\restoreWarnings();
1031 
1032  return $unserializedParams;
1033  }
1034 
1043  public function addTags( $tags ) {
1044  if ( is_string( $tags ) ) {
1045  $this->tags[] = $tags;
1046  } else {
1047  $this->tags = array_merge( $tags, $this->tags );
1048  }
1049  }
1050 }
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
Definition: User.php:525
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:115
This module processes the email notifications when the current page is changed.
const RC_CATEGORIZE
Definition: Defines.php:140
Utility class for creating new RC entries.
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...
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
the array() calling protocol came about after MediaWiki 1.4rc1.
const SRC_CATEGORIZE
static getChangeTypes()
Get an array of all change types.
getArticleID($flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition: Title.php:3171
doMarkPatrolled(User $user, $auto=false, $tags=null)
Mark this RecentChange as patrolled.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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:133
if(!$wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:664
getCharacterDifference($old=0, $new=0)
Returns the change size (HTML).
parseParams()
Parses and returns the rc_params attribute.
static newFromId($rcid)
Obtain the recent change with a given rc_id value.
static newFromConds($conds, $fname=__METHOD__, $dbType=DB_REPLICA)
Find the first recent change matching some specific conditions.
$comment
null for the local wiki Added in
Definition: hooks.txt:1555
getParam($name)
Get a parameter value.
static newFromId($id)
Static factory method for creation from a given user ID.
Definition: User.php:548
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context $revId
Definition: hooks.txt:1046
save($noudp=false)
Writes the data in this object to the database.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static isIPAddress($ip)
Determine if a string is as valid IP address or network (CIDR prefix).
Definition: IP.php:79
const DB_MASTER
Definition: defines.php:23
getName()
Get the user name, or the IP of an anonymous user.
Definition: User.php:2108
static record($rc, $auto=false, User $user=null, $tags=null)
Record a log event for a change being patrolled.
Definition: PatrolLog.php:41
getPerformer()
Get the User object of the person who performed this change.
getAttribute($name)
Get an attribute value.
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: defines.php:6
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.
static newForCategorization($timestamp, Title $categoryTitle, User $user=null, $comment, Title $pageTitle, $oldRevId, $newRevId, $lastTimestamp, $bot, $ip= '', $deleted=0)
Constructs a RecentChange object for the given categorization This does not call save() on the object...
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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:2094
diffLinkTrail($forceCur)
Gets the end part of the diff URL associated with this object Blank if no diff link should be display...
static notifyLog($timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC= '')
unserialize($serialized)
Definition: ApiMessage.php:102
isAllowed($action= '')
Internal mechanics of testing a permission.
Definition: User.php:3443
getDBkey()
Get the main part with underscores.
Definition: Title.php:898
if($limit) $timestamp
static checkIPAddress($ip)
static showCharacterDifference($old, $new, IContextSource $context=null)
Show formatted char difference.
static array $changeTypes
Array of change types.
$params
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: defines.php:11
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:1936
const SRC_EXTERNAL
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:921
array $tags
List of tags to apply.
setExtra($extra)
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
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 temp or archived zone 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:1442
static selectFields()
Return the list of recentchanges fields that should be selected to create a new recentchanges object...
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 local account $user
Definition: hooks.txt:242
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2736
static array static newFromRow($row)
static singleton($wiki=false)
static parseFromRCType($rcType)
Parsing RC_* constants to human-readable test.
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
$wgUseEnotif
Definition: Setup.php:343
reallyMarkPatrolled()
Mark this RecentChange patrolled, without error checking.
static getEngine($uri)
Gets the stream engine object for a given URI from $wgRCEngines.
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:36
static markPatrolled($change, $auto=false, $tags=null)
Mark a given change as patrolled.
notifyRCFeeds(array $feeds=null)
Notify all the feeds about the change.
addTags($tags)
Tags to append to the recent change, and associated revision/log.
setAttribs($attribs)
int $counter
Line number of recent change.
$line
Definition: cdb.php:59
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
const RC_EXTERNAL
Definition: Defines.php:139
const RC_NEW
Definition: Defines.php:137
static addCallableUpdate($callable, $stage=self::POSTSEND, IDatabase $dbw=null)
Add a callable update.
const DB_REPLICA
Definition: defines.php:22
This is to display changes made to all articles linked in an article.
serialize()
Definition: ApiMessage.php:94
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...
loadFromRow($row)
Initialises the members of this object from a mysql row object.
static newLogEntry($timestamp, &$title, &$user, $actionComment, $ip, $type, $action, $target, $logComment, $params, $newId=0, $actionCommentIRC= '', $revId=0, $isPatrollable=false)
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 local account incomplete not yet checked for validity & $retval
Definition: hooks.txt:242
static parseToRCType($type)
Parsing text to RC_* constants.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2491
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
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:1230
const RC_EDIT
Definition: Defines.php:136
const RC_LOG
Definition: Defines.php:138
getPrefixedDBkey()
Get the prefixed database key form.
Definition: Title.php:1443
$wgUser
Definition: Setup.php:806
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300