MediaWiki  1.34.0
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 
183  public $fileIsTemp;
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 
447  return $this->contentHandler;
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 }
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:55
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:254
WikiRevision\getUser
getUser()
Definition: WikiRevision.php:418
WikiRevision\$format
string $format
Definition: WikiRevision.php:79
WikiRevision\$filename
$filename
Definition: WikiRevision.php:162
WikiRevision\$type
string $type
Definition: WikiRevision.php:121
WikiRevision\setUserObj
setUserObj( $user)
Definition: WikiRevision.php:247
WikiRevision\$src
string null $src
Definition: WikiRevision.php:168
WikiRevision\getComment
getComment()
Definition: WikiRevision.php:491
WikiRevision\setTags
setTags(array $tags)
Definition: WikiRevision.php:330
WikiRevision\downloadSource
downloadSource()
Definition: WikiRevision.php:682
WikiRevision\setNoUpdates
setNoUpdates( $noupdates)
Definition: WikiRevision.php:386
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
WikiRevision\setComment
setComment( $text)
Definition: WikiRevision.php:287
WikiRevision\$userObj
User $userObj
Definition: WikiRevision.php:67
WikiRevision\isTempSrc
isTempSrc()
Definition: WikiRevision.php:553
WikiRevision\importUpload
importUpload()
Definition: WikiRevision.php:671
WikiRevision\$user_text
string $user_text
Definition: WikiRevision.php:61
WikiRevision\getSrc
getSrc()
Definition: WikiRevision.php:507
WikiRevision\$size
int $size
Definition: WikiRevision.php:91
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1869
ImportableUploadRevisionImporter\downloadSource
downloadSource(ImportableUploadRevision $wikiRevision)
Definition: ImportableUploadRevisionImporter.php:150
WikiRevision\getTitle
getTitle()
Definition: WikiRevision.php:394
WikiRevision\getSha1
getSha1()
Definition: WikiRevision.php:515
WikiRevision\setSha1Base36
setSha1Base36( $sha1base36)
Definition: WikiRevision.php:322
WikiRevision\getFilename
getFilename()
Definition: WikiRevision.php:561
WikiRevision\$model
string $model
Definition: WikiRevision.php:73
WikiRevision\setText
setText( $text)
Definition: WikiRevision.php:279
WikiRevision\setFilename
setFilename( $filename)
Definition: WikiRevision.php:338
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:515
WikiRevision\setUsername
setUsername( $user)
Definition: WikiRevision.php:239
ImportableUploadRevision
Definition: ImportableUploadRevision.php:6
WikiRevision\getType
getType()
Definition: WikiRevision.php:585
WikiRevision\__construct
__construct(Config $config)
Definition: WikiRevision.php:198
WikiRevision\getModel
getModel()
Definition: WikiRevision.php:467
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:136
WikiRevision\$isTemp
bool $isTemp
Definition: WikiRevision.php:175
WikiRevision\$minor
bool $minor
Definition: WikiRevision.php:115
WikiRevision\$params
string $params
Definition: WikiRevision.php:133
WikiRevision\$mNoUpdates
bool $mNoUpdates
Definition: WikiRevision.php:186
Config
Interface for configuration instances.
Definition: Config.php:28
WikiRevision\getParams
getParams()
Definition: WikiRevision.php:601
WikiRevision\setUserIP
setUserIP( $ip)
Definition: WikiRevision.php:255
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiRevision\getTags
getTags()
Definition: WikiRevision.php:537
WikiRevision\$content
Content $content
Definition: WikiRevision.php:97
WikiRevision\getFormat
getFormat()
Definition: WikiRevision.php:479
MediaWiki\Logger\LoggerFactory
PSR-3 logger instance factory.
Definition: LoggerFactory.php:45
WikiRevision\$contentHandler
ContentHandler $contentHandler
Definition: WikiRevision.php:103
WikiRevision\getTimestamp
getTimestamp()
Definition: WikiRevision.php:410
WikiRevision\setModel
setModel( $model)
Definition: WikiRevision.php:263
WikiRevision\getSha1Base36
getSha1Base36()
Definition: WikiRevision.php:526
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2575
WikiRevision\setMinor
setMinor( $minor)
Definition: WikiRevision.php:295
DB_MASTER
const DB_MASTER
Definition: defines.php:26
WikiRevision\$action
string $action
Definition: WikiRevision.php:127
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:913
WikiRevision\setID
setID( $id)
Definition: WikiRevision.php:222
WikiRevision\getArchiveName
getArchiveName()
Definition: WikiRevision.php:569
WikiRevision\setFormat
setFormat( $format)
Definition: WikiRevision.php:271
WikiRevision\getMinor
getMinor()
Definition: WikiRevision.php:499
WikiRevision\getText
getText()
Definition: WikiRevision.php:434
WikiRevision\getContent
getContent()
Definition: WikiRevision.php:454
WikiRevision\$text
string $text
Definition: WikiRevision.php:85
WikiRevision\$sha1base36
bool string $sha1base36
Definition: WikiRevision.php:145
ImportableOldRevision
Definition: ImportableOldRevision.php:6
WikiRevision\setType
setType( $type)
Definition: WikiRevision.php:362
WikiRevision\$timestamp
string $timestamp
Definition: WikiRevision.php:55
WikiRevision\$tags
string[] $tags
Definition: WikiRevision.php:151
WikiRevision\getContentHandler
getContentHandler()
Definition: WikiRevision.php:442
WikiRevision\setTitle
setTitle( $title)
Definition: WikiRevision.php:207
WikiRevision\setTimestamp
setTimestamp( $ts)
Definition: WikiRevision.php:230
Content
Base interface for content objects.
Definition: Content.php:34
WikiRevision\setParams
setParams( $params)
Definition: WikiRevision.php:378
Title
Represents a title within MediaWiki.
Definition: Title.php:42
WikiRevision\importLogItem
importLogItem()
Definition: WikiRevision.php:623
ImportableUploadRevisionImporter
Definition: ImportableUploadRevisionImporter.php:9
WikiRevision\$fileIsTemp
$fileIsTemp
Definition: WikiRevision.php:183
WikiRevision\setSrc
setSrc( $src)
Definition: WikiRevision.php:303
WikiRevision
Represents a revision, log entry or upload during the import process.
Definition: WikiRevision.php:37
WikiRevision\setFileSrc
setFileSrc( $src, $isTemp)
Definition: WikiRevision.php:312
WikiRevision\setArchiveName
setArchiveName( $archiveName)
Definition: WikiRevision.php:346
WikiRevision\getFileSrc
getFileSrc()
Definition: WikiRevision.php:545
WikiRevision\$title
Title $title
Definition: WikiRevision.php:43
WikiRevision\getUserObj
getUserObj()
Definition: WikiRevision.php:426
WikiRevision\importOldRevision
importOldRevision()
Definition: WikiRevision.php:610
WikiRevision\getID
getID()
Definition: WikiRevision.php:402
WikiRevision\setAction
setAction( $action)
Definition: WikiRevision.php:370
WikiRevision\$comment
string $comment
Definition: WikiRevision.php:109
WikiRevision\$archiveName
string $archiveName
Definition: WikiRevision.php:157
CommentStore\getStore
static getStore()
Definition: CommentStore.php:139
WikiRevision\setSize
setSize( $size)
Definition: WikiRevision.php:354
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:51
WikiRevision\$id
int $id
Definition: WikiRevision.php:49
WikiRevision\getSize
getSize()
Definition: WikiRevision.php:577
WikiRevision\$config
$config
Definition: WikiRevision.php:192
WikiRevision\getAction
getAction()
Definition: WikiRevision.php:593
WikiRevision\$fileSrc
string $fileSrc
Definition: WikiRevision.php:139