Index: trunk/phase3/includes/api/ApiMove.php |
— | — | @@ -61,12 +61,24 @@ |
62 | 62 | $this->dieUsageMsg(array('notanarticle')); |
63 | 63 | $fromTalk = $fromTitle->getTalkPage(); |
64 | 64 | |
65 | | - |
66 | 65 | $toTitle = Title::newFromText($params['to']); |
67 | 66 | if(!$toTitle) |
68 | 67 | $this->dieUsageMsg(array('invalidtitle', $params['to'])); |
69 | 68 | $toTalk = $toTitle->getTalkPage(); |
70 | 69 | |
| 70 | + // Run getUserPermissionsErrors() here so we get message arguments too, |
| 71 | + // rather than just a message key. The latter is troublesome for messages |
| 72 | + // that use arguments. |
| 73 | + // FIXME: moveTo() should really return an array, requires some |
| 74 | + // refactoring of other code, though (mainly SpecialMovepage.php) |
| 75 | + $errors = array_merge($fromTitle->getUserPermissionsErrors('move', $wgUser), |
| 76 | + $fromTitle->getUserPermissionsErrors('edit', $wgUser), |
| 77 | + $toTitle->getUserPermissionsErrors('move', $wgUser), |
| 78 | + $toTitle->getUserPermissionsErrors('edit', $wgUser)); |
| 79 | + if(!empty($errors)) |
| 80 | + // We don't care about multiple errors, just report one of them |
| 81 | + $this->dieUsageMsg(current($errors)); |
| 82 | + |
71 | 83 | $dbw = wfGetDB(DB_MASTER); |
72 | 84 | $dbw->begin(); |
73 | 85 | $retval = $fromTitle->moveTo($toTitle, true, $params['reason'], !$params['noredirect']); |
Index: trunk/phase3/includes/api/ApiProtect.php |
— | — | @@ -43,24 +43,23 @@ |
44 | 44 | |
45 | 45 | $titleObj = NULL; |
46 | 46 | if(!isset($params['title'])) |
47 | | - $this->dieUsage('The title parameter must be set', 'notitle'); |
| 47 | + $this->dieUsageMsg(array('missingparam', 'title')); |
48 | 48 | if(!isset($params['token'])) |
49 | | - $this->dieUsage('The token parameter must be set', 'notoken'); |
| 49 | + $this->dieUsageMsg(array('missingparam', 'token')); |
50 | 50 | if(!isset($params['protections']) || empty($params['protections'])) |
51 | | - $this->dieUsage('The protections parameter must be set', 'noprotections'); |
| 51 | + $this->dieUsageMsg(array('missingparam', 'protections')); |
52 | 52 | |
53 | | - if($wgUser->isBlocked()) |
54 | | - $this->dieUsage('You have been blocked from editing', 'blocked'); |
55 | | - if(wfReadOnly()) |
56 | | - $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
57 | 53 | if(!$wgUser->matchEditToken($params['token'])) |
58 | | - $this->dieUsage('Invalid token', 'badtoken'); |
| 54 | + $this->dieUsageMsg(array('sessionfailure')); |
59 | 55 | |
60 | 56 | $titleObj = Title::newFromText($params['title']); |
61 | 57 | if(!$titleObj) |
62 | | - $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle'); |
63 | | - if(!$titleObj->userCan('protect')) |
64 | | - $this->dieUsage('You don\'t have permission to change protection levels', 'permissiondenied'); |
| 58 | + $this->dieUsageMsg(array('invalidtitle', $params['title'])); |
| 59 | + |
| 60 | + $errors = $titleObj->getUserPermissionsErrors('protect', $wgUser); |
| 61 | + if(!empty($errors)) |
| 62 | + // We don't care about multiple errors, just report one of them |
| 63 | + $this->dieUsageMsg(current($errors)); |
65 | 64 | |
66 | 65 | if(in_array($params['expiry'], array('infinite', 'indefinite', 'never'))) |
67 | 66 | $expiry = Block::infinity(); |
— | — | @@ -68,11 +67,11 @@ |
69 | 68 | { |
70 | 69 | $expiry = strtotime($params['expiry']); |
71 | 70 | if($expiry < 0 || $expiry == false) |
72 | | - $this->dieUsage('Invalid expiry time', 'invalidexpiry'); |
| 71 | + $this->dieUsageMsg(array('invalidexpiry')); |
73 | 72 | |
74 | 73 | $expiry = wfTimestamp(TS_MW, $expiry); |
75 | 74 | if($expiry < wfTimestampNow()) |
76 | | - $this->dieUsage('Expiry time is in the past', 'pastexpiry'); |
| 75 | + $this->dieUsageMsg(array('pastexpiry')); |
77 | 76 | } |
78 | 77 | |
79 | 78 | $protections = array(); |
— | — | @@ -81,9 +80,9 @@ |
82 | 81 | $p = explode('=', $prot); |
83 | 82 | $protections[$p[0]] = ($p[1] == 'all' ? '' : $p[1]); |
84 | 83 | if($titleObj->exists() && $p[0] == 'create') |
85 | | - $this->dieUsage("Existing titles can't be protected with 'create'", 'create-titleexists'); |
| 84 | + $this->dieUsageMsg(array('create-titleexists')); |
86 | 85 | if(!$titleObj->exists() && $p[0] != 'create') |
87 | | - $this->dieUsage("Missing titles can only be protected with 'create'", 'missingtitle'); |
| 86 | + $this->dieUsageMsg(array('missingtitles-createonly')); |
88 | 87 | } |
89 | 88 | |
90 | 89 | $dbw = wfGetDb(DB_MASTER); |
— | — | @@ -95,9 +94,15 @@ |
96 | 95 | $ok = $titleObj->updateTitleProtection($protections['create'], $params['reason'], $expiry); |
97 | 96 | if(!$ok) |
98 | 97 | // This is very weird. Maybe the article was deleted or the user was blocked/desysopped in the meantime? |
99 | | - $this->dieUsage('Unknown error', 'unknownerror'); |
| 98 | + // Just throw an unknown error in this case, as it's very likely to be a race condition |
| 99 | + $this->dieUsageMsg(array()); |
100 | 100 | $dbw->commit(); |
101 | | - $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason'], 'expiry' => wfTimestamp(TS_ISO_8601, $expiry)); |
| 101 | + $res = array('title' => $titleObj->getPrefixedText(), 'reason' => $params['reason']); |
| 102 | + if($expiry == Block::infinity()) |
| 103 | + $res['expiry'] = 'infinity'; |
| 104 | + else |
| 105 | + $res['expiry'] = wfTimestamp(TS_ISO_8601, $expiry); |
| 106 | + |
102 | 107 | if($params['cascade']) |
103 | 108 | $res['cascade'] = ''; |
104 | 109 | $res['protections'] = $protections; |
Index: trunk/phase3/includes/api/ApiBase.php |
— | — | @@ -597,7 +597,11 @@ |
598 | 598 | // API-specific messages |
599 | 599 | 'missingparam' => array('code' => 'no$1', 'info' => "The \$1 parameter must be set"), |
600 | 600 | 'invalidtitle' => array('code' => 'invalidtitle', 'info' => "Bad title ``\$1''"), |
601 | | - 'invaliduser' => array('code' => 'invaliduser', 'info' => "Invalid username ``\$1''") |
| 601 | + 'invaliduser' => array('code' => 'invaliduser', 'info' => "Invalid username ``\$1''"), |
| 602 | + 'invalidexpiry' => array('code' => 'invalidexpiry', 'info' => "Invalid expiry time"), |
| 603 | + 'pastexpiry' => array('code' => 'pastexpiry', 'info' => "Expiry time is in the past"), |
| 604 | + 'create-titleexists' => array('code' => 'create-titleexists', 'info' => "Existing titles can't be protected with 'create'"), |
| 605 | + 'missingtitle-createonly' => array('code' => 'missingtitle-createonly', 'info' => "Missing titles can only be protected with 'create'"), |
602 | 606 | ); |
603 | 607 | |
604 | 608 | /** |