MediaWiki  1.23.14
Revision.php
Go to the documentation of this file.
1 <?php
26 class Revision implements IDBAccessObject {
27  protected $mId;
28 
32  protected $mPage;
33  protected $mUserText;
34  protected $mOrigUserText;
35  protected $mUser;
36  protected $mMinorEdit;
37  protected $mTimestamp;
38  protected $mDeleted;
39  protected $mSize;
40  protected $mSha1;
41  protected $mParentId;
42  protected $mComment;
43  protected $mText;
44  protected $mTextRow;
45 
49  protected $mTitle;
50  protected $mCurrent;
51  protected $mContentModel;
52  protected $mContentFormat;
53 
57  protected $mContent;
58 
62  protected $mContentHandler;
63 
67  protected $mQueryFlags = 0;
68 
69  // Revision deletion constants
70  const DELETED_TEXT = 1;
71  const DELETED_COMMENT = 2;
72  const DELETED_USER = 4;
73  const DELETED_RESTRICTED = 8;
74  const SUPPRESSED_USER = 12; // convenience
75 
76  // Audience options for accessors
77  const FOR_PUBLIC = 1;
78  const FOR_THIS_USER = 2;
79  const RAW = 3;
80 
93  public static function newFromId( $id, $flags = 0 ) {
94  return self::newFromConds( array( 'rev_id' => intval( $id ) ), $flags );
95  }
96 
111  public static function newFromTitle( $title, $id = 0, $flags = 0 ) {
112  $conds = array(
113  'page_namespace' => $title->getNamespace(),
114  'page_title' => $title->getDBkey()
115  );
116  if ( $id ) {
117  // Use the specified ID
118  $conds['rev_id'] = $id;
119  return self::newFromConds( $conds, (int)$flags );
120  } else {
121  // Use a join to get the latest revision
122  $conds[] = 'rev_id=page_latest';
123  $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
124  return self::loadFromConds( $db, $conds, $flags );
125  }
126  }
127 
142  public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) {
143  $conds = array( 'page_id' => $pageId );
144  if ( $revId ) {
145  $conds['rev_id'] = $revId;
146  } else {
147  // Use a join to get the latest revision
148  $conds[] = 'rev_id = page_latest';
149  }
150  return self::newFromConds( $conds, (int)$flags );
151  }
152 
164  public static function newFromArchiveRow( $row, $overrides = array() ) {
165  global $wgContentHandlerUseDB;
166 
167  $attribs = $overrides + array(
168  'page' => isset( $row->ar_page_id ) ? $row->ar_page_id : null,
169  'id' => isset( $row->ar_rev_id ) ? $row->ar_rev_id : null,
170  'comment' => $row->ar_comment,
171  'user' => $row->ar_user,
172  'user_text' => $row->ar_user_text,
173  'timestamp' => $row->ar_timestamp,
174  'minor_edit' => $row->ar_minor_edit,
175  'text_id' => isset( $row->ar_text_id ) ? $row->ar_text_id : null,
176  'deleted' => $row->ar_deleted,
177  'len' => $row->ar_len,
178  'sha1' => isset( $row->ar_sha1 ) ? $row->ar_sha1 : null,
179  'content_model' => isset( $row->ar_content_model ) ? $row->ar_content_model : null,
180  'content_format' => isset( $row->ar_content_format ) ? $row->ar_content_format : null,
181  );
182 
183  if ( !$wgContentHandlerUseDB ) {
184  unset( $attribs['content_model'] );
185  unset( $attribs['content_format'] );
186  }
187 
188  if ( !isset( $attribs['title'] )
189  && isset( $row->ar_namespace )
190  && isset( $row->ar_title ) ) {
191 
192  $attribs['title'] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
193  }
194 
195  if ( isset( $row->ar_text ) && !$row->ar_text_id ) {
196  // Pre-1.5 ar_text row
197  $attribs['text'] = self::getRevisionText( $row, 'ar_' );
198  if ( $attribs['text'] === false ) {
199  throw new MWException( 'Unable to load text from archive row (possibly bug 22624)' );
200  }
201  }
202  return new self( $attribs );
203  }
204 
211  public static function newFromRow( $row ) {
212  return new self( $row );
213  }
214 
223  public static function loadFromId( $db, $id ) {
224  return self::loadFromConds( $db, array( 'rev_id' => intval( $id ) ) );
225  }
226 
237  public static function loadFromPageId( $db, $pageid, $id = 0 ) {
238  $conds = array( 'rev_page' => intval( $pageid ), 'page_id' => intval( $pageid ) );
239  if ( $id ) {
240  $conds['rev_id'] = intval( $id );
241  } else {
242  $conds[] = 'rev_id=page_latest';
243  }
244  return self::loadFromConds( $db, $conds );
245  }
246 
257  public static function loadFromTitle( $db, $title, $id = 0 ) {
258  if ( $id ) {
259  $matchId = intval( $id );
260  } else {
261  $matchId = 'page_latest';
262  }
263  return self::loadFromConds( $db,
264  array(
265  "rev_id=$matchId",
266  'page_namespace' => $title->getNamespace(),
267  'page_title' => $title->getDBkey()
268  )
269  );
270  }
271 
282  public static function loadFromTimestamp( $db, $title, $timestamp ) {
283  return self::loadFromConds( $db,
284  array(
285  'rev_timestamp' => $db->timestamp( $timestamp ),
286  'page_namespace' => $title->getNamespace(),
287  'page_title' => $title->getDBkey()
288  )
289  );
290  }
291 
299  private static function newFromConds( $conditions, $flags = 0 ) {
300  $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
301  $rev = self::loadFromConds( $db, $conditions, $flags );
302  if ( is_null( $rev ) && wfGetLB()->getServerCount() > 1 ) {
303  if ( !( $flags & self::READ_LATEST ) ) {
304  $dbw = wfGetDB( DB_MASTER );
305  $rev = self::loadFromConds( $dbw, $conditions, $flags );
306  }
307  }
308  if ( $rev ) {
309  $rev->mQueryFlags = $flags;
310  }
311  return $rev;
312  }
313 
323  private static function loadFromConds( $db, $conditions, $flags = 0 ) {
324  $res = self::fetchFromConds( $db, $conditions, $flags );
325  if ( $res ) {
326  $row = $res->fetchObject();
327  if ( $row ) {
328  $ret = new Revision( $row );
329  return $ret;
330  }
331  }
332  $ret = null;
333  return $ret;
334  }
335 
344  public static function fetchRevision( $title ) {
345  return self::fetchFromConds(
346  wfGetDB( DB_SLAVE ),
347  array(
348  'rev_id=page_latest',
349  'page_namespace' => $title->getNamespace(),
350  'page_title' => $title->getDBkey()
351  )
352  );
353  }
354 
365  private static function fetchFromConds( $db, $conditions, $flags = 0 ) {
366  $fields = array_merge(
367  self::selectFields(),
368  self::selectPageFields(),
369  self::selectUserFields()
370  );
371  $options = array( 'LIMIT' => 1 );
372  if ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING ) {
373  $options[] = 'FOR UPDATE';
374  }
375  return $db->select(
376  array( 'revision', 'page', 'user' ),
377  $fields,
378  $conditions,
379  __METHOD__,
380  $options,
381  array( 'page' => self::pageJoinCond(), 'user' => self::userJoinCond() )
382  );
383  }
384 
391  public static function userJoinCond() {
392  return array( 'LEFT JOIN', array( 'rev_user != 0', 'user_id = rev_user' ) );
393  }
394 
401  public static function pageJoinCond() {
402  return array( 'INNER JOIN', array( 'page_id = rev_page' ) );
403  }
404 
410  public static function selectFields() {
411  global $wgContentHandlerUseDB;
412 
413  $fields = array(
414  'rev_id',
415  'rev_page',
416  'rev_text_id',
417  'rev_timestamp',
418  'rev_comment',
419  'rev_user_text',
420  'rev_user',
421  'rev_minor_edit',
422  'rev_deleted',
423  'rev_len',
424  'rev_parent_id',
425  'rev_sha1',
426  );
427 
428  if ( $wgContentHandlerUseDB ) {
429  $fields[] = 'rev_content_format';
430  $fields[] = 'rev_content_model';
431  }
432 
433  return $fields;
434  }
435 
441  public static function selectArchiveFields() {
442  global $wgContentHandlerUseDB;
443  $fields = array(
444  'ar_id',
445  'ar_page_id',
446  'ar_rev_id',
447  'ar_text',
448  'ar_text_id',
449  'ar_timestamp',
450  'ar_comment',
451  'ar_user_text',
452  'ar_user',
453  'ar_minor_edit',
454  'ar_deleted',
455  'ar_len',
456  'ar_parent_id',
457  'ar_sha1',
458  );
459 
460  if ( $wgContentHandlerUseDB ) {
461  $fields[] = 'ar_content_format';
462  $fields[] = 'ar_content_model';
463  }
464  return $fields;
465  }
466 
472  public static function selectTextFields() {
473  return array(
474  'old_text',
475  'old_flags'
476  );
477  }
478 
483  public static function selectPageFields() {
484  return array(
485  'page_namespace',
486  'page_title',
487  'page_id',
488  'page_latest',
489  'page_is_redirect',
490  'page_len',
491  );
492  }
493 
498  public static function selectUserFields() {
499  return array( 'user_name' );
500  }
501 
508  public static function getParentLengths( $db, array $revIds ) {
509  $revLens = array();
510  if ( !$revIds ) {
511  return $revLens; // empty
512  }
513  wfProfileIn( __METHOD__ );
514  $res = $db->select( 'revision',
515  array( 'rev_id', 'rev_len' ),
516  array( 'rev_id' => $revIds ),
517  __METHOD__ );
518  foreach ( $res as $row ) {
519  $revLens[$row->rev_id] = $row->rev_len;
520  }
521  wfProfileOut( __METHOD__ );
522  return $revLens;
523  }
524 
532  function __construct( $row ) {
533  if ( is_object( $row ) ) {
534  $this->mId = intval( $row->rev_id );
535  $this->mPage = intval( $row->rev_page );
536  $this->mTextId = intval( $row->rev_text_id );
537  $this->mComment = $row->rev_comment;
538  $this->mUser = intval( $row->rev_user );
539  $this->mMinorEdit = intval( $row->rev_minor_edit );
540  $this->mTimestamp = $row->rev_timestamp;
541  $this->mDeleted = intval( $row->rev_deleted );
542 
543  if ( !isset( $row->rev_parent_id ) ) {
544  $this->mParentId = null;
545  } else {
546  $this->mParentId = intval( $row->rev_parent_id );
547  }
548 
549  if ( !isset( $row->rev_len ) ) {
550  $this->mSize = null;
551  } else {
552  $this->mSize = intval( $row->rev_len );
553  }
554 
555  if ( !isset( $row->rev_sha1 ) ) {
556  $this->mSha1 = null;
557  } else {
558  $this->mSha1 = $row->rev_sha1;
559  }
560 
561  if ( isset( $row->page_latest ) ) {
562  $this->mCurrent = ( $row->rev_id == $row->page_latest );
563  $this->mTitle = Title::newFromRow( $row );
564  } else {
565  $this->mCurrent = false;
566  $this->mTitle = null;
567  }
568 
569  if ( !isset( $row->rev_content_model ) || is_null( $row->rev_content_model ) ) {
570  $this->mContentModel = null; # determine on demand if needed
571  } else {
572  $this->mContentModel = strval( $row->rev_content_model );
573  }
574 
575  if ( !isset( $row->rev_content_format ) || is_null( $row->rev_content_format ) ) {
576  $this->mContentFormat = null; # determine on demand if needed
577  } else {
578  $this->mContentFormat = strval( $row->rev_content_format );
579  }
580 
581  // Lazy extraction...
582  $this->mText = null;
583  if ( isset( $row->old_text ) ) {
584  $this->mTextRow = $row;
585  } else {
586  // 'text' table row entry will be lazy-loaded
587  $this->mTextRow = null;
588  }
589 
590  // Use user_name for users and rev_user_text for IPs...
591  $this->mUserText = null; // lazy load if left null
592  if ( $this->mUser == 0 ) {
593  $this->mUserText = $row->rev_user_text; // IP user
594  } elseif ( isset( $row->user_name ) ) {
595  $this->mUserText = $row->user_name; // logged-in user
596  }
597  $this->mOrigUserText = $row->rev_user_text;
598  } elseif ( is_array( $row ) ) {
599  // Build a new revision to be saved...
600  global $wgUser; // ugh
601 
602  # if we have a content object, use it to set the model and type
603  if ( !empty( $row['content'] ) ) {
604  // @todo when is that set? test with external store setup! check out insertOn() [dk]
605  if ( !empty( $row['text_id'] ) ) {
606  throw new MWException( "Text already stored in external store (id {$row['text_id']}), " .
607  "can't serialize content object" );
608  }
609 
610  $row['content_model'] = $row['content']->getModel();
611  # note: mContentFormat is initializes later accordingly
612  # note: content is serialized later in this method!
613  # also set text to null?
614  }
615 
616  $this->mId = isset( $row['id'] ) ? intval( $row['id'] ) : null;
617  $this->mPage = isset( $row['page'] ) ? intval( $row['page'] ) : null;
618  $this->mTextId = isset( $row['text_id'] ) ? intval( $row['text_id'] ) : null;
619  $this->mUserText = isset( $row['user_text'] )
620  ? strval( $row['user_text'] ) : $wgUser->getName();
621  $this->mUser = isset( $row['user'] ) ? intval( $row['user'] ) : $wgUser->getId();
622  $this->mMinorEdit = isset( $row['minor_edit'] ) ? intval( $row['minor_edit'] ) : 0;
623  $this->mTimestamp = isset( $row['timestamp'] )
624  ? strval( $row['timestamp'] ) : wfTimestampNow();
625  $this->mDeleted = isset( $row['deleted'] ) ? intval( $row['deleted'] ) : 0;
626  $this->mSize = isset( $row['len'] ) ? intval( $row['len'] ) : null;
627  $this->mParentId = isset( $row['parent_id'] ) ? intval( $row['parent_id'] ) : null;
628  $this->mSha1 = isset( $row['sha1'] ) ? strval( $row['sha1'] ) : null;
629 
630  $this->mContentModel = isset( $row['content_model'] )
631  ? strval( $row['content_model'] ) : null;
632  $this->mContentFormat = isset( $row['content_format'] )
633  ? strval( $row['content_format'] ) : null;
634 
635  // Enforce spacing trimming on supplied text
636  $this->mComment = isset( $row['comment'] ) ? trim( strval( $row['comment'] ) ) : null;
637  $this->mText = isset( $row['text'] ) ? rtrim( strval( $row['text'] ) ) : null;
638  $this->mTextRow = null;
639 
640  $this->mTitle = isset( $row['title'] ) ? $row['title'] : null;
641 
642  // if we have a Content object, override mText and mContentModel
643  if ( !empty( $row['content'] ) ) {
644  if ( !( $row['content'] instanceof Content ) ) {
645  throw new MWException( '`content` field must contain a Content object.' );
646  }
647 
648  $handler = $this->getContentHandler();
649  $this->mContent = $row['content'];
650 
651  $this->mContentModel = $this->mContent->getModel();
652  $this->mContentHandler = null;
653 
654  $this->mText = $handler->serializeContent( $row['content'], $this->getContentFormat() );
655  } elseif ( !is_null( $this->mText ) ) {
656  $handler = $this->getContentHandler();
657  $this->mContent = $handler->unserializeContent( $this->mText );
658  }
659 
660  // If we have a Title object, make sure it is consistent with mPage.
661  if ( $this->mTitle && $this->mTitle->exists() ) {
662  if ( $this->mPage === null ) {
663  // if the page ID wasn't known, set it now
664  $this->mPage = $this->mTitle->getArticleID();
665  } elseif ( $this->mTitle->getArticleID() !== $this->mPage ) {
666  // Got different page IDs. This may be legit (e.g. during undeletion),
667  // but it seems worth mentioning it in the log.
668  wfDebug( "Page ID " . $this->mPage . " mismatches the ID " .
669  $this->mTitle->getArticleID() . " provided by the Title object." );
670  }
671  }
672 
673  $this->mCurrent = false;
674 
675  // If we still have no length, see it we have the text to figure it out
676  if ( !$this->mSize ) {
677  if ( !is_null( $this->mContent ) ) {
678  $this->mSize = $this->mContent->getSize();
679  } else {
680  #NOTE: this should never happen if we have either text or content object!
681  $this->mSize = null;
682  }
683  }
684 
685  // Same for sha1
686  if ( $this->mSha1 === null ) {
687  $this->mSha1 = is_null( $this->mText ) ? null : self::base36Sha1( $this->mText );
688  }
689 
690  // force lazy init
691  $this->getContentModel();
692  $this->getContentFormat();
693  } else {
694  throw new MWException( 'Revision constructor passed invalid row format.' );
695  }
696  $this->mUnpatrolled = null;
697  }
698 
704  public function getId() {
705  return $this->mId;
706  }
707 
714  public function setId( $id ) {
715  $this->mId = $id;
716  }
717 
723  public function getTextId() {
724  return $this->mTextId;
725  }
726 
732  public function getParentId() {
733  return $this->mParentId;
734  }
735 
741  public function getSize() {
742  return $this->mSize;
743  }
744 
750  public function getSha1() {
751  return $this->mSha1;
752  }
753 
761  public function getTitle() {
762  if ( isset( $this->mTitle ) ) {
763  return $this->mTitle;
764  }
765  //rev_id is defined as NOT NULL, but this revision may not yet have been inserted.
766  if ( !is_null( $this->mId ) ) {
767  $dbr = wfGetDB( DB_SLAVE );
768  $row = $dbr->selectRow(
769  array( 'page', 'revision' ),
770  self::selectPageFields(),
771  array( 'page_id=rev_page',
772  'rev_id' => $this->mId ),
773  __METHOD__ );
774  if ( $row ) {
775  $this->mTitle = Title::newFromRow( $row );
776  }
777  }
778 
779  if ( !$this->mTitle && !is_null( $this->mPage ) && $this->mPage > 0 ) {
780  $this->mTitle = Title::newFromID( $this->mPage );
781  }
782 
783  return $this->mTitle;
784  }
785 
791  public function setTitle( $title ) {
792  $this->mTitle = $title;
793  }
794 
800  public function getPage() {
801  return $this->mPage;
802  }
803 
817  public function getUser( $audience = self::FOR_PUBLIC, User $user = null ) {
818  if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) {
819  return 0;
820  } elseif ( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER, $user ) ) {
821  return 0;
822  } else {
823  return $this->mUser;
824  }
825  }
826 
832  public function getRawUser() {
833  return $this->mUser;
834  }
835 
849  public function getUserText( $audience = self::FOR_PUBLIC, User $user = null ) {
850  if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_USER ) ) {
851  return '';
852  } elseif ( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_USER, $user ) ) {
853  return '';
854  } else {
855  return $this->getRawUserText();
856  }
857  }
858 
864  public function getRawUserText() {
865  if ( $this->mUserText === null ) {
866  $this->mUserText = User::whoIs( $this->mUser ); // load on demand
867  if ( $this->mUserText === false ) {
868  # This shouldn't happen, but it can if the wiki was recovered
869  # via importing revs and there is no user table entry yet.
870  $this->mUserText = $this->mOrigUserText;
871  }
872  }
873  return $this->mUserText;
874  }
875 
889  function getComment( $audience = self::FOR_PUBLIC, User $user = null ) {
890  if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_COMMENT ) ) {
891  return '';
892  } elseif ( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_COMMENT, $user ) ) {
893  return '';
894  } else {
895  return $this->mComment;
896  }
897  }
898 
904  public function getRawComment() {
905  return $this->mComment;
906  }
907 
911  public function isMinor() {
912  return (bool)$this->mMinorEdit;
913  }
914 
918  public function isUnpatrolled() {
919  if ( $this->mUnpatrolled !== null ) {
920  return $this->mUnpatrolled;
921  }
922  $rc = $this->getRecentChange();
923  if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == 0 ) {
924  $this->mUnpatrolled = $rc->getAttribute( 'rc_id' );
925  } else {
926  $this->mUnpatrolled = 0;
927  }
928  return $this->mUnpatrolled;
929  }
930 
937  public function getRecentChange() {
938  $dbr = wfGetDB( DB_SLAVE );
940  array(
941  'rc_user_text' => $this->getRawUserText(),
942  'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
943  'rc_this_oldid' => $this->getId()
944  ),
945  __METHOD__
946  );
947  }
948 
954  public function isDeleted( $field ) {
955  return ( $this->mDeleted & $field ) == $field;
956  }
957 
963  public function getVisibility() {
964  return (int)$this->mDeleted;
965  }
966 
983  public function getText( $audience = self::FOR_PUBLIC, User $user = null ) {
984  ContentHandler::deprecated( __METHOD__, '1.21' );
985 
986  $content = $this->getContent( $audience, $user );
987  return ContentHandler::getContentText( $content ); # returns the raw content text, if applicable
988  }
989 
1004  public function getContent( $audience = self::FOR_PUBLIC, User $user = null ) {
1005  if ( $audience == self::FOR_PUBLIC && $this->isDeleted( self::DELETED_TEXT ) ) {
1006  return null;
1007  } elseif ( $audience == self::FOR_THIS_USER && !$this->userCan( self::DELETED_TEXT, $user ) ) {
1008  return null;
1009  } else {
1010  return $this->getContentInternal();
1011  }
1012  }
1013 
1022  public function getRawText() {
1023  ContentHandler::deprecated( __METHOD__, "1.21" );
1024  return $this->getText( self::RAW );
1025  }
1026 
1033  public function getSerializedData() {
1034  if ( is_null( $this->mText ) ) {
1035  $this->mText = $this->loadText();
1036  }
1037 
1038  return $this->mText;
1039  }
1040 
1050  protected function getContentInternal() {
1051  if ( is_null( $this->mContent ) ) {
1052  // Revision is immutable. Load on demand:
1053  if ( is_null( $this->mText ) ) {
1054  $this->mText = $this->loadText();
1055  }
1056 
1057  if ( $this->mText !== null && $this->mText !== false ) {
1058  // Unserialize content
1059  $handler = $this->getContentHandler();
1060  $format = $this->getContentFormat();
1061 
1062  $this->mContent = $handler->unserializeContent( $this->mText, $format );
1063  } else {
1064  $this->mContent = false; // negative caching!
1065  }
1066  }
1067 
1068  // NOTE: copy() will return $this for immutable content objects
1069  return $this->mContent ? $this->mContent->copy() : null;
1070  }
1071 
1082  public function getContentModel() {
1083  if ( !$this->mContentModel ) {
1084  $title = $this->getTitle();
1085  $this->mContentModel = ( $title ? $title->getContentModel() : CONTENT_MODEL_WIKITEXT );
1086 
1087  assert( !empty( $this->mContentModel ) );
1088  }
1089 
1090  return $this->mContentModel;
1091  }
1092 
1102  public function getContentFormat() {
1103  if ( !$this->mContentFormat ) {
1104  $handler = $this->getContentHandler();
1105  $this->mContentFormat = $handler->getDefaultFormat();
1106 
1107  assert( !empty( $this->mContentFormat ) );
1108  }
1109 
1110  return $this->mContentFormat;
1111  }
1112 
1119  public function getContentHandler() {
1120  if ( !$this->mContentHandler ) {
1121  $model = $this->getContentModel();
1122  $this->mContentHandler = ContentHandler::getForModelID( $model );
1123 
1124  $format = $this->getContentFormat();
1125 
1126  if ( !$this->mContentHandler->isSupportedFormat( $format ) ) {
1127  throw new MWException( "Oops, the content format $format is not supported for "
1128  . "this content model, $model" );
1129  }
1130  }
1131 
1132  return $this->mContentHandler;
1133  }
1134 
1138  public function getTimestamp() {
1139  return wfTimestamp( TS_MW, $this->mTimestamp );
1140  }
1141 
1145  public function isCurrent() {
1146  return $this->mCurrent;
1147  }
1148 
1154  public function getPrevious() {
1155  if ( $this->getTitle() ) {
1156  $prev = $this->getTitle()->getPreviousRevisionID( $this->getId() );
1157  if ( $prev ) {
1158  return self::newFromTitle( $this->getTitle(), $prev );
1159  }
1160  }
1161  return null;
1162  }
1163 
1169  public function getNext() {
1170  if ( $this->getTitle() ) {
1171  $next = $this->getTitle()->getNextRevisionID( $this->getId() );
1172  if ( $next ) {
1173  return self::newFromTitle( $this->getTitle(), $next );
1174  }
1175  }
1176  return null;
1177  }
1178 
1186  private function getPreviousRevisionId( $db ) {
1187  if ( is_null( $this->mPage ) ) {
1188  return 0;
1189  }
1190  # Use page_latest if ID is not given
1191  if ( !$this->mId ) {
1192  $prevId = $db->selectField( 'page', 'page_latest',
1193  array( 'page_id' => $this->mPage ),
1194  __METHOD__ );
1195  } else {
1196  $prevId = $db->selectField( 'revision', 'rev_id',
1197  array( 'rev_page' => $this->mPage, 'rev_id < ' . $this->mId ),
1198  __METHOD__,
1199  array( 'ORDER BY' => 'rev_id DESC' ) );
1200  }
1201  return intval( $prevId );
1202  }
1203 
1217  public static function getRevisionText( $row, $prefix = 'old_', $wiki = false ) {
1218  wfProfileIn( __METHOD__ );
1219 
1220  # Get data
1221  $textField = $prefix . 'text';
1222  $flagsField = $prefix . 'flags';
1223 
1224  if ( isset( $row->$flagsField ) ) {
1225  $flags = explode( ',', $row->$flagsField );
1226  } else {
1227  $flags = array();
1228  }
1229 
1230  if ( isset( $row->$textField ) ) {
1231  $text = $row->$textField;
1232  } else {
1233  wfProfileOut( __METHOD__ );
1234  return false;
1235  }
1236 
1237  # Use external methods for external objects, text in table is URL-only then
1238  if ( in_array( 'external', $flags ) ) {
1239  $url = $text;
1240  $parts = explode( '://', $url, 2 );
1241  if ( count( $parts ) == 1 || $parts[1] == '' ) {
1242  wfProfileOut( __METHOD__ );
1243  return false;
1244  }
1245  $text = ExternalStore::fetchFromURL( $url, array( 'wiki' => $wiki ) );
1246  }
1247 
1248  // If the text was fetched without an error, convert it
1249  if ( $text !== false ) {
1250  $text = self::decompressRevisionText( $text, $flags );
1251  }
1252  wfProfileOut( __METHOD__ );
1253  return $text;
1254  }
1255 
1266  public static function compressRevisionText( &$text ) {
1267  global $wgCompressRevisions;
1268  $flags = array();
1269 
1270  # Revisions not marked this way will be converted
1271  # on load if $wgLegacyCharset is set in the future.
1272  $flags[] = 'utf-8';
1273 
1274  if ( $wgCompressRevisions ) {
1275  if ( function_exists( 'gzdeflate' ) ) {
1276  $text = gzdeflate( $text );
1277  $flags[] = 'gzip';
1278  } else {
1279  wfDebug( __METHOD__ . " -- no zlib support, not compressing\n" );
1280  }
1281  }
1282  return implode( ',', $flags );
1283  }
1284 
1292  public static function decompressRevisionText( $text, $flags ) {
1293  if ( in_array( 'gzip', $flags ) ) {
1294  # Deal with optional compression of archived pages.
1295  # This can be done periodically via maintenance/compressOld.php, and
1296  # as pages are saved if $wgCompressRevisions is set.
1297  $text = gzinflate( $text );
1298  }
1299 
1300  if ( in_array( 'object', $flags ) ) {
1301  # Generic compressed storage
1302  $obj = unserialize( $text );
1303  if ( !is_object( $obj ) ) {
1304  // Invalid object
1305  return false;
1306  }
1307  $text = $obj->getText();
1308  }
1309 
1310  global $wgLegacyEncoding;
1311  if ( $text !== false && $wgLegacyEncoding
1312  && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags )
1313  ) {
1314  # Old revisions kept around in a legacy encoding?
1315  # Upconvert on demand.
1316  # ("utf8" checked for compatibility with some broken
1317  # conversion scripts 2008-12-30)
1319  $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
1320  }
1321 
1322  return $text;
1323  }
1324 
1333  public function insertOn( $dbw ) {
1334  global $wgDefaultExternalStore, $wgContentHandlerUseDB;
1335 
1336  wfProfileIn( __METHOD__ );
1337 
1338  $this->checkContentModel();
1339 
1340  $data = $this->mText;
1342 
1343  # Write to external storage if required
1344  if ( $wgDefaultExternalStore ) {
1345  // Store and get the URL
1346  $data = ExternalStore::insertToDefault( $data );
1347  if ( !$data ) {
1348  wfProfileOut( __METHOD__ );
1349  throw new MWException( "Unable to store text to external storage" );
1350  }
1351  if ( $flags ) {
1352  $flags .= ',';
1353  }
1354  $flags .= 'external';
1355  }
1356 
1357  # Record the text (or external storage URL) to the text table
1358  if ( !isset( $this->mTextId ) ) {
1359  $old_id = $dbw->nextSequenceValue( 'text_old_id_seq' );
1360  $dbw->insert( 'text',
1361  array(
1362  'old_id' => $old_id,
1363  'old_text' => $data,
1364  'old_flags' => $flags,
1365  ), __METHOD__
1366  );
1367  $this->mTextId = $dbw->insertId();
1368  }
1369 
1370  if ( $this->mComment === null ) {
1371  $this->mComment = "";
1372  }
1373 
1374  # Record the edit in revisions
1375  $rev_id = isset( $this->mId )
1376  ? $this->mId
1377  : $dbw->nextSequenceValue( 'revision_rev_id_seq' );
1378  $row = array(
1379  'rev_id' => $rev_id,
1380  'rev_page' => $this->mPage,
1381  'rev_text_id' => $this->mTextId,
1382  'rev_comment' => $this->mComment,
1383  'rev_minor_edit' => $this->mMinorEdit ? 1 : 0,
1384  'rev_user' => $this->mUser,
1385  'rev_user_text' => $this->mUserText,
1386  'rev_timestamp' => $dbw->timestamp( $this->mTimestamp ),
1387  'rev_deleted' => $this->mDeleted,
1388  'rev_len' => $this->mSize,
1389  'rev_parent_id' => is_null( $this->mParentId )
1390  ? $this->getPreviousRevisionId( $dbw )
1391  : $this->mParentId,
1392  'rev_sha1' => is_null( $this->mSha1 )
1393  ? Revision::base36Sha1( $this->mText )
1394  : $this->mSha1,
1395  );
1396 
1397  if ( $wgContentHandlerUseDB ) {
1398  //NOTE: Store null for the default model and format, to save space.
1399  //XXX: Makes the DB sensitive to changed defaults.
1400  // Make this behavior optional? Only in miser mode?
1401 
1402  $model = $this->getContentModel();
1403  $format = $this->getContentFormat();
1404 
1405  $title = $this->getTitle();
1406 
1407  if ( $title === null ) {
1408  wfProfileOut( __METHOD__ );
1409  throw new MWException( "Insufficient information to determine the title of the "
1410  . "revision's page!" );
1411  }
1412 
1413  $defaultModel = ContentHandler::getDefaultModelFor( $title );
1414  $defaultFormat = ContentHandler::getForModelID( $defaultModel )->getDefaultFormat();
1415 
1416  $row['rev_content_model'] = ( $model === $defaultModel ) ? null : $model;
1417  $row['rev_content_format'] = ( $format === $defaultFormat ) ? null : $format;
1418  }
1419 
1420  $dbw->insert( 'revision', $row, __METHOD__ );
1421 
1422  $this->mId = !is_null( $rev_id ) ? $rev_id : $dbw->insertId();
1423 
1424  wfRunHooks( 'RevisionInsertComplete', array( &$this, $data, $flags ) );
1426  wfProfileOut( __METHOD__ );
1427  return $this->mId;
1428  }
1429 
1430  protected function checkContentModel() {
1431  global $wgContentHandlerUseDB;
1432 
1433  $title = $this->getTitle(); //note: may return null for revisions that have not yet been inserted.
1434 
1435  $model = $this->getContentModel();
1436  $format = $this->getContentFormat();
1437  $handler = $this->getContentHandler();
1438 
1439  if ( !$handler->isSupportedFormat( $format ) ) {
1440  $t = $title->getPrefixedDBkey();
1441 
1442  throw new MWException( "Can't use format $format with content model $model on $t" );
1443  }
1444 
1445  if ( !$wgContentHandlerUseDB && $title ) {
1446  // if $wgContentHandlerUseDB is not set,
1447  // all revisions must use the default content model and format.
1448 
1449  $defaultModel = ContentHandler::getDefaultModelFor( $title );
1450  $defaultHandler = ContentHandler::getForModelID( $defaultModel );
1451  $defaultFormat = $defaultHandler->getDefaultFormat();
1452 
1453  if ( $this->getContentModel() != $defaultModel ) {
1454  $t = $title->getPrefixedDBkey();
1455 
1456  throw new MWException( "Can't save non-default content model with "
1457  . "\$wgContentHandlerUseDB disabled: model is $model, "
1458  . "default for $t is $defaultModel" );
1459  }
1460 
1461  if ( $this->getContentFormat() != $defaultFormat ) {
1462  $t = $title->getPrefixedDBkey();
1463 
1464  throw new MWException( "Can't use non-default content format with "
1465  . "\$wgContentHandlerUseDB disabled: format is $format, "
1466  . "default for $t is $defaultFormat" );
1467  }
1468  }
1469 
1470  $content = $this->getContent( Revision::RAW );
1471 
1472  if ( !$content || !$content->isValid() ) {
1473  $t = $title->getPrefixedDBkey();
1474 
1475  throw new MWException( "Content of $t is not valid! Content model is $model" );
1476  }
1477  }
1478 
1484  public static function base36Sha1( $text ) {
1485  return wfBaseConvert( sha1( $text ), 16, 36, 31 );
1486  }
1487 
1494  protected function loadText() {
1495  wfProfileIn( __METHOD__ );
1496 
1497  // Caching may be beneficial for massive use of external storage
1498  global $wgRevisionCacheExpiry, $wgMemc;
1499  $textId = $this->getTextId();
1500  $key = wfMemcKey( 'revisiontext', 'textid', $textId );
1501  if ( $wgRevisionCacheExpiry ) {
1502  $text = $wgMemc->get( $key );
1503  if ( is_string( $text ) ) {
1504  wfDebug( __METHOD__ . ": got id $textId from cache\n" );
1505  wfProfileOut( __METHOD__ );
1506  return $text;
1507  }
1508  }
1509 
1510  // If we kept data for lazy extraction, use it now...
1511  if ( isset( $this->mTextRow ) ) {
1512  $row = $this->mTextRow;
1513  $this->mTextRow = null;
1514  } else {
1515  $row = null;
1516  }
1517 
1518  if ( !$row ) {
1519  // Text data is immutable; check slaves first.
1520  $dbr = wfGetDB( DB_SLAVE );
1521  $row = $dbr->selectRow( 'text',
1522  array( 'old_text', 'old_flags' ),
1523  array( 'old_id' => $textId ),
1524  __METHOD__ );
1525  }
1526 
1527  // Fallback to the master in case of slave lag. Also use FOR UPDATE if it was
1528  // used to fetch this revision to avoid missing the row due to REPEATABLE-READ.
1529  $forUpdate = ( $this->mQueryFlags & self::READ_LOCKING == self::READ_LOCKING );
1530  if ( !$row && ( $forUpdate || wfGetLB()->getServerCount() > 1 ) ) {
1531  $dbw = wfGetDB( DB_MASTER );
1532  $row = $dbw->selectRow( 'text',
1533  array( 'old_text', 'old_flags' ),
1534  array( 'old_id' => $textId ),
1535  __METHOD__,
1536  $forUpdate ? array( 'FOR UPDATE' ) : array() );
1537  }
1538 
1539  if ( !$row ) {
1540  wfDebugLog( 'Revision', "No text row with ID '$textId' (revision {$this->getId()})." );
1541  }
1542 
1543  $text = self::getRevisionText( $row );
1544  if ( $row && $text === false ) {
1545  wfDebugLog( 'Revision', "No blob for text row '$textId' (revision {$this->getId()})." );
1546  }
1547 
1548  # No negative caching -- negative hits on text rows may be due to corrupted slave servers
1549  if ( $wgRevisionCacheExpiry && $text !== false ) {
1550  $wgMemc->set( $key, $text, $wgRevisionCacheExpiry );
1551  }
1552 
1553  wfProfileOut( __METHOD__ );
1554 
1555  return $text;
1556  }
1557 
1572  public static function newNullRevision( $dbw, $pageId, $summary, $minor ) {
1573  global $wgContentHandlerUseDB;
1574 
1575  wfProfileIn( __METHOD__ );
1576 
1577  $fields = array( 'page_latest', 'page_namespace', 'page_title',
1578  'rev_text_id', 'rev_len', 'rev_sha1' );
1579 
1580  if ( $wgContentHandlerUseDB ) {
1581  $fields[] = 'rev_content_model';
1582  $fields[] = 'rev_content_format';
1583  }
1584 
1585  $current = $dbw->selectRow(
1586  array( 'page', 'revision' ),
1587  $fields,
1588  array(
1589  'page_id' => $pageId,
1590  'page_latest=rev_id',
1591  ),
1592  __METHOD__ );
1593 
1594  if ( $current ) {
1595  $row = array(
1596  'page' => $pageId,
1597  'comment' => $summary,
1598  'minor_edit' => $minor,
1599  'text_id' => $current->rev_text_id,
1600  'parent_id' => $current->page_latest,
1601  'len' => $current->rev_len,
1602  'sha1' => $current->rev_sha1
1603  );
1604 
1605  if ( $wgContentHandlerUseDB ) {
1606  $row['content_model'] = $current->rev_content_model;
1607  $row['content_format'] = $current->rev_content_format;
1608  }
1609 
1610  $revision = new Revision( $row );
1611  $revision->setTitle( Title::makeTitle( $current->page_namespace, $current->page_title ) );
1612  } else {
1613  $revision = null;
1614  }
1615 
1616  wfProfileOut( __METHOD__ );
1617  return $revision;
1618  }
1619 
1630  public function userCan( $field, User $user = null ) {
1631  return self::userCanBitfield( $this->mDeleted, $field, $user );
1632  }
1633 
1646  public static function userCanBitfield( $bitfield, $field, User $user = null ) {
1647  if ( $bitfield & $field ) { // aspect is deleted
1648  if ( $bitfield & self::DELETED_RESTRICTED ) {
1649  $permission = 'suppressrevision';
1650  } elseif ( $field & self::DELETED_TEXT ) {
1651  $permission = 'deletedtext';
1652  } else {
1653  $permission = 'deletedhistory';
1654  }
1655  wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
1656  if ( $user === null ) {
1657  global $wgUser;
1658  $user = $wgUser;
1659  }
1660  return $user->isAllowed( $permission );
1661  } else {
1662  return true;
1663  }
1664  }
1665 
1673  static function getTimestampFromId( $title, $id ) {
1674  $dbr = wfGetDB( DB_SLAVE );
1675  // Casting fix for databases that can't take '' for rev_id
1676  if ( $id == '' ) {
1677  $id = 0;
1678  }
1679  $conds = array( 'rev_id' => $id );
1680  $conds['rev_page'] = $title->getArticleID();
1681  $timestamp = $dbr->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
1682  if ( $timestamp === false && wfGetLB()->getServerCount() > 1 ) {
1683  # Not in slave, try master
1684  $dbw = wfGetDB( DB_MASTER );
1685  $timestamp = $dbw->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__ );
1686  }
1687  return wfTimestamp( TS_MW, $timestamp );
1688  }
1689 
1697  static function countByPageId( $db, $id ) {
1698  $row = $db->selectRow( 'revision', array( 'revCount' => 'COUNT(*)' ),
1699  array( 'rev_page' => $id ), __METHOD__ );
1700  if ( $row ) {
1701  return $row->revCount;
1702  }
1703  return 0;
1704  }
1705 
1713  static function countByTitle( $db, $title ) {
1714  $id = $title->getArticleID();
1715  if ( $id ) {
1716  return self::countByPageId( $db, $id );
1717  }
1718  return 0;
1719  }
1720 
1736  public static function userWasLastToEdit( $db, $pageId, $userId, $since ) {
1737  if ( !$userId ) {
1738  return false;
1739  }
1740 
1741  if ( is_int( $db ) ) {
1742  $db = wfGetDB( $db );
1743  }
1744 
1745  $res = $db->select( 'revision',
1746  'rev_user',
1747  array(
1748  'rev_page' => $pageId,
1749  'rev_timestamp > ' . $db->addQuotes( $db->timestamp( $since ) )
1750  ),
1751  __METHOD__,
1752  array( 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ) );
1753  foreach ( $res as $row ) {
1754  if ( $row->rev_user != $userId ) {
1755  return false;
1756  }
1757  }
1758  return true;
1759  }
1760 }
Revision\FOR_PUBLIC
const FOR_PUBLIC
Definition: Revision.php:72
ContentHandler\deprecated
static deprecated( $func, $version, $component=false)
Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if self::$enableDeprecationWa...
Definition: ContentHandler.php:1030
Revision\DELETED_USER
const DELETED_USER
Definition: Revision.php:67
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:55
Revision\getTimestamp
getTimestamp()
Definition: Revision.php:1133
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:311
Revision\$mPage
int null $mPage
Definition: Revision.php:31
$wgUser
$wgUser
Definition: Setup.php:572
Revision\DELETED_RESTRICTED
const DELETED_RESTRICTED
Definition: Revision.php:68
Revision\getRawText
getRawText()
Fetch revision text without regard for view restrictions.
Definition: Revision.php:1017
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
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:844
Revision\DELETED_COMMENT
const DELETED_COMMENT
Definition: Revision.php:66
Revision\$mTimestamp
$mTimestamp
Definition: Revision.php:36
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Revision\newFromId
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Definition: Revision.php:88
content
per default it will return the text for text based content
Definition: contenthandler.txt:107
Revision\getPreviousRevisionId
getPreviousRevisionId( $db)
Get previous revision Id for this page_id This is used to populate rev_parent_id on save.
Definition: Revision.php:1181
Revision\getRawUser
getRawUser()
Fetch revision's user id without regard for the current user's permissions.
Definition: Revision.php:827
Revision\pageJoinCond
static pageJoinCond()
Return the value of a select() page conds array for the page table.
Definition: Revision.php:396
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:812
Revision\newNullRevision
static newNullRevision( $dbw, $pageId, $summary, $minor)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1567
Revision\$mContentModel
$mContentModel
Definition: Revision.php:49
Revision\loadText
loadText()
Lazy-load the revision's text.
Definition: Revision.php:1489
Revision\$mContentHandler
null ContentHandler $mContentHandler
Definition: Revision.php:58
Revision\getSize
getSize()
Returns the length of the text in this revision, or null if unknown.
Definition: Revision.php:736
$wgMemc
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest to get request data $wgMemc
Definition: globals.txt:25
wfGetLB
wfGetLB( $wiki=false)
Get a load balancer object.
Definition: GlobalFunctions.php:3724
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3714
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
Revision\setId
setId( $id)
Set the revision ID.
Definition: Revision.php:709
Revision\getContent
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
Definition: Revision.php:999
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1087
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
Revision\getPage
getPage()
Get the page ID.
Definition: Revision.php:795
Revision\$mComment
$mComment
Definition: Revision.php:41
Revision\$mParentId
$mParentId
Definition: Revision.php:40
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
RecentChange\newFromConds
static newFromConds( $conds, $fname=__METHOD__, $options=array())
Find the first recent change matching some specific conditions.
Definition: RecentChange.php:136
Revision\$mTextRow
$mTextRow
Definition: Revision.php:43
Revision\getRevisionText
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row $row is usually an object from wfFetchRow(),...
Definition: Revision.php:1212
Revision\getParentId
getParentId()
Get parent revision ID (the original previous page revision)
Definition: Revision.php:727
Revision\$mTitle
null Title $mTitle
Definition: Revision.php:47
Revision\setTitle
setTitle( $title)
Set the title of the revision.
Definition: Revision.php:786
Revision\$mSize
$mSize
Definition: Revision.php:38
Revision\getContentHandler
getContentHandler()
Returns the content handler appropriate for this revision's content model.
Definition: Revision.php:1114
Revision\fetchFromConds
static fetchFromConds( $db, $conditions, $flags=0)
Given a set of conditions, return a ResultWrapper which will return matching database rows with the f...
Definition: Revision.php:360
Revision\getSerializedData
getSerializedData()
Fetch original serialized data without regard for view restrictions.
Definition: Revision.php:1028
Revision\isCurrent
isCurrent()
Definition: Revision.php:1140
Revision\userCanBitfield
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this revision,...
Definition: Revision.php:1641
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:283
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:137
Revision\getSha1
getSha1()
Returns the base36 sha1 of the text in this revision, or null if unknown.
Definition: Revision.php:745
Revision\loadFromId
static loadFromId( $db, $id)
Load a page revision from a given revision ID number.
Definition: Revision.php:218
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2124
IDBAccessObject
Interface for database access objects.
Definition: IDBAccessObject.php:47
Revision\getId
getId()
Get revision ID.
Definition: Revision.php:699
Revision\getContentModel
getContentModel()
Returns the content model for this revision.
Definition: Revision.php:1077
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:1328
Revision\base36Sha1
static base36Sha1( $text)
Get the base 36 SHA-1 value for a string of text.
Definition: Revision.php:1479
Revision\getTimestampFromId
static getTimestampFromId( $title, $id)
Get rev_timestamp from rev_id, without loading the rest of the row.
Definition: Revision.php:1668
Revision\getRecentChange
getRecentChange()
Get the RC object belonging to the current revision, if there's one.
Definition: Revision.php:932
Revision\$mQueryFlags
int $mQueryFlags
Definition: Revision.php:62
Revision\selectTextFields
static selectTextFields()
Return the list of text fields that should be selected to read the revision text.
Definition: Revision.php:467
$dbr
$dbr
Definition: testCompression.php:48
IDBAccessObject\READ_LOCKING
const READ_LOCKING
Definition: IDBAccessObject.php:50
Revision\FOR_THIS_USER
const FOR_THIS_USER
Definition: Revision.php:73
Revision
Definition: Revision.php:26
Revision\SUPPRESSED_USER
const SUPPRESSED_USER
Definition: Revision.php:69
ContentHandler\getDefaultModelFor
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
Definition: ContentHandler.php:193
MWException
MediaWiki exception.
Definition: MWException.php:26
Revision\getNext
getNext()
Get next revision for this title.
Definition: Revision.php:1164
wfMemcKey
wfMemcKey()
Get a cache key.
Definition: GlobalFunctions.php:3635
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:345
ExternalStore\insertToDefault
static insertToDefault( $data, array $params=array())
Like insert() above, but does more of the work for us.
Definition: ExternalStore.php:169
Revision\isUnpatrolled
isUnpatrolled()
Definition: Revision.php:913
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:232
Revision\compressRevisionText
static compressRevisionText(&$text)
If $wgCompressRevisions is enabled, we will compress data.
Definition: Revision.php:1261
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4066
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Revision\fetchRevision
static fetchRevision( $title)
Return a wrapper for a series of database rows to fetch all of a given page's revisions in turn.
Definition: Revision.php:339
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2561
Revision\$mMinorEdit
$mMinorEdit
Definition: Revision.php:35
Revision\countByTitle
static countByTitle( $db, $title)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1708
Revision\getPrevious
getPrevious()
Get previous revision for this title.
Definition: Revision.php:1149
Revision\countByPageId
static countByPageId( $db, $id)
Get count of revisions per page...not very efficient.
Definition: Revision.php:1692
Revision\newFromConds
static newFromConds( $conditions, $flags=0)
Given a set of conditions, fetch a revision.
Definition: Revision.php:294
$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:1530
Revision\selectPageFields
static selectPageFields()
Return the list of page fields that should be selected from page table.
Definition: Revision.php:478
Revision\getTitle
getTitle()
Returns the title of the page associated with this entry or null.
Definition: Revision.php:756
Revision\checkContentModel
checkContentModel()
Definition: Revision.php:1425
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:1731
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2478
Revision\newFromTitle
static newFromTitle( $title, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given title.
Definition: Revision.php:106
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:980
Revision\__construct
__construct( $row)
Constructor.
Definition: Revision.php:527
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
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:436
User\whoIs
static whoIs( $id)
Get the username corresponding to a given user ID.
Definition: User.php:484
Revision\getParentLengths
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
Definition: Revision.php:503
Revision\getVisibility
getVisibility()
Get the deletion bitfield of the revision.
Definition: Revision.php:958
Revision\getTextId
getTextId()
Get text row ID.
Definition: Revision.php:718
Revision\getText
getText( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision text if it's available to the specified audience.
Definition: Revision.php:978
Revision\newFromArchiveRow
static newFromArchiveRow( $row, $overrides=array())
Make a fake revision object from an archive table row.
Definition: Revision.php:159
Revision\isDeleted
isDeleted( $field)
Definition: Revision.php:949
Revision\newFromRow
static newFromRow( $row)
Definition: Revision.php:206
Revision\$mContent
Content null bool $mContent
Definition: Revision.php:54
Revision\RAW
const RAW
Definition: Revision.php:74
Revision\$mSha1
$mSha1
Definition: Revision.php:39
Revision\getRawUserText
getRawUserText()
Fetch revision's username without regard for view restrictions.
Definition: Revision.php:859
Revision\$mUserText
$mUserText
Definition: Revision.php:32
$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:237
Revision\getContentFormat
getContentFormat()
Returns the content format for this revision.
Definition: Revision.php:1097
$summary
$summary
Definition: importImages.php:120
Content
Base interface for content objects.
Definition: Content.php:34
$rev
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition: hooks.txt:1337
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
Title
Represents a title within MediaWiki.
Definition: Title.php:35
Revision\$mContentFormat
$mContentFormat
Definition: Revision.php:50
ContentHandler\getContentText
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
Definition: ContentHandler.php:94
ExternalStore\fetchFromURL
static fetchFromURL( $url, array $params=array())
Fetch data from given URL.
Definition: ExternalStore.php:75
on
We ve cleaned up the code here by removing clumps of infrequently used code and moving them off somewhere else It s much easier for someone working with this code to see what s _really_ going on
Definition: hooks.txt:86
Revision\$mCurrent
$mCurrent
Definition: Revision.php:48
wfBaseConvert
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
Definition: GlobalFunctions.php:3432
needed
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when needed(most notably, OutputPage::addWikiText()). The StandardSkin object is a complete implementation
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Revision\$mDeleted
$mDeleted
Definition: Revision.php:37
Revision\userJoinCond
static userJoinCond()
Return the value of a select() JOIN conds array for the user table.
Definition: Revision.php:386
Revision\$mId
$mId
Definition: Revision.php:27
Revision\loadFromTimestamp
static loadFromTimestamp( $db, $title, $timestamp)
Load the revision for the given title with the given timestamp.
Definition: Revision.php:277
Revision\getContentInternal
getContentInternal()
Gets the content object for the revision (or null on failure).
Definition: Revision.php:1045
Revision\getRawComment
getRawComment()
Fetch revision comment without regard for the current user's permissions.
Definition: Revision.php:899
Revision\getComment
getComment( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision comment if it's available to the specified audience.
Definition: Revision.php:884
Revision\loadFromConds
static loadFromConds( $db, $conditions, $flags=0)
Given a set of conditions, fetch a revision from the given database connection.
Definition: Revision.php:318
Revision\$mText
$mText
Definition: Revision.php:42
Revision\isMinor
isMinor()
Definition: Revision.php:906
Revision\selectUserFields
static selectUserFields()
Return the list of user fields that should be selected from user table.
Definition: Revision.php:493
$t
$t
Definition: testCompression.php:65
Revision\selectFields
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition: Revision.php:405
Revision\decompressRevisionText
static decompressRevisionText( $text, $flags)
Re-converts revision text according to it's flags.
Definition: Revision.php:1287
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:252
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530
Revision\$mUser
$mUser
Definition: Revision.php:34
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
Title\newFromID
static newFromID( $id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:297
$res
$res
Definition: database.txt:21
Revision\$mOrigUserText
$mOrigUserText
Definition: Revision.php:33
Revision\DELETED_TEXT
const DELETED_TEXT
Definition: Revision.php:65
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:1625