MediaWiki  1.34.0
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;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Title\newFromText
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
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
$maintClass
$maintClass
Definition: getText.php:67
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:504
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
GetTextMaint\__construct
__construct()
Default constructor.
Definition: getText.php:36
Revision\newFromTitle
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
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
$title
$title
Definition: testCompression.php:34
GetTextMaint
Maintenance script that outputs page text to stdout.
Definition: getText.php:35
GetTextMaint\execute
execute()
Do the actual work.
Definition: getText.php:43
$content
$content
Definition: router.php:78
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:319
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:288
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:371