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