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;
getArg( $argId=0, $default=null)
Get an argument.
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
$maintClass
Definition: pageExists.php:51
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
addDescription( $text)
Set the description text.
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
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