MediaWiki REL1_33
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
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
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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:40
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:585
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 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:894
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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:26
title