MediaWiki  1.23.12
protect.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
31 class Protect extends Maintenance {
32  public function __construct() {
33  parent::__construct();
34  $this->mDescription = "Protect or unprotect a page from the command line.";
35  $this->addOption( 'unprotect', 'Removes protection' );
36  $this->addOption( 'semiprotect', 'Adds semi-protection' );
37  $this->addOption( 'cascade', 'Add cascading protection' );
38  $this->addOption( 'user', 'Username to protect with', false, true, 'u' );
39  $this->addOption( 'reason', 'Reason for un/protection', false, true, 'r' );
40  $this->addArg( 'title', 'Title to protect', true );
41  }
42 
43  public function execute() {
44  $userName = $this->getOption( 'u', 'Maintenance script' );
45  $reason = $this->getOption( 'r', '' );
46 
47  $cascade = $this->hasOption( 'cascade' );
48 
49  $protection = "sysop";
50  if ( $this->hasOption( 'semiprotect' ) ) {
51  $protection = "autoconfirmed";
52  } elseif ( $this->hasOption( 'unprotect' ) ) {
53  $protection = "";
54  }
55 
56  $user = User::newFromName( $userName );
57  if ( !$user ) {
58  $this->error( "Invalid username", true );
59  }
60 
61  // @todo FIXME: This is reset 7 lines down.
62  $restrictions = array( 'edit' => $protection, 'move' => $protection );
63 
64  $t = Title::newFromText( $this->getArg() );
65  if ( !$t ) {
66  $this->error( "Invalid title", true );
67  }
68 
69  $restrictions = array();
70  foreach ( $t->getRestrictionTypes() as $type ) {
71  $restrictions[$type] = $protection;
72  }
73 
74  # un/protect the article
75  $this->output( "Updating protection status... " );
76 
77  $page = WikiPage::factory( $t );
78  $status = $page->doUpdateRestrictions( $restrictions, array(), $cascade, $reason, $user );
79 
80  if ( $status->isOK() ) {
81  $this->output( "done\n" );
82  } else {
83  $this->output( "failed\n" );
84  }
85  }
86 }
87 
88 $maintClass = "Protect";
89 require_once RUN_MAINTENANCE_IF_MAIN;
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
Protect
Maintenance script that protects or unprotects a page.
Definition: protect.php:31
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Protect\execute
execute()
Do the actual work.
Definition: protect.php:43
$maintClass
$maintClass
Definition: protect.php:88
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:207
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Protect\__construct
__construct()
Default constructor.
Definition: protect.php:32
$t
$t
Definition: testCompression.php:65
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:246
$type
$type
Definition: testCompression.php:46