MediaWiki  master
view.php
Go to the documentation of this file.
1 <?php
25 
26 require_once __DIR__ . '/Maintenance.php';
27 
33 class 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;
65 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:42
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:332
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
ViewCLI
Maintenance script to show page contents.
Definition: view.php:33
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:511
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:355
ViewCLI\execute
execute()
Do the actual work.
Definition: view.php:40
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:89
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:143
$title
$title
Definition: testCompression.php:38
$content
$content
Definition: router.php:78
ViewCLI\__construct
__construct()
Default constructor.
Definition: view.php:34
TextContent
Content object implementation for representing flat text.
Definition: TextContent.php:37
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:326
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:460
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:378
$maintClass
$maintClass
Definition: view.php:64