MediaWiki REL1_34
WikiRevision.php
Go to the documentation of this file.
1<?php
28
38
43 public $title = null;
44
49 public $id = 0;
50
55 public $timestamp = "20010115000000";
56
61 public $user_text = "";
62
67 public $userObj = null;
68
73 public $model = null;
74
79 public $format = null;
80
85 public $text = "";
86
91 protected $size;
92
97 public $content = null;
98
103 protected $contentHandler = null;
104
109 public $comment = "";
110
115 public $minor = false;
116
121 public $type = "";
122
127 public $action = "";
128
133 public $params = "";
134
139 public $fileSrc = '';
140
145 public $sha1base36 = false;
146
151 protected $tags = [];
152
157 public $archiveName = '';
158
162 protected $filename;
163
168 protected $src = null;
169
175 public $isTemp = false;
176
184
186 private $mNoUpdates = false;
187
192 private $config;
193
198 public function __construct( Config $config ) {
199 $this->config = $config;
200 }
201
207 public function setTitle( $title ) {
208 if ( is_object( $title ) ) {
209 $this->title = $title;
210 } elseif ( is_null( $title ) ) {
211 throw new MWException( "WikiRevision given a null title in import. "
212 . "You may need to adjust \$wgLegalTitleChars." );
213 } else {
214 throw new MWException( "WikiRevision given non-object title in import." );
215 }
216 }
217
222 public function setID( $id ) {
223 $this->id = $id;
224 }
225
230 public function setTimestamp( $ts ) {
231 # 2003-08-05T18:30:02Z
232 $this->timestamp = wfTimestamp( TS_MW, $ts );
233 }
234
239 public function setUsername( $user ) {
240 $this->user_text = $user;
241 }
242
247 public function setUserObj( $user ) {
248 $this->userObj = $user;
249 }
250
255 public function setUserIP( $ip ) {
256 $this->user_text = $ip;
257 }
258
263 public function setModel( $model ) {
264 $this->model = $model;
265 }
266
271 public function setFormat( $format ) {
272 $this->format = $format;
273 }
274
279 public function setText( $text ) {
280 $this->text = $text;
281 }
282
287 public function setComment( $text ) {
288 $this->comment = $text;
289 }
290
295 public function setMinor( $minor ) {
296 $this->minor = (bool)$minor;
297 }
298
303 public function setSrc( $src ) {
304 $this->src = $src;
305 }
306
312 public function setFileSrc( $src, $isTemp ) {
313 $this->fileSrc = $src;
314 $this->fileIsTemp = $isTemp;
315 $this->isTemp = $isTemp;
316 }
317
322 public function setSha1Base36( $sha1base36 ) {
323 $this->sha1base36 = $sha1base36;
324 }
325
330 public function setTags( array $tags ) {
331 $this->tags = $tags;
332 }
333
338 public function setFilename( $filename ) {
339 $this->filename = $filename;
340 }
341
346 public function setArchiveName( $archiveName ) {
347 $this->archiveName = $archiveName;
348 }
349
354 public function setSize( $size ) {
355 $this->size = intval( $size );
356 }
357
362 public function setType( $type ) {
363 $this->type = $type;
364 }
365
370 public function setAction( $action ) {
371 $this->action = $action;
372 }
373
378 public function setParams( $params ) {
379 $this->params = $params;
380 }
381
386 public function setNoUpdates( $noupdates ) {
387 $this->mNoUpdates = $noupdates;
388 }
389
394 public function getTitle() {
395 return $this->title;
396 }
397
402 public function getID() {
403 return $this->id;
404 }
405
410 public function getTimestamp() {
411 return $this->timestamp;
412 }
413
418 public function getUser() {
419 return $this->user_text;
420 }
421
426 public function getUserObj() {
427 return $this->userObj;
428 }
429
434 public function getText() {
435 return $this->text;
436 }
437
442 public function getContentHandler() {
443 if ( is_null( $this->contentHandler ) ) {
444 $this->contentHandler = ContentHandler::getForModelID( $this->getModel() );
445 }
446
448 }
449
454 public function getContent() {
455 if ( is_null( $this->content ) ) {
456 $handler = $this->getContentHandler();
457 $this->content = $handler->unserializeContent( $this->text, $this->getFormat() );
458 }
459
460 return $this->content;
461 }
462
467 public function getModel() {
468 if ( is_null( $this->model ) ) {
469 $this->model = $this->getTitle()->getContentModel();
470 }
471
472 return $this->model;
473 }
474
479 public function getFormat() {
480 if ( is_null( $this->format ) ) {
481 $this->format = $this->getContentHandler()->getDefaultFormat();
482 }
483
484 return $this->format;
485 }
486
491 public function getComment() {
492 return $this->comment;
493 }
494
499 public function getMinor() {
500 return $this->minor;
501 }
502
507 public function getSrc() {
508 return $this->src;
509 }
510
515 public function getSha1() {
516 if ( $this->sha1base36 ) {
517 return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
518 }
519 return false;
520 }
521
526 public function getSha1Base36() {
527 if ( $this->sha1base36 ) {
528 return $this->sha1base36;
529 }
530 return false;
531 }
532
537 public function getTags() {
538 return $this->tags;
539 }
540
545 public function getFileSrc() {
546 return $this->fileSrc;
547 }
548
553 public function isTempSrc() {
554 return $this->isTemp;
555 }
556
561 public function getFilename() {
562 return $this->filename;
563 }
564
569 public function getArchiveName() {
570 return $this->archiveName;
571 }
572
577 public function getSize() {
578 return $this->size;
579 }
580
585 public function getType() {
586 return $this->type;
587 }
588
593 public function getAction() {
594 return $this->action;
595 }
596
601 public function getParams() {
602 return $this->params;
603 }
604
610 public function importOldRevision() {
611 if ( $this->mNoUpdates ) {
612 $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporterNoUpdates();
613 } else {
614 $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporter();
615 }
616 return $importer->import( $this );
617 }
618
623 public function importLogItem() {
624 $dbw = wfGetDB( DB_MASTER );
625
626 $user = $this->getUserObj() ?: User::newFromName( $this->getUser(), false );
627
628 # @todo FIXME: This will not record autoblocks
629 if ( !$this->getTitle() ) {
630 wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
631 $this->timestamp . "\n" );
632 return false;
633 }
634 # Check if it exists already
635 // @todo FIXME: Use original log ID (better for backups)
636 $prior = $dbw->selectField( 'logging', '1',
637 [ 'log_type' => $this->getType(),
638 'log_action' => $this->getAction(),
639 'log_timestamp' => $dbw->timestamp( $this->timestamp ),
640 'log_namespace' => $this->getTitle()->getNamespace(),
641 'log_title' => $this->getTitle()->getDBkey(),
642 'log_params' => $this->params ],
643 __METHOD__
644 );
645 // @todo FIXME: This could fail slightly for multiple matches :P
646 if ( $prior ) {
647 wfDebug( __METHOD__
648 . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
649 . $this->timestamp . "\n" );
650 return false;
651 }
652 $data = [
653 'log_type' => $this->type,
654 'log_action' => $this->action,
655 'log_timestamp' => $dbw->timestamp( $this->timestamp ),
656 'log_namespace' => $this->getTitle()->getNamespace(),
657 'log_title' => $this->getTitle()->getDBkey(),
658 'log_params' => $this->params
659 ] + CommentStore::getStore()->insert( $dbw, 'log_comment', $this->getComment() )
660 + ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user );
661 $dbw->insert( 'logging', $data, __METHOD__ );
662
663 return true;
664 }
665
671 public function importUpload() {
672 $importer = MediaWikiServices::getInstance()->getWikiRevisionUploadImporter();
673 $statusValue = $importer->import( $this );
674 return $statusValue->isGood();
675 }
676
682 public function downloadSource() {
683 $importer = new ImportableUploadRevisionImporter(
684 $this->config->get( 'EnableUploads' ),
685 LoggerFactory::getInstance( 'UploadRevisionImporter' )
686 );
687 return $importer->downloadSource( $this );
688 }
689
690}
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.
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:51
Represents a revision, log entry or upload during the import process.
setAction( $action)
setFilename( $filename)
setMinor( $minor)
string $timestamp
string null $src
setTitle( $title)
__construct(Config $config)
setTags(array $tags)
setParams( $params)
setUsername( $user)
setUserObj( $user)
setArchiveName( $archiveName)
setSha1Base36( $sha1base36)
bool string $sha1base36
string $user_text
ContentHandler $contentHandler
setComment( $text)
Content $content
string $archiveName
setModel( $model)
setFileSrc( $src, $isTemp)
setNoUpdates( $noupdates)
setFormat( $format)
Interface for configuration instances.
Definition Config.php:28
Base interface for content objects.
Definition Content.php:34
const DB_MASTER
Definition defines.php:26