Index: trunk/extensions/SemanticForms/SemanticForms.php |
— | — | @@ -156,12 +156,11 @@ |
157 | 157 | $wgAutoloadClasses['SFParserFunctions'] = $sfgIP . '/includes/SF_ParserFunctions.php'; |
158 | 158 | $wgAutoloadClasses['SFAutocompleteAPI'] = $sfgIP . '/includes/SF_AutocompleteAPI.php'; |
159 | 159 | $wgAutoloadClasses['SFAutoeditAPI'] = $sfgIP . '/includes/SF_AutoeditAPI.php'; |
160 | | -$wgAutoloadClasses['SFAutoEditAjaxHandler'] = $sfgIP . '/includes/SF_AutoEditAjaxHandler.php'; |
161 | 160 | $wgJobClasses['createPage'] = 'SFCreatePageJob'; |
162 | 161 | $wgAutoloadClasses['SFCreatePageJob'] = $sfgIP . '/includes/SF_CreatePageJob.php'; |
163 | 162 | require_once( $sfgIP . '/languages/SF_Language.php' ); |
164 | 163 | |
165 | | -$wgAjaxExportList[] = 'SFAutoEditAjaxHandler::handleAutoEdit'; |
| 164 | +$wgAjaxExportList[] = 'SFAutoeditAPI::handleAutoEdit'; |
166 | 165 | |
167 | 166 | $wgExtensionMessagesFiles['SemanticForms'] = $sfgIP . '/languages/SF_Messages.php'; |
168 | 167 | $wgExtensionAliasesFiles['SemanticForms'] = $sfgIP . '/languages/SF_Aliases.php'; |
Index: trunk/extensions/SemanticForms/includes/SF_AutoEditAjaxHandler.php |
— | — | @@ -1,380 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -/** |
5 | | - * |
6 | | - * @file |
7 | | - * @ingroup SF |
8 | | - */ |
9 | | - |
10 | | -/** |
11 | | - * Ajax handler for the autoedit parser function and for the |
12 | | - * submit and continue button in forms |
13 | | - * |
14 | | - * @author Stephan Gambke |
15 | | - * @ingroup SF |
16 | | - */ |
17 | | -class SFAutoEditAjaxHandler { |
18 | | - |
19 | | - private $mOptions = array( ); |
20 | | - |
21 | | - static function handleAutoEdit ( $optionsString = null, $prefillFromExisting = 'true' ) { |
22 | | - $handler = new self( $optionsString ); |
23 | | - return $handler->storeSemanticData( $prefillFromExisting === 'true' ); |
24 | | - } |
25 | | - |
26 | | - function __construct ( $options ) { |
27 | | - |
28 | | - global $wgParser, $wgUser, $wgVersion; |
29 | | - |
30 | | - $title = Title::newFromText( 'DummyTitle' ); |
31 | | - |
32 | | - if ( !StubObject::isRealObject( $wgParser ) ) |
33 | | - $wgParser->_unstub(); |
34 | | - |
35 | | - $wgParser->startExternalParse( $title, ParserOptions::newFromUser( $wgUser ), Parser::OT_HTML, true ); |
36 | | - |
37 | | - // parse options |
38 | | - $this->parseDataFromQueryString( $this->mOptions, $options ); |
39 | | - } |
40 | | - |
41 | | - /** |
42 | | - * |
43 | | - * @global $wgOut |
44 | | - * @global $wgRequest |
45 | | - * @global <type> $wgUser |
46 | | - * @global <type> $wgParser |
47 | | - * @return <type> |
48 | | - */ |
49 | | - private function storeSemanticData ( $prefillFromExisting = true ) { |
50 | | - |
51 | | - global $wgOut, $wgRequest, $wgParser, $wgTitle; |
52 | | - |
53 | | - if ( !array_key_exists( 'ok text', $this->mOptions ) ) { |
54 | | - $this->mOptions['ok text'] = wfMsg( 'sf_autoedit_success' ); |
55 | | - } |
56 | | - |
57 | | - if ( !array_key_exists( 'error text', $this->mOptions ) ) { |
58 | | - $this->mOptions['error text'] = '$1'; |
59 | | - } |
60 | | - |
61 | | - |
62 | | - $oldRequest = $wgRequest; |
63 | | - |
64 | | - // If the wiki is read-only we might as well stop right away |
65 | | - if ( wfReadOnly ( ) ) { |
66 | | - $result = new AjaxResponse( wfMsg( 'sf_autoedit_readonly', wfReadOnlyReason() ) ); |
67 | | - $result->setResponseCode( '400 Bad Request' ); |
68 | | - return $result; |
69 | | - } |
70 | | - |
71 | | - // If we have no target article and no form we might as well stop right away |
72 | | - if ( !array_key_exists( 'target', $this->mOptions ) |
73 | | - && !array_key_exists( 'form', $this->mOptions ) ) { |
74 | | - $result = new AjaxResponse( wfMsg( 'sf_autoedit_notargetspecified' ) ); |
75 | | - $result->setResponseCode( '400 Bad Request' ); |
76 | | - return $result; |
77 | | - } |
78 | | - |
79 | | - // check if form was specified |
80 | | - if ( !array_key_exists( 'form', $this->mOptions ) ) { |
81 | | - |
82 | | - // If no form was specified, find the default one for |
83 | | - // this page. |
84 | | - $title = Title::newFromText( $this->mOptions['target'] ); |
85 | | - $form_names = SFFormLinker::getDefaultFormsForPage( $title ); |
86 | | - |
87 | | - // if no form can be found, return |
88 | | - if ( count( $form_names ) == 0 ) { |
89 | | - $result = new AjaxResponse( wfMsg( 'sf_autoedit_noformfound' ) ); |
90 | | - $result->setResponseCode( '400 Bad Request' ); |
91 | | - return $result; |
92 | | - } |
93 | | - |
94 | | - // if more than one form found, return |
95 | | - if ( count( $form_names ) > 1 ) { |
96 | | - $result = new AjaxResponse( wfMsg( 'sf_autoedit_toomanyformsfound' ) ); |
97 | | - $result->setResponseCode( '400 Bad Request' ); |
98 | | - return $result; |
99 | | - } |
100 | | - |
101 | | - // There should now be exactly one form. |
102 | | - $this->mOptions['form'] = $form_names[0]; |
103 | | - } |
104 | | - |
105 | | - // we only care for the form's body |
106 | | - $wgOut->setArticleBodyOnly( true ); |
107 | | - |
108 | | - $formedit = new SFFormEdit(); |
109 | | - $data = array( ); |
110 | | - |
111 | | - // Get the form definition and target page (if there is one), |
112 | | - // as specified in the options string, then create the actual |
113 | | - // HTML form from them, and call that form to modify or create |
114 | | - // the page. |
115 | | - if ( $prefillFromExisting ) { |
116 | | - $wgRequest = new FauxRequest( $this->mOptions, true ); |
117 | | - |
118 | | - // get the Semantic Form |
119 | | - if ( array_key_exists( 'target', $this->mOptions ) ) { |
120 | | - $formedit->execute( $this->mOptions['form'] . '/' . $this->mOptions['target'] ); |
121 | | - } else { |
122 | | - $formedit->execute( $this->mOptions['form'] ); |
123 | | - } |
124 | | - |
125 | | - // extract its data |
126 | | - $form = $this->parseDataFromHTMLFrag( $data, trim( $wgOut->getHTML() ), 'sfForm' ); |
127 | | - |
128 | | - if ( !$form ) { |
129 | | - // something went wrong |
130 | | - $wgRequest = $oldRequest; |
131 | | - |
132 | | - $result = new AjaxResponse( wfMsg( 'sf_autoedit_nosemanticform', |
133 | | - array( |
134 | | - $this->mOptions['target'], |
135 | | - $this->mOptions['form'] ) ) ); |
136 | | - $result->setResponseCode( '400 Bad Request' ); |
137 | | - return $result; |
138 | | - } |
139 | | - } else { |
140 | | - $this->addToArray( $data, "wpSave", "Save" ); |
141 | | - } |
142 | | - // and modify as specified |
143 | | - $data = $this->array_merge_recursive_distinct( $data, $this->mOptions ); |
144 | | - |
145 | | - //////////////////////////////////////////////////////////////////////// |
146 | | - // Store the modified form |
147 | | - //$wgOut->clearHTML(); |
148 | | - $wgRequest = new FauxRequest( $data, true ); |
149 | | - |
150 | | - // get the MW form |
151 | | - if ( array_key_exists( 'target', $this->mOptions ) ) { |
152 | | - $formedit->execute( $this->mOptions['form'] . '/' . $this->mOptions['target'], false ); |
153 | | - } else { |
154 | | - $formedit->execute( $this->mOptions['form'], false ); |
155 | | - } |
156 | | - |
157 | | - $wgParser->getOptions()->enableLimitReport( false ); |
158 | | - |
159 | | - $wgRequest = $oldRequest; |
160 | | - |
161 | | - if ( $formedit->mError ) { |
162 | | - |
163 | | - $msg = $wgParser->parse( |
164 | | - wfMsgReplaceArgs( $this->mOptions['error text'], array( $formedit->mError ) ), |
165 | | - $wgTitle, |
166 | | - $wgParser->getOptions() |
167 | | - )->getText(); |
168 | | - |
169 | | - $result = new AjaxResponse( $msg ); |
170 | | - $result->setResponseCode( '400 Bad Request' ); |
171 | | - } else { |
172 | | - |
173 | | - header( "X-Location: " . $wgOut->getRedirect() ); |
174 | | - header( "X-Form: " . $formedit->mForm ); |
175 | | - header( "X-Target: " . $formedit->mTarget ); |
176 | | - |
177 | | - $msg = $wgParser->recursiveTagParse( wfMsgReplaceArgs( $this->mOptions['ok text'], array( $formedit->mTarget, $formedit->mForm ) ) ); |
178 | | - |
179 | | - $result = new AjaxResponse( $msg ); |
180 | | - } |
181 | | - |
182 | | - return $result; |
183 | | - } |
184 | | - |
185 | | - private function parseDataFromHTMLFrag ( &$data, $html, $formID ) { |
186 | | - $doc = new DOMDocument(); |
187 | | - @$doc->loadHTML( |
188 | | - '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head><body>' |
189 | | - . $html |
190 | | - . '</body></html>' |
191 | | - ); |
192 | | - |
193 | | - $form = $doc->getElementById( $formID ); |
194 | | - |
195 | | - if ( !$form ) { |
196 | | - return null; |
197 | | - } |
198 | | - |
199 | | - // Process input tags |
200 | | - $inputs = $form->getElementsByTagName( 'input' ); |
201 | | - |
202 | | - for ( $i = 0; $i < $inputs->length; $i++ ) { |
203 | | - |
204 | | - $input = $inputs->item( $i ); |
205 | | - $type = $input->getAttribute( 'type' ); |
206 | | - $name = trim( $input->getAttribute( 'name' ) ); |
207 | | - |
208 | | - if ( !$name ) |
209 | | - continue; |
210 | | - |
211 | | - if ( $type == '' ) |
212 | | - $type = 'text'; |
213 | | - |
214 | | - switch ( $type ) { |
215 | | - case 'checkbox': |
216 | | - case 'radio': |
217 | | - if ( $input->getAttribute( 'checked' ) ) |
218 | | - $this->addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
219 | | - break; |
220 | | - |
221 | | - //case 'button': |
222 | | - case 'hidden': |
223 | | - case 'image': |
224 | | - case 'password': |
225 | | - //case 'reset': |
226 | | - //case 'submit': |
227 | | - case 'text': |
228 | | - $this->addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
229 | | - break; |
230 | | - |
231 | | - case 'submit': |
232 | | - if ( $name == "wpSave" ) |
233 | | - $this->addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
234 | | - } |
235 | | - } |
236 | | - |
237 | | - // Process select tags |
238 | | - $selects = $form->getElementsByTagName( 'select' ); |
239 | | - |
240 | | - for ( $i = 0; $i < $selects->length; $i++ ) { |
241 | | - |
242 | | - $select = $selects->item( $i ); |
243 | | - $name = trim( $select->getAttribute( 'name' ) ); |
244 | | - |
245 | | - if ( !$name ) |
246 | | - continue; |
247 | | - |
248 | | - $values = array( ); |
249 | | - $options = $select->getElementsByTagName( 'option' ); |
250 | | - |
251 | | - if ( count( $options ) && (!$select->hasAttribute( "multiple" ) || $options->item( 0 )->hasAttribute( 'selected' ) ) ) { |
252 | | - $this->addToArray( $data, $name, $options->item( 0 )->getAttribute( 'value' ) ); |
253 | | - } |
254 | | - |
255 | | - for ( $o = 1; $o < $options->length; $o++ ) { |
256 | | - if ( $options->item( $o )->hasAttribute( 'selected' ) ) |
257 | | - $this->addToArray( $data, $name, $options->item( $o )->getAttribute( 'value' ) ); |
258 | | - } |
259 | | - } |
260 | | - |
261 | | - // Process textarea tags |
262 | | - $textareas = $form->getElementsByTagName( 'textarea' ); |
263 | | - |
264 | | - for ( $i = 0; $i < $textareas->length; $i++ ) { |
265 | | - |
266 | | - $textarea = $textareas->item( $i ); |
267 | | - $name = trim( $textarea->getAttribute( 'name' ) ); |
268 | | - |
269 | | - if ( !$name ) |
270 | | - continue; |
271 | | - |
272 | | - $this->addToArray( $data, $name, $textarea->textContent ); |
273 | | - } |
274 | | - |
275 | | - return $form; |
276 | | - } |
277 | | - |
278 | | - /** |
279 | | - * Parses data from a query string into the $data array |
280 | | - * |
281 | | - * @global $wgParser |
282 | | - * @global $wgOut |
283 | | - * @param Array $data |
284 | | - * @param String $queryString |
285 | | - * @param Boolean $expand If this is set to true, field values will get |
286 | | - * urldecoded and expanded. This allows us to have parser functions |
287 | | - * skip handling by the MW parser on page creation (since they will be |
288 | | - * URL-encoded), and to instead have them handled by #autoedit. |
289 | | - * This can prevent cache issues, such as when dealing with the |
290 | | - * {{#time:}} parser function. |
291 | | - * @return <type> |
292 | | - */ |
293 | | - private function parseDataFromQueryString ( &$data, $queryString ) { |
294 | | - $params = explode( '&', $queryString ); |
295 | | - |
296 | | - foreach ( $params as $i => $param ) { |
297 | | - $elements = explode( '=', $param, 2 ); |
298 | | - |
299 | | - $key = trim( urldecode( $elements[0] ) ); |
300 | | - $value = count( $elements ) > 1 ? urldecode( $elements[1] ) : null; |
301 | | - |
302 | | - if ( $key == "query string" ) { |
303 | | - $this->parseDataFromQueryString( $data, $value ); |
304 | | - } else { |
305 | | - $this->addToArray( $data, $key, $value ); |
306 | | - } |
307 | | - } |
308 | | - |
309 | | - return $data; |
310 | | - } |
311 | | - |
312 | | - // This function recursively inserts the value into a tree. |
313 | | - // $array is root |
314 | | - // $key identifies path to position in tree. |
315 | | - // Format: 1stLevelName[2ndLevel][3rdLevel][...], i.e. normal array notation |
316 | | - // $value: the value to insert |
317 | | - // $toplevel: if this is a toplevel value. |
318 | | - private function addToArray( &$array, $key, $value, $toplevel = true ) { |
319 | | - $matches = array(); |
320 | | - |
321 | | - if ( preg_match( '/^([^\[\]]*)\[([^\[\]]*)\](.*)/', $key, $matches ) ) { |
322 | | - |
323 | | - // for some reason toplevel keys get their spaces encoded by MW. |
324 | | - // We have to imitate that. |
325 | | - // FIXME: Are there other cases than spaces? |
326 | | - if ( $toplevel ) { |
327 | | - $key = str_replace( ' ', '_', $matches[1] ); |
328 | | - } else { |
329 | | - $key = $matches[1]; |
330 | | - } |
331 | | - |
332 | | - if ( !array_key_exists( $key, $array ) ) |
333 | | - $array[$key] = array(); |
334 | | - |
335 | | - $this->addToArray( $array[$key], $matches[2] . $matches[3], $value, false ); |
336 | | - } else { |
337 | | - |
338 | | - if ( $key ) { |
339 | | - $array[$key] = $value; |
340 | | - } else { |
341 | | - array_push( $array, $value ); |
342 | | - } |
343 | | - } |
344 | | - } |
345 | | - |
346 | | - /** |
347 | | - * array_merge_recursive merges arrays, but it converts values with duplicate |
348 | | - * keys to arrays rather than overwriting the value in the first array with the duplicate |
349 | | - * value in the second array, as array_merge does. |
350 | | - * |
351 | | - * array_merge_recursive_distinct does not change the datatypes of the values in the arrays. |
352 | | - * Matching keys' values in the second array overwrite those in the first array. |
353 | | - * |
354 | | - * Parameters are passed by reference, though only for performance reasons. They're not |
355 | | - * altered by this function. |
356 | | - * |
357 | | - * See http://www.php.net/manual/en/function.array-merge-recursive.php#92195 |
358 | | - * |
359 | | - * @param array $array1 |
360 | | - * @param array $array2 |
361 | | - * @return array |
362 | | - * @author Daniel <daniel (at) danielsmedegaardbuus (dot) dk> |
363 | | - * @author Gabriel Sobrinho <gabriel (dot) sobrinho (at) gmail (dot) com> |
364 | | - */ |
365 | | - private function array_merge_recursive_distinct ( array &$array1, array &$array2 ) { |
366 | | - |
367 | | - $merged = $array1; |
368 | | - |
369 | | - foreach ( $array2 as $key => &$value ) { |
370 | | - if ( is_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) { |
371 | | - $merged[$key] = $this->array_merge_recursive_distinct( $merged[$key], $value ); |
372 | | - } else { |
373 | | - $merged[$key] = $value; |
374 | | - } |
375 | | - } |
376 | | - |
377 | | - return $merged; |
378 | | - } |
379 | | - |
380 | | -} |
381 | | - |
Index: trunk/extensions/SemanticForms/includes/SF_AutoeditAPI.php |
— | — | @@ -19,31 +19,101 @@ |
20 | 20 | class SFAutoeditAPI extends ApiBase { |
21 | 21 | |
22 | 22 | private $mOptions; |
| 23 | + private $mIsApiQuery = true; |
23 | 24 | |
| 25 | + static function handleAutoEdit( $optionsString = null, $prefillFromExisting = 'true' ) { |
| 26 | + |
| 27 | + global $wgParser; |
| 28 | + |
| 29 | + $handler = new self( null, 'sfautoedit' ); |
| 30 | + $handler->isApiQuery( false ); |
| 31 | + $options = $handler->setOptionsString( $optionsString ); |
| 32 | + |
| 33 | + // get oktext (or use default) |
| 34 | + if ( array_key_exists( 'ok text', $options ) ) { |
| 35 | + $oktext = $options['ok text']; |
| 36 | + } else { |
| 37 | + $oktext = wfMsg( 'sf_autoedit_success' ); |
| 38 | + } |
| 39 | + |
| 40 | + // get errortext (or use default) |
| 41 | + if ( array_key_exists( 'error text', $options ) ) { |
| 42 | + $errortext = $options['error text']; |
| 43 | + } else { |
| 44 | + $errortext = '$1'; |
| 45 | + } |
| 46 | + |
| 47 | + // process data |
| 48 | + // result will be true or an error message |
| 49 | + $result = $handler->storeSemanticData( $prefillFromExisting === 'true' ); |
| 50 | + |
| 51 | + // wrap result in ok/error message |
| 52 | + if ( $result === true ) { |
| 53 | + |
| 54 | + $options = $handler->getOptions(); |
| 55 | + $result = wfMsgReplaceArgs( $oktext, array($options['target'], $options['form']) ); |
| 56 | + |
| 57 | + } else { |
| 58 | + |
| 59 | + $result = wfMsgReplaceArgs( $errortext, array($result) ); |
| 60 | + } |
| 61 | + |
| 62 | + // initialize parser |
| 63 | + $title = Title::newFromText( 'DummyTitle' ); |
| 64 | + |
| 65 | + if ( !StubObject::isRealObject( $wgParser ) ) { |
| 66 | + $wgParser->_unstub(); |
| 67 | + } |
| 68 | + |
| 69 | + $wgParser->getOptions()->enableLimitReport( false ); |
| 70 | + |
| 71 | + |
| 72 | + return $wgParser->parse( $result, $title, $wgParser->getOptions() )->getText(); |
| 73 | + } |
| 74 | + |
24 | 75 | /** |
25 | | - * Evaluates the parameters, performs the requested query, and sets up |
| 76 | + * Getter/setter for the ApiQuery flag. |
| 77 | + * |
| 78 | + * If this is set, we are in an API query, else we are in an Ajax query. |
| 79 | + * |
| 80 | + * @param bool $isApiQuery Optional. The new value |
| 81 | + * @return The old value |
| 82 | + */ |
| 83 | + function isApiQuery() { |
| 84 | + $ret = $this->mIsApiQuery; |
| 85 | + |
| 86 | + $params = func_get_args(); |
| 87 | + |
| 88 | + if ( isset( $params[0] ) ) { |
| 89 | + $this->mIsApiQuery = $params[0]; |
| 90 | + } |
| 91 | + return $ret; |
| 92 | + } |
| 93 | + |
| 94 | + function setOptionsString( $options ) { |
| 95 | + return $this->parseDataFromQueryString( $this->mOptions, $options ); |
| 96 | + } |
| 97 | + |
| 98 | + function getOptions() { |
| 99 | + return $this->mOptions; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Evaluates the parameters, performs the requested API query, and sets up |
26 | 104 | * the result. |
27 | 105 | */ |
28 | 106 | function execute() { |
29 | 107 | $this->mOptions = $_POST + $_GET; |
| 108 | + $this->isApiQuery( true ); |
30 | 109 | |
31 | | - // ensure 'form' key exists |
32 | | - if ( !array_key_exists( 'form', $this->mOptions ) ) { |
33 | | - $this->mOptions['form'] = null; |
34 | | - } |
35 | | - |
36 | | - // ensure 'target' key exists |
37 | | - if ( !array_key_exists( 'target', $this->mOptions ) ) { |
38 | | - $this->mOptions['target'] = null; |
39 | | - } |
40 | | - |
41 | | - // if query parameter was used, unpack it |
| 110 | + // if this is an Ajax request |
42 | 111 | if ( array_key_exists( 'query', $this->mOptions ) ) { |
43 | | - $this->parseDataFromQueryString( $this->mOptions, $this->mOptions['query'] ); |
| 112 | + // if 'query' parameter was used, unpack it |
| 113 | + $this->setOptionsString( $this->mOptions['query'] ); |
44 | 114 | unset( $this->mOptions['query'] ); |
45 | 115 | } |
46 | 116 | |
47 | | - $this->storeSemanticData(); |
| 117 | + return $this->storeSemanticData(); |
48 | 118 | } |
49 | 119 | |
50 | 120 | /** |
— | — | @@ -121,29 +191,37 @@ |
122 | 192 | } |
123 | 193 | |
124 | 194 | /** |
125 | | - * |
126 | | - * @global $wgOut |
127 | | - * @global $wgRequest |
128 | | - * @global <type> $wgUser |
129 | | - * @global <type> $wgParser |
130 | | - * @return <type> |
| 195 | + * This method will try to store the data in mOptions. |
| 196 | + * |
| 197 | + * It will return true on success or an error message on failure. |
| 198 | + * The used form and target page will be available in mOptions after |
| 199 | + * execution of the method. |
| 200 | + * |
| 201 | + * @param bool $prefillFromExisting If this is set, existing values in the page will be used to prefill the form. |
| 202 | + * @return true or an error message |
131 | 203 | */ |
132 | 204 | private function storeSemanticData( $prefillFromExisting = true ) { |
133 | 205 | |
134 | | - global $wgOut, $wgRequest, $wgParser, $wgTitle; |
| 206 | + global $wgOut, $wgRequest; |
135 | 207 | |
136 | 208 | // If the wiki is read-only we might as well stop right away |
137 | 209 | if ( wfReadOnly ( ) ) { |
| 210 | + return $this->reportError( wfMsg( 'sf_autoedit_readonly', wfReadOnlyReason() ) ); |
| 211 | + } |
138 | 212 | |
139 | | - $this->reportError( wfMsg( 'sf_autoedit_readonly', wfReadOnlyReason() ) ); |
140 | | - return; |
| 213 | + // ensure 'form' key exists |
| 214 | + if ( !array_key_exists( 'form', $this->mOptions ) ) { |
| 215 | + $this->mOptions['form'] = null; |
141 | 216 | } |
142 | 217 | |
| 218 | + // ensure 'target' key exists |
| 219 | + if ( !array_key_exists( 'target', $this->mOptions ) ) { |
| 220 | + $this->mOptions['target'] = null; |
| 221 | + } |
| 222 | + |
143 | 223 | // If we have no target article and no form we might as well stop right away |
144 | 224 | if ( !$this->mOptions['target'] && !$this->mOptions['form'] ) { |
145 | | - |
146 | | - $this->reportError( wfMsg( 'sf_autoedit_notargetspecified' ) ); |
147 | | - return; |
| 225 | + return $this->reportError( wfMsg( 'sf_autoedit_notargetspecified' ) ); |
148 | 226 | } |
149 | 227 | |
150 | 228 | // check if form was specified |
— | — | @@ -156,14 +234,12 @@ |
157 | 235 | |
158 | 236 | // if no form can be found, return |
159 | 237 | if ( count( $form_names ) == 0 ) { |
160 | | - $this->reportError( wfMsg( 'sf_autoedit_noformfound' ) ); |
161 | | - return; |
| 238 | + return $this->reportError( wfMsg( 'sf_autoedit_noformfound' ) ); |
162 | 239 | } |
163 | 240 | |
164 | 241 | // if more than one form found, return |
165 | 242 | if ( count( $form_names ) > 1 ) { |
166 | | - $this->reportError( wfMsg( 'sf_autoedit_toomanyformsfound' ) ); |
167 | | - return; |
| 243 | + return $this->reportError( wfMsg( 'sf_autoedit_toomanyformsfound' ) ); |
168 | 244 | } |
169 | 245 | |
170 | 246 | // There should now be exactly one form. |
— | — | @@ -199,12 +275,11 @@ |
200 | 276 | // something went wrong |
201 | 277 | $wgRequest = $oldRequest; |
202 | 278 | |
203 | | - $this->reportError( wfMsg( 'sf_autoedit_nosemanticform', |
| 279 | + return $this->reportError( wfMsg( 'sf_autoedit_nosemanticform', |
204 | 280 | array( |
205 | 281 | $this->mOptions['target'], |
206 | 282 | $this->mOptions['form']) ) |
207 | 283 | ); |
208 | | - return; |
209 | 284 | } |
210 | 285 | } else { |
211 | 286 | $this->addToArray( $data, "wpSave", "Save" ); |
— | — | @@ -224,30 +299,33 @@ |
225 | 300 | $formedit->execute( $this->mOptions['form'], false ); |
226 | 301 | } |
227 | 302 | |
228 | | - $wgParser->getOptions()->enableLimitReport( false ); |
| 303 | + $this->mOptions['form'] = $formedit->mForm; |
| 304 | + $this->mOptions['target'] = $formedit->mTarget; |
229 | 305 | |
230 | 306 | $wgRequest = $oldRequest; |
231 | 307 | |
232 | 308 | if ( $formedit->mError ) { |
233 | 309 | |
234 | | - $this->reportError( $msg ); |
| 310 | + return $this->reportError( $formedit->mError ); |
235 | 311 | } else { |
236 | 312 | |
237 | 313 | header( "X-Location: " . $wgOut->getRedirect() ); |
238 | 314 | header( "X-Form: " . $formedit->mForm ); |
239 | 315 | header( "X-Target: " . $formedit->mTarget ); |
240 | 316 | |
241 | | - $this->getResult()->addValue( null, 'result', |
242 | | - array( |
243 | | - 'code' => '200', |
244 | | - 'location' => $wgOut->getRedirect(), |
245 | | - 'form' => $formedit->mForm, |
246 | | - 'target' => $formedit->mTarget |
247 | | - ) |
248 | | - ); |
| 317 | + if ( $this->isApiQuery() ) { |
| 318 | + $this->getResult()->addValue( null, 'result', |
| 319 | + array( |
| 320 | + 'code' => '200', |
| 321 | + 'location' => $wgOut->getRedirect(), |
| 322 | + 'form' => $formedit->mForm, |
| 323 | + 'target' => $formedit->mTarget |
| 324 | + ) |
| 325 | + ); |
| 326 | + } |
249 | 327 | } |
250 | 328 | |
251 | | - return; |
| 329 | + return true; |
252 | 330 | } |
253 | 331 | |
254 | 332 | private function parseDataFromHTMLFrag( &$data, $html, $formID ) { |
— | — | @@ -365,7 +443,7 @@ |
366 | 444 | $key = trim( urldecode( $elements[0] ) ); |
367 | 445 | $value = count( $elements ) > 1 ? urldecode( $elements[1] ) : null; |
368 | 446 | |
369 | | - if ( $key == "query" ) { |
| 447 | + if ( $key == "query" || $key == "query string" ) { |
370 | 448 | $this->parseDataFromQueryString( $data, $value ); |
371 | 449 | } else { |
372 | 450 | $this->addToArray( $data, $key, $value ); |
— | — | @@ -449,7 +527,10 @@ |
450 | 528 | */ |
451 | 529 | private function reportError( $msg ) { |
452 | 530 | header( 'HTTP/Status: 400 Bad Request' ); |
453 | | - $this->getResult()->addValue( null, 'result', array('code' => '400', '*' => $msg) ); |
| 531 | + if ( $this->isApiQuery() ) { |
| 532 | + $this->getResult()->addValue( null, 'result', array('code' => '400', '*' => $msg) ); |
| 533 | + } |
| 534 | + return $msg; |
454 | 535 | } |
455 | 536 | |
456 | 537 | } |
Index: trunk/extensions/SemanticForms/libs/SF_autoedit.js |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | |
38 | 38 | sajax_request_type = 'POST'; |
39 | 39 | |
40 | | - sajax_do_call( 'SFAutoEditAjaxHandler::handleAutoEdit', data, function( ajaxHeader ){ |
| 40 | + sajax_do_call( 'SFAutoeditAPI::handleAutoEdit', data, function( ajaxHeader ){ |
41 | 41 | jresult.empty().append( ajaxHeader.responseText ); |
42 | 42 | |
43 | 43 | if ( ajaxHeader.status == 200 ) { |
Index: trunk/extensions/SemanticForms/libs/SF_submit.js |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | sajax_request_type = 'POST'; |
62 | 62 | var form = $('#sfForm'); |
63 | 63 | |
64 | | - sajax_do_call( 'SFAutoEditAjaxHandler::handleAutoEdit', new Array(collectData( form ), false), function( ajaxHeader ){ |
| 64 | + sajax_do_call( 'SFAutoeditAPI::handleAutoEdit', new Array(collectData( form ), false), function( ajaxHeader ){ |
65 | 65 | |
66 | 66 | if ( ajaxHeader.status == 200 ) { |
67 | 67 | |
— | — | @@ -142,6 +142,8 @@ |
143 | 143 | |
144 | 144 | } |
145 | 145 | |
| 146 | + params += "&wpMinoredit=1"; |
| 147 | + |
146 | 148 | return params; |
147 | 149 | } |
148 | 150 | |