Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PageExists
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 * @ingroup Maintenance
6 */
7
8// @codeCoverageIgnoreStart
9require_once __DIR__ . '/Maintenance.php';
10// @codeCoverageIgnoreEnd
11
12use MediaWiki\Maintenance\Maintenance;
13use MediaWiki\Title\Title;
14
15/**
16 * @ingroup Maintenance
17 */
18class PageExists extends Maintenance {
19    public function __construct() {
20        parent::__construct();
21        $this->addDescription( 'Report whether a specific page exists' );
22        $this->addArg( 'title', 'Page title to check whether it exists' );
23    }
24
25    /** @inheritDoc */
26    public function execute() {
27        $titleArg = $this->getArg( 0 );
28        $title = Title::newFromText( $titleArg );
29        $pageExists = $title && $title->exists();
30
31        if ( $pageExists ) {
32            $text = "{$title} exists.\n";
33        } else {
34            $text = "{$titleArg} doesn't exist.\n";
35        }
36        $this->output( $text );
37        return $pageExists;
38    }
39}
40
41// @codeCoverageIgnoreStart
42$maintClass = PageExists::class;
43require_once RUN_MAINTENANCE_IF_MAIN;
44// @codeCoverageIgnoreEnd