MediaWiki  master
view.php
Go to the documentation of this file.
1 <?php
25 
26 require_once __DIR__ . '/Maintenance.php';
27 
33 class ViewCLI extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->addDescription( 'Show article contents on the command line' );
37  $this->addArg( 'title', 'Title of article to view' );
38  }
39 
40  public function execute() {
41  $title = Title::newFromText( $this->getArg( 0 ) );
42  if ( !$title ) {
43  $this->fatalError( "Invalid title" );
44  }
45 
46  $page = WikiPage::factory( $title );
47 
48  $content = $page->getContent( RevisionRecord::RAW );
49  if ( !$content ) {
50  $this->fatalError( "Page has no content" );
51  }
52  if ( !$content instanceof TextContent ) {
53  $this->fatalError( "Non-text content models not supported" );
54  }
55 
56  $this->output( $content->getText() );
57  }
58 }
59 
60 $maintClass = ViewCLI::class;
61 require_once RUN_MAINTENANCE_IF_MAIN;
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:142
getArg( $argId=0, $default=null)
Get an argument.
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:86
addDescription( $text)
Set the description text.
execute()
Definition: view.php:40
addArg( $arg, $description, $required=true)
Add some args that are needed.
$maintClass
Definition: view.php:60
output( $out, $channel=null)
Throw some output to the user.
__construct()
Definition: view.php:34
$content
Definition: router.php:78
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script to show page contents.
Definition: view.php:33
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:317