r96853 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96852‎ | r96853 | r96854 >
Date:15:21, 12 September 2011
Author:catrope
Status:ok
Tags:
Comment:
RL2: Kill ApiGadgetManager, no longer needed
Modified paths:
  • /branches/RL2/extensions/Gadgets/api/ApiGadgetManager.php (deleted) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/api/ApiGadgetManager.php
@@ -1,140 +0,0 @@
2 -<?php
3 -/**
4 - * Created on July 31st, 2011
5 - * API for Gadgets extension
6 - *
7 - * This program is free software; you can redistribute it and/or modify
8 - * it under the terms of the GNU General Public License as published by
9 - * the Free Software Foundation; either version 2 of the License, or
10 - * (at your option) any later version.
11 - *
12 - * This program is distributed in the hope that it will be useful,
13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 - * GNU General Public License for more details.
16 - *
17 - * You should have received a copy of the GNU General Public License along
18 - * with this program; if not, write to the Free Software Foundation, Inc.,
19 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 - * http://www.gnu.org/copyleft/gpl.html
21 - */
22 -
23 -class ApiGadgetManager extends ApiBase {
24 - public function __construct( $main, $action ) {
25 - parent::__construct( $main, $action );
26 - }
27 -
28 - public function execute() {
29 - global $wgUser;
30 - $params = $this->extractRequestParams();
31 -
32 - $op = $params['op'];
33 - if ( !$wgUser->isAllowed( "gadgets-manager-$op" ) ) {
34 - $this->dieUsage( "You are not allowed to $op gadgets", 'permissiondenied' );
35 - }
36 -
37 - if ( $op === 'modify' ) {
38 - if ( $params['edittimestamp'] === null ) {
39 - $this->dieUsageMsg( array( 'missingparam', 'edittimestamp' ) );
40 - }
41 - }
42 -
43 - $repo = new LocalGadgetRepo( array() );
44 - if ( $op === 'create' || $op === 'modify' ) {
45 - if ( $params['json'] === null ) {
46 - $this->dieUsageMsg( array( 'missingparam', 'json' ) );
47 - }
48 - $json = FormatJson::decode( $params['json'], true );
49 - if ( $json === null ) {
50 - $this->dieUsage( 'Invalid JSON specified for json parameter', 'invalidjson' );
51 - }
52 - if ( !Gadget::isValidPropertiesArray( $json ) ) {
53 - $this->dieUsage( 'Invalid properties array specified for json parameter', 'invalidproperties' );
54 - }
55 -
56 - // FIXME: Passing lasttimestamp into the constructor like this is a bit hacky
57 - $gadget = new Gadget( $params['id'], $repo, $json, $params['edittimestamp'] );
58 - }
59 -
60 - if ( $op === 'create' ) {
61 - $status = $repo->addGadget( $gadget );
62 - } else if ( $op === 'modify' ) {
63 - $status = $repo->modifyGadget( $gadget );
64 - } else if ( $op === 'delete' ) {
65 - $status = $repo->deleteGadget( $params['id'] );
66 - }
67 -
68 - if ( !$status->isGood() ) {
69 - $errors = $status->getErrorsArray();
70 - $this->dieUsageMsg( $errors[0] ); // TODO: Actually register all the error messages in ApiBase::$messageMap somehow
71 - }
72 -
73 - $r = array( 'result' => 'success', 'id' => $params['id'], 'op' => $op );
74 - $this->getResult()->addValue( null, $this->getModuleName(), $r );
75 - }
76 -
77 - public function mustBePosted() {
78 - return true;
79 - }
80 -
81 - public function isWriteMode() {
82 - return true;
83 - }
84 -
85 - public function getAllowedParams() {
86 - return array(
87 - 'op' => array(
88 - ApiBase::PARAM_TYPE => array( 'create', 'modify', 'delete' ),
89 - ApiBase::PARAM_REQUIRED => true
90 - ),
91 - 'id' => array(
92 - ApiBase::PARAM_TYPE => 'string',
93 - ApiBase::PARAM_REQUIRED => true
94 - ),
95 - 'json' => array(
96 - ApiBase::PARAM_TYPE => 'string'
97 - ),
98 - 'token' => null,
99 - 'edittimestamp' => array(
100 - ApiBase::PARAM_TYPE => 'timestamp'
101 - )
102 - );
103 - }
104 -
105 - public function getParamDescription() {
106 - return array(
107 - 'op' => 'Operation to carry out',
108 - 'id' => 'Gadget id',
109 - 'json' => 'If op=create or op=modify, JSON blob with the new gadget metadata. Ignored if op=delete',
110 - 'edittimestamp' => 'If op=modify, the last modified timestamp of the gadget metadata, exactly as given by list=gadgets',
111 - 'token' => 'Edit token',
112 - );
113 - }
114 -
115 - public function getDescription() {
116 - return 'Create, modify and delete gadgets.';
117 - }
118 -
119 - public function getPossibleErrors() {
120 - return array_merge( parent::getPossibleErrors(), array(
121 - // TODO
122 - ) );
123 - }
124 -
125 - public function needsToken() {
126 - return true;
127 - }
128 -
129 - public function getTokenSalt() {
130 - return '';
131 - }
132 -
133 - protected function getExamples() {
134 - return array(
135 - );
136 - }
137 -
138 - public function getVersion() {
139 - return __CLASS__ . ': $Id$';
140 - }
141 -}

Follow-up revisions

RevisionCommit summaryAuthorDate
r96854RL2: Followup r96853, also remove registration of ApiGadgetManagercatrope15:22, 12 September 2011

Status & tagging log