MediaWiki  master
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 ( $title === null ) {
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 
443  public function getContentHandler() {
444  if ( $this->contentHandler === null ) {
445  $this->contentHandler = MediaWikiServices::getInstance()
446  ->getContentHandlerFactory()
447  ->getContentHandler( $this->getModel() );
448  }
449 
450  return $this->contentHandler;
451  }
452 
457  public function getContent() {
458  if ( $this->content === null ) {
459  $handler = $this->getContentHandler();
460  $this->content = $handler->unserializeContent( $this->text, $this->getFormat() );
461  }
462 
463  return $this->content;
464  }
465 
470  public function getModel() {
471  if ( $this->model === null ) {
472  $this->model = $this->getTitle()->getContentModel();
473  }
474 
475  return $this->model;
476  }
477 
482  public function getFormat() {
483  if ( $this->format === null ) {
484  $this->format = $this->getContentHandler()->getDefaultFormat();
485  }
486 
487  return $this->format;
488  }
489 
494  public function getComment() {
495  return $this->comment;
496  }
497 
502  public function getMinor() {
503  return $this->minor;
504  }
505 
510  public function getSrc() {
511  return $this->src;
512  }
513 
518  public function getSha1() {
519  if ( $this->sha1base36 ) {
520  return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
521  }
522  return false;
523  }
524 
529  public function getSha1Base36() {
530  if ( $this->sha1base36 ) {
531  return $this->sha1base36;
532  }
533  return false;
534  }
535 
540  public function getTags() {
541  return $this->tags;
542  }
543 
548  public function getFileSrc() {
549  return $this->fileSrc;
550  }
551 
556  public function isTempSrc() {
557  return $this->isTemp;
558  }
559 
564  public function getFilename() {
565  return $this->filename;
566  }
567 
572  public function getArchiveName() {
573  return $this->archiveName;
574  }
575 
580  public function getSize() {
581  return $this->size;
582  }
583 
588  public function getType() {
589  return $this->type;
590  }
591 
596  public function getAction() {
597  return $this->action;
598  }
599 
604  public function getParams() {
605  return $this->params;
606  }
607 
613  public function importOldRevision() {
614  if ( $this->mNoUpdates ) {
615  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporterNoUpdates();
616  } else {
617  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporter();
618  }
619  return $importer->import( $this );
620  }
621 
626  public function importLogItem() {
627  $dbw = wfGetDB( DB_MASTER );
628 
629  $user = $this->getUserObj() ?: User::newFromName( $this->getUser(), false );
630 
631  # @todo FIXME: This will not record autoblocks
632  if ( !$this->getTitle() ) {
633  wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
634  $this->timestamp . "\n" );
635  return false;
636  }
637  # Check if it exists already
638  // @todo FIXME: Use original log ID (better for backups)
639  $prior = $dbw->selectField( 'logging', '1',
640  [ 'log_type' => $this->getType(),
641  'log_action' => $this->getAction(),
642  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
643  'log_namespace' => $this->getTitle()->getNamespace(),
644  'log_title' => $this->getTitle()->getDBkey(),
645  'log_params' => $this->params ],
646  __METHOD__
647  );
648  // @todo FIXME: This could fail slightly for multiple matches :P
649  if ( $prior ) {
650  wfDebug( __METHOD__
651  . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
652  . $this->timestamp . "\n" );
653  return false;
654  }
655  $data = [
656  'log_type' => $this->type,
657  'log_action' => $this->action,
658  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
659  'log_namespace' => $this->getTitle()->getNamespace(),
660  'log_title' => $this->getTitle()->getDBkey(),
661  'log_params' => $this->params
662  ] + CommentStore::getStore()->insert( $dbw, 'log_comment', $this->getComment() )
663  + ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user );
664  $dbw->insert( 'logging', $data, __METHOD__ );
665 
666  return true;
667  }
668 
674  public function importUpload() {
675  $importer = MediaWikiServices::getInstance()->getWikiRevisionUploadImporter();
676  $statusValue = $importer->import( $this );
677  return $statusValue->isGood();
678  }
679 
685  public function downloadSource() {
686  $importer = new ImportableUploadRevisionImporter(
687  $this->config->get( 'EnableUploads' ),
688  LoggerFactory::getInstance( 'UploadRevisionImporter' )
689  );
690  return $importer->downloadSource( $this );
691  }
692 
693 }
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:55
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:494
WikiRevision\setTags
setTags(array $tags)
Definition: WikiRevision.php:330
WikiRevision\downloadSource
downloadSource()
Definition: WikiRevision.php:685
WikiRevision\setNoUpdates
setNoUpdates( $noupdates)
Definition: WikiRevision.php:386
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:137
WikiRevision\setComment
setComment( $text)
Definition: WikiRevision.php:287
WikiRevision\$userObj
User $userObj
Definition: WikiRevision.php:67
WikiRevision\isTempSrc
isTempSrc()
Definition: WikiRevision.php:556
WikiRevision\importUpload
importUpload()
Definition: WikiRevision.php:674
WikiRevision\$user_text
string $user_text
Definition: WikiRevision.php:61
WikiRevision\getSrc
getSrc()
Definition: WikiRevision.php:510
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:1806
ImportableUploadRevisionImporter\downloadSource
downloadSource(ImportableUploadRevision $wikiRevision)
Definition: ImportableUploadRevisionImporter.php:150
WikiRevision\getTitle
getTitle()
Definition: WikiRevision.php:394
WikiRevision\getSha1
getSha1()
Definition: WikiRevision.php:518
WikiRevision\setSha1Base36
setSha1Base36( $sha1base36)
Definition: WikiRevision.php:322
WikiRevision\getFilename
getFilename()
Definition: WikiRevision.php:564
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:536
WikiRevision\setUsername
setUsername( $user)
Definition: WikiRevision.php:239
ImportableUploadRevision
Definition: ImportableUploadRevision.php:6
WikiRevision\getType
getType()
Definition: WikiRevision.php:588
WikiRevision\__construct
__construct(Config $config)
Definition: WikiRevision.php:198
WikiRevision\getModel
getModel()
Definition: WikiRevision.php:470
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:139
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:604
WikiRevision\setUserIP
setUserIP( $ip)
Definition: WikiRevision.php:255
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiRevision\getTags
getTags()
Definition: WikiRevision.php:540
WikiRevision\$content
Content $content
Definition: WikiRevision.php:97
WikiRevision\getFormat
getFormat()
Definition: WikiRevision.php:482
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:529
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2497
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:572
WikiRevision\setFormat
setFormat( $format)
Definition: WikiRevision.php:271
WikiRevision\getMinor
getMinor()
Definition: WikiRevision.php:502
WikiRevision\getText
getText()
Definition: WikiRevision.php:434
WikiRevision\getContent
getContent()
Definition: WikiRevision.php:457
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:443
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:626
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:548
WikiRevision\$title
Title $title
Definition: WikiRevision.php:43
WikiRevision\getUserObj
getUserObj()
Definition: WikiRevision.php:426
WikiRevision\importOldRevision
importOldRevision()
Definition: WikiRevision.php:613
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:116
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:54
WikiRevision\$id
int $id
Definition: WikiRevision.php:49
WikiRevision\getSize
getSize()
Definition: WikiRevision.php:580
WikiRevision\$config
Config $config
Definition: WikiRevision.php:192
WikiRevision\getAction
getAction()
Definition: WikiRevision.php:596
WikiRevision\$fileSrc
string $fileSrc
Definition: WikiRevision.php:139