MediaWiki master
view.php
Go to the documentation of this file.
1<?php
14
15// @codeCoverageIgnoreStart
16require_once __DIR__ . '/Maintenance.php';
17// @codeCoverageIgnoreEnd
18
24class ViewCLI extends Maintenance {
25 public function __construct() {
26 parent::__construct();
27 $this->addDescription( 'Show article contents on the command line' );
28 $this->addArg( 'title', 'Title of article to view' );
29 }
30
31 public function execute() {
32 $title = Title::newFromText( $this->getArg( 0 ) );
33 if ( !$title ) {
34 $this->fatalError( "Invalid title" );
35 } elseif ( $title->isSpecialPage() ) {
36 $this->fatalError( "Special Pages not supported" );
37 } elseif ( !$title->exists() ) {
38 $this->fatalError( "Page does not exist" );
39 }
40
41 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
42
43 $content = $page->getContent( RevisionRecord::RAW );
44 if ( !$content ) {
45 $this->fatalError( "Page has no content" );
46 }
47 if ( !$content instanceof TextContent ) {
48 $this->fatalError( "Non-text content models not supported" );
49 }
50
51 $this->output( $content->getText() );
52 }
53}
54
55// @codeCoverageIgnoreStart
56$maintClass = ViewCLI::class;
57require_once RUN_MAINTENANCE_IF_MAIN;
58// @codeCoverageIgnoreEnd
Content object implementation for representing flat text.
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.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Page revision base class.
Represents a title within MediaWiki.
Definition Title.php:69
Maintenance script to show page contents.
Definition view.php:24
execute()
Do the actual work.
Definition view.php:31
__construct()
Default constructor.
Definition view.php:25
$maintClass
Definition view.php:56