]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiProtect.php
MediaWiki 1.15.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiProtect.php
index 522d02b2ee36cbf5caf0795fc420c5b85f8b5b25..aad37066e5cf238390613b9acd2b4b239cf12e20 100644 (file)
@@ -38,7 +38,6 @@ class ApiProtect extends ApiBase {
 
        public function execute() {
                global $wgUser, $wgRestrictionTypes, $wgRestrictionLevels;
-               $this->getMain()->requestWriteMode();
                $params = $this->extractRequestParams();
 
                $titleObj = NULL;
@@ -59,7 +58,7 @@ class ApiProtect extends ApiBase {
                $errors = $titleObj->getUserPermissionsErrors('protect', $wgUser);
                if($errors)
                        // We don't care about multiple errors, just report one of them
-                       $this->dieUsageMsg(current($errors));
+                       $this->dieUsageMsg(reset($errors));
 
                $expiry = (array)$params['expiry'];
                if(count($expiry) != count($params['protections']))
@@ -106,10 +105,12 @@ class ApiProtect extends ApiBase {
                }
 
                $cascade = $params['cascade'];
-               if($titleObj->exists()) {
-                       $articleObj = new Article($titleObj);
+               $articleObj = new Article($titleObj);
+               if($params['watch'])
+                       $articleObj->doWatch();
+               if($titleObj->exists())
                        $ok = $articleObj->updateRestrictions($protections, $params['reason'], $cascade, $expiryarray);
-               else
+               else
                        $ok = $titleObj->updateTitleProtection($protections['create'], $params['reason'], $expiryarray['create']);
                if(!$ok)
                        // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime?
@@ -125,6 +126,10 @@ class ApiProtect extends ApiBase {
 
        public function mustBePosted() { return true; }
 
+       public function isWriteMode() {
+               return true;
+       }
+
        public function getAllowedParams() {
                return array (
                        'title' => null,
@@ -138,7 +143,8 @@ class ApiProtect extends ApiBase {
                                ApiBase :: PARAM_DFLT => 'infinite',
                        ),
                        'reason' => '',
-                       'cascade' => false
+                       'cascade' => false,
+                       'watch' => false,
                );
        }
 
@@ -152,6 +158,7 @@ class ApiProtect extends ApiBase {
                        'reason' => 'Reason for (un)protecting (optional)',
                        'cascade' => array('Enable cascading protection (i.e. protect pages included in this page)',
                                        'Ignored if not all protection levels are \'sysop\' or \'protect\''),
+                       'watch' => 'If set, add the page being (un)protected to your watchlist',
                );
        }
 
@@ -169,6 +176,6 @@ class ApiProtect extends ApiBase {
        }
 
        public function getVersion() {
-               return __CLASS__ . ': $Id: ApiProtect.php 44426 2008-12-10 22:39:41Z catrope $';
+               return __CLASS__ . ': $Id: ApiProtect.php 48122 2009-03-07 12:58:41Z catrope $';
        }
 }