MediaWiki  1.33.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 
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 }
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:252
WikiRevision\getUser
getUser()
Definition: WikiRevision.php:405
WikiRevision\$format
string $format
Definition: WikiRevision.php:87
WikiRevision\$filename
$filename
Definition: WikiRevision.php:164
WikiRevision\$type
string $type
Definition: WikiRevision.php:129
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
WikiRevision\setUserObj
setUserObj( $user)
Definition: WikiRevision.php:242
WikiRevision\$src
string null $src
Definition: WikiRevision.php:170
WikiRevision\getComment
getComment()
Definition: WikiRevision.php:478
WikiRevision\downloadSource
downloadSource()
Definition: WikiRevision.php:661
WikiRevision\setNoUpdates
setNoUpdates( $noupdates)
Definition: WikiRevision.php:373
WikiRevision\setComment
setComment( $text)
Definition: WikiRevision.php:282
WikiRevision\$userObj
User $userObj
Definition: WikiRevision.php:75
WikiRevision\isTempSrc
isTempSrc()
Definition: WikiRevision.php:532
WikiRevision\importUpload
importUpload()
Definition: WikiRevision.php:650
WikiRevision\$user_text
string $user_text
Definition: WikiRevision.php:69
WikiRevision\getSrc
getSrc()
Definition: WikiRevision.php:494
WikiRevision\$size
int $size
Definition: WikiRevision.php:99
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
ImportableUploadRevisionImporter\downloadSource
downloadSource(ImportableUploadRevision $wikiRevision)
Definition: ImportableUploadRevisionImporter.php:148
WikiRevision\getTitle
getTitle()
Definition: WikiRevision.php:381
WikiRevision\$user
int $user
Definition: WikiRevision.php:63
WikiRevision\getSha1
getSha1()
Definition: WikiRevision.php:502
WikiRevision\setSha1Base36
setSha1Base36( $sha1base36)
Definition: WikiRevision.php:317
WikiRevision\getFilename
getFilename()
Definition: WikiRevision.php:540
WikiRevision\$model
string $model
Definition: WikiRevision.php:81
WikiRevision\setText
setText( $text)
Definition: WikiRevision.php:274
WikiRevision\setFilename
setFilename( $filename)
Definition: WikiRevision.php:325
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
WikiRevision\setUsername
setUsername( $user)
Definition: WikiRevision.php:234
ImportableUploadRevision
Definition: ImportableUploadRevision.php:6
WikiRevision\getType
getType()
Definition: WikiRevision.php:564
WikiRevision\__construct
__construct(Config $config)
Definition: WikiRevision.php:193
WikiRevision\getModel
getModel()
Definition: WikiRevision.php:454
ActorMigration\newMigration
static newMigration()
Static constructor.
Definition: ActorMigration.php:111
WikiRevision\$isTemp
bool $isTemp
Definition: WikiRevision.php:177
WikiRevision\$minor
bool $minor
Definition: WikiRevision.php:123
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:141
WikiRevision\$mNoUpdates
bool $mNoUpdates
Definition: WikiRevision.php:188
Config
Interface for configuration instances.
Definition: Config.php:28
WikiRevision\getParams
getParams()
Definition: WikiRevision.php:580
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
WikiRevision\setUserIP
setUserIP( $ip)
Definition: WikiRevision.php:250
MWException
MediaWiki exception.
Definition: MWException.php:26
WikiRevision\$content
Content $content
Definition: WikiRevision.php:105
WikiRevision\getFormat
getFormat()
Definition: WikiRevision.php:466
WikiRevision\$contentHandler
ContentHandler $contentHandler
Definition: WikiRevision.php:111
WikiRevision\getTimestamp
getTimestamp()
Definition: WikiRevision.php:397
$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 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
WikiRevision\setModel
setModel( $model)
Definition: WikiRevision.php:258
WikiRevision\getSha1Base36
getSha1Base36()
Definition: WikiRevision.php:513
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
WikiRevision\setMinor
setMinor( $minor)
Definition: WikiRevision.php:290
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:135
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:949
WikiRevision\setID
setID( $id)
Definition: WikiRevision.php:217
captcha-old.action
action
Definition: captcha-old.py:212
WikiRevision\getArchiveName
getArchiveName()
Definition: WikiRevision.php:548
WikiRevision\setFormat
setFormat( $format)
Definition: WikiRevision.php:266
WikiRevision\getMinor
getMinor()
Definition: WikiRevision.php:486
WikiRevision\getText
getText()
Definition: WikiRevision.php:421
WikiRevision\getContent
getContent()
Definition: WikiRevision.php:441
WikiRevision\$text
string $text
Definition: WikiRevision.php:93
WikiRevision\$sha1base36
bool string $sha1base36
Definition: WikiRevision.php:153
ImportableOldRevision
Definition: ImportableOldRevision.php:6
WikiRevision\setType
setType( $type)
Definition: WikiRevision.php:349
title
title
Definition: parserTests.txt:245
WikiRevision\$timestamp
string $timestamp
Definition: WikiRevision.php:55
WikiRevision\getContentHandler
getContentHandler()
Definition: WikiRevision.php:429
WikiRevision\setTitle
setTitle( $title)
Definition: WikiRevision.php:202
WikiRevision\setTimestamp
setTimestamp( $ts)
Definition: WikiRevision.php:225
format
if the prop value should be in the metadata multi language array format
Definition: hooks.txt:1644
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:365
Title
Represents a title within MediaWiki.
Definition: Title.php:40
WikiRevision\importLogItem
importLogItem()
Definition: WikiRevision.php:602
ImportableUploadRevisionImporter
Definition: ImportableUploadRevisionImporter.php:8
WikiRevision\$fileIsTemp
$fileIsTemp
Definition: WikiRevision.php:185
WikiRevision\setSrc
setSrc( $src)
Definition: WikiRevision.php:298
WikiRevision
Represents a revision, log entry or upload during the import process.
Definition: WikiRevision.php:37
WikiRevision\setFileSrc
setFileSrc( $src, $isTemp)
Definition: WikiRevision.php:307
WikiRevision\setArchiveName
setArchiveName( $archiveName)
Definition: WikiRevision.php:333
WikiRevision\getFileSrc
getFileSrc()
Definition: WikiRevision.php:524
WikiRevision\$title
Title $title
Definition: WikiRevision.php:43
WikiRevision\getUserObj
getUserObj()
Definition: WikiRevision.php:413
WikiRevision\importOldRevision
importOldRevision()
Definition: WikiRevision.php:589
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:389
WikiRevision\setAction
setAction( $action)
Definition: WikiRevision.php:357
WikiRevision\$comment
string $comment
Definition: WikiRevision.php:117
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:159
CommentStore\getStore
static getStore()
Definition: CommentStore.php:130
WikiRevision\setSize
setSize( $size)
Definition: WikiRevision.php:341
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
WikiRevision\$id
int $id
Definition: WikiRevision.php:49
WikiRevision\getSize
getSize()
Definition: WikiRevision.php:556
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:191
WikiRevision\getAction
getAction()
Definition: WikiRevision.php:572
WikiRevision\$fileSrc
string $fileSrc
Definition: WikiRevision.php:147