27 require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
37 $this->
addDescription(
'Protect or unprotect a page from the command line.' );
38 $this->
addOption(
'unprotect',
'Removes protection' );
39 $this->
addOption(
'semiprotect',
'Adds semi-protection' );
40 $this->
addOption(
'cascade',
'Add cascading protection' );
41 $this->
addOption(
'user',
'Username to protect with',
false,
true,
'u' );
42 $this->
addOption(
'reason',
'Reason for un/protection',
false,
true,
'r' );
43 $this->
addArg(
'title',
'Title to protect',
true );
47 $userName = $this->
getOption(
'user',
false );
48 $reason = $this->
getOption(
'reason',
'' );
52 $protection =
"sysop";
53 if ( $this->
hasOption(
'semiprotect' ) ) {
54 $protection =
"autoconfirmed";
55 } elseif ( $this->
hasOption(
'unprotect' ) ) {
59 if ( $userName ===
false ) {
60 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
62 $user = User::newFromName( $userName );
68 $t = Title::newFromText( $this->
getArg( 0 ) );
75 foreach ( $services->getRestrictionStore()->listApplicableRestrictionTypes(
$t ) as $type ) {
76 $restrictions[$type] = $protection;
79 # un/protect the article
80 $this->
output(
"Updating protection status..." );
82 $page = $services->getWikiPageFactory()->newFromTitle(
$t );
83 $status = $page->doUpdateRestrictions( $restrictions, [], $cascade, $reason, $user );
85 if ( $status->isOK() ) {
88 $this->
output(
"failed\n" );
94 require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
getArg( $argId=0, $default=null)
Get an argument.
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.
Maintenance script that protects or unprotects a page.
__construct()
Default constructor.
execute()
Do the actual work.