Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AddChangeTag
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * Adds a change tag to the wiki.
5 *
6 * @license GPL-2.0-or-later
7 * @file
8 * @ingroup Maintenance
9 */
10
11use MediaWiki\ChangeTags\ChangeTags;
12use MediaWiki\Maintenance\Maintenance;
13use MediaWiki\Permissions\UltimateAuthority;
14use MediaWiki\User\User;
15
16// @codeCoverageIgnoreStart
17require_once __DIR__ . '/Maintenance.php';
18// @codeCoverageIgnoreEnd
19
20/**
21 * Adds a change tag to the wiki
22 *
23 * @ingroup Maintenance
24 * @since 1.32
25 */
26class AddChangeTag extends Maintenance {
27
28    public function __construct() {
29        parent::__construct();
30        $this->addDescription( 'Adds a change tag to the wiki.' );
31
32        $this->addOption( 'tag', 'Tag to add', true, true );
33        $this->addOption( 'reason', 'Reason for adding the tag', true, true );
34    }
35
36    public function execute() {
37        $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [ 'steal' => true ] );
38
39        $tag = $this->getOption( 'tag' );
40
41        $status = ChangeTags::createTagWithChecks(
42            $tag,
43            $this->getOption( 'reason' ),
44            new UltimateAuthority( $user )
45        );
46
47        if ( !$status->isGood() ) {
48            $this->fatalError( $status );
49        }
50
51        $this->output( "$tag was created.\n" );
52    }
53}
54
55// @codeCoverageIgnoreStart
56$maintClass = AddChangeTag::class;
57require_once RUN_MAINTENANCE_IF_MAIN;
58// @codeCoverageIgnoreEnd