MediaWiki master
view.php
Go to the documentation of this file.
1<?php
27
28require_once __DIR__ . '/Maintenance.php';
29
35class ViewCLI extends Maintenance {
36 public function __construct() {
37 parent::__construct();
38 $this->addDescription( 'Show article contents on the command line' );
39 $this->addArg( 'title', 'Title of article to view' );
40 }
41
42 public function execute() {
43 $title = Title::newFromText( $this->getArg( 0 ) );
44 if ( !$title ) {
45 $this->fatalError( "Invalid title" );
46 } elseif ( $title->isSpecialPage() ) {
47 $this->fatalError( "Special Pages not supported" );
48 } elseif ( !$title->exists() ) {
49 $this->fatalError( "Page does not exist" );
50 }
51
52 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
53
54 $content = $page->getContent( RevisionRecord::RAW );
55 if ( !$content ) {
56 $this->fatalError( "Page has no content" );
57 }
58 if ( !$content instanceof TextContent ) {
59 $this->fatalError( "Non-text content models not supported" );
60 }
61
62 $this->output( $content->getText() );
63 }
64}
65
66$maintClass = ViewCLI::class;
67require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
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.
Content object implementation for representing flat text.
Page revision base class.
Represents a title within MediaWiki.
Definition Title.php:78
Maintenance script to show page contents.
Definition view.php:35
execute()
Do the actual work.
Definition view.php:42
__construct()
Default constructor.
Definition view.php:36
$maintClass
Definition view.php:66