MediaWiki  1.32.0
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
53 
54  // Audience options for accessors
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() {
319 
320  wfDeprecated( __METHOD__, '1.31' );
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 used anymore.
325  throw new BadMethodCallException(
326  'Cannot use ' . __METHOD__
327  . ' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
328  );
329  }
330 
331  return [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ];
332  }
333 
341  public static function pageJoinCond() {
342  wfDeprecated( __METHOD__, '1.31' );
343  return [ 'INNER JOIN', [ 'page_id = rev_page' ] ];
344  }
345 
352  public static function selectFields() {
355 
357  // If code is using this instead of self::getQueryInfo(), there's a
358  // decent chance it's going to try to directly access
359  // $row->rev_user or $row->rev_user_text and we can't give it
360  // useful values here once those aren't being used anymore.
361  throw new BadMethodCallException(
362  'Cannot use ' . __METHOD__
363  . ' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
364  );
365  }
366 
368  // If code is using this instead of self::getQueryInfo(), there's a
369  // decent chance it's going to try to directly access
370  // $row->rev_text_id or $row->rev_content_model and we can't give it
371  // useful values here once those aren't being written anymore,
372  // and may not exist at all.
373  throw new BadMethodCallException(
374  'Cannot use ' . __METHOD__ . ' when $wgMultiContentRevisionSchemaMigrationStage '
375  . 'does not have SCHEMA_COMPAT_WRITE_OLD set.'
376  );
377  }
378 
379  wfDeprecated( __METHOD__, '1.31' );
380 
381  $fields = [
382  'rev_id',
383  'rev_page',
384  'rev_text_id',
385  'rev_timestamp',
386  'rev_user_text',
387  'rev_user',
388  'rev_actor' => 'NULL',
389  'rev_minor_edit',
390  'rev_deleted',
391  'rev_len',
392  'rev_parent_id',
393  'rev_sha1',
394  ];
395 
396  $fields += CommentStore::getStore()->getFields( 'rev_comment' );
397 
398  if ( $wgContentHandlerUseDB ) {
399  $fields[] = 'rev_content_format';
400  $fields[] = 'rev_content_model';
401  }
402 
403  return $fields;
404  }
405 
412  public static function selectArchiveFields() {
415 
417  // If code is using this instead of self::getQueryInfo(), there's a
418  // decent chance it's going to try to directly access
419  // $row->ar_user or $row->ar_user_text and we can't give it
420  // useful values here once those aren't being used anymore.
421  throw new BadMethodCallException(
422  'Cannot use ' . __METHOD__
423  . ' when $wgActorTableSchemaMigrationStage has SCHEMA_COMPAT_READ_NEW'
424  );
425  }
426 
428  // If code is using this instead of self::getQueryInfo(), there's a
429  // decent chance it's going to try to directly access
430  // $row->ar_text_id or $row->ar_content_model and we can't give it
431  // useful values here once those aren't being written anymore,
432  // and may not exist at all.
433  throw new BadMethodCallException(
434  'Cannot use ' . __METHOD__ . ' when $wgMultiContentRevisionSchemaMigrationStage '
435  . 'does not have SCHEMA_COMPAT_WRITE_OLD set.'
436  );
437  }
438 
439  wfDeprecated( __METHOD__, '1.31' );
440 
441  $fields = [
442  'ar_id',
443  'ar_page_id',
444  'ar_rev_id',
445  'ar_text_id',
446  'ar_timestamp',
447  'ar_user_text',
448  'ar_user',
449  'ar_actor' => 'NULL',
450  'ar_minor_edit',
451  'ar_deleted',
452  'ar_len',
453  'ar_parent_id',
454  'ar_sha1',
455  ];
456 
457  $fields += CommentStore::getStore()->getFields( 'ar_comment' );
458 
459  if ( $wgContentHandlerUseDB ) {
460  $fields[] = 'ar_content_format';
461  $fields[] = 'ar_content_model';
462  }
463  return $fields;
464  }
465 
472  public static function selectTextFields() {
473  wfDeprecated( __METHOD__, '1.31' );
474  return [
475  'old_text',
476  'old_flags'
477  ];
478  }
479 
485  public static function selectPageFields() {
486  wfDeprecated( __METHOD__, '1.31' );
487  return [
488  'page_namespace',
489  'page_title',
490  'page_id',
491  'page_latest',
492  'page_is_redirect',
493  'page_len',
494  ];
495  }
496 
502  public static function selectUserFields() {
503  wfDeprecated( __METHOD__, '1.31' );
504  return [ 'user_name' ];
505  }
506 
521  public static function getQueryInfo( $options = [] ) {
522  return self::getRevisionStore()->getQueryInfo( $options );
523  }
524 
535  public static function getArchiveQueryInfo() {
536  return self::getRevisionStore()->getArchiveQueryInfo();
537  }
538 
548  public static function getParentLengths( $db, array $revIds ) {
549  return self::getRevisionStore()->listRevisionSizes( $db, $revIds );
550  }
551 
559  function __construct( $row, $queryFlags = 0, Title $title = null ) {
560  global $wgUser;
561 
562  if ( $row instanceof RevisionRecord ) {
563  $this->mRecord = $row;
564  } elseif ( is_array( $row ) ) {
565  // If no user is specified, fall back to using the global user object, to stay
566  // compatible with pre-1.31 behavior.
567  if ( !isset( $row['user'] ) && !isset( $row['user_text'] ) ) {
568  $row['user'] = $wgUser;
569  }
570 
571  $this->mRecord = self::getRevisionFactory()->newMutableRevisionFromArray(
572  $row,
573  $queryFlags,
574  $this->ensureTitle( $row, $queryFlags, $title )
575  );
576  } elseif ( is_object( $row ) ) {
577  $this->mRecord = self::getRevisionFactory()->newRevisionFromRow(
578  $row,
579  $queryFlags,
580  $this->ensureTitle( $row, $queryFlags, $title )
581  );
582  } else {
583  throw new InvalidArgumentException(
584  '$row must be a row object, an associative array, or a RevisionRecord'
585  );
586  }
587  }
588 
599  private function ensureTitle( $row, $queryFlags, $title = null ) {
600  if ( $title ) {
601  return $title;
602  }
603 
604  if ( is_array( $row ) ) {
605  if ( isset( $row['title'] ) ) {
606  if ( !( $row['title'] instanceof Title ) ) {
607  throw new MWException( 'title field must contain a Title object.' );
608  }
609 
610  return $row['title'];
611  }
612 
613  $pageId = $row['page'] ?? 0;
614  $revId = $row['id'] ?? 0;
615  } else {
616  $pageId = $row->rev_page ?? 0;
617  $revId = $row->rev_id ?? 0;
618  }
619 
620  try {
621  $title = self::getRevisionStore()->getTitle( $pageId, $revId, $queryFlags );
622  } catch ( RevisionAccessException $ex ) {
623  // construct a dummy title!
624  wfLogWarning( __METHOD__ . ': ' . $ex->getMessage() );
625 
626  // NOTE: this Title will only be used inside RevisionRecord
627  $title = Title::makeTitleSafe( NS_SPECIAL, "Badtitle/ID=$pageId" );
628  $title->resetArticleID( $pageId );
629  }
630 
631  return $title;
632  }
633 
637  public function getRevisionRecord() {
638  return $this->mRecord;
639  }
640 
646  public function getId() {
647  return $this->mRecord->getId();
648  }
649 
662  public function setId( $id ) {
663  if ( $this->mRecord instanceof MutableRevisionRecord ) {
664  $this->mRecord->setId( intval( $id ) );
665  } else {
666  throw new MWException( __METHOD__ . ' is not supported on this instance' );
667  }
668  }
669 
684  public function setUserIdAndName( $id, $name ) {
685  if ( $this->mRecord instanceof MutableRevisionRecord ) {
686  $user = User::newFromAnyId( intval( $id ), $name, null );
687  $this->mRecord->setUser( $user );
688  } else {
689  throw new MWException( __METHOD__ . ' is not supported on this instance' );
690  }
691  }
692 
696  private function getMainSlotRaw() {
697  return $this->mRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
698  }
699 
712  public function getTextId() {
713  $slot = $this->getMainSlotRaw();
714  return $slot->hasAddress()
715  ? self::getBlobStore()->getTextIdFromAddress( $slot->getAddress() )
716  : null;
717  }
718 
725  public function getParentId() {
726  return $this->mRecord->getParentId();
727  }
728 
734  public function getSize() {
735  try {
736  return $this->mRecord->getSize();
737  } catch ( RevisionAccessException $ex ) {
738  return null;
739  }
740  }
741 
747  public function getSha1() {
748  try {
749  return $this->mRecord->getSha1();
750  } catch ( RevisionAccessException $ex ) {
751  return null;
752  }
753  }
754 
763  public function getTitle() {
764  $linkTarget = $this->mRecord->getPageAsLinkTarget();
765  return Title::newFromLinkTarget( $linkTarget );
766  }
767 
775  public function setTitle( $title ) {
776  if ( !$title->equals( $this->getTitle() ) ) {
777  throw new InvalidArgumentException(
778  $title->getPrefixedText()
779  . ' is not the same as '
780  . $this->mRecord->getPageAsLinkTarget()->__toString()
781  );
782  }
783  }
784 
790  public function getPage() {
791  return $this->mRecord->getPageId();
792  }
793 
807  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
808  global $wgUser;
809 
810  if ( $audience === self::FOR_THIS_USER && !$user ) {
811  $user = $wgUser;
812  }
813 
814  $user = $this->mRecord->getUser( $audience, $user );
815  return $user ? $user->getId() : 0;
816  }
817 
831  public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) {
832  global $wgUser;
833 
834  if ( $audience === self::FOR_THIS_USER && !$user ) {
835  $user = $wgUser;
836  }
837 
838  $user = $this->mRecord->getUser( $audience, $user );
839  return $user ? $user->getName() : '';
840  }
854  function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
855  global $wgUser;
856 
857  if ( $audience === self::FOR_THIS_USER && !$user ) {
858  $user = $wgUser;
859  }
860 
861  $comment = $this->mRecord->getComment( $audience, $user );
862  return $comment === null ? null : $comment->text;
863  }
864 
868  public function isMinor() {
869  return $this->mRecord->isMinor();
870  }
871 
875  public function isUnpatrolled() {
876  return self::getRevisionStore()->getRcIdIfUnpatrolled( $this->mRecord );
877  }
878 
888  public function getRecentChange( $flags = 0 ) {
889  return self::getRevisionStore()->getRecentChange( $this->mRecord, $flags );
890  }
891 
897  public function isDeleted( $field ) {
898  return $this->mRecord->isDeleted( $field );
899  }
900 
906  public function getVisibility() {
907  return $this->mRecord->getVisibility();
908  }
909 
924  public function getContent( $audience = self::FOR_PUBLIC, User $user = null ) {
925  global $wgUser;
926 
927  if ( $audience === self::FOR_THIS_USER && !$user ) {
928  $user = $wgUser;
929  }
930 
931  try {
932  return $this->mRecord->getContent( SlotRecord::MAIN, $audience, $user );
933  }
934  catch ( RevisionAccessException $e ) {
935  return null;
936  }
937  }
938 
947  public function getSerializedData() {
948  $slot = $this->getMainSlotRaw();
949  return $slot->getContent()->serialize();
950  }
951 
964  public function getContentModel() {
965  return $this->getMainSlotRaw()->getModel();
966  }
967 
979  public function getContentFormat() {
980  $format = $this->getMainSlotRaw()->getFormat();
981 
982  if ( $format === null ) {
983  // if no format was stored along with the blob, fall back to default format
984  $format = $this->getContentHandler()->getDefaultFormat();
985  }
986 
987  return $format;
988  }
989 
996  public function getContentHandler() {
998  }
999 
1003  public function getTimestamp() {
1004  return $this->mRecord->getTimestamp();
1005  }
1006 
1010  public function isCurrent() {
1011  return ( $this->mRecord instanceof RevisionStoreRecord ) && $this->mRecord->isCurrent();
1012  }
1013 
1019  public function getPrevious() {
1020  $title = $this->getTitle();
1021  $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord, $title );
1022  return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
1023  }
1024 
1030  public function getNext() {
1031  $title = $this->getTitle();
1032  $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord, $title );
1033  return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
1034  }
1035 
1050  public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) {
1051  $textField = $prefix . 'text';
1052  $flagsField = $prefix . 'flags';
1053 
1054  if ( isset( $row->$flagsField ) ) {
1055  $flags = explode( ',', $row->$flagsField );
1056  } else {
1057  $flags = [];
1058  }
1059 
1060  if ( isset( $row->$textField ) ) {
1061  $text = $row->$textField;
1062  } else {
1063  return false;
1064  }
1065 
1066  $cacheKey = isset( $row->old_id )
1067  ? SqlBlobStore::makeAddressFromTextId( $row->old_id )
1068  : null;
1069 
1070  $revisionText = self::getBlobStore( $wiki )->expandBlob( $text, $flags, $cacheKey );
1071 
1072  if ( $revisionText === false ) {
1073  if ( isset( $row->old_id ) ) {
1074  wfLogWarning( __METHOD__ . ": Bad data in text row {$row->old_id}! " );
1075  } else {
1076  wfLogWarning( __METHOD__ . ": Bad data in text row! " );
1077  }
1078  return false;
1079  }
1080 
1081  return $revisionText;
1082  }
1083 
1094  public static function compressRevisionText( &$text ) {
1095  return self::getBlobStore()->compressData( $text );
1096  }
1097 
1105  public static function decompressRevisionText( $text, $flags ) {
1106  if ( $text === false ) {
1107  // Text failed to be fetched; nothing to do
1108  return false;
1109  }
1110 
1111  return self::getBlobStore()->decompressData( $text, $flags );
1112  }
1113 
1122  public function insertOn( $dbw ) {
1123  global $wgUser;
1124 
1125  // Note that $this->mRecord->getId() will typically return null here, but not always,
1126  // e.g. not when restoring a revision.
1127 
1128  if ( $this->mRecord->getUser( RevisionRecord::RAW ) === null ) {
1129  if ( $this->mRecord instanceof MutableRevisionRecord ) {
1130  $this->mRecord->setUser( $wgUser );
1131  } else {
1132  throw new MWException( 'Cannot insert revision with no associated user.' );
1133  }
1134  }
1135 
1136  $rec = self::getRevisionStore()->insertRevisionOn( $this->mRecord, $dbw );
1137 
1138  $this->mRecord = $rec;
1139 
1140  // Avoid PHP 7.1 warning of passing $this by reference
1141  $revision = $this;
1142 
1143  return $rec->getId();
1144  }
1145 
1151  public static function base36Sha1( $text ) {
1152  return SlotRecord::base36Sha1( $text );
1153  }
1154 
1170  public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
1171  global $wgUser;
1172  if ( !$user ) {
1173  $user = $wgUser;
1174  }
1175 
1176  $comment = CommentStoreComment::newUnsavedComment( $summary, null );
1177 
1179  if ( $title === null ) {
1180  return null;
1181  }
1182 
1183  $rec = self::getRevisionStore()->newNullRevision( $dbw, $title, $comment, $minor, $user );
1184 
1185  return $rec ? new Revision( $rec ) : null;
1186  }
1187 
1198  public function userCan( $field, User $user = null ) {
1199  return self::userCanBitfield( $this->getVisibility(), $field, $user );
1200  }
1201 
1216  public static function userCanBitfield( $bitfield, $field, User $user = null,
1217  Title $title = null
1218  ) {
1219  global $wgUser;
1220 
1221  if ( !$user ) {
1222  $user = $wgUser;
1223  }
1224 
1225  return RevisionRecord::userCanBitfield( $bitfield, $field, $user, $title );
1226  }
1227 
1236  static function getTimestampFromId( $title, $id, $flags = 0 ) {
1237  return self::getRevisionStore()->getTimestampFromId( $title, $id, $flags );
1238  }
1239 
1247  static function countByPageId( $db, $id ) {
1248  return self::getRevisionStore()->countRevisionsByPageId( $db, $id );
1249  }
1250 
1258  static function countByTitle( $db, $title ) {
1259  return self::getRevisionStore()->countRevisionsByTitle( $db, $title );
1260  }
1261 
1278  public static function userWasLastToEdit( $db, $pageId, $userId, $since ) {
1279  if ( is_int( $db ) ) {
1280  $db = wfGetDB( $db );
1281  }
1282 
1283  return self::getRevisionStore()->userWasLastToEdit( $db, $pageId, $userId, $since );
1284  }
1285 
1299  public static function newKnownCurrent( IDatabase $db, $pageIdOrTitle, $revId = 0 ) {
1300  $title = $pageIdOrTitle instanceof Title
1301  ? $pageIdOrTitle
1302  : Title::newFromID( $pageIdOrTitle );
1303 
1304  if ( !$title ) {
1305  return false;
1306  }
1307 
1308  $record = self::getRevisionLookup()->getKnownCurrentRevision( $title, $revId );
1309  return $record ? new Revision( $record ) : false;
1310  }
1311 }
Revision\FOR_PUBLIC
const FOR_PUBLIC
Definition: Revision.php:55
Revision\newFromArchiveRow
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
Definition: Revision.php:167
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:49
Revision\getTimestamp
getTimestamp()
Definition: Revision.php:1003
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:297
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:66
$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
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:50
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:33
Revision\newKnownCurrent
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:1299
Revision\getUserText
getUserText( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
Definition: Revision.php:831
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:45
Revision\SUPPRESSED_ALL
const SUPPRESSED_ALL
Definition: Revision.php:52
SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_NEW
Definition: Defines.php:287
Revision\DELETED_COMMENT
const DELETED_COMMENT
Definition: Revision.php:48
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:114
Revision\pageJoinCond
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:341
Revision\getUser
getUser( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
Definition: Revision.php:807
Revision\userCanBitfield
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,...
Definition: Revision.php:1216
Revision\getSize
getSize()
Returns the length of the text in this revision, or null if unknown.
Definition: Revision.php:734
Revision\RevisionStore
Service for looking up page revisions.
Definition: RevisionStore.php:76
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects.
Definition: SqlBlobStore.php:50
Revision\setId
setId( $id)
Set the revision ID.
Definition: Revision.php:662
Revision\getContent
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
Definition: Revision.php:924
Revision\getPage
getPage()
Get the page ID.
Definition: Revision.php:790
Revision\getBlobStore
static getBlobStore( $wiki=false)
Definition: Revision.php:87
$wgMultiContentRevisionSchemaMigrationStage
int $wgMultiContentRevisionSchemaMigrationStage
RevisionStore table schema migration stage (content, slots, content_models & slot_roles tables).
Definition: DefaultSettings.php:8988
Revision\getRevisionText
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
Definition: Revision.php:1050
Revision\getParentId
getParentId()
Get parent revision ID (the original previous page revision)
Definition: Revision.php:725
Revision\setTitle
setTitle( $title)
Set the title of the revision.
Definition: Revision.php:775
Revision\getContentHandler
getContentHandler()
Returns the content handler appropriate for this revision's content model.
Definition: Revision.php:996
User\newFromAnyId
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Definition: User.php:682
Revision\RevisionFactory
Service for constructing revision objects.
Definition: RevisionFactory.php:37
Revision\getArchiveQueryInfo
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
Definition: Revision.php:535
Revision\getSerializedData
getSerializedData()
Get original serialized data (without checking view restrictions)
Definition: Revision.php:947
wfLogWarning
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
Definition: GlobalFunctions.php:1145
Revision\getRecentChange
getRecentChange( $flags=0)
Get the RC object belonging to the current revision, if there's one.
Definition: Revision.php:888
Revision\TEXT_CACHE_GROUP
const TEXT_CACHE_GROUP
Definition: Revision.php:59
Revision\isCurrent
isCurrent()
Definition: Revision.php:1010
Wikimedia\Rdbms\ResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: ResultWrapper.php:24
Revision\newFromPageId
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
Revision\getSha1
getSha1()
Returns the base36 sha1 of the content in this revision, or null if unknown.
Definition: Revision.php:747
Revision\loadFromId
static loadFromId( $db, $id)
Load a page revision from a given revision ID number.
Definition: Revision.php:238
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:55
Revision\getId
getId()
Get revision ID.
Definition: Revision.php:646
Revision\getContentModel
getContentModel()
Returns the content model for the main slot of this revision.
Definition: Revision.php:964
Wikimedia\Rdbms\FakeResultWrapper
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Definition: FakeResultWrapper.php:11
$wgContentHandlerUseDB
$wgContentHandlerUseDB
Set to false to disable use of the database fields introduced by the ContentHandler facility.
Definition: DefaultSettings.php:8624
Revision\getRevisionStore
static getRevisionStore()
Definition: Revision.php:64
Revision\insertOn
insertOn( $dbw)
Insert a new revision into the database, returning the new revision ID number on success and dies hor...
Definition: Revision.php:1122
Revision\getRevisionFactory
static getRevisionFactory()
Definition: Revision.php:78
Revision\base36Sha1
static base36Sha1( $text)
Get the base 36 SHA-1 value for a string of text.
Definition: Revision.php:1151
Revision\RevisionLookup
Service for looking up page revisions.
Definition: RevisionLookup.php:38
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
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Revision\selectTextFields
static selectTextFields()
Return the list of text fields that should be selected to read the revision text.
Definition: Revision.php:472
Revision\FOR_THIS_USER
const FOR_THIS_USER
Definition: Revision.php:56
Revision
Definition: Revision.php:41
Revision\newFromTitle
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
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
Revision\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: Revision.php:51
Revision\getQueryInfo
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition: Revision.php:521
MWException
MediaWiki exception.
Definition: MWException.php:26
Revision\getNext
getNext()
Get next revision for this title.
Definition: Revision.php:1030
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1118
Revision\setUserIdAndName
setUserIdAndName( $id, $name)
Set the user ID/name.
Definition: Revision.php:684
Revision\getTimestampFromId
static getTimestampFromId( $title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
Definition: Revision.php:1236
Title\newFromLinkTarget
static newFromLinkTarget(LinkTarget $linkTarget)
Create a new Title from a LinkTarget.
Definition: Title.php:251
Revision\isUnpatrolled
isUnpatrolled()
Definition: Revision.php:875
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
Revision\loadFromPageId
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
Revision\compressRevisionText
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
Definition: Revision.php:1094
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
Revision\RevisionRecord\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: RevisionRecord.php:508
Revision\RevisionRecord\RAW
const RAW
Definition: RevisionRecord.php:59
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:545
Revision\SlotRecord\base36Sha1
static base36Sha1( $blob)
Get the base 36 SHA-1 value for a string of text.
Definition: SlotRecord.php:609
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
Revision\countByTitle
static countByTitle( $db, $title)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1258
Revision\getPrevious
getPrevious()
Get previous revision for this title.
Definition: Revision.php:1019
Revision\countByPageId
static countByPageId( $db, $id)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1247
Revision\selectPageFields
static selectPageFields()
Return the list of page fields that should be selected from page table.
Definition: Revision.php:485
Revision\ensureTitle
ensureTitle( $row, $queryFlags, $title=null)
Make sure we have some Title object for use by the constructor.
Definition: Revision.php:599
Revision\getTitle
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:763
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
Revision\userWasLastToEdit
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:1278
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:573
Revision\RevisionRecord\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: RevisionRecord.php:52
Revision\selectArchiveFields
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
Definition: Revision.php:412
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2213
Revision\RevisionRecord\DELETED_USER
const DELETED_USER
Definition: RevisionRecord.php:50
Revision\$mRecord
RevisionRecord $mRecord
Definition: Revision.php:44
Revision\MutableRevisionRecord
Mutable RevisionRecord implementation, for building new revision entries programmatically.
Definition: MutableRevisionRecord.php:41
Revision\getParentLengths
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:548
Revision\getVisibility
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:906
Revision\getTextId
getTextId()
Get the ID of the row of the text table that contains the content of the revision's main slot,...
Definition: Revision.php:712
SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_WRITE_OLD
Definition: Defines.php:284
Title\GAID_FOR_UPDATE
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:54
Revision\isDeleted
isDeleted( $field)
Definition: Revision.php:897
Revision\newFromRow
static newFromRow( $row)
Definition: Revision.php:218
Revision\RAW
const RAW
Definition: Revision.php:57
Revision\RevisionStoreRecord
A RevisionRecord representing an existing revision persisted in the revision table.
Definition: RevisionStoreRecord.php:39
Revision\SlotRecord\MAIN
const MAIN
Definition: SlotRecord.php:41
Revision\getMainSlotRaw
getMainSlotRaw()
Definition: Revision.php:696
Revision\getContentFormat
getContentFormat()
Returns the content format for the main slot of this revision.
Definition: Revision.php:979
Revision\fetchRevision
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
Revision\RevisionRecord\FOR_PUBLIC
const FOR_PUBLIC
Definition: RevisionRecord.php:57
Title
Represents a title within MediaWiki.
Definition: Title.php:39
Revision\RevisionRecord\DELETED_COMMENT
const DELETED_COMMENT
Definition: RevisionRecord.php:49
$options
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:2036
Revision\RevisionRecord\DELETED_TEXT
const DELETED_TEXT
Definition: RevisionRecord.php:48
Revision\userJoinCond
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:317
Revision\loadFromTimestamp
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition: Revision.php:291
Revision\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
Definition: Revision.php:854
Revision\newNullRevision
static newNullRevision( $dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1170
Revision\__construct
__construct( $row, $queryFlags=0, Title $title=null)
Definition: Revision.php:559
Revision\isMinor
isMinor()
Definition: Revision.php:868
Revision\selectUserFields
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:502
Revision\RevisionRecord\SUPPRESSED_ALL
const SUPPRESSED_ALL
Definition: RevisionRecord.php:53
Revision\RevisionRecord\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: RevisionRecord.php:51
MediaWikiServices
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
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
Revision\getRevisionRecord
getRevisionRecord()
Definition: Revision.php:637
Revision\selectFields
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:352
Revision\decompressRevisionText
static decompressRevisionText( $text, $flags)
Re-converts revision text according to it's flags.
Definition: Revision.php:1105
Revision\loadFromTitle
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
CommentStore\getStore
static getStore()
Definition: CommentStore.php:125
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:47
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:427
Revision\RevisionRecord\FOR_THIS_USER
const FOR_THIS_USER
Definition: RevisionRecord.php:58
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:47
Revision\userCan
userCan( $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1198
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39
Revision\getRevisionLookup
static getRevisionLookup()
Definition: Revision.php:71
$wgActorTableSchemaMigrationStage
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
Definition: DefaultSettings.php:9006