MediaWiki REL1_35
WikiRevision.php
Go to the documentation of this file.
1<?php
30
40
45 public $title = null;
46
51 public $id = 0;
52
57 public $timestamp = "20010115000000";
58
63 public $user_text = "";
64
69 public $userObj = null;
70
76 public $model = null;
77
83 public $format = null;
84
90 public $text = "";
91
96 protected $size;
97
103 public $content = null;
104
109 protected $contentHandler = null;
110
115 public $comment = "";
116
120 private $slots;
121
126 public $minor = false;
127
132 public $type = "";
133
138 public $action = "";
139
144 public $params = "";
145
150 public $fileSrc = '';
151
156 public $sha1base36 = false;
157
162 protected $tags = [];
163
168 public $archiveName = '';
169
173 protected $filename;
174
179 protected $src = null;
180
186 public $isTemp = false;
187
195
197 private $mNoUpdates = false;
198
203 private $config;
204
209 public function __construct( Config $config ) {
210 $this->config = $config;
211 $this->slots = new MutableRevisionSlots();
212 }
213
219 public function setTitle( $title ) {
220 if ( is_object( $title ) ) {
221 $this->title = $title;
222 } elseif ( $title === null ) {
223 throw new MWException( "WikiRevision given a null title in import. "
224 . "You may need to adjust \$wgLegalTitleChars." );
225 } else {
226 throw new MWException( "WikiRevision given non-object title in import." );
227 }
228 }
229
234 public function setID( $id ) {
235 $this->id = $id;
236 }
237
242 public function setTimestamp( $ts ) {
243 # 2003-08-05T18:30:02Z
244 $this->timestamp = wfTimestamp( TS_MW, $ts );
245 }
246
251 public function setUsername( $user ) {
252 $this->user_text = $user;
253 }
254
259 public function setUserObj( $user ) {
260 $this->userObj = $user;
261 }
262
267 public function setUserIP( $ip ) {
268 $this->user_text = $ip;
269 }
270
276 public function setModel( $model ) {
277 $this->model = $model;
278 }
279
285 public function setFormat( $format ) {
286 $this->format = $format;
287 }
288
294 public function setText( $text ) {
295 $handler = ContentHandler::getForModelID( $this->model );
296 $content = $handler->unserializeContent( $text );
297 $this->setContent( SlotRecord::MAIN, $content );
298 }
299
305 public function setContent( $role, $content ) {
306 $this->slots->setContent( $role, $content );
307
308 // backwards compat
309 if ( $role === SlotRecord::MAIN ) {
310 $this->content = $content;
311 $this->model = $content->getModel();
312 $this->format = $content->getDefaultFormat();
313 $this->text = $content->serialize();
314 }
315 }
316
321 public function setComment( $text ) {
322 $this->comment = $text;
323 }
324
329 public function setMinor( $minor ) {
330 $this->minor = (bool)$minor;
331 }
332
337 public function setSrc( $src ) {
338 $this->src = $src;
339 }
340
346 public function setFileSrc( $src, $isTemp ) {
347 $this->fileSrc = $src;
348 $this->fileIsTemp = $isTemp;
349 $this->isTemp = $isTemp;
350 }
351
356 public function setSha1Base36( $sha1base36 ) {
357 $this->sha1base36 = $sha1base36;
358 }
359
364 public function setTags( array $tags ) {
365 $this->tags = $tags;
366 }
367
372 public function setFilename( $filename ) {
373 $this->filename = $filename;
374 }
375
380 public function setArchiveName( $archiveName ) {
381 $this->archiveName = $archiveName;
382 }
383
388 public function setSize( $size ) {
389 $this->size = intval( $size );
390 }
391
396 public function setType( $type ) {
397 $this->type = $type;
398 }
399
404 public function setAction( $action ) {
405 $this->action = $action;
406 }
407
412 public function setParams( $params ) {
413 $this->params = $params;
414 }
415
420 public function setNoUpdates( $noupdates ) {
421 $this->mNoUpdates = $noupdates;
422 }
423
428 public function getTitle() {
429 return $this->title;
430 }
431
436 public function getID() {
437 return $this->id;
438 }
439
444 public function getTimestamp() {
445 return $this->timestamp;
446 }
447
452 public function getUser() {
453 return $this->user_text;
454 }
455
460 public function getUserObj() {
461 return $this->userObj;
462 }
463
468 public function getText() {
469 return $this->text;
470 }
471
478 public function getContentHandler() {
479 if ( $this->contentHandler === null ) {
480 $this->contentHandler = MediaWikiServices::getInstance()
481 ->getContentHandlerFactory()
482 ->getContentHandler( $this->getModel() );
483 }
484
486 }
487
493 public function getContent( $role = SlotRecord::MAIN ) {
494 return $this->slots->getContent( $role );
495 }
496
502 public function getSlot( $role ) {
503 return $this->slots->getSlot( $role );
504 }
505
510 public function getSlotRoles() {
511 return $this->slots->getSlotRoles();
512 }
513
519 public function getModel() {
520 if ( $this->model === null ) {
521 $this->model = $this->getTitle()->getContentModel();
522 }
523
524 return $this->model;
525 }
526
532 public function getFormat() {
533 if ( $this->format === null ) {
534 $this->format = $this->getContentHandler()->getDefaultFormat();
535 }
536
537 return $this->format;
538 }
539
544 public function getComment() {
545 return $this->comment;
546 }
547
552 public function getMinor() {
553 return $this->minor;
554 }
555
560 public function getSrc() {
561 return $this->src;
562 }
563
568 public function getSha1() {
569 if ( $this->sha1base36 ) {
570 return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
571 }
572 return false;
573 }
574
579 public function getSha1Base36() {
580 if ( $this->sha1base36 ) {
581 return $this->sha1base36;
582 }
583 return false;
584 }
585
590 public function getTags() {
591 return $this->tags;
592 }
593
598 public function getFileSrc() {
599 return $this->fileSrc;
600 }
601
606 public function isTempSrc() {
607 return $this->isTemp;
608 }
609
614 public function getFilename() {
615 return $this->filename;
616 }
617
622 public function getArchiveName() {
623 return $this->archiveName;
624 }
625
630 public function getSize() {
631 return $this->size;
632 }
633
638 public function getType() {
639 return $this->type;
640 }
641
646 public function getAction() {
647 return $this->action;
648 }
649
654 public function getParams() {
655 return $this->params;
656 }
657
663 public function importOldRevision() {
664 if ( $this->mNoUpdates ) {
665 $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporterNoUpdates();
666 } else {
667 $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporter();
668 }
669 return $importer->import( $this );
670 }
671
676 public function importLogItem() {
677 $dbw = wfGetDB( DB_MASTER );
678
679 $user = $this->getUserObj() ?: User::newFromName( $this->getUser(), false );
680
681 # @todo FIXME: This will not record autoblocks
682 if ( !$this->getTitle() ) {
683 wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
684 $this->timestamp );
685 return false;
686 }
687 # Check if it exists already
688 // @todo FIXME: Use original log ID (better for backups)
689 $prior = $dbw->selectField( 'logging', '1',
690 [ 'log_type' => $this->getType(),
691 'log_action' => $this->getAction(),
692 'log_timestamp' => $dbw->timestamp( $this->timestamp ),
693 'log_namespace' => $this->getTitle()->getNamespace(),
694 'log_title' => $this->getTitle()->getDBkey(),
695 'log_params' => $this->params ],
696 __METHOD__
697 );
698 // @todo FIXME: This could fail slightly for multiple matches :P
699 if ( $prior ) {
700 wfDebug( __METHOD__
701 . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
702 . $this->timestamp );
703 return false;
704 }
705 $data = [
706 'log_type' => $this->type,
707 'log_action' => $this->action,
708 'log_timestamp' => $dbw->timestamp( $this->timestamp ),
709 'log_namespace' => $this->getTitle()->getNamespace(),
710 'log_title' => $this->getTitle()->getDBkey(),
711 'log_params' => $this->params
712 ] + CommentStore::getStore()->insert( $dbw, 'log_comment', $this->getComment() )
713 + ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user );
714 $dbw->insert( 'logging', $data, __METHOD__ );
715
716 return true;
717 }
718
724 public function importUpload() {
725 $importer = MediaWikiServices::getInstance()->getWikiRevisionUploadImporter();
726 $statusValue = $importer->import( $this );
727 return $statusValue->isGood();
728 }
729
735 public function downloadSource() {
736 $importer = new ImportableUploadRevisionImporter(
737 $this->config->get( 'EnableUploads' ),
738 LoggerFactory::getInstance( 'UploadRevisionImporter' )
739 );
740 return $importer->downloadSource( $this );
741 }
742
743}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
A content handler knows how do deal with a specific type of content on a wiki page.
MediaWiki exception.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Mutable version of RevisionSlots, for constructing a new revision.
Value object representing a content slot associated with a page revision.
Represents a title within MediaWiki.
Definition Title.php:42
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:60
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:541
Represents a revision, log entry or upload during the import process.
setAction( $action)
setContent( $role, $content)
setFilename( $filename)
setMinor( $minor)
string $timestamp
string null $src
setTitle( $title)
__construct(Config $config)
setTags(array $tags)
getContent( $role=SlotRecord::MAIN)
setParams( $params)
setUsername( $user)
setUserObj( $user)
setArchiveName( $archiveName)
MutableRevisionSlots $slots
setSha1Base36( $sha1base36)
bool string $sha1base36
string $user_text
ContentHandler $contentHandler
setComment( $text)
string $archiveName
setModel( $model)
setFileSrc( $src, $isTemp)
setNoUpdates( $noupdates)
setFormat( $format)
Interface for configuration instances.
Definition Config.php:30
Base interface for content objects.
Definition Content.php:35
getModel()
Returns the ID of the content model used by this Content object.
serialize( $format=null)
Convenience method for serializing this Content object.
getDefaultFormat()
Convenience method that returns the default serialization format for the content model that this Cont...
const DB_MASTER
Definition defines.php:29