MediaWiki  master
view.php
Go to the documentation of this file.
1 <?php
26 
27 require_once __DIR__ . '/Maintenance.php';
28 
34 class ViewCLI extends Maintenance {
35  public function __construct() {
36  parent::__construct();
37  $this->addDescription( 'Show article contents on the command line' );
38  $this->addArg( 'title', 'Title of article to view' );
39  }
40 
41  public function execute() {
42  $title = Title::newFromText( $this->getArg( 0 ) );
43  if ( !$title ) {
44  $this->fatalError( "Invalid title" );
45  } elseif ( $title->isSpecialPage() ) {
46  $this->fatalError( "Special Pages not supported" );
47  } elseif ( !$title->exists() ) {
48  $this->fatalError( "Page does not exist" );
49  }
50 
51  $page = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $title );
52 
53  $content = $page->getContent( RevisionRecord::RAW );
54  if ( !$content ) {
55  $this->fatalError( "Page has no content" );
56  }
57  if ( !$content instanceof TextContent ) {
58  $this->fatalError( "Non-text content models not supported" );
59  }
60 
61  $this->output( $content->getText() );
62  }
63 }
64 
65 $maintClass = ViewCLI::class;
66 require_once RUN_MAINTENANCE_IF_MAIN;
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:382
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
ViewCLI
Maintenance script to show page contents.
Definition: view.php:34
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:195
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
ViewCLI\execute
execute()
Do the actual work.
Definition: view.php:41
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
$title
$title
Definition: testCompression.php:38
$content
$content
Definition: router.php:76
ViewCLI\__construct
__construct()
Default constructor.
Definition: view.php:35
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:39
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:300
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:353
$maintClass
$maintClass
Definition: view.php:65