MediaWiki  1.34.0
dumpRev.php
Go to the documentation of this file.
1 <?php
26 
27 require_once __DIR__ . '/../Maintenance.php';
28 
35 class DumpRev extends Maintenance {
36  public function __construct() {
37  parent::__construct();
38  $this->addArg( 'rev-id', 'Revision ID', true );
39  }
40 
41  public function execute() {
42  $id = (int)$this->getArg( 0 );
43 
44  $lookup = MediaWikiServices::getInstance()->getRevisionLookup();
45  $rev = $lookup->getRevisionById( $id );
46  if ( !$rev ) {
47  $this->fatalError( "Row not found" );
48  }
49 
50  $content = $rev->getContent( SlotRecord::MAIN );
51  if ( !$content ) {
52  $this->fatalError( "Text not found" );
53  }
54 
55  $blobStore = MediaWikiServices::getInstance()->getBlobStore();
56  $slot = $rev->getSlot( SlotRecord::MAIN );
57  $text = $blobStore->getBlob( $slot->getAddress() );
58 
59  $this->output( "Text length: " . strlen( $text ) . "\n" );
60  $this->output( substr( $text, 0, 100 ) . "\n" );
61  }
62 }
63 
64 $maintClass = DumpRev::class;
65 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:504
DumpRev
Maintenance script that gets the text of a revision, resolving external storage if needed.
Definition: dumpRev.php:35
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
DumpRev\__construct
__construct()
Default constructor.
Definition: dumpRev.php:36
$content
$content
Definition: router.php:78
$maintClass
$maintClass
Definition: dumpRev.php:64
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:319
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
DumpRev\execute
execute()
Do the actual work.
Definition: dumpRev.php:41
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:371
Revision\SlotRecord
Value object representing a content slot associated with a page revision.
Definition: SlotRecord.php:39