MediaWiki  master
pageExists.php
Go to the documentation of this file.
1 <?php
22 require_once __DIR__ . '/Maintenance.php';
23 
27 class PageExists extends Maintenance {
28  public function __construct() {
29  parent::__construct();
30  $this->addDescription( 'Report whether a specific page exists' );
31  $this->addArg( 'title', 'Page title to check whether it exists' );
32  }
33 
34  public function execute() {
35  $titleArg = $this->getArg( 0 );
36  $title = Title::newFromText( $titleArg );
37  $pageExists = $title && $title->exists();
38 
39  $code = 0;
40  if ( $pageExists ) {
41  $text = "{$title} exists.";
42  } else {
43  $text = "{$titleArg} doesn't exist.";
44  $code = 1;
45  }
46  $this->output( $text );
47  exit( $code );
48  }
49 }
50 
51 $maintClass = PageExists::class;
52 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
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:355
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:89
PageExists\__construct
__construct()
Default constructor.
Definition: pageExists.php:28
$title
$title
Definition: testCompression.php:38
$maintClass
$maintClass
Definition: pageExists.php:51
PageExists
Definition: pageExists.php:27
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
PageExists\execute
execute()
Do the actual work.
Definition: pageExists.php:34