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
Adds a change tag to the wiki.
__construct()
Default constructor.
execute()
Do the actual work.
static createTagWithChecks(string $tag, string $reason, Authority $performer, bool $ignoreWarnings=false, array $logEntryTags=[])
Creates a tag by adding it to change_tag_def table.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Represents an authority that has all permissions.
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
Definition: User.php:793
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.
Definition: User.php:117