15require_once __DIR__ .
'/Maintenance.php';
25 parent::__construct();
26 $this->
addDescription(
'Protect or unprotect a page from the command line.' );
27 $this->
addOption(
'unprotect',
'Removes protection' );
28 $this->
addOption(
'semiprotect',
'Adds semi-protection' );
29 $this->
addOption(
'cascade',
'Add cascading protection' );
30 $this->
addOption(
'user',
'Username to protect with',
false,
true,
'u' );
31 $this->
addOption(
'reason',
'Reason for un/protection',
false,
true,
'r' );
32 $this->
addArg(
'title',
'Title to protect',
true );
36 $userName = $this->
getOption(
'user',
false );
37 $reason = $this->
getOption(
'reason',
'' );
41 $protection =
"sysop";
42 if ( $this->
hasOption(
'semiprotect' ) ) {
43 $protection =
"autoconfirmed";
44 } elseif ( $this->
hasOption(
'unprotect' ) ) {
48 if ( $userName ===
false ) {
49 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
51 $user = User::newFromName( $userName );
57 $t = Title::newFromText( $this->
getArg( 0 ) );
64 foreach ( $services->getRestrictionStore()->listApplicableRestrictionTypes( $t ) as $type ) {
65 $restrictions[$type] = $protection;
68 # un/protect the article
69 $this->
output(
"Updating protection status..." );
72 $page = $services->getWikiPageFactory()->newFromTitle( $t );
73 $status = $page->doUpdateRestrictions( $restrictions, [], $cascade, $reason, $user );
76 if ( $status->isOK() ) {
79 $this->
output(
"failed\n" );
86require_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.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Maintenance script that protects or unprotects a page.
__construct()
Default constructor.
execute()
Do the actual work.