MediaWiki REL1_34
getText.php
Go to the documentation of this file.
1<?php
27
28require_once __DIR__ . '/Maintenance.php';
29
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Outputs page text to stdout' );
39 $this->addOption( 'show-private', 'Show the text even if it\'s not available to the public' );
40 $this->addArg( 'title', 'Page title' );
41 }
42
43 public function execute() {
44 $titleText = $this->getArg( 0 );
45 $title = Title::newFromText( $titleText );
46 if ( !$title ) {
47 $this->fatalError( "$titleText is not a valid title.\n" );
48 }
49
51 if ( !$rev ) {
52 $titleText = $title->getPrefixedText();
53 $this->fatalError( "Page $titleText does not exist.\n" );
54 }
55 $content = $rev->getContent( $this->hasOption( 'show-private' )
56 ? RevisionRecord::RAW
57 : RevisionRecord::FOR_PUBLIC );
58
59 if ( $content === false ) {
60 $titleText = $title->getPrefixedText();
61 $this->fatalError( "Couldn't extract the text from $titleText.\n" );
62 }
63 $this->output( $content->serialize() );
64 }
65}
66
67$maintClass = GetTextMaint::class;
68require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that outputs page text to stdout.
Definition getText.php:35
execute()
Do the actual work.
Definition getText.php:43
__construct()
Default constructor.
Definition getText.php:36
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Page revision base class.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition Revision.php:138
$maintClass
Definition getText.php:67
$content
Definition router.php:78