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 
63  public $user = 0;
64 
69  public $user_text = "";
70 
75  public $userObj = null;
76 
81  public $model = null;
82 
87  public $format = null;
88 
93  public $text = "";
94 
99  protected $size;
100 
105  public $content = null;
106 
111  protected $contentHandler = null;
112 
117  public $comment = "";
118 
123  public $minor = false;
124 
129  public $type = "";
130 
135  public $action = "";
136 
141  public $params = "";
142 
147  public $fileSrc = '';
148 
153  public $sha1base36 = false;
154 
159  public $archiveName = '';
160 
164  protected $filename;
165 
170  protected $src = null;
171 
177  public $isTemp = false;
178 
185  public $fileIsTemp;
186 
188  private $mNoUpdates = false;
189 
191  private $config;
192 
193  public function __construct( Config $config ) {
194  $this->config = $config;
195  }
196 
202  public function setTitle( $title ) {
203  if ( is_object( $title ) ) {
204  $this->title = $title;
205  } elseif ( is_null( $title ) ) {
206  throw new MWException( "WikiRevision given a null title in import. "
207  . "You may need to adjust \$wgLegalTitleChars." );
208  } else {
209  throw new MWException( "WikiRevision given non-object title in import." );
210  }
211  }
212 
217  public function setID( $id ) {
218  $this->id = $id;
219  }
220 
225  public function setTimestamp( $ts ) {
226  # 2003-08-05T18:30:02Z
227  $this->timestamp = wfTimestamp( TS_MW, $ts );
228  }
229 
234  public function setUsername( $user ) {
235  $this->user_text = $user;
236  }
237 
242  public function setUserObj( $user ) {
243  $this->userObj = $user;
244  }
245 
250  public function setUserIP( $ip ) {
251  $this->user_text = $ip;
252  }
253 
258  public function setModel( $model ) {
259  $this->model = $model;
260  }
261 
266  public function setFormat( $format ) {
267  $this->format = $format;
268  }
269 
274  public function setText( $text ) {
275  $this->text = $text;
276  }
277 
282  public function setComment( $text ) {
283  $this->comment = $text;
284  }
285 
290  public function setMinor( $minor ) {
291  $this->minor = (bool)$minor;
292  }
293 
298  public function setSrc( $src ) {
299  $this->src = $src;
300  }
301 
307  public function setFileSrc( $src, $isTemp ) {
308  $this->fileSrc = $src;
309  $this->fileIsTemp = $isTemp;
310  $this->isTemp = $isTemp;
311  }
312 
317  public function setSha1Base36( $sha1base36 ) {
318  $this->sha1base36 = $sha1base36;
319  }
320 
325  public function setFilename( $filename ) {
326  $this->filename = $filename;
327  }
328 
333  public function setArchiveName( $archiveName ) {
334  $this->archiveName = $archiveName;
335  }
336 
341  public function setSize( $size ) {
342  $this->size = intval( $size );
343  }
344 
349  public function setType( $type ) {
350  $this->type = $type;
351  }
352 
357  public function setAction( $action ) {
358  $this->action = $action;
359  }
360 
365  public function setParams( $params ) {
366  $this->params = $params;
367  }
368 
373  public function setNoUpdates( $noupdates ) {
374  $this->mNoUpdates = $noupdates;
375  }
376 
381  public function getTitle() {
382  return $this->title;
383  }
384 
389  public function getID() {
390  return $this->id;
391  }
392 
397  public function getTimestamp() {
398  return $this->timestamp;
399  }
400 
405  public function getUser() {
406  return $this->user_text;
407  }
408 
413  public function getUserObj() {
414  return $this->userObj;
415  }
416 
421  public function getText() {
422  return $this->text;
423  }
424 
429  public function getContentHandler() {
430  if ( is_null( $this->contentHandler ) ) {
431  $this->contentHandler = ContentHandler::getForModelID( $this->getModel() );
432  }
433 
434  return $this->contentHandler;
435  }
436 
441  public function getContent() {
442  if ( is_null( $this->content ) ) {
443  $handler = $this->getContentHandler();
444  $this->content = $handler->unserializeContent( $this->text, $this->getFormat() );
445  }
446 
447  return $this->content;
448  }
449 
454  public function getModel() {
455  if ( is_null( $this->model ) ) {
456  $this->model = $this->getTitle()->getContentModel();
457  }
458 
459  return $this->model;
460  }
461 
466  public function getFormat() {
467  if ( is_null( $this->format ) ) {
468  $this->format = $this->getContentHandler()->getDefaultFormat();
469  }
470 
471  return $this->format;
472  }
473 
478  public function getComment() {
479  return $this->comment;
480  }
481 
486  public function getMinor() {
487  return $this->minor;
488  }
489 
494  public function getSrc() {
495  return $this->src;
496  }
497 
502  public function getSha1() {
503  if ( $this->sha1base36 ) {
504  return Wikimedia\base_convert( $this->sha1base36, 36, 16 );
505  }
506  return false;
507  }
508 
513  public function getSha1Base36() {
514  if ( $this->sha1base36 ) {
515  return $this->sha1base36;
516  }
517  return false;
518  }
519 
524  public function getFileSrc() {
525  return $this->fileSrc;
526  }
527 
532  public function isTempSrc() {
533  return $this->isTemp;
534  }
535 
540  public function getFilename() {
541  return $this->filename;
542  }
543 
548  public function getArchiveName() {
549  return $this->archiveName;
550  }
551 
556  public function getSize() {
557  return $this->size;
558  }
559 
564  public function getType() {
565  return $this->type;
566  }
567 
572  public function getAction() {
573  return $this->action;
574  }
575 
580  public function getParams() {
581  return $this->params;
582  }
583 
589  public function importOldRevision() {
590  if ( $this->mNoUpdates ) {
591  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporterNoUpdates();
592  } else {
593  $importer = MediaWikiServices::getInstance()->getWikiRevisionOldRevisionImporter();
594  }
595  return $importer->import( $this );
596  }
597 
602  public function importLogItem() {
603  $dbw = wfGetDB( DB_MASTER );
604 
605  $user = $this->getUserObj() ?: User::newFromName( $this->getUser(), false );
606 
607  # @todo FIXME: This will not record autoblocks
608  if ( !$this->getTitle() ) {
609  wfDebug( __METHOD__ . ": skipping invalid {$this->type}/{$this->action} log time, timestamp " .
610  $this->timestamp . "\n" );
611  return false;
612  }
613  # Check if it exists already
614  // @todo FIXME: Use original log ID (better for backups)
615  $prior = $dbw->selectField( 'logging', '1',
616  [ 'log_type' => $this->getType(),
617  'log_action' => $this->getAction(),
618  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
619  'log_namespace' => $this->getTitle()->getNamespace(),
620  'log_title' => $this->getTitle()->getDBkey(),
621  'log_params' => $this->params ],
622  __METHOD__
623  );
624  // @todo FIXME: This could fail slightly for multiple matches :P
625  if ( $prior ) {
626  wfDebug( __METHOD__
627  . ": skipping existing item for Log:{$this->type}/{$this->action}, timestamp "
628  . $this->timestamp . "\n" );
629  return false;
630  }
631  $data = [
632  'log_type' => $this->type,
633  'log_action' => $this->action,
634  'log_timestamp' => $dbw->timestamp( $this->timestamp ),
635  'log_namespace' => $this->getTitle()->getNamespace(),
636  'log_title' => $this->getTitle()->getDBkey(),
637  'log_params' => $this->params
638  ] + CommentStore::getStore()->insert( $dbw, 'log_comment', $this->getComment() )
639  + ActorMigration::newMigration()->getInsertValues( $dbw, 'log_user', $user );
640  $dbw->insert( 'logging', $data, __METHOD__ );
641 
642  return true;
643  }
644 
650  public function importUpload() {
651  $importer = MediaWikiServices::getInstance()->getWikiRevisionUploadImporter();
652  $statusValue = $importer->import( $this );
653  return $statusValue->isGood();
654  }
655 
661  public function downloadSource() {
662  $importer = new ImportableUploadRevisionImporter(
663  $this->config->get( 'EnableUploads' ),
664  LoggerFactory::getInstance( 'UploadRevisionImporter' )
665  );
666  return $importer->downloadSource( $this );
667  }
668 
669 }
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:780
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:780
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:589
setNoUpdates( $noupdates)
setParams( $params)
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1641
setUsername( $user)