MediaWiki  master
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;
getArg( $argId=0, $default=null)
Get an argument.
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
execute()
Definition: dumpRev.php:41
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
Maintenance script that gets the text of a revision, resolving external storage if needed...
Definition: dumpRev.php:35
$maintClass
Definition: dumpRev.php:64
addArg( $arg, $description, $required=true)
Add some args that are needed.
__construct()
Definition: dumpRev.php:36
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.