MediaWiki  master
addChangeTag.php
Go to the documentation of this file.
1 <?php
2 
26 
27 require_once __DIR__ . '/Maintenance.php';
28 
35 class AddChangeTag extends Maintenance {
36 
37  public function __construct() {
38  parent::__construct();
39  $this->addDescription( 'Adds a change tag to the wiki.' );
40 
41  $this->addOption( 'tag', 'Tag to add', true, true );
42  $this->addOption( 'reason', 'Reason for adding the tag', true, true );
43  }
44 
45  public function execute() {
46  $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [ 'steal' => true ] );
47 
48  $tag = $this->getOption( 'tag' );
49 
51  $tag,
52  $this->getOption( 'reason' ),
53  new UltimateAuthority( $user )
54  );
55 
56  if ( !$status->isGood() ) {
57  $this->fatalError( $status->getMessage( false, false, 'en' )->text() );
58  }
59 
60  $this->output( "$tag was created.\n" );
61  }
62 }
63 
64 $maintClass = AddChangeTag::class;
65 require_once RUN_MAINTENANCE_IF_MAIN;
$maintClass
$maintClass
Definition: addChangeTag.php:64
ChangeTags\createTagWithChecks
static createTagWithChecks( $tag, $reason, Authority $performer, $ignoreWarnings=false, array $logEntryTags=[])
Creates a tag by adding it to change_tag_def table.
Definition: ChangeTags.php:1407
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
User\newSystemUser
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
Definition: User.php:803
AddChangeTag\execute
execute()
Do the actual work.
Definition: addChangeTag.php:45
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:249
MediaWiki\Permissions\UltimateAuthority
Represents an authority that has all permissions.
Definition: UltimateAuthority.php:35
AddChangeTag
Adds a change tag to the wiki.
Definition: addChangeTag.php:35
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:286
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435
AddChangeTag\__construct
__construct()
Default constructor.
Definition: addChangeTag.php:37
User\MAINTENANCE_SCRIPT_USER
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.
Definition: User.php:113