MediaWiki master
view.php
Go to the documentation of this file.
1<?php
27
28// @codeCoverageIgnoreStart
29require_once __DIR__ . '/Maintenance.php';
30// @codeCoverageIgnoreEnd
31
37class ViewCLI extends Maintenance {
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Show article contents on the command line' );
41 $this->addArg( 'title', 'Title of article to view' );
42 }
43
44 public function execute() {
45 $title = Title::newFromText( $this->getArg( 0 ) );
46 if ( !$title ) {
47 $this->fatalError( "Invalid title" );
48 } elseif ( $title->isSpecialPage() ) {
49 $this->fatalError( "Special Pages not supported" );
50 } elseif ( !$title->exists() ) {
51 $this->fatalError( "Page does not exist" );
52 }
53
54 $page = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
55
56 $content = $page->getContent( RevisionRecord::RAW );
57 if ( !$content ) {
58 $this->fatalError( "Page has no content" );
59 }
60 if ( !$content instanceof TextContent ) {
61 $this->fatalError( "Non-text content models not supported" );
62 }
63
64 $this->output( $content->getText() );
65 }
66}
67
68// @codeCoverageIgnoreStart
69$maintClass = ViewCLI::class;
70require_once RUN_MAINTENANCE_IF_MAIN;
71// @codeCoverageIgnoreEnd
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:37
execute()
Do the actual work.
Definition view.php:44
__construct()
Default constructor.
Definition view.php:38
$maintClass
Definition view.php:69