MediaWiki REL1_35
getText.php
Go to the documentation of this file.
1<?php
29
30require_once __DIR__ . '/Maintenance.php';
31
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Outputs page text to stdout' );
41 $this->addOption( 'show-private', 'Show the text even if it\'s not available to the public' );
42 $this->addArg( 'title', 'Page title' );
43 }
44
45 public function execute() {
46 $titleText = $this->getArg( 0 );
47 $title = Title::newFromText( $titleText );
48 if ( !$title ) {
49 $this->fatalError( "$titleText is not a valid title.\n" );
50 }
51
52 $rev = MediaWikiServices::getInstance()
53 ->getRevisionLookup()
54 ->getRevisionByTitle( $title );
55 if ( !$rev ) {
56 $titleText = $title->getPrefixedText();
57 $this->fatalError( "Page $titleText does not exist.\n" );
58 }
59
60 $audience = $this->hasOption( 'show-private' ) ?
61 RevisionRecord::RAW :
62 RevisionRecord::FOR_PUBLIC;
63 $content = $rev->getContent( SlotRecord::MAIN, $audience );
64
65 if ( $content === false ) {
66 $titleText = $title->getPrefixedText();
67 $this->fatalError( "Couldn't extract the text from $titleText.\n" );
68 }
69 $this->output( $content->serialize() );
70 }
71}
72
73$maintClass = GetTextMaint::class;
74require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that outputs page text to stdout.
Definition getText.php:37
execute()
Do the actual work.
Definition getText.php:45
__construct()
Default constructor.
Definition getText.php:38
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 was set.
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Value object representing a content slot associated with a page revision.
$maintClass
Definition getText.php:73
$content
Definition router.php:76