MediaWiki  master
Revision.php
Go to the documentation of this file.
1 <?php
37 
41 class Revision implements IDBAccessObject {
42 
44  protected $mRecord;
45 
46  // Revision deletion constants
47  const DELETED_TEXT = RevisionRecord::DELETED_TEXT;
48  const DELETED_COMMENT = RevisionRecord::DELETED_COMMENT;
49  const DELETED_USER = RevisionRecord::DELETED_USER;
50  const DELETED_RESTRICTED = RevisionRecord::DELETED_RESTRICTED;
51  const SUPPRESSED_USER = RevisionRecord::SUPPRESSED_USER;
52  const SUPPRESSED_ALL = RevisionRecord::SUPPRESSED_ALL;
53 
54  // Audience options for accessors
55  const FOR_PUBLIC = RevisionRecord::FOR_PUBLIC;
56  const FOR_THIS_USER = RevisionRecord::FOR_THIS_USER;
57  const RAW = RevisionRecord::RAW;
58 
59  const TEXT_CACHE_GROUP = SqlBlobStore::TEXT_CACHE_GROUP;
60 
64  protected static function getRevisionStore() {
65  return MediaWikiServices::getInstance()->getRevisionStore();
66  }
67 
71  protected static function getRevisionLookup() {
72  return MediaWikiServices::getInstance()->getRevisionLookup();
73  }
74 
78  protected static function getRevisionFactory() {
79  return MediaWikiServices::getInstance()->getRevisionFactory();
80  }
81 
87  protected static function getBlobStore( $wiki = false ) {
88  $store = MediaWikiServices::getInstance()
89  ->getBlobStoreFactory()
90  ->newSqlBlobStore( $wiki );
91 
92  if ( !$store instanceof SqlBlobStore ) {
93  throw new RuntimeException(
94  'The backwards compatibility code in Revision currently requires the BlobStore '
95  . 'service to be an SqlBlobStore instance, but it is a ' . get_class( $store )
96  );
97  }
98 
99  return $store;
100  }
101 
114  public static function newFromId( $id, $flags = 0 ) {
115  $rec = self::getRevisionLookup()->getRevisionById( $id, $flags );
116  return $rec === null ? null : new Revision( $rec, $flags );
117  }
118 
133  public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0 ) {
134  $rec = self::getRevisionLookup()->getRevisionByTitle( $linkTarget, $id, $flags );
135  return $rec === null ? null : new Revision( $rec, $flags );
136  }
137 
152  public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) {
153  $rec = self::getRevisionLookup()->getRevisionByPageId( $pageId, $revId, $flags );
154  return $rec === null ? null : new Revision( $rec, $flags );
155  }
156 
167  public static function newFromArchiveRow( $row, $overrides = [] ) {
174  if ( array_key_exists( 'page', $overrides ) ) {
175  $overrides['page_id'] = $overrides['page'];
176  unset( $overrides['page'] );
177  }
178 
184  $title = null;
185  if ( isset( $overrides['title'] ) ) {
186  if ( !( $overrides['title'] instanceof Title ) ) {
187  throw new MWException( 'title field override must contain a Title object.' );
188  }
189 
190  $title = $overrides['title'];
191  }
192  if ( $title !== null ) {
193  if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
194  $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
195  } else {
196  throw new InvalidArgumentException(
197  'A Title or ar_namespace and ar_title must be given'
198  );
199  }
200  }
201 
202  $rec = self::getRevisionFactory()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
203  return new Revision( $rec, self::READ_NORMAL, $title );
204  }
205 
218  public static function newFromRow( $row ) {
219  if ( is_array( $row ) ) {
220  $rec = self::getRevisionFactory()->newMutableRevisionFromArray( $row );
221  } else {
222  $rec = self::getRevisionFactory()->newRevisionFromRow( $row );
223  }
224 
225  return new Revision( $rec );
226  }
227 
238  public static function loadFromId( $db, $id ) {
239  wfDeprecated( __METHOD__, '1.31' ); // no known callers
240  $rec = self::getRevisionStore()->loadRevisionFromId( $db, $id );
241  return $rec === null ? null : new Revision( $rec );
242  }
243 
256  public static function loadFromPageId( $db, $pageid, $id = 0 ) {
257  $rec = self::getRevisionStore()->loadRevisionFromPageId( $db, $pageid, $id );
258  return $rec === null ? null : new Revision( $rec );
259  }
260 
273  public static function loadFromTitle( $db, $title, $id = 0 ) {
274  $rec = self::getRevisionStore()->loadRevisionFromTitle( $db, $title, $id );
275  return $rec === null ? null : new Revision( $rec );
276  }
277 
291  public static function loadFromTimestamp( $db, $title, $timestamp ) {
292  $rec = self::getRevisionStore()->loadRevisionFromTimestamp( $db, $title, $timestamp );
293  return $rec === null ? null : new Revision( $rec );
294  }
295 
305  public static function fetchRevision( LinkTarget $title ) {
306  wfDeprecated( __METHOD__, '1.31' );
307  return new FakeResultWrapper( [] );
308  }
309 
317  public static function userJoinCond() {
318  global $wgActorTableSchemaMigrationStage;
319 
320  wfDeprecated( __METHOD__, '1.31' );
321  if ( $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
322  // If code is using this instead of self::getQueryInfo(), there's
323  // no way the join it's trying to do can work once the old fields
324  // aren't being written anymore.
325  throw new BadMethodCallException(
326  'Cannot use ' . __METHOD__ . ' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
327  );
328  }
329 
330  return [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ];
331  }
332 
340  public static function pageJoinCond() {
341  wfDeprecated( __METHOD__, '1.31' );
342  return [ 'INNER JOIN', [ 'page_id = rev_page' ] ];
343  }
344 
351  public static function selectFields() {
352  global $wgContentHandlerUseDB, $wgActorTableSchemaMigrationStage;
353 
354  if ( $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
355  // If code is using this instead of self::getQueryInfo(), there's a
356  // decent chance it's going to try to directly access
357  // $row->rev_user or $row->rev_user_text and we can't give it
358  // useful values here once those aren't being written anymore.
359  throw new BadMethodCallException(
360  'Cannot use ' . __METHOD__ . ' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
361  );
362  }
363 
364  wfDeprecated( __METHOD__, '1.31' );
365 
366  $fields = [
367  'rev_id',
368  'rev_page',
369  'rev_text_id',
370  'rev_timestamp',
371  'rev_user_text',
372  'rev_user',
373  'rev_actor' => 'NULL',
374  'rev_minor_edit',
375  'rev_deleted',
376  'rev_len',
377  'rev_parent_id',
378  'rev_sha1',
379  ];
380 
381  $fields += CommentStore::getStore()->getFields( 'rev_comment' );
382 
383  if ( $wgContentHandlerUseDB ) {
384  $fields[] = 'rev_content_format';
385  $fields[] = 'rev_content_model';
386  }
387 
388  return $fields;
389  }
390 
397  public static function selectArchiveFields() {
398  global $wgContentHandlerUseDB, $wgActorTableSchemaMigrationStage;
399 
400  if ( $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
401  // If code is using this instead of self::getQueryInfo(), there's a
402  // decent chance it's going to try to directly access
403  // $row->ar_user or $row->ar_user_text and we can't give it
404  // useful values here once those aren't being written anymore.
405  throw new BadMethodCallException(
406  'Cannot use ' . __METHOD__ . ' when $wgActorTableSchemaMigrationStage > MIGRATION_WRITE_BOTH'
407  );
408  }
409 
410  wfDeprecated( __METHOD__, '1.31' );
411 
412  $fields = [
413  'ar_id',
414  'ar_page_id',
415  'ar_rev_id',
416  'ar_text_id',
417  'ar_timestamp',
418  'ar_user_text',
419  'ar_user',
420  'ar_actor' => 'NULL',
421  'ar_minor_edit',
422  'ar_deleted',
423  'ar_len',
424  'ar_parent_id',
425  'ar_sha1',
426  ];
427 
428  $fields += CommentStore::getStore()->getFields( 'ar_comment' );
429 
430  if ( $wgContentHandlerUseDB ) {
431  $fields[] = 'ar_content_format';
432  $fields[] = 'ar_content_model';
433  }
434  return $fields;
435  }
436 
443  public static function selectTextFields() {
444  wfDeprecated( __METHOD__, '1.31' );
445  return [
446  'old_text',
447  'old_flags'
448  ];
449  }
450 
456  public static function selectPageFields() {
457  wfDeprecated( __METHOD__, '1.31' );
458  return [
459  'page_namespace',
460  'page_title',
461  'page_id',
462  'page_latest',
463  'page_is_redirect',
464  'page_len',
465  ];
466  }
467 
473  public static function selectUserFields() {
474  wfDeprecated( __METHOD__, '1.31' );
475  return [ 'user_name' ];
476  }
477 
492  public static function getQueryInfo( $options = [] ) {
493  return self::getRevisionStore()->getQueryInfo( $options );
494  }
495 
506  public static function getArchiveQueryInfo() {
507  return self::getRevisionStore()->getArchiveQueryInfo();
508  }
509 
519  public static function getParentLengths( $db, array $revIds ) {
520  return self::getRevisionStore()->listRevisionSizes( $db, $revIds );
521  }
522 
530  function __construct( $row, $queryFlags = 0, Title $title = null ) {
531  global $wgUser;
532 
533  if ( $row instanceof RevisionRecord ) {
534  $this->mRecord = $row;
535  } elseif ( is_array( $row ) ) {
536  // If no user is specified, fall back to using the global user object, to stay
537  // compatible with pre-1.31 behavior.
538  if ( !isset( $row['user'] ) && !isset( $row['user_text'] ) ) {
539  $row['user'] = $wgUser;
540  }
541 
542  $this->mRecord = self::getRevisionFactory()->newMutableRevisionFromArray(
543  $row,
544  $queryFlags,
545  $this->ensureTitle( $row, $queryFlags, $title )
546  );
547  } elseif ( is_object( $row ) ) {
548  $this->mRecord = self::getRevisionFactory()->newRevisionFromRow(
549  $row,
550  $queryFlags,
551  $this->ensureTitle( $row, $queryFlags, $title )
552  );
553  } else {
554  throw new InvalidArgumentException(
555  '$row must be a row object, an associative array, or a RevisionRecord'
556  );
557  }
558  }
559 
570  private function ensureTitle( $row, $queryFlags, $title = null ) {
571  if ( $title ) {
572  return $title;
573  }
574 
575  if ( is_array( $row ) ) {
576  if ( isset( $row['title'] ) ) {
577  if ( !( $row['title'] instanceof Title ) ) {
578  throw new MWException( 'title field must contain a Title object.' );
579  }
580 
581  return $row['title'];
582  }
583 
584  $pageId = isset( $row['page'] ) ? $row['page'] : 0;
585  $revId = isset( $row['id'] ) ? $row['id'] : 0;
586  } else {
587  $pageId = isset( $row->rev_page ) ? $row->rev_page : 0;
588  $revId = isset( $row->rev_id ) ? $row->rev_id : 0;
589  }
590 
591  try {
592  $title = self::getRevisionStore()->getTitle( $pageId, $revId, $queryFlags );
593  } catch ( RevisionAccessException $ex ) {
594  // construct a dummy title!
595  wfLogWarning( __METHOD__ . ': ' . $ex->getMessage() );
596 
597  // NOTE: this Title will only be used inside RevisionRecord
598  $title = Title::makeTitleSafe( NS_SPECIAL, "Badtitle/ID=$pageId" );
599  $title->resetArticleID( $pageId );
600  }
601 
602  return $title;
603  }
604 
608  public function getRevisionRecord() {
609  return $this->mRecord;
610  }
611 
617  public function getId() {
618  return $this->mRecord->getId();
619  }
620 
633  public function setId( $id ) {
634  if ( $this->mRecord instanceof MutableRevisionRecord ) {
635  $this->mRecord->setId( intval( $id ) );
636  } else {
637  throw new MWException( __METHOD__ . ' is not supported on this instance' );
638  }
639  }
640 
655  public function setUserIdAndName( $id, $name ) {
656  if ( $this->mRecord instanceof MutableRevisionRecord ) {
657  $user = User::newFromAnyId( intval( $id ), $name, null );
658  $this->mRecord->setUser( $user );
659  } else {
660  throw new MWException( __METHOD__ . ' is not supported on this instance' );
661  }
662  }
663 
667  private function getMainSlotRaw() {
668  return $this->mRecord->getSlot( 'main', RevisionRecord::RAW );
669  }
670 
683  public function getTextId() {
684  $slot = $this->getMainSlotRaw();
685  return $slot->hasAddress()
686  ? self::getBlobStore()->getTextIdFromAddress( $slot->getAddress() )
687  : null;
688  }
689 
696  public function getParentId() {
697  return $this->mRecord->getParentId();
698  }
699 
705  public function getSize() {
706  try {
707  return $this->mRecord->getSize();
708  } catch ( RevisionAccessException $ex ) {
709  return null;
710  }
711  }
712 
718  public function getSha1() {
719  try {
720  return $this->mRecord->getSha1();
721  } catch ( RevisionAccessException $ex ) {
722  return null;
723  }
724  }
725 
734  public function getTitle() {
735  $linkTarget = $this->mRecord->getPageAsLinkTarget();
736  return Title::newFromLinkTarget( $linkTarget );
737  }
738 
746  public function setTitle( $title ) {
747  if ( !$title->equals( $this->getTitle() ) ) {
748  throw new InvalidArgumentException(
749  $title->getPrefixedText()
750  . ' is not the same as '
751  . $this->mRecord->getPageAsLinkTarget()->__toString()
752  );
753  }
754  }
755 
761  public function getPage() {
762  return $this->mRecord->getPageId();
763  }
764 
778  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
779  global $wgUser;
780 
781  if ( $audience === self::FOR_THIS_USER && !$user ) {
782  $user = $wgUser;
783  }
784 
785  $user = $this->mRecord->getUser( $audience, $user );
786  return $user ? $user->getId() : 0;
787  }
788 
802  public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) {
803  global $wgUser;
804 
805  if ( $audience === self::FOR_THIS_USER && !$user ) {
806  $user = $wgUser;
807  }
808 
809  $user = $this->mRecord->getUser( $audience, $user );
810  return $user ? $user->getName() : '';
811  }
825  function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
826  global $wgUser;
827 
828  if ( $audience === self::FOR_THIS_USER && !$user ) {
829  $user = $wgUser;
830  }
831 
832  $comment = $this->mRecord->getComment( $audience, $user );
833  return $comment === null ? null : $comment->text;
834  }
835 
839  public function isMinor() {
840  return $this->mRecord->isMinor();
841  }
842 
846  public function isUnpatrolled() {
847  return self::getRevisionStore()->getRcIdIfUnpatrolled( $this->mRecord );
848  }
849 
859  public function getRecentChange( $flags = 0 ) {
860  return self::getRevisionStore()->getRecentChange( $this->mRecord, $flags );
861  }
862 
868  public function isDeleted( $field ) {
869  return $this->mRecord->isDeleted( $field );
870  }
871 
877  public function getVisibility() {
878  return $this->mRecord->getVisibility();
879  }
880 
895  public function getContent( $audience = self::FOR_PUBLIC, User $user = null ) {
896  global $wgUser;
897 
898  if ( $audience === self::FOR_THIS_USER && !$user ) {
899  $user = $wgUser;
900  }
901 
902  try {
903  return $this->mRecord->getContent( 'main', $audience, $user );
904  }
905  catch ( RevisionAccessException $e ) {
906  return null;
907  }
908  }
909 
918  public function getSerializedData() {
919  $slot = $this->getMainSlotRaw();
920  return $slot->getContent()->serialize();
921  }
922 
935  public function getContentModel() {
936  return $this->getMainSlotRaw()->getModel();
937  }
938 
950  public function getContentFormat() {
951  $format = $this->getMainSlotRaw()->getFormat();
952 
953  if ( $format === null ) {
954  // if no format was stored along with the blob, fall back to default format
955  $format = $this->getContentHandler()->getDefaultFormat();
956  }
957 
958  return $format;
959  }
960 
967  public function getContentHandler() {
969  }
970 
974  public function getTimestamp() {
975  return $this->mRecord->getTimestamp();
976  }
977 
981  public function isCurrent() {
982  return ( $this->mRecord instanceof RevisionStoreRecord ) && $this->mRecord->isCurrent();
983  }
984 
990  public function getPrevious() {
991  $title = $this->getTitle();
992  $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord, $title );
993  return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
994  }
995 
1001  public function getNext() {
1002  $title = $this->getTitle();
1003  $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord, $title );
1004  return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
1005  }
1006 
1021  public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) {
1022  $textField = $prefix . 'text';
1023  $flagsField = $prefix . 'flags';
1024 
1025  if ( isset( $row->$flagsField ) ) {
1026  $flags = explode( ',', $row->$flagsField );
1027  } else {
1028  $flags = [];
1029  }
1030 
1031  if ( isset( $row->$textField ) ) {
1032  $text = $row->$textField;
1033  } else {
1034  return false;
1035  }
1036 
1037  $cacheKey = isset( $row->old_id )
1038  ? SqlBlobStore::makeAddressFromTextId( $row->old_id )
1039  : null;
1040 
1041  return self::getBlobStore( $wiki )->expandBlob( $text, $flags, $cacheKey );
1042  }
1043 
1054  public static function compressRevisionText( &$text ) {
1055  return self::getBlobStore()->compressData( $text );
1056  }
1057 
1065  public static function decompressRevisionText( $text, $flags ) {
1066  return self::getBlobStore()->decompressData( $text, $flags );
1067  }
1068 
1077  public function insertOn( $dbw ) {
1078  global $wgUser;
1079 
1080  // Note that $this->mRecord->getId() will typically return null here, but not always,
1081  // e.g. not when restoring a revision.
1082 
1083  if ( $this->mRecord->getUser( RevisionRecord::RAW ) === null ) {
1084  if ( $this->mRecord instanceof MutableRevisionRecord ) {
1085  $this->mRecord->setUser( $wgUser );
1086  } else {
1087  throw new MWException( 'Cannot insert revision with no associated user.' );
1088  }
1089  }
1090 
1091  $rec = self::getRevisionStore()->insertRevisionOn( $this->mRecord, $dbw );
1092 
1093  $this->mRecord = $rec;
1094 
1095  // Avoid PHP 7.1 warning of passing $this by reference
1096  $revision = $this;
1097  // TODO: hard-deprecate in 1.32 (or even 1.31?)
1098  Hooks::run( 'RevisionInsertComplete', [ &$revision, null, null ] );
1099 
1100  return $rec->getId();
1101  }
1102 
1108  public static function base36Sha1( $text ) {
1109  return SlotRecord::base36Sha1( $text );
1110  }
1111 
1127  public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
1128  global $wgUser;
1129  if ( !$user ) {
1130  $user = $wgUser;
1131  }
1132 
1133  $comment = CommentStoreComment::newUnsavedComment( $summary, null );
1134 
1136  if ( $title === null ) {
1137  return null;
1138  }
1139 
1140  $rec = self::getRevisionStore()->newNullRevision( $dbw, $title, $comment, $minor, $user );
1141 
1142  return new Revision( $rec );
1143  }
1144 
1155  public function userCan( $field, User $user = null ) {
1156  return self::userCanBitfield( $this->getVisibility(), $field, $user );
1157  }
1158 
1173  public static function userCanBitfield( $bitfield, $field, User $user = null,
1174  Title $title = null
1175  ) {
1176  global $wgUser;
1177 
1178  if ( !$user ) {
1179  $user = $wgUser;
1180  }
1181 
1182  return RevisionRecord::userCanBitfield( $bitfield, $field, $user, $title );
1183  }
1184 
1193  static function getTimestampFromId( $title, $id, $flags = 0 ) {
1194  return self::getRevisionStore()->getTimestampFromId( $title, $id, $flags );
1195  }
1196 
1204  static function countByPageId( $db, $id ) {
1205  return self::getRevisionStore()->countRevisionsByPageId( $db, $id );
1206  }
1207 
1215  static function countByTitle( $db, $title ) {
1216  return self::getRevisionStore()->countRevisionsByTitle( $db, $title );
1217  }
1218 
1235  public static function userWasLastToEdit( $db, $pageId, $userId, $since ) {
1236  if ( is_int( $db ) ) {
1237  $db = wfGetDB( $db );
1238  }
1239 
1240  return self::getRevisionStore()->userWasLastToEdit( $db, $pageId, $userId, $since );
1241  }
1242 
1256  public static function newKnownCurrent( IDatabase $db, $pageIdOrTitle, $revId = 0 ) {
1257  $title = $pageIdOrTitle instanceof Title
1258  ? $pageIdOrTitle
1259  : Title::newFromID( $pageIdOrTitle );
1260 
1261  if ( !$title ) {
1262  return false;
1263  }
1264 
1265  $record = self::getRevisionLookup()->getKnownCurrentRevision( $title, $revId );
1266  return $record ? new Revision( $record ) : false;
1267  }
1268 }
Service for storing and loading Content objects.
const FOR_THIS_USER
Definition: Revision.php:56
static newFromID($id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:416
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
the array() calling protocol came about after MediaWiki 1.4rc1.
static getRevisionText($row, $prefix= 'old_', $wiki=false)
Get revision text associated with an old or archive row.
Definition: Revision.php:1021
const TEXT_CACHE_GROUP
Definition: Revision.php:59
static fetchRevision(LinkTarget $title)
Return a wrapper for a series of database rows to fetch all of a given page's revisions in turn...
Definition: Revision.php:305
setTitle($title)
Set the title of the revision.
Definition: Revision.php:746
getRevisionRecord()
Definition: Revision.php:608
getPage()
Get the page ID.
Definition: Revision.php:761
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getTimestamp()
Definition: Revision.php:974
static getForModelID($modelId)
Returns the ContentHandler singleton for the given model ID.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
Definition: hooks.txt:2195
setUserIdAndName($id, $name)
Set the user ID/name.
Definition: Revision.php:655
static getTimestampFromId($title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
Definition: Revision.php:1193
static getRevisionLookup()
Definition: Revision.php:71
const NS_SPECIAL
Definition: Defines.php:54
static newUnsavedComment($comment, array $data=null)
Create a new, unsaved CommentStoreComment.
ensureTitle($row, $queryFlags, $title=null)
Make sure we have some Title object for use by the constructor.
Definition: Revision.php:570
const MIGRATION_WRITE_BOTH
Definition: Defines.php:294
Page revision base class.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
isUnpatrolled()
Definition: Revision.php:846
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
Definition: Revision.php:397
static newFromPageId($pageId, $revId=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given page ID...
Definition: Revision.php:152
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:244
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target...
Definition: Revision.php:133
getSerializedData()
Get original serialized data (without checking view restrictions)
Definition: Revision.php:918
static getQueryInfo($options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:492
getMainSlotRaw()
Definition: Revision.php:667
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:46
RevisionRecord $mRecord
Definition: Revision.php:44
isDeleted($field)
Definition: Revision.php:868
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:734
getParentId()
Get parent revision ID (the original previous page revision)
Definition: Revision.php:696
const FOR_PUBLIC
Definition: Revision.php:55
getUserText($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
Definition: Revision.php:802
static newKnownCurrent(IDatabase $db, $pageIdOrTitle, $revId=0)
Load a revision based on a known page ID and current revision ID from the DB.
Definition: Revision.php:1256
getId()
Get revision ID.
Definition: Revision.php:617
static loadFromTimestamp($db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition: Revision.php:291
getContentHandler()
Returns the content handler appropriate for this revision's content model.
Definition: Revision.php:967
static newNullRevision($dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1127
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:54
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
Definition: Revision.php:1054
static getRevisionFactory()
Definition: Revision.php:78
Mutable RevisionRecord implementation, for building new revision entries programmatically.
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 & $options
Definition: hooks.txt:2019
__construct($row, $queryFlags=0, Title $title=null)
Definition: Revision.php:530
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:351
static selectTextFields()
Return the list of text fields that should be selected to read the revision text. ...
Definition: Revision.php:443
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
userCan($field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision, if it's marked as deleted.
Definition: Revision.php:1155
getComment($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
Definition: Revision.php:825
Exception representing a failure to look up a revision.
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:562
const DELETED_RESTRICTED
Definition: Revision.php:50
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
Definition: Revision.php:506
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:941
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:203
static loadFromTitle($db, $title, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
Definition: Revision.php:273
getPrevious()
Get previous revision for this title.
Definition: Revision.php:990
setId($id)
Set the revision ID.
Definition: Revision.php:633
const RAW
Definition: Revision.php:57
static newFromAnyId($userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:651
getRecentChange($flags=0)
Get the RC object belonging to the current revision, if there's one.
Definition: Revision.php:859
getContentModel()
Returns the content model for the main slot of this revision.
Definition: Revision.php:935
static getRevisionStore()
Definition: Revision.php:64
const DELETED_TEXT
Definition: Revision.php:47
const SUPPRESSED_USER
Definition: Revision.php:51
static countByPageId($db, $id)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1204
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:114
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:340
A RevisionRecord representing an existing revision persisted in the revision table.
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:877
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
const DELETED_USER
Definition: Revision.php:49
static getStore()
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
getTextId()
Get the ID of the row of the text table that contains the content of the revision's main slot...
Definition: Revision.php:683
insertOn($dbw)
Insert a new revision into the database, returning the new revision ID number on success and dies hor...
Definition: Revision.php:1077
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
static countByTitle($db, $title)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1215
getContent($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
Definition: Revision.php:895
static newFromRow($row)
Definition: Revision.php:218
static loadFromPageId($db, $pageid, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
Definition: Revision.php:256
getNext()
Get next revision for this title.
Definition: Revision.php:1001
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
static getParentLengths($db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:519
static base36Sha1($text)
Get the base 36 SHA-1 value for a string of text.
Definition: Revision.php:1108
getUser($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
Definition: Revision.php:778
static selectPageFields()
Return the list of page fields that should be selected from page table.
Definition: Revision.php:456
static userCanBitfield($bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision, if it's marked as deleted.
Definition: Revision.php:1173
wfLogWarning($msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
const DELETED_COMMENT
Definition: Revision.php:48
static userWasLastToEdit($db, $pageId, $userId, $since)
Check if no edits were made by other users since the time a user started editing the page...
Definition: Revision.php:1235
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:317
getContentFormat()
Returns the content format for the main slot of this revision.
Definition: Revision.php:950
static loadFromId($db, $id)
Load a page revision from a given revision ID number.
Definition: Revision.php:238
static newFromArchiveRow($row, $overrides=[])
Make a fake revision object from an archive table row.
Definition: Revision.php:167
static getBlobStore($wiki=false)
Definition: Revision.php:87
getSize()
Returns the length of the text in this revision, or null if unknown.
Definition: Revision.php:705
static decompressRevisionText($text, $flags)
Re-converts revision text according to it's flags.
Definition: Revision.php:1065
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:473
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:534
getSha1()
Returns the base36 sha1 of the content in this revision, or null if unknown.
Definition: Revision.php:718
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:244
const SUPPRESSED_ALL
Definition: Revision.php:52
isCurrent()
Definition: Revision.php:981