MediaWiki  master
view.php
Go to the documentation of this file.
1 <?php
26 
27 require_once __DIR__ . '/Maintenance.php';
28 
34 class ViewCLI extends Maintenance {
35  public function __construct() {
36  parent::__construct();
37  $this->addDescription( 'Show article contents on the command line' );
38  $this->addArg( 'title', 'Title of article to view' );
39  }
40 
41  public function execute() {
42  $title = Title::newFromText( $this->getArg( 0 ) );
43  if ( !$title ) {
44  $this->fatalError( "Invalid title" );
45  } elseif ( $title->isSpecialPage() ) {
46  $this->fatalError( "Special Pages not supported" );
47  } elseif ( !$title->exists() ) {
48  $this->fatalError( "Page does not exist" );
49  }
50 
51  $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
52 
53  $content = $page->getContent( RevisionRecord::RAW );
54  if ( !$content ) {
55  $this->fatalError( "Page has no content" );
56  }
57  if ( !$content instanceof TextContent ) {
58  $this->fatalError( "Non-text content models not supported" );
59  }
60 
61  $this->output( $content->getText() );
62  }
63 }
64 
65 $maintClass = ViewCLI::class;
66 require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Service locator for MediaWiki core services.
Page revision base class.
Content object implementation for representing flat text.
Definition: TextContent.php:40
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:370
Maintenance script to show page contents.
Definition: view.php:34
execute()
Do the actual work.
Definition: view.php:41
__construct()
Default constructor.
Definition: view.php:35
$content
Definition: router.php:76
$maintClass
Definition: view.php:65