MediaWiki  master
getText.php
Go to the documentation of this file.
1 <?php
27 
28 require_once __DIR__ . '/Maintenance.php';
29 
35 class GetTextMaint extends Maintenance {
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;
68 require_once RUN_MAINTENANCE_IF_MAIN;
getArg( $argId=0, $default=null)
Get an argument.
Maintenance script that outputs page text to stdout.
Definition: getText.php:35
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
hasOption( $name)
Checks to see if a particular option exists.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that&#39;s attached to a given link target...
Definition: Revision.php:138
addDescription( $text)
Set the description text.
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
$maintClass
Definition: getText.php:67
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.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:316