Index: branches/apiedit/phase3/includes/AutoLoader.php |
— | — | @@ -311,6 +311,7 @@ |
312 | 312 | 'ApiMain' => 'includes/api/ApiMain.php', |
313 | 313 | 'ApiOpenSearch' => 'includes/api/ApiOpenSearch.php', |
314 | 314 | 'ApiPageSet' => 'includes/api/ApiPageSet.php', |
| 315 | + 'ApiProtect' => 'includes/api/ApiProtect.php', |
315 | 316 | 'ApiQuery' => 'includes/api/ApiQuery.php', |
316 | 317 | 'ApiQueryAllpages' => 'includes/api/ApiQueryAllpages.php', |
317 | 318 | 'ApiQueryAllLinks' => 'includes/api/ApiQueryAllLinks.php', |
Index: branches/apiedit/phase3/includes/Article.php |
— | — | @@ -1719,6 +1719,7 @@ |
1720 | 1720 | if( wfRunHooks( 'ArticleProtect', array( &$this, &$wgUser, $limit, $reason ) ) ) { |
1721 | 1721 | |
1722 | 1722 | $dbw = wfGetDB( DB_MASTER ); |
| 1723 | + $dbw->begin(); |
1723 | 1724 | |
1724 | 1725 | $encodedExpiry = Block::encodeExpiry($expiry, $dbw ); |
1725 | 1726 | |
— | — | @@ -1792,6 +1793,7 @@ |
1793 | 1794 | } else { |
1794 | 1795 | $log->addEntry( 'unprotect', $this->mTitle, $reason ); |
1795 | 1796 | } |
| 1797 | + $dbw->commit(); |
1796 | 1798 | |
1797 | 1799 | } # End hook |
1798 | 1800 | } # End "changed" check |
Index: branches/apiedit/phase3/includes/api/ApiProtect.php |
— | — | @@ -0,0 +1,139 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Sep 1, 2007 |
| 6 | + * API for MediaWiki 1.8+ |
| 7 | + * |
| 8 | + * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl |
| 9 | + * |
| 10 | + * This program is free software; you can redistribute it and/or modify |
| 11 | + * it under the terms of the GNU General Public License as published by |
| 12 | + * the Free Software Foundation; either version 2 of the License, or |
| 13 | + * (at your option) any later version. |
| 14 | + * |
| 15 | + * This program is distributed in the hope that it will be useful, |
| 16 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | + * GNU General Public License for more details. |
| 19 | + * |
| 20 | + * You should have received a copy of the GNU General Public License along |
| 21 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | + * http://www.gnu.org/copyleft/gpl.html |
| 24 | + */ |
| 25 | + |
| 26 | +if (!defined('MEDIAWIKI')) { |
| 27 | + // Eclipse helper - will be ignored in production |
| 28 | + require_once ("ApiBase.php"); |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * @addtogroup API |
| 33 | + */ |
| 34 | +class ApiProtect extends ApiBase { |
| 35 | + |
| 36 | + public function __construct($main, $action) { |
| 37 | + parent :: __construct($main, $action); |
| 38 | + } |
| 39 | + |
| 40 | + public function execute() { |
| 41 | + global $wgUser; |
| 42 | + $params = $this->extractRequestParams(); |
| 43 | + |
| 44 | + $titleObj = NULL; |
| 45 | + if(!isset($params['title'])) |
| 46 | + $this->dieUsage('The title parameter must be set', 'notarget'); |
| 47 | + if(!isset($params['token'])) |
| 48 | + $this->dieUsage('The token parameter must be set', 'notoken'); |
| 49 | + if(!isset($params['protections']) || empty($params['protections'])) |
| 50 | + $this->dieUsage('The protections parameter must be set', 'noprotections'); |
| 51 | + |
| 52 | + if(!$wgUser->isAllowed('protect')) |
| 53 | + $this->dieUsage('You don\'t have permission to change protection levels', 'permissiondenied'); |
| 54 | + if($wgUser->isBlocked()) |
| 55 | + $this->dieUsage('You have been blocked from editing', 'blocked'); |
| 56 | + if(wfReadOnly()) |
| 57 | + $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
| 58 | + if(!$wgUser->matchEditToken($params['token'])) |
| 59 | + $this->dieUsage('Invalid token', 'badtoken'); |
| 60 | + |
| 61 | + $titleObj = Title::newFromText($params['title']); |
| 62 | + if(!$titleObj) |
| 63 | + $this->dieUsage("bad title {$params['title']}", 'invalidtitle'); |
| 64 | + if(!$titleObj->exists()) |
| 65 | + $this->dieUsage("{$params['title']} doesn't exist", "nonexistenttitle"); |
| 66 | + $articleObj = new Article($titleObj); |
| 67 | + |
| 68 | + if(in_array($params['expiry'], array('infinite', 'indefinite', 'never'))) |
| 69 | + $expiry = Block::infinity(); |
| 70 | + else |
| 71 | + { |
| 72 | + $expiry = strtotime($params['expiry']); |
| 73 | + if($expiry < 0 || $expiry == false) |
| 74 | + $this->dieUsage('Invalid expiry time', 'invalidexpiry'); |
| 75 | + |
| 76 | + $expiry = wfTimestamp(TS_MW, $expiry); |
| 77 | + if($expiry < wfTimestampNow()) |
| 78 | + $this->dieUsage('Expiry time is in the past', 'pastexpiry'); |
| 79 | + } |
| 80 | + |
| 81 | + $protections = array(); |
| 82 | + foreach($params['protections'] as $prot) |
| 83 | + { |
| 84 | + $p = explode('=', $prot); |
| 85 | + $protections[$p[0]] = ($p[1] == 'all' ? '' : $p[1]); |
| 86 | + } |
| 87 | + |
| 88 | + $ok = $articleObj->updateRestrictions($protections, $params['reason'], $params['cascade'], $expiry); |
| 89 | + if(!$ok) |
| 90 | + // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? |
| 91 | + $this->dieUsage('Unknown error', 'unknownerror'); |
| 92 | + $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'], 'expiry' => $expiry); |
| 93 | + if($params['cascade']) |
| 94 | + $res['cascade'] = ''; |
| 95 | + $res['protections'] = $protections; |
| 96 | + $this->getResult()->addValue(null, $this->getModuleName(), $res); |
| 97 | + } |
| 98 | + |
| 99 | + protected function getAllowedParams() { |
| 100 | + return array ( |
| 101 | + 'title' => null, |
| 102 | + 'token' => null, |
| 103 | + 'protections' => array( |
| 104 | + ApiBase :: PARAM_ISMULTI => true |
| 105 | + ), |
| 106 | + 'expiry' => 'infinite', |
| 107 | + 'reason' => '', |
| 108 | + 'cascade' => false |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + protected function getParamDescription() { |
| 113 | + return array ( |
| 114 | + 'title' => 'Title of the page you want to restore.', |
| 115 | + 'token' => 'A protect token previously retrieved through prop=info', |
| 116 | + 'protections' => 'Pipe-separated list of protection levels, formatted action=group (e.g. edit=sysop)', |
| 117 | + 'expiry' => 'Expiry timestamp. If set to \'infinite\', \'indefinite\' or \'never\', the protection never expires.', |
| 118 | + 'reason' => 'Reason for (un)protecting (optional)', |
| 119 | + 'cascade' => 'Enable cascading protection (i.e. protect pages included in this page)' |
| 120 | + ); |
| 121 | + } |
| 122 | + |
| 123 | + protected function getDescription() { |
| 124 | + return array( |
| 125 | + 'Change the protection level of a page.' |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + protected function getExamples() { |
| 130 | + return array ( |
| 131 | + 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=sysop|move=sysop&cascade&expiry=20070901163000', |
| 132 | + 'api.php?action=protect&title=Main%20Page&token=123ABC&protections=edit=all|move=all&reason=Lifting%20restrictions' |
| 133 | + ); |
| 134 | + } |
| 135 | + |
| 136 | + public function getVersion() { |
| 137 | + return __CLASS__ . ': $Id$'; |
| 138 | + } |
| 139 | +} |
| 140 | +?> |
Property changes on: branches/apiedit/phase3/includes/api/ApiProtect.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 141 | + native |
Index: branches/apiedit/phase3/includes/api/ApiMain.php |
— | — | @@ -57,6 +57,7 @@ |
58 | 58 | 'rollback' => 'ApiRollback', |
59 | 59 | 'delete' => 'ApiDelete', |
60 | 60 | 'undelete' => 'ApiUndelete', |
| 61 | + 'protect' => 'ApiProtect', |
61 | 62 | 'opensearch' => 'ApiOpenSearch', |
62 | 63 | 'feedwatchlist' => 'ApiFeedWatchlist', |
63 | 64 | 'help' => 'ApiHelp', |
Index: branches/apiedit/phase3/CHANGED |
— | — | @@ -9,6 +9,7 @@ |
10 | 10 | ** Introduced Article::ROLLBACK_* constants for rollback()'s return values (r23627) |
11 | 11 | * Made a separate function (Article::generateReason()) for generating deletion reasons (r23590) |
12 | 12 | * Added begin() and commit() to Article::doDeleteArticle() (r23590) |
| 13 | +* Added begin() and commit() to Article::updateRestrictions() (r25388) |
13 | 14 | |
14 | 15 | SpecialUndelete.php |
15 | 16 | * Added begin() and commit() to PageArchive::undelete() (r23687) |
— | — | @@ -33,11 +34,14 @@ |
34 | 35 | api/ApiUndelete.php (NEW) |
35 | 36 | * action=undelete module that wraps around PageArchive::undelete() (r23687, r23697) |
36 | 37 | |
| 38 | +api/ApiProtect.php (NEW) |
| 39 | +* action=protect module that wraps around Article::updateRestrictions() (r25388) |
| 40 | + |
37 | 41 | AutoLoader.php |
38 | | -* Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiQueryDeletedRevs (r23668), ApiUndelete (r23687) |
| 42 | +* Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiQueryDeletedRevs (r23668), ApiUndelete (r23687), ApiProtect (r23588) |
39 | 43 | |
40 | 44 | api/ApiMain.php |
41 | | -* Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiUndelete (r23687) |
| 45 | +* Added entries for ApiRollback (r23562), ApiDelete (r23590), ApiUndelete (r23687), ApiProtect (r23588) |
42 | 46 | |
43 | 47 | api/ApiQuery.php |
44 | | -* Added entry for ApiQueryDeletedRevs (r23668) |
\ No newline at end of file |
| 48 | +* Added entry for ApiQueryDeletedRevs (r23668) |