MediaWiki REL1_31
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
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
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}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
A content handler knows how do deal with a specific type of content on a wiki page.
MediaWiki exception.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Represents a title within MediaWiki.
Definition Title.php:39
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:53
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:591
Represents a revision, log entry or upload during the import process.
setAction( $action)
setFilename( $filename)
setMinor( $minor)
string $timestamp
string null $src
setTitle( $title)
__construct(Config $config)
setParams( $params)
setUsername( $user)
setUserObj( $user)
setArchiveName( $archiveName)
setSha1Base36( $sha1base36)
bool string $sha1base36
string $user_text
ContentHandler $contentHandler
setComment( $text)
string $archiveName
setModel( $model)
setFileSrc( $src, $isTemp)
setNoUpdates( $noupdates)
setFormat( $format)
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:903
Interface for configuration instances.
Definition Config.php:28
Base interface for content objects.
Definition Content.php:34
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 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:30
const DB_MASTER
Definition defines.php:29