MediaWiki  master
Revision.php
Go to the documentation of this file.
1 <?php
36 
40 class Revision implements IDBAccessObject {
41 
43  protected $mRecord;
44 
45  // Revision deletion constants
46  const DELETED_TEXT = RevisionRecord::DELETED_TEXT;
47  const DELETED_COMMENT = RevisionRecord::DELETED_COMMENT;
48  const DELETED_USER = RevisionRecord::DELETED_USER;
49  const DELETED_RESTRICTED = RevisionRecord::DELETED_RESTRICTED;
50  const SUPPRESSED_USER = RevisionRecord::SUPPRESSED_USER;
51  const SUPPRESSED_ALL = RevisionRecord::SUPPRESSED_ALL;
52 
53  // Audience options for accessors
54  const FOR_PUBLIC = RevisionRecord::FOR_PUBLIC;
55  const FOR_THIS_USER = RevisionRecord::FOR_THIS_USER;
56  const RAW = RevisionRecord::RAW;
57 
58  const TEXT_CACHE_GROUP = SqlBlobStore::TEXT_CACHE_GROUP;
59 
63  protected static function getRevisionStore() {
64  return MediaWikiServices::getInstance()->getRevisionStore();
65  }
66 
72  protected static function getBlobStore( $wiki = false ) {
73  $store = MediaWikiServices::getInstance()
74  ->getBlobStoreFactory()
75  ->newSqlBlobStore( $wiki );
76 
77  if ( !$store instanceof SqlBlobStore ) {
78  throw new RuntimeException(
79  'The backwards compatibility code in Revision currently requires the BlobStore '
80  . 'service to be an SqlBlobStore instance, but it is a ' . get_class( $store )
81  );
82  }
83 
84  return $store;
85  }
86 
99  public static function newFromId( $id, $flags = 0 ) {
100  $rec = self::getRevisionStore()->getRevisionById( $id, $flags );
101  return $rec === null ? null : new Revision( $rec, $flags );
102  }
103 
118  public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0 ) {
119  $rec = self::getRevisionStore()->getRevisionByTitle( $linkTarget, $id, $flags );
120  return $rec === null ? null : new Revision( $rec, $flags );
121  }
122 
137  public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) {
138  $rec = self::getRevisionStore()->getRevisionByPageId( $pageId, $revId, $flags );
139  return $rec === null ? null : new Revision( $rec, $flags );
140  }
141 
152  public static function newFromArchiveRow( $row, $overrides = [] ) {
159  if ( array_key_exists( 'page', $overrides ) ) {
160  $overrides['page_id'] = $overrides['page'];
161  unset( $overrides['page'] );
162  }
163 
169  $title = null;
170  if ( isset( $overrides['title'] ) ) {
171  if ( !( $overrides['title'] instanceof Title ) ) {
172  throw new MWException( 'title field override must contain a Title object.' );
173  }
174 
175  $title = $overrides['title'];
176  }
177  if ( $title !== null ) {
178  if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
179  $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
180  } else {
181  throw new InvalidArgumentException(
182  'A Title or ar_namespace and ar_title must be given'
183  );
184  }
185  }
186 
187  $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
188  return new Revision( $rec, self::READ_NORMAL, $title );
189  }
190 
203  public static function newFromRow( $row ) {
204  if ( is_array( $row ) ) {
205  $rec = self::getRevisionStore()->newMutableRevisionFromArray( $row );
206  } else {
207  $rec = self::getRevisionStore()->newRevisionFromRow( $row );
208  }
209 
210  return new Revision( $rec );
211  }
212 
223  public static function loadFromId( $db, $id ) {
224  wfDeprecated( __METHOD__, '1.31' ); // no known callers
225  $rec = self::getRevisionStore()->loadRevisionFromId( $db, $id );
226  return $rec === null ? null : new Revision( $rec );
227  }
228 
241  public static function loadFromPageId( $db, $pageid, $id = 0 ) {
242  $rec = self::getRevisionStore()->loadRevisionFromPageId( $db, $pageid, $id );
243  return $rec === null ? null : new Revision( $rec );
244  }
245 
258  public static function loadFromTitle( $db, $title, $id = 0 ) {
259  $rec = self::getRevisionStore()->loadRevisionFromTitle( $db, $title, $id );
260  return $rec === null ? null : new Revision( $rec );
261  }
262 
276  public static function loadFromTimestamp( $db, $title, $timestamp ) {
277  $rec = self::getRevisionStore()->loadRevisionFromTimestamp( $db, $title, $timestamp );
278  return $rec === null ? null : new Revision( $rec );
279  }
280 
290  public static function fetchRevision( LinkTarget $title ) {
291  wfDeprecated( __METHOD__, '1.31' );
292  return new FakeResultWrapper( [] );
293  }
294 
302  public static function userJoinCond() {
303  wfDeprecated( __METHOD__, '1.31' );
304  return [ 'LEFT JOIN', [ 'rev_user != 0', 'user_id = rev_user' ] ];
305  }
306 
314  public static function pageJoinCond() {
315  wfDeprecated( __METHOD__, '1.31' );
316  return [ 'INNER JOIN', [ 'page_id = rev_page' ] ];
317  }
318 
325  public static function selectFields() {
326  global $wgContentHandlerUseDB;
327 
328  wfDeprecated( __METHOD__, '1.31' );
329 
330  $fields = [
331  'rev_id',
332  'rev_page',
333  'rev_text_id',
334  'rev_timestamp',
335  'rev_user_text',
336  'rev_user',
337  'rev_minor_edit',
338  'rev_deleted',
339  'rev_len',
340  'rev_parent_id',
341  'rev_sha1',
342  ];
343 
344  $fields += CommentStore::newKey( 'rev_comment' )->getFields();
345 
346  if ( $wgContentHandlerUseDB ) {
347  $fields[] = 'rev_content_format';
348  $fields[] = 'rev_content_model';
349  }
350 
351  return $fields;
352  }
353 
360  public static function selectArchiveFields() {
361  global $wgContentHandlerUseDB;
362 
363  wfDeprecated( __METHOD__, '1.31' );
364 
365  $fields = [
366  'ar_id',
367  'ar_page_id',
368  'ar_rev_id',
369  'ar_text',
370  'ar_text_id',
371  'ar_timestamp',
372  'ar_user_text',
373  'ar_user',
374  'ar_minor_edit',
375  'ar_deleted',
376  'ar_len',
377  'ar_parent_id',
378  'ar_sha1',
379  ];
380 
381  $fields += CommentStore::newKey( 'ar_comment' )->getFields();
382 
383  if ( $wgContentHandlerUseDB ) {
384  $fields[] = 'ar_content_format';
385  $fields[] = 'ar_content_model';
386  }
387  return $fields;
388  }
389 
396  public static function selectTextFields() {
397  wfDeprecated( __METHOD__, '1.31' );
398  return [
399  'old_text',
400  'old_flags'
401  ];
402  }
403 
409  public static function selectPageFields() {
410  wfDeprecated( __METHOD__, '1.31' );
411  return [
412  'page_namespace',
413  'page_title',
414  'page_id',
415  'page_latest',
416  'page_is_redirect',
417  'page_len',
418  ];
419  }
420 
426  public static function selectUserFields() {
427  wfDeprecated( __METHOD__, '1.31' );
428  return [ 'user_name' ];
429  }
430 
445  public static function getQueryInfo( $options = [] ) {
446  return self::getRevisionStore()->getQueryInfo( $options );
447  }
448 
459  public static function getArchiveQueryInfo() {
460  return self::getRevisionStore()->getArchiveQueryInfo();
461  }
462 
472  public static function getParentLengths( $db, array $revIds ) {
473  return self::getRevisionStore()->listRevisionSizes( $db, $revIds );
474  }
475 
483  function __construct( $row, $queryFlags = 0, Title $title = null ) {
484  global $wgUser;
485 
486  if ( $row instanceof RevisionRecord ) {
487  $this->mRecord = $row;
488  } elseif ( is_array( $row ) ) {
489  // If no user is specified, fall back to using the global user object, to stay
490  // compatible with pre-1.31 behavior.
491  if ( !isset( $row['user'] ) && !isset( $row['user_text'] ) ) {
492  $row['user'] = $wgUser;
493  }
494 
495  $this->mRecord = self::getRevisionStore()->newMutableRevisionFromArray(
496  $row,
497  $queryFlags,
498  $this->ensureTitle( $row, $queryFlags, $title )
499  );
500  } elseif ( is_object( $row ) ) {
501  $this->mRecord = self::getRevisionStore()->newRevisionFromRow(
502  $row,
503  $queryFlags,
504  $this->ensureTitle( $row, $queryFlags, $title )
505  );
506  } else {
507  throw new InvalidArgumentException(
508  '$row must be a row object, an associative array, or a RevisionRecord'
509  );
510  }
511  }
512 
523  private function ensureTitle( $row, $queryFlags, $title = null ) {
524  if ( $title ) {
525  return $title;
526  }
527 
528  if ( is_array( $row ) ) {
529  if ( isset( $row['title'] ) ) {
530  if ( !( $row['title'] instanceof Title ) ) {
531  throw new MWException( 'title field must contain a Title object.' );
532  }
533 
534  return $row['title'];
535  }
536 
537  $pageId = isset( $row['page'] ) ? $row['page'] : 0;
538  $revId = isset( $row['id'] ) ? $row['id'] : 0;
539  } else {
540  $pageId = isset( $row->rev_page ) ? $row->rev_page : 0;
541  $revId = isset( $row->rev_id ) ? $row->rev_id : 0;
542  }
543 
544  try {
545  $title = self::getRevisionStore()->getTitle( $pageId, $revId, $queryFlags );
546  } catch ( RevisionAccessException $ex ) {
547  // construct a dummy title!
548  wfLogWarning( __METHOD__ . ': ' . $ex->getMessage() );
549 
550  // NOTE: this Title will only be used inside RevisionRecord
551  $title = Title::makeTitleSafe( NS_SPECIAL, "Badtitle/ID=$pageId" );
552  $title->resetArticleID( $pageId );
553  }
554 
555  return $title;
556  }
557 
561  public function getRevisionRecord() {
562  return $this->mRecord;
563  }
564 
570  public function getId() {
571  return $this->mRecord->getId();
572  }
573 
586  public function setId( $id ) {
587  if ( $this->mRecord instanceof MutableRevisionRecord ) {
588  $this->mRecord->setId( intval( $id ) );
589  } else {
590  throw new MWException( __METHOD__ . ' is not supported on this instance' );
591  }
592  }
593 
608  public function setUserIdAndName( $id, $name ) {
609  if ( $this->mRecord instanceof MutableRevisionRecord ) {
610  $user = new UserIdentityValue( intval( $id ), $name );
611  $this->mRecord->setUser( $user );
612  } else {
613  throw new MWException( __METHOD__ . ' is not supported on this instance' );
614  }
615  }
616 
620  private function getMainSlotRaw() {
621  return $this->mRecord->getSlot( 'main', RevisionRecord::RAW );
622  }
623 
636  public function getTextId() {
637  $slot = $this->getMainSlotRaw();
638  return $slot->hasAddress()
639  ? self::getBlobStore()->getTextIdFromAddress( $slot->getAddress() )
640  : null;
641  }
642 
649  public function getParentId() {
650  return $this->mRecord->getParentId();
651  }
652 
658  public function getSize() {
659  try {
660  return $this->mRecord->getSize();
661  } catch ( RevisionAccessException $ex ) {
662  return null;
663  }
664  }
665 
671  public function getSha1() {
672  try {
673  return $this->mRecord->getSha1();
674  } catch ( RevisionAccessException $ex ) {
675  return null;
676  }
677  }
678 
687  public function getTitle() {
688  $linkTarget = $this->mRecord->getPageAsLinkTarget();
689  return Title::newFromLinkTarget( $linkTarget );
690  }
691 
699  public function setTitle( $title ) {
700  if ( !$title->equals( $this->getTitle() ) ) {
701  throw new InvalidArgumentException(
702  $title->getPrefixedText()
703  . ' is not the same as '
704  . $this->mRecord->getPageAsLinkTarget()->__toString()
705  );
706  }
707  }
708 
714  public function getPage() {
715  return $this->mRecord->getPageId();
716  }
717 
731  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
732  global $wgUser;
733 
734  if ( $audience === self::FOR_THIS_USER && !$user ) {
735  $user = $wgUser;
736  }
737 
738  $user = $this->mRecord->getUser( $audience, $user );
739  return $user ? $user->getId() : 0;
740  }
741 
748  public function getRawUser() {
749  wfDeprecated( __METHOD__, '1.25' );
750  return $this->getUser( self::RAW );
751  }
752 
766  public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) {
767  global $wgUser;
768 
769  if ( $audience === self::FOR_THIS_USER && !$user ) {
770  $user = $wgUser;
771  }
772 
773  $user = $this->mRecord->getUser( $audience, $user );
774  return $user ? $user->getName() : '';
775  }
776 
783  public function getRawUserText() {
784  wfDeprecated( __METHOD__, '1.25' );
785  return $this->getUserText( self::RAW );
786  }
787 
801  function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
802  global $wgUser;
803 
804  if ( $audience === self::FOR_THIS_USER && !$user ) {
805  $user = $wgUser;
806  }
807 
808  $comment = $this->mRecord->getComment( $audience, $user );
809  return $comment === null ? null : $comment->text;
810  }
811 
818  public function getRawComment() {
819  wfDeprecated( __METHOD__, '1.25' );
820  return $this->getComment( self::RAW );
821  }
822 
826  public function isMinor() {
827  return $this->mRecord->isMinor();
828  }
829 
833  public function isUnpatrolled() {
834  return self::getRevisionStore()->getRcIdIfUnpatrolled( $this->mRecord );
835  }
836 
846  public function getRecentChange( $flags = 0 ) {
847  return self::getRevisionStore()->getRecentChange( $this->mRecord, $flags );
848  }
849 
855  public function isDeleted( $field ) {
856  return $this->mRecord->isDeleted( $field );
857  }
858 
864  public function getVisibility() {
865  return $this->mRecord->getVisibility();
866  }
867 
882  public function getContent( $audience = self::FOR_PUBLIC, User $user = null ) {
883  global $wgUser;
884 
885  if ( $audience === self::FOR_THIS_USER && !$user ) {
886  $user = $wgUser;
887  }
888 
889  try {
890  return $this->mRecord->getContent( 'main', $audience, $user );
891  }
892  catch ( RevisionAccessException $e ) {
893  return null;
894  }
895  }
896 
905  public function getSerializedData() {
906  $slot = $this->getMainSlotRaw();
907  return $slot->getContent()->serialize();
908  }
909 
922  public function getContentModel() {
923  return $this->getMainSlotRaw()->getModel();
924  }
925 
937  public function getContentFormat() {
938  $format = $this->getMainSlotRaw()->getFormat();
939 
940  if ( $format === null ) {
941  // if no format was stored along with the blob, fall back to default format
942  $format = $this->getContentHandler()->getDefaultFormat();
943  }
944 
945  return $format;
946  }
947 
954  public function getContentHandler() {
956  }
957 
961  public function getTimestamp() {
962  return $this->mRecord->getTimestamp();
963  }
964 
968  public function isCurrent() {
969  return ( $this->mRecord instanceof RevisionStoreRecord ) && $this->mRecord->isCurrent();
970  }
971 
977  public function getPrevious() {
978  $title = $this->getTitle();
979  $rec = self::getRevisionStore()->getPreviousRevision( $this->mRecord, $title );
980  return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
981  }
982 
988  public function getNext() {
989  $title = $this->getTitle();
990  $rec = self::getRevisionStore()->getNextRevision( $this->mRecord, $title );
991  return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
992  }
993 
1008  public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) {
1009  $textField = $prefix . 'text';
1010  $flagsField = $prefix . 'flags';
1011 
1012  if ( isset( $row->$flagsField ) ) {
1013  $flags = explode( ',', $row->$flagsField );
1014  } else {
1015  $flags = [];
1016  }
1017 
1018  if ( isset( $row->$textField ) ) {
1019  $text = $row->$textField;
1020  } else {
1021  return false;
1022  }
1023 
1024  $cacheKey = isset( $row->old_id ) ? ( 'tt:' . $row->old_id ) : null;
1025 
1026  return self::getBlobStore( $wiki )->expandBlob( $text, $flags, $cacheKey );
1027  }
1028 
1039  public static function compressRevisionText( &$text ) {
1040  return self::getBlobStore()->compressData( $text );
1041  }
1042 
1050  public static function decompressRevisionText( $text, $flags ) {
1051  return self::getBlobStore()->decompressData( $text, $flags );
1052  }
1053 
1062  public function insertOn( $dbw ) {
1063  global $wgUser;
1064 
1065  // Note that $this->mRecord->getId() will typically return null here, but not always,
1066  // e.g. not when restoring a revision.
1067 
1068  if ( $this->mRecord->getUser( RevisionRecord::RAW ) === null ) {
1069  if ( $this->mRecord instanceof MutableRevisionRecord ) {
1070  $this->mRecord->setUser( $wgUser );
1071  } else {
1072  throw new MWException( 'Cannot insert revision with no associated user.' );
1073  }
1074  }
1075 
1076  $rec = self::getRevisionStore()->insertRevisionOn( $this->mRecord, $dbw );
1077 
1078  $this->mRecord = $rec;
1079 
1080  // Avoid PHP 7.1 warning of passing $this by reference
1081  $revision = $this;
1082  // TODO: hard-deprecate in 1.32 (or even 1.31?)
1083  Hooks::run( 'RevisionInsertComplete', [ &$revision, null, null ] );
1084 
1085  return $rec->getId();
1086  }
1087 
1093  public static function base36Sha1( $text ) {
1094  return SlotRecord::base36Sha1( $text );
1095  }
1096 
1112  public static function newNullRevision( $dbw, $pageId, $summary, $minor, $user = null ) {
1113  global $wgUser;
1114  if ( !$user ) {
1115  $user = $wgUser;
1116  }
1117 
1118  $comment = CommentStoreComment::newUnsavedComment( $summary, null );
1119 
1121  if ( $title === null ) {
1122  return null;
1123  }
1124 
1125  $rec = self::getRevisionStore()->newNullRevision( $dbw, $title, $comment, $minor, $user );
1126 
1127  return new Revision( $rec );
1128  }
1129 
1140  public function userCan( $field, User $user = null ) {
1141  return self::userCanBitfield( $this->getVisibility(), $field, $user );
1142  }
1143 
1158  public static function userCanBitfield( $bitfield, $field, User $user = null,
1159  Title $title = null
1160  ) {
1161  global $wgUser;
1162 
1163  if ( !$user ) {
1164  $user = $wgUser;
1165  }
1166 
1167  return RevisionRecord::userCanBitfield( $bitfield, $field, $user, $title );
1168  }
1169 
1178  static function getTimestampFromId( $title, $id, $flags = 0 ) {
1179  return self::getRevisionStore()->getTimestampFromId( $title, $id, $flags );
1180  }
1181 
1189  static function countByPageId( $db, $id ) {
1190  return self::getRevisionStore()->countRevisionsByPageId( $db, $id );
1191  }
1192 
1200  static function countByTitle( $db, $title ) {
1201  return self::getRevisionStore()->countRevisionsByTitle( $db, $title );
1202  }
1203 
1220  public static function userWasLastToEdit( $db, $pageId, $userId, $since ) {
1221  if ( is_int( $db ) ) {
1222  $db = wfGetDB( $db );
1223  }
1224 
1225  return self::getRevisionStore()->userWasLastToEdit( $db, $pageId, $userId, $since );
1226  }
1227 
1241  public static function newKnownCurrent( IDatabase $db, $pageIdOrTitle, $revId = 0 ) {
1242  $title = $pageIdOrTitle instanceof Title
1243  ? $pageIdOrTitle
1244  : Title::newFromID( $pageIdOrTitle );
1245 
1246  if ( !$title ) {
1247  return false;
1248  }
1249 
1250  $record = self::getRevisionStore()->getKnownCurrentRevision( $title, $revId );
1251  return $record ? new Revision( $record ) : false;
1252  }
1253 }
Service for storing and loading Content objects.
const FOR_THIS_USER
Definition: Revision.php:55
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:1008
const TEXT_CACHE_GROUP
Definition: Revision.php:58
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:290
setTitle($title)
Set the title of the revision.
Definition: Revision.php:699
getRevisionRecord()
Definition: Revision.php:561
getPage()
Get the page ID.
Definition: Revision.php:714
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getTimestamp()
Definition: Revision.php:961
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:2149
setUserIdAndName($id, $name)
Set the user ID/name.
Definition: Revision.php:608
static getTimestampFromId($title, $id, $flags=0)
Get rev_timestamp from rev_id, without loading the rest of the row.
Definition: Revision.php:1178
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:523
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:833
static selectArchiveFields()
Return the list of revision fields that should be selected to create a new revision from an archive r...
Definition: Revision.php:360
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:137
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:118
getSerializedData()
Get original serialized data (without checking view restrictions)
Definition: Revision.php:905
static getQueryInfo($options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object...
Definition: Revision.php:445
getRawComment()
Fetch revision comment without regard for the current user's permissions.
Definition: Revision.php:818
getMainSlotRaw()
Definition: Revision.php:620
The User object encapsulates all of the user-specific settings (user_id, name, rights, email address, options, last login time).
Definition: User.php:52
RevisionRecord $mRecord
Definition: Revision.php:43
isDeleted($field)
Definition: Revision.php:855
getTitle()
Returns the title of the page associated with this entry.
Definition: Revision.php:687
getParentId()
Get parent revision ID (the original previous page revision)
Definition: Revision.php:649
const FOR_PUBLIC
Definition: Revision.php:54
getUserText($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's username if it's available to the specified audience.
Definition: Revision.php:766
getRawUserText()
Fetch revision's username without regard for view restrictions.
Definition: Revision.php:783
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:1241
getId()
Get revision ID.
Definition: Revision.php:570
static loadFromTimestamp($db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition: Revision.php:276
getContentHandler()
Returns the content handler appropriate for this revision's content model.
Definition: Revision.php:954
static newNullRevision($dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1112
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:1039
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:1973
__construct($row, $queryFlags=0, Title $title=null)
Definition: Revision.php:483
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:325
static selectTextFields()
Return the list of text fields that should be selected to read the revision text. ...
Definition: Revision.php:396
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:1140
getComment($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
Definition: Revision.php:801
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:49
Value object representing a user's identity.
static getArchiveQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archived revision objec...
Definition: Revision.php:459
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:935
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:258
getPrevious()
Get previous revision for this title.
Definition: Revision.php:977
setId($id)
Set the revision ID.
Definition: Revision.php:586
const RAW
Definition: Revision.php:56
getRecentChange($flags=0)
Get the RC object belonging to the current revision, if there's one.
Definition: Revision.php:846
getContentModel()
Returns the content model for the main slot of this revision.
Definition: Revision.php:922
static getRevisionStore()
Definition: Revision.php:63
const DELETED_TEXT
Definition: Revision.php:46
const SUPPRESSED_USER
Definition: Revision.php:50
static countByPageId($db, $id)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1189
static newFromId($id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:99
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:314
A RevisionRecord representing an existing revision persisted in the revision table.
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:864
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:48
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:636
insertOn($dbw)
Insert a new revision into the database, returning the new revision ID number on success and dies hor...
Definition: Revision.php:1062
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:1200
getContent($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
Definition: Revision.php:882
static newFromRow($row)
Definition: Revision.php:203
static loadFromPageId($db, $pageid, $id=0)
Load either the current, or a specified, revision that's attached to a given page.
Definition: Revision.php:241
static newKey($key)
Static constructor for easier chaining.
getNext()
Get next revision for this title.
Definition: Revision.php:988
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:472
static base36Sha1($text)
Get the base 36 SHA-1 value for a string of text.
Definition: Revision.php:1093
getUser($audience=self::FOR_PUBLIC, User $user=null)
Fetch revision's user id if it's available to the specified audience.
Definition: Revision.php:731
static selectPageFields()
Return the list of page fields that should be selected from page table.
Definition: Revision.php:409
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:1158
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:47
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:1220
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:302
getContentFormat()
Returns the content format for the main slot of this revision.
Definition: Revision.php:937
static loadFromId($db, $id)
Load a page revision from a given revision ID number.
Definition: Revision.php:223
static newFromArchiveRow($row, $overrides=[])
Make a fake revision object from an archive table row.
Definition: Revision.php:152
getRawUser()
Fetch revision's user id without regard for the current user's permissions.
Definition: Revision.php:748
static getBlobStore($wiki=false)
Definition: Revision.php:72
getSize()
Returns the length of the text in this revision, or null if unknown.
Definition: Revision.php:658
static decompressRevisionText($text, $flags)
Re-converts revision text according to it's flags.
Definition: Revision.php:1050
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:426
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:671
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:51
isCurrent()
Definition: Revision.php:968
$wgUser
Definition: Setup.php:892