MediaWiki REL1_34
view.php
Go to the documentation of this file.
1<?php
25
26require_once __DIR__ . '/Maintenance.php';
27
33class 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 } elseif ( $title->isSpecialPage() ) {
45 $this->fatalError( "Special Pages not supported" );
46 } elseif ( !$title->exists() ) {
47 $this->fatalError( "Page does not exist" );
48 }
49
50 $page = WikiPage::factory( $title );
51
52 $content = $page->getContent( RevisionRecord::RAW );
53 if ( !$content ) {
54 $this->fatalError( "Page has no content" );
55 }
56 if ( !$content instanceof TextContent ) {
57 $this->fatalError( "Non-text content models not supported" );
58 }
59
60 $this->output( $content->getText() );
61 }
62}
63
64$maintClass = ViewCLI::class;
65require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
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.
Page revision base class.
Content object implementation for representing flat text.
Maintenance script to show page contents.
Definition view.php:33
execute()
Do the actual work.
Definition view.php:40
__construct()
Default constructor.
Definition view.php:34
$content
Definition router.php:78
$maintClass
Definition view.php:64