MediaWiki  1.32.0
WikiRevision.php
Go to the documentation of this file.
1 <?php
28 
38 
44  public $importer = null;
45 
50  public $title = null;
51 
56  public $id = 0;
57 
62  public $timestamp = "20010115000000";
63 
70  public $user = 0;
71 
76  public $user_text = "";
77 
82  public $userObj = null;
83 
88  public $model = null;
89 
94  public $format = null;
95 
100  public $text = "";
101 
106  protected $size;
107 
112  public $content = null;
113 
118  protected $contentHandler = null;
119 
124  public $comment = "";
125 
130  public $minor = false;
131 
136  public $type = "";
137 
142  public $action = "";
143 
148  public $params = "";
149 
154  public $fileSrc = '';
155 
160  public $sha1base36 = false;
161 
166  public $archiveName = '';
167 
171  protected $filename;
172 
177  protected $src = null;
178 
184  public $isTemp = false;
185 
192  public $fileIsTemp;
193 
195  private $mNoUpdates = false;
196 
198  private $config;
199 
200  public function __construct( Config $config ) {
201  $this->config = $config;
202  }
203 
209  public function setTitle( $title ) {
210  if ( is_object( $title ) ) {
211  $this->title = $title;
212  } elseif ( is_null( $title ) ) {
213  throw new MWException( "WikiRevision given a null title in import. "
214  . "You may need to adjust \$wgLegalTitleChars." );
215  } else {
216  throw new MWException( "WikiRevision given non-object title in import." );
217  }
218  }
219 
224  public function setID( $id ) {
225  $this->id = $id;
226  }
227 
232  public function setTimestamp( $ts ) {
233  # 2003-08-05T18:30:02Z
234  $this->timestamp = wfTimestamp( TS_MW, $ts );
235  }
236 
241  public function setUsername( $user ) {
242  $this->user_text = $user;
243  }
244 
249  public function setUserObj( $user ) {
250  $this->userObj = $user;
251  }
252 
257  public function setUserIP( $ip ) {
258  $this->user_text = $ip;
259  }
260 
265  public function setModel( $model ) {
266  $this->model = $model;
267  }
268 
273  public function setFormat( $format ) {
274  $this->format = $format;
275  }
276 
281  public function setText( $text ) {
282  $this->text = $text;
283  }
284 
289  public function setComment( $text ) {
290  $this->comment = $text;
291  }
292 
297  public function setMinor( $minor ) {
298  $this->minor = (bool)$minor;
299  }
300 
305  public function setSrc( $src ) {
306  $this->src = $src;
307  }
308 
314  public function setFileSrc( $src, $isTemp ) {
315  $this->fileSrc = $src;
316  $this->fileIsTemp = $isTemp;
317  $this->isTemp = $isTemp;
318  }
319 
324  public function setSha1Base36( $sha1base36 ) {
325  $this->sha1base36 = $sha1base36;
326  }
327 
332  public function setFilename( $filename ) {
333  $this->filename = $filename;
334  }
335 
340  public function setArchiveName( $archiveName ) {
341  $this->archiveName = $archiveName;
342  }
343 
348  public function setSize( $size ) {
349  $this->size = intval( $size );
350  }
351 
356  public function setType( $type ) {
357  $this->type = $type;
358  }
359 
364  public function setAction( $action ) {
365  $this->action = $action;
366  }
367 
372  public function setParams( $params ) {
373  $this->params = $params;
374  }
375 
380  public function setNoUpdates( $noupdates ) {
381  $this->mNoUpdates = $noupdates;
382  }
383 
388  public function getTitle() {
389  return $this->title;
390  }
391 
396  public function getID() {
397  return $this->id;
398  }
399 
404  public function getTimestamp() {
405  return $this->timestamp;
406  }
407 
412  public function getUser() {
413  return $this->user_text;
414  }
415 
420  public function getUserObj() {
421  return $this->userObj;
422  }
423 
428  public function getText() {
429  return $this->text;
430  }
431 
436  public function getContentHandler() {
437  if ( is_null( $this->contentHandler ) ) {
438  $this->contentHandler = ContentHandler::getForModelID( $this->getModel() );
439  }
440 
441  return $this->contentHandler;
442  }
443 
448  public function getContent() {
449  if ( is_null( $this->content ) ) {
450  $handler = $this->getContentHandler();
451  $this->content = $handler->unserializeContent( $this->text, $this->getFormat() );
452  }
453 
454  return $this->content;
455  }
456 
461  public function getModel() {
462  if ( is_null( $this->model ) ) {
463  $this->model = $this->getTitle()->getContentModel();
464  }
465 
466  return $this->model;
467  }
468 
473  public function getFormat() {
474  if ( is_null( $this->format ) ) {
475  $this->format = $this->getContentHandler()->getDefaultFormat();
476  }
477 
478  return $this->format;
479  }
480 
485  public function getComment() {
486  return $this->comment;
487  }
488 
493  public function getMinor() {
494  return $this->minor;
495  }
496 
501  public function getSrc() {
502  return $this->src;
503  }
504 
509  public function getSha1() {
510  if ( $this->sha1base36 ) {
511  return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
512  }
513  return false;
514  }
515 
520  public function getSha1Base36() {
521  if ( $this->sha1base36 ) {
522  return $this->sha1base36;
523  }
524  return false;
525  }
526 
531  public function getFileSrc() {
532  return $this->fileSrc;
533  }
534 
539  public function isTempSrc() {
540  return $this->isTemp;
541  }
542 
547  public function getFilename() {
548  return $this->filename;
549  }
550 
555  public function getArchiveName() {
556  return $this->archiveName;
557  }
558 
563  public function getSize() {
564  return $this->size;
565  }
566 
571  public function getType() {
572  return $this->type;
573  }
574 
579  public function getAction() {
580  return $this->action;
581  }
582 
587  public function getParams() {
588  return $this->params;
589  }
590 
596  public function importOldRevision() {
597  if ( $this->mNoUpdates ) {
598  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporterNoUpdates();
599  } else {
600  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporter();
601  }
602  return $importer->import( $this );
603  }
604 
609  public function importLogItem() {
610  $dbw = wfGetDB( DB_MASTER );
611 
612  $user = $this->getUserObj() ?: User::newFromName( $this->getUser(), false );
613 
614  # @todo FIXME: This will not record autoblocks
615  if ( !$this->getTitle() ) {
616  wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
617  $this->timestamp . "\n" );
618  return false;
619  }
620  # Check if it exists already
621  // @todo FIXME: Use original log ID (better for backups)
622  $prior = $dbw->selectField( 'logging', '1',
623  [ 'log_type' => $this->getType(),
624  'log_action' => $this->getAction(),
625  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
626  'log_namespace' => $this->getTitle()->getNamespace(),
627  'log_title' => $this->getTitle()->getDBkey(),
628  'log_params' => $this->params ],
629  __METHOD__
630  );
631  // @todo FIXME: This could fail slightly for multiple matches :P
632  if ( $prior ) {
633  wfDebug( __METHOD__
634  . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
635  . $this->timestamp . "\n" );
636  return false;
637  }
638  $data = [
639  'log_type' => $this->type,
640  'log_action' => $this->action,
641  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
642  'log_namespace' => $this->getTitle()->getNamespace(),
643  'log_title' => $this->getTitle()->getDBkey(),
644  'log_params' => $this->params
645  ] + CommentStore::getStore()->insert( $dbw, 'log_comment', $this->getComment() )
646  + ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user );
647  $dbw->insert( 'logging', $data, __METHOD__ );
648 
649  return true;
650  }
651 
657  public function importUpload() {
658  $importer = MediaWikiServices::getInstance()->getWikiRevisionUploadImporter();
659  $statusValue = $importer->import( $this );
660  return $statusValue->isGood();
661  }
662 
668  public function downloadSource() {
670  $this->config->get( 'EnableUploads' ),
671  LoggerFactory::getInstance( 'UploadRevisionImporter' )
672  );
673  return $importer->downloadSource( $this );
674  }
675 
676 }
ContentHandler
A content handler knows how do deal with a specific type of content on a wiki page.
Definition: ContentHandler.php:53
ContentHandler\getForModelID
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
Definition: ContentHandler.php:297
WikiRevision\getUser
getUser()
Definition: WikiRevision.php:412
WikiRevision\$format
string $format
Definition: WikiRevision.php:94
WikiRevision\$filename
$filename
Definition: WikiRevision.php:171
WikiRevision\$type
string $type
Definition: WikiRevision.php:136
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
WikiRevision\setUserObj
setUserObj( $user)
Definition: WikiRevision.php:249
WikiRevision\$src
string null $src
Definition: WikiRevision.php:177
WikiRevision\getComment
getComment()
Definition: WikiRevision.php:485
WikiRevision\downloadSource
downloadSource()
Definition: WikiRevision.php:668
WikiRevision\setNoUpdates
setNoUpdates( $noupdates)
Definition: WikiRevision.php:380
WikiRevision\setComment
setComment( $text)
Definition: WikiRevision.php:289
WikiRevision\$userObj
User $userObj
Definition: WikiRevision.php:82
WikiRevision\isTempSrc
isTempSrc()
Definition: WikiRevision.php:539
WikiRevision\importUpload
importUpload()
Definition: WikiRevision.php:657
WikiRevision\$user_text
string $user_text
Definition: WikiRevision.php:76
WikiRevision\getSrc
getSrc()
Definition: WikiRevision.php:501
WikiRevision\$size
int $size
Definition: WikiRevision.php:106
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1954
WikiRevision\getTitle
getTitle()
Definition: WikiRevision.php:388
WikiRevision\$user
int $user
Definition: WikiRevision.php:70
WikiRevision\getSha1
getSha1()
Definition: WikiRevision.php:509
WikiRevision\setSha1Base36
setSha1Base36( $sha1base36)
Definition: WikiRevision.php:324
WikiRevision\getFilename
getFilename()
Definition: WikiRevision.php:547
WikiRevision\$model
string $model
Definition: WikiRevision.php:88
WikiRevision\setText
setText( $text)
Definition: WikiRevision.php:281
WikiRevision\$importer
$importer
Definition: WikiRevision.php:44
WikiRevision\setFilename
setFilename( $filename)
Definition: WikiRevision.php:332
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:592
WikiRevision\setUsername
setUsername( $user)
Definition: WikiRevision.php:241
ImportableUploadRevision
Definition: ImportableUploadRevision.php:6
WikiRevision\getType
getType()
Definition: WikiRevision.php:571
WikiRevision\__construct
__construct(Config $config)
Definition: WikiRevision.php:200
WikiRevision\getModel
getModel()
Definition: WikiRevision.php:461
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
WikiRevision\$isTemp
bool $isTemp
Definition: WikiRevision.php:184
WikiRevision\$minor
bool $minor
Definition: WikiRevision.php:130
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
WikiRevision\$params
string $params
Definition: WikiRevision.php:148
WikiRevision\$mNoUpdates
bool $mNoUpdates
Definition: WikiRevision.php:195
Config
Interface for configuration instances.
Definition: Config.php:28
WikiRevision\getParams
getParams()
Definition: WikiRevision.php:587
WikiRevision\setUserIP
setUserIP( $ip)
Definition: WikiRevision.php:257
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiRevision\$content
Content $content
Definition: WikiRevision.php:112
WikiRevision\getFormat
getFormat()
Definition: WikiRevision.php:473
WikiRevision\$contentHandler
ContentHandler $contentHandler
Definition: WikiRevision.php:118
WikiRevision\getTimestamp
getTimestamp()
Definition: WikiRevision.php:404
WikiRevision\setModel
setModel( $model)
Definition: WikiRevision.php:265
WikiRevision\getSha1Base36
getSha1Base36()
Definition: WikiRevision.php:520
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2693
WikiRevision\setMinor
setMinor( $minor)
Definition: WikiRevision.php:297
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
DB_MASTER
const DB_MASTER
Definition: defines.php:26
WikiRevision\$action
string $action
Definition: WikiRevision.php:142
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:988
WikiRevision\setID
setID( $id)
Definition: WikiRevision.php:224
captcha-old.action
action
Definition: captcha-old.py:212
WikiRevision\getArchiveName
getArchiveName()
Definition: WikiRevision.php:555
WikiRevision\setFormat
setFormat( $format)
Definition: WikiRevision.php:273
WikiRevision\getMinor
getMinor()
Definition: WikiRevision.php:493
WikiRevision\getText
getText()
Definition: WikiRevision.php:428
WikiRevision\getContent
getContent()
Definition: WikiRevision.php:448
WikiRevision\$text
string $text
Definition: WikiRevision.php:100
WikiRevision\$sha1base36
bool string $sha1base36
Definition: WikiRevision.php:160
ImportableOldRevision
Definition: ImportableOldRevision.php:6
WikiRevision\setType
setType( $type)
Definition: WikiRevision.php:356
title
title
Definition: parserTests.txt:239
WikiRevision\$timestamp
string $timestamp
Definition: WikiRevision.php:62
WikiRevision\getContentHandler
getContentHandler()
Definition: WikiRevision.php:436
WikiRevision\setTitle
setTitle( $title)
Definition: WikiRevision.php:209
$handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:813
WikiRevision\setTimestamp
setTimestamp( $ts)
Definition: WikiRevision.php:232
format
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1683
Content
Base interface for content objects.
Definition: Content.php:34
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
WikiRevision\setParams
setParams( $params)
Definition: WikiRevision.php:372
Title
Represents a title within MediaWiki.
Definition: Title.php:39
WikiRevision\importLogItem
importLogItem()
Definition: WikiRevision.php:609
ImportableUploadRevisionImporter
Definition: ImportableUploadRevisionImporter.php:8
WikiRevision\$fileIsTemp
$fileIsTemp
Definition: WikiRevision.php:192
WikiRevision\setSrc
setSrc( $src)
Definition: WikiRevision.php:305
WikiRevision
Represents a revision, log entry or upload during the import process.
Definition: WikiRevision.php:37
WikiRevision\setFileSrc
setFileSrc( $src, $isTemp)
Definition: WikiRevision.php:314
WikiRevision\setArchiveName
setArchiveName( $archiveName)
Definition: WikiRevision.php:340
WikiRevision\getFileSrc
getFileSrc()
Definition: WikiRevision.php:531
WikiRevision\$title
Title $title
Definition: WikiRevision.php:50
WikiRevision\getUserObj
getUserObj()
Definition: WikiRevision.php:420
WikiRevision\importOldRevision
importOldRevision()
Definition: WikiRevision.php:596
LoggerFactory
MediaWiki Logger LoggerFactory implements a PSR[0] compatible message logging system Named Psr Log LoggerInterface instances can be obtained from the MediaWiki Logger LoggerFactory::getInstance() static method. MediaWiki\Logger\LoggerFactory expects a class implementing the MediaWiki\Logger\Spi interface to act as a factory for new Psr\Log\LoggerInterface instances. The "Spi" in MediaWiki\Logger\Spi stands for "service provider interface". An SPI is an API intended to be implemented or extended by a third party. This software design pattern is intended to enable framework extension and replaceable components. It is specifically used in the MediaWiki\Logger\LoggerFactory service to allow alternate PSR-3 logging implementations to be easily integrated with MediaWiki. The service provider interface allows the backend logging library to be implemented in multiple ways. The $wgMWLoggerDefaultSpi global provides the classname of the default MediaWiki\Logger\Spi implementation to be loaded at runtime. This can either be the name of a class implementing the MediaWiki\Logger\Spi with a zero argument const ructor or a callable that will return an MediaWiki\Logger\Spi instance. Alternately the MediaWiki\Logger\LoggerFactory MediaWiki Logger LoggerFactory
Definition: logger.txt:5
WikiRevision\getID
getID()
Definition: WikiRevision.php:396
WikiRevision\setAction
setAction( $action)
Definition: WikiRevision.php:364
WikiRevision\$comment
string $comment
Definition: WikiRevision.php:124
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
WikiRevision\$archiveName
string $archiveName
Definition: WikiRevision.php:166
CommentStore\getStore
static getStore()
Definition: CommentStore.php:125
WikiRevision\setSize
setSize( $size)
Definition: WikiRevision.php:348
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:47
WikiRevision\$id
int $id
Definition: WikiRevision.php:56
WikiRevision\getSize
getSize()
Definition: WikiRevision.php:563
type
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition: postgres.txt:22
WikiRevision\$config
$config
Definition: WikiRevision.php:198
WikiRevision\getAction
getAction()
Definition: WikiRevision.php:579
WikiRevision\$fileSrc
string $fileSrc
Definition: WikiRevision.php:154