MediaWiki master
dumpRev.php
Go to the documentation of this file.
1<?php
12
13// @codeCoverageIgnoreStart
14require_once __DIR__ . '/../Maintenance.php';
15// @codeCoverageIgnoreEnd
16
23class DumpRev extends Maintenance {
24 public function __construct() {
25 parent::__construct();
26 $this->addArg( 'rev-id', 'Revision ID', true );
27 }
28
29 public function execute() {
30 $id = (int)$this->getArg( 0 );
31
32 $lookup = $this->getServiceContainer()->getRevisionLookup();
33 $rev = $lookup->getRevisionById( $id );
34 if ( !$rev ) {
35 $this->fatalError( "Row not found" );
36 }
37
38 $content = $rev->getContent( SlotRecord::MAIN );
39 if ( !$content ) {
40 $this->fatalError( "Text not found" );
41 }
42
43 $blobStore = $this->getServiceContainer()->getBlobStore();
44 $slot = $rev->getSlot( SlotRecord::MAIN );
45 $text = $blobStore->getBlob( $slot->getAddress() );
46
47 $this->output( "Text length: " . strlen( $text ) . "\n" );
48 $this->output( substr( $text, 0, 100 ) . "\n" );
49 }
50}
51
52// @codeCoverageIgnoreStart
53$maintClass = DumpRev::class;
54require_once RUN_MAINTENANCE_IF_MAIN;
55// @codeCoverageIgnoreEnd
Maintenance script that gets the text of a revision, resolving external storage if needed.
Definition dumpRev.php:23
execute()
Do the actual work.
Definition dumpRev.php:29
__construct()
Default constructor.
Definition dumpRev.php:24
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:53