| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
use MediaWiki\Revision\RevisionRecord; |
| 27 |
use MediaWiki\Revision\SlotRecord; |
| 28 |
use MediaWiki\Title\Title; |
| 29 |
|
| 30 |
|
| 31 |
require_once __DIR__ . '/Maintenance.php'; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class GetTextMaint extends Maintenance { |
| 40 |
public function __construct() { |
| 41 |
parent::__construct(); |
| 42 |
$this->addDescription( 'Outputs page text to stdout' ); |
| 43 |
$this->addOption( 'show-private', 'Show the text even if it\'s not available to the public' ); |
| 44 |
$this->addArg( 'title', 'Page title' ); |
| 45 |
$this->addOption( 'revision', 'Revision ID', false, true ); |
| 46 |
} |
| 47 |
|
| 48 |
public function execute() { |
| 49 |
$titleText = $this->getArg( 0 ); |
| 50 |
$title = Title::newFromText( $titleText ); |
| 51 |
if ( !$title ) { |
| 52 |
$this->fatalError( "$titleText is not a valid title.\n" ); |
| 53 |
} |
| 54 |
|
| 55 |
if ( !$title->exists() ) { |
| 56 |
$titleText = $title->getPrefixedText(); |
| 57 |
$this->fatalError( "Page $titleText does not exist.\n" ); |
| 58 |
} |
| 59 |
|
| 60 |
$revId = (int)$this->getOption( 'revision', $title->getLatestRevID() ); |
| 61 |
|
| 62 |
$rev = $this->getServiceContainer() |
| 63 |
->getRevisionLookup() |
| 64 |
->getRevisionByTitle( $title, $revId ); |
| 65 |
|
| 66 |
if ( !$rev ) { |
| 67 |
$titleText = $title->getPrefixedText(); |
| 68 |
$this->fatalError( "Could not load revision $revId of $titleText.\n" ); |
| 69 |
} |
| 70 |
|
| 71 |
$audience = $this->hasOption( 'show-private' ) ? |
| 72 |
RevisionRecord::RAW : |
| 73 |
RevisionRecord::FOR_PUBLIC; |
| 74 |
$content = $rev->getContent( SlotRecord::MAIN, $audience ); |
| 75 |
|
| 76 |
if ( $content === null ) { |
| 77 |
$titleText = $title->getPrefixedText(); |
| 78 |
$this->fatalError( "Couldn't extract the text from $titleText.\n" ); |
| 79 |
} |
| 80 |
$this->output( $content->serialize() ); |
| 81 |
|
| 82 |
if ( stream_isatty( STDOUT ) ) { |
| 83 |
|
| 84 |
|
| 85 |
$this->output( "\n" ); |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
$maintClass = GetTextMaint::class; |
| 92 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 93 |
|