MediaWiki  1.34.0
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  }
45 
46  $page = WikiPage::factory( $title );
47 
48  $content = $page->getContent( RevisionRecord::RAW );
49  if ( !$content ) {
50  $this->fatalError( "Page has no content" );
51  }
52  if ( !$content instanceof TextContent ) {
53  $this->fatalError( "Non-text content models not supported" );
54  }
55 
56  $this->output( $content->getText() );
57  }
58 }
59 
60 $maintClass = ViewCLI::class;
61 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
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:316
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:504
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
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:82
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:142
$title
$title
Definition: testCompression.php:34
$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:319
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:371
$maintClass
$maintClass
Definition: view.php:60