Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.33% covered (success)
93.33%
14 / 15
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
DumpRev
93.33% covered (success)
93.33%
14 / 15
50.00% covered (danger)
50.00%
1 / 2
4.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 execute
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
3.00
1<?php
2/**
3 * Get the text of a revision, resolving external storage if needed.
4 *
5 * @license GPL-2.0-or-later
6 * @file
7 * @ingroup Maintenance ExternalStorage
8 */
9
10use MediaWiki\Maintenance\Maintenance;
11use MediaWiki\Revision\SlotRecord;
12
13// @codeCoverageIgnoreStart
14require_once __DIR__ . '/../Maintenance.php';
15// @codeCoverageIgnoreEnd
16
17/**
18 * Maintenance script that gets the text of a revision,
19 * resolving external storage if needed.
20 *
21 * @ingroup Maintenance ExternalStorage
22 */
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