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  public $archiveName = '';
152 
156  protected $filename;
157 
162  protected $src = null;
163 
169  public $isTemp = false;
170 
177  public $fileIsTemp;
178 
180  private $mNoUpdates = false;
181 
183  private $config;
184 
185  public function __construct( Config $config ) {
186  $this->config = $config;
187  }
188 
194  public function setTitle( $title ) {
195  if ( is_object( $title ) ) {
196  $this->title = $title;
197  } elseif ( is_null( $title ) ) {
198  throw new MWException( "WikiRevision given a null title in import. "
199  . "You may need to adjust \$wgLegalTitleChars." );
200  } else {
201  throw new MWException( "WikiRevision given non-object title in import." );
202  }
203  }
204 
209  public function setID( $id ) {
210  $this->id = $id;
211  }
212 
217  public function setTimestamp( $ts ) {
218  # 2003-08-05T18:30:02Z
219  $this->timestamp = wfTimestamp( TS_MW, $ts );
220  }
221 
226  public function setUsername( $user ) {
227  $this->user_text = $user;
228  }
229 
234  public function setUserObj( $user ) {
235  $this->userObj = $user;
236  }
237 
242  public function setUserIP( $ip ) {
243  $this->user_text = $ip;
244  }
245 
250  public function setModel( $model ) {
251  $this->model = $model;
252  }
253 
258  public function setFormat( $format ) {
259  $this->format = $format;
260  }
261 
266  public function setText( $text ) {
267  $this->text = $text;
268  }
269 
274  public function setComment( $text ) {
275  $this->comment = $text;
276  }
277 
282  public function setMinor( $minor ) {
283  $this->minor = (bool)$minor;
284  }
285 
290  public function setSrc( $src ) {
291  $this->src = $src;
292  }
293 
299  public function setFileSrc( $src, $isTemp ) {
300  $this->fileSrc = $src;
301  $this->fileIsTemp = $isTemp;
302  $this->isTemp = $isTemp;
303  }
304 
309  public function setSha1Base36( $sha1base36 ) {
310  $this->sha1base36 = $sha1base36;
311  }
312 
317  public function setFilename( $filename ) {
318  $this->filename = $filename;
319  }
320 
325  public function setArchiveName( $archiveName ) {
326  $this->archiveName = $archiveName;
327  }
328 
333  public function setSize( $size ) {
334  $this->size = intval( $size );
335  }
336 
341  public function setType( $type ) {
342  $this->type = $type;
343  }
344 
349  public function setAction( $action ) {
350  $this->action = $action;
351  }
352 
357  public function setParams( $params ) {
358  $this->params = $params;
359  }
360 
365  public function setNoUpdates( $noupdates ) {
366  $this->mNoUpdates = $noupdates;
367  }
368 
373  public function getTitle() {
374  return $this->title;
375  }
376 
381  public function getID() {
382  return $this->id;
383  }
384 
389  public function getTimestamp() {
390  return $this->timestamp;
391  }
392 
397  public function getUser() {
398  return $this->user_text;
399  }
400 
405  public function getUserObj() {
406  return $this->userObj;
407  }
408 
413  public function getText() {
414  return $this->text;
415  }
416 
421  public function getContentHandler() {
422  if ( is_null( $this->contentHandler ) ) {
423  $this->contentHandler = ContentHandler::getForModelID( $this->getModel() );
424  }
425 
426  return $this->contentHandler;
427  }
428 
433  public function getContent() {
434  if ( is_null( $this->content ) ) {
435  $handler = $this->getContentHandler();
436  $this->content = $handler->unserializeContent( $this->text, $this->getFormat() );
437  }
438 
439  return $this->content;
440  }
441 
446  public function getModel() {
447  if ( is_null( $this->model ) ) {
448  $this->model = $this->getTitle()->getContentModel();
449  }
450 
451  return $this->model;
452  }
453 
458  public function getFormat() {
459  if ( is_null( $this->format ) ) {
460  $this->format = $this->getContentHandler()->getDefaultFormat();
461  }
462 
463  return $this->format;
464  }
465 
470  public function getComment() {
471  return $this->comment;
472  }
473 
478  public function getMinor() {
479  return $this->minor;
480  }
481 
486  public function getSrc() {
487  return $this->src;
488  }
489 
494  public function getSha1() {
495  if ( $this->sha1base36 ) {
496  return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
497  }
498  return false;
499  }
500 
505  public function getSha1Base36() {
506  if ( $this->sha1base36 ) {
507  return $this->sha1base36;
508  }
509  return false;
510  }
511 
516  public function getFileSrc() {
517  return $this->fileSrc;
518  }
519 
524  public function isTempSrc() {
525  return $this->isTemp;
526  }
527 
532  public function getFilename() {
533  return $this->filename;
534  }
535 
540  public function getArchiveName() {
541  return $this->archiveName;
542  }
543 
548  public function getSize() {
549  return $this->size;
550  }
551 
556  public function getType() {
557  return $this->type;
558  }
559 
564  public function getAction() {
565  return $this->action;
566  }
567 
572  public function getParams() {
573  return $this->params;
574  }
575 
581  public function importOldRevision() {
582  if ( $this->mNoUpdates ) {
583  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporterNoUpdates();
584  } else {
585  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporter();
586  }
587  return $importer->import( $this );
588  }
589 
594  public function importLogItem() {
595  $dbw = wfGetDB( DB_MASTER );
596 
597  $user = $this->getUserObj() ?: User::newFromName( $this->getUser(), false );
598 
599  # @todo FIXME: This will not record autoblocks
600  if ( !$this->getTitle() ) {
601  wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
602  $this->timestamp . "\n" );
603  return false;
604  }
605  # Check if it exists already
606  // @todo FIXME: Use original log ID (better for backups)
607  $prior = $dbw->selectField( 'logging', '1',
608  [ 'log_type' => $this->getType(),
609  'log_action' => $this->getAction(),
610  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
611  'log_namespace' => $this->getTitle()->getNamespace(),
612  'log_title' => $this->getTitle()->getDBkey(),
613  'log_params' => $this->params ],
614  __METHOD__
615  );
616  // @todo FIXME: This could fail slightly for multiple matches :P
617  if ( $prior ) {
618  wfDebug( __METHOD__
619  . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
620  . $this->timestamp . "\n" );
621  return false;
622  }
623  $data = [
624  'log_type' => $this->type,
625  'log_action' => $this->action,
626  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
627  'log_namespace' => $this->getTitle()->getNamespace(),
628  'log_title' => $this->getTitle()->getDBkey(),
629  'log_params' => $this->params
630  ] + CommentStore::getStore()->insert( $dbw, 'log_comment', $this->getComment() )
631  + ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user );
632  $dbw->insert( 'logging', $data, __METHOD__ );
633 
634  return true;
635  }
636 
642  public function importUpload() {
643  $importer = MediaWikiServices::getInstance()->getWikiRevisionUploadImporter();
644  $statusValue = $importer->import( $this );
645  return $statusValue->isGood();
646  }
647 
653  public function downloadSource() {
654  $importer = new ImportableUploadRevisionImporter(
655  $this->config->get( 'EnableUploads' ),
656  LoggerFactory::getInstance( 'UploadRevisionImporter' )
657  );
658  return $importer->downloadSource( $this );
659  }
660 
661 }
downloadSource(ImportableUploadRevision $wikiRevision)
string null $src
setAction( $action)
bool string $sha1base36
setFilename( $filename)
per default it will return the text for text based content
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
string $format
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
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
setModel( $model)
setMinor( $minor)
setUserObj( $user)
Content $content
title
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
const DB_MASTER
Definition: defines.php:26
setSize( $size)
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:767
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
static newMigration()
Static constructor.
Interface for configuration instances.
Definition: Config.php:28
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
setType( $type)
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Represents a revision, log entry or upload during the import process.
setTitle( $title)
setTimestamp( $ts)
string $archiveName
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:767
string $timestamp
setText( $text)
setFileSrc( $src, $isTemp)
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
ContentHandler $contentHandler
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
static getStore()
setFormat( $format)
__construct(Config $config)
setArchiveName( $archiveName)
string $user_text
setSha1Base36( $sha1base36)
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
setComment( $text)
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:535
setNoUpdates( $noupdates)
setParams( $params)
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1622
setUsername( $user)