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