Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php |
— | — | @@ -377,7 +377,7 @@ |
378 | 378 | $this->mPageTitle = $wgTitle; |
379 | 379 | } elseif ( $is_query ) { |
380 | 380 | $this->mPageTitle = Title::newFromText( 'RunQuery dummy title' ); |
381 | | - } elseif ( $page_name === '' ) { |
| 381 | + } elseif ( $page_name === '' || $page_name === null ) { |
382 | 382 | $this->mPageTitle = Title::newFromText( |
383 | 383 | $wgRequest->getVal( 'namespace' ) . ":Semantic Forms permissions test" ); |
384 | 384 | } else { |
Index: trunk/extensions/SemanticForms/includes/SF_AutoeditAPI.php |
— | — | @@ -125,6 +125,13 @@ |
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
| 129 | + * Sets the options array |
| 130 | + */ |
| 131 | + function setOptions( $options ) { |
| 132 | + $this->mOptions = $options; |
| 133 | + } |
| 134 | + |
| 135 | + /** |
129 | 136 | * Evaluates the parameters, performs the requested API query, and sets up |
130 | 137 | * the result. |
131 | 138 | */ |
— | — | @@ -228,7 +235,7 @@ |
229 | 236 | * @param bool $prefillFromExisting If this is set, existing values in the page will be used to prefill the form. |
230 | 237 | * @return true or an error message |
231 | 238 | */ |
232 | | - private function storeSemanticData( $prefillFromExisting = true ) { |
| 239 | + public function storeSemanticData( $prefillFromExisting = true ) { |
233 | 240 | |
234 | 241 | global $wgOut, $wgRequest; |
235 | 242 | |
— | — | @@ -310,7 +317,7 @@ |
311 | 318 | ); |
312 | 319 | } |
313 | 320 | } else { |
314 | | - $this->addToArray( $data, "wpSave", "Save" ); |
| 321 | + self::addToArray( $data, "wpSave", "Save" ); |
315 | 322 | } |
316 | 323 | // and modify as specified |
317 | 324 | $data = $this->array_merge_recursive_distinct( $data, $this->mOptions ); |
— | — | @@ -337,9 +344,11 @@ |
338 | 345 | return $this->reportError( $formedit->mError ); |
339 | 346 | } else { |
340 | 347 | |
341 | | - header( "X-Location: " . $wgOut->getRedirect() ); |
342 | | - header( "X-Form: " . $formedit->mForm ); |
343 | | - header( "X-Target: " . $formedit->mTarget ); |
| 348 | + if ( !headers_sent() ) { |
| 349 | + header( "X-Location: " . $wgOut->getRedirect() ); |
| 350 | + header( "X-Form: " . $formedit->mForm ); |
| 351 | + header( "X-Target: " . $formedit->mTarget ); |
| 352 | + } |
344 | 353 | |
345 | 354 | if ( $this->isApiQuery() ) { |
346 | 355 | $this->getResult()->addValue( null, 'result', |
— | — | @@ -389,7 +398,7 @@ |
390 | 399 | case 'checkbox': |
391 | 400 | case 'radio': |
392 | 401 | if ( $input->getAttribute( 'checked' ) ) |
393 | | - $this->addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
| 402 | + self::addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
394 | 403 | break; |
395 | 404 | |
396 | 405 | // case 'button': |
— | — | @@ -399,12 +408,12 @@ |
400 | 409 | // case 'reset': |
401 | 410 | // case 'submit': |
402 | 411 | case 'text': |
403 | | - $this->addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
| 412 | + self::addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
404 | 413 | break; |
405 | 414 | |
406 | 415 | case 'submit': |
407 | 416 | if ( $name == "wpSave" ) |
408 | | - $this->addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
| 417 | + self::addToArray( $data, $name, $input->getAttribute( 'value' ) ); |
409 | 418 | } |
410 | 419 | } |
411 | 420 | |
— | — | @@ -422,12 +431,12 @@ |
423 | 432 | $options = $select->getElementsByTagName( 'option' ); |
424 | 433 | |
425 | 434 | if ( count( $options ) && ( !$select->hasAttribute( "multiple" ) || $options->item( 0 )->hasAttribute( 'selected' ) ) ) { |
426 | | - $this->addToArray( $data, $name, $options->item( 0 )->getAttribute( 'value' ) ); |
| 435 | + self::addToArray( $data, $name, $options->item( 0 )->getAttribute( 'value' ) ); |
427 | 436 | } |
428 | 437 | |
429 | 438 | for ( $o = 1; $o < $options->length; $o++ ) { |
430 | 439 | if ( $options->item( $o )->hasAttribute( 'selected' ) ) |
431 | | - $this->addToArray( $data, $name, $options->item( $o )->getAttribute( 'value' ) ); |
| 440 | + self::addToArray( $data, $name, $options->item( $o )->getAttribute( 'value' ) ); |
432 | 441 | } |
433 | 442 | } |
434 | 443 | |
— | — | @@ -442,7 +451,7 @@ |
443 | 452 | if ( !$name ) |
444 | 453 | continue; |
445 | 454 | |
446 | | - $this->addToArray( $data, $name, $textarea->textContent ); |
| 455 | + self::addToArray( $data, $name, $textarea->textContent ); |
447 | 456 | } |
448 | 457 | |
449 | 458 | return $form; |
— | — | @@ -467,7 +476,7 @@ |
468 | 477 | if ( $key == "query" || $key == "query string" ) { |
469 | 478 | $this->parseDataFromQueryString( $data, $value ); |
470 | 479 | } else { |
471 | | - $this->addToArray( $data, $key, $value ); |
| 480 | + self::addToArray( $data, $key, $value ); |
472 | 481 | } |
473 | 482 | } |
474 | 483 | |
— | — | @@ -480,7 +489,7 @@ |
481 | 490 | // Format: 1stLevelName[2ndLevel][3rdLevel][...], i.e. normal array notation |
482 | 491 | // $value: the value to insert |
483 | 492 | // $toplevel: if this is a toplevel value. |
484 | | - private function addToArray( &$array, $key, $value, $toplevel = true ) { |
| 493 | + public static function addToArray( &$array, $key, $value, $toplevel = true ) { |
485 | 494 | $matches = array(); |
486 | 495 | |
487 | 496 | if ( preg_match( '/^([^\[\]]*)\[([^\[\]]*)\](.*)/', $key, $matches ) ) { |
— | — | @@ -497,7 +506,7 @@ |
498 | 507 | if ( !array_key_exists( $key, $array ) ) |
499 | 508 | $array[$key] = array(); |
500 | 509 | |
501 | | - $this->addToArray( $array[$key], $matches[2] . $matches[3], $value, false ); |
| 510 | + self::addToArray( $array[$key], $matches[2] . $matches[3], $value, false ); |
502 | 511 | } else { |
503 | 512 | |
504 | 513 | if ( $key ) { |
— | — | @@ -548,7 +557,9 @@ |
549 | 558 | */ |
550 | 559 | private function reportError( $msg ) { |
551 | 560 | if ( $this->isApiQuery() ) { |
552 | | - header( 'HTTP/Status: 400 Bad Request' ); |
| 561 | + if ( !headers_sent() ) { |
| 562 | + header( 'HTTP/Status: 400 Bad Request' ); |
| 563 | + } |
553 | 564 | $this->getResult()->addValue( null, 'result', array( 'code' => '400', '*' => $msg ) ); |
554 | 565 | } |
555 | 566 | return $msg; |
Index: trunk/extensions/SemanticForms/includes/SF_ParserFunctions.php |
— | — | @@ -156,114 +156,13 @@ |
157 | 157 | } |
158 | 158 | |
159 | 159 | static function renderFormLink ( &$parser ) { |
160 | | - global $wgVersion; |
161 | 160 | |
162 | 161 | $params = func_get_args(); |
163 | 162 | array_shift( $params ); // We don't need the parser. |
164 | | - // Set defaults. |
165 | | - $inFormName = $inLinkStr = $inLinkType = $inTooltip = |
166 | | - $inQueryStr = $inTargetName = ''; |
167 | | - $classStr = ""; |
168 | | - // assign params |
169 | | - // - support unlabelled params, for backwards compatibility |
170 | | - // - parse and sanitize all parameter values |
171 | | - foreach ( $params as $i => $param ) { |
172 | | - $elements = explode( '=', $param, 2 ); |
173 | | - |
174 | | - // set param_name and value |
175 | | - if ( count( $elements ) > 1 ) { |
176 | | - $param_name = trim( $elements[0] ); |
177 | | - |
178 | | - // parse (and sanitize) parameter values |
179 | | - $value = trim( $parser->recursiveTagParse( $elements[1] ) ); |
180 | | - } else { |
181 | | - $param_name = null; |
182 | | - |
183 | | - // parse (and sanitize) parameter values |
184 | | - $value = trim( $parser->recursiveTagParse( $param ) ); |
185 | | - } |
186 | | - |
187 | | - if ( $param_name == 'form' ) { |
188 | | - $inFormName = $value; |
189 | | - } elseif ( $param_name == 'link text' ) { |
190 | | - $inLinkStr = $value; |
191 | | - } elseif ( $param_name == 'link type' ) { |
192 | | - $inLinkType = $value; |
193 | | - } elseif ( $param_name == 'query string' ) { |
194 | | - $inQueryStr = Sanitizer::decodeCharReferences( $value ); |
195 | | - } elseif ( $param_name == 'tooltip' ) { |
196 | | - $inTooltip = Sanitizer::decodeCharReferences( $value ); |
197 | | - } elseif ( $param_name == 'target' ) { |
198 | | - $inTargetName = $value; |
199 | | - } elseif ( $param_name == null && $value == 'popup' ) { |
200 | | - self::loadScriptsForPopupForm( $parser ); |
201 | | - $classStr = 'popupformlink'; |
202 | | - } |
203 | | - elseif ( $i == 0 ) { |
204 | | - $inFormName = $value; |
205 | | - } elseif ( $i == 1 ) { |
206 | | - $inLinkStr = $value; |
207 | | - } elseif ( $i == 2 ) { |
208 | | - $inLinkType = $value; |
209 | | - } elseif ( $i == 3 ) { |
210 | | - $inQueryStr = Sanitizer::decodeCharReferences( $value ); |
211 | | - } |
212 | | - } |
213 | | - |
214 | | - $ad = SFUtils::getSpecialPage( 'FormEdit' ); |
215 | | - $link_url = $ad->getTitle()->getLocalURL() . "/$inFormName"; |
216 | | - if ( ! empty( $inTargetName ) ) { |
217 | | - $link_url .= "/$inTargetName"; |
218 | | - } |
219 | | - $link_url = str_replace( ' ', '_', $link_url ); |
220 | | - $hidden_inputs = ""; |
221 | | - if ( $inQueryStr != '' ) { |
222 | | - // Special handling for the buttons - query string |
223 | | - // has to be turned into hidden inputs. |
224 | | - if ( $inLinkType == 'button' || $inLinkType == 'post button' ) { |
225 | | - // Change HTML-encoded ampersands to |
226 | | - // URL-encoded ampersands, so that the string |
227 | | - // doesn't get split up on the '&'. |
228 | | - $inQueryStr = str_replace( '&', '%26', $inQueryStr ); |
229 | | - $query_components = explode( '&', $inQueryStr ); |
230 | | - foreach ( $query_components as $query_component ) { |
231 | | - $query_component = urldecode( $query_component ); |
232 | | - $var_and_val = explode( '=', $query_component ); |
233 | | - if ( count( $var_and_val ) == 2 ) { |
234 | | - $hidden_inputs .= SFFormUtils::hiddenFieldHTML( $var_and_val[0], $var_and_val[1] ); |
235 | | - } |
236 | | - } |
237 | | - } else { |
238 | | - $link_url .= ( strstr( $link_url, '?' ) ) ? '&' : '?'; |
239 | | - // URL-encode the spaces, newlines, ampersands etc. |
240 | | - // in the query string. |
241 | | - // (Should this just be a general urlencode?) |
242 | | - $inQueryStr = str_replace( array( ' ', '+', '&', "\n", '#' ), |
243 | | - array( '%20', '%2B', '%26', '%0A', '%23' ), |
244 | | - $inQueryStr ); |
245 | | - $link_url .= $inQueryStr; |
246 | | - } |
247 | | - } |
248 | | - if ( $inLinkType == 'button' || $inLinkType == 'post button' ) { |
249 | | - $formMethod = ( $inLinkType == 'button' ) ? 'get' : 'post'; |
250 | | - $str = Html::rawElement( 'form', array( 'action' => $link_url, 'method' => $formMethod, 'class' => $classStr ), |
251 | | - Html::rawElement( 'button', array( 'type' => 'submit', 'value' => $inLinkStr ), $inLinkStr ) . |
252 | | - $hidden_inputs |
253 | | - ); |
254 | | - } else { |
255 | | - // If a target page has been specified but it doesn't |
256 | | - // exist, make it a red link. |
257 | | - if ( ! empty( $inTargetName ) ) { |
258 | | - $targetTitle = Title::newFromText( $inTargetName ); |
259 | | - if ( is_null( $targetTitle ) || !$targetTitle->exists() ) { |
260 | | - $classStr .= " new"; |
261 | | - } |
262 | | - } |
263 | | - $str = Html::rawElement( 'a', array( 'href' => $link_url, 'class' => $classStr, 'title' => $inTooltip ), $inLinkStr ); |
264 | | - } |
| 163 | + |
265 | 164 | // hack to remove newline from beginning of output, thanks to |
266 | 165 | // http://jimbojw.com/wiki/index.php?title=Raw_HTML_Output_from_a_MediaWiki_Parser_Function |
267 | | - return $parser->insertStripItem( $str, $parser->mStripState ); |
| 166 | + return $parser->insertStripItem( SFUtils::createFormLink( $parser, 'FormEdit', $params ), $parser->mStripState ); |
268 | 167 | } |
269 | 168 | |
270 | 169 | static function renderFormInput ( &$parser ) { |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -888,4 +888,122 @@ |
889 | 889 | return true; |
890 | 890 | } |
891 | 891 | |
| 892 | + static function createFormLink ( &$parser, $specialPageName, $params ) { |
| 893 | + global $wgVersion; |
| 894 | + |
| 895 | + // Set defaults. |
| 896 | + $inFormName = $inLinkStr = $inLinkType = $inTooltip = |
| 897 | + $inQueryStr = $inTargetName = ''; |
| 898 | + $classStr = ""; |
| 899 | + $inQueryArr = array(); |
| 900 | + // assign params |
| 901 | + // - support unlabelled params, for backwards compatibility |
| 902 | + // - parse and sanitize all parameter values |
| 903 | + foreach ( $params as $i => $param ) { |
| 904 | + $elements = explode( '=', $param, 2 ); |
| 905 | + |
| 906 | + // set param_name and value |
| 907 | + if ( count( $elements ) > 1 ) { |
| 908 | + $param_name = trim( $elements[0] ); |
| 909 | + |
| 910 | + // parse (and sanitize) parameter values |
| 911 | + $value = trim( $parser->recursiveTagParse( $elements[1] ) ); |
| 912 | + } else { |
| 913 | + $param_name = null; |
| 914 | + |
| 915 | + // parse (and sanitize) parameter values |
| 916 | + $value = trim( $parser->recursiveTagParse( $param ) ); |
| 917 | + } |
| 918 | + |
| 919 | + if ( $param_name == 'form' ) { |
| 920 | + $inFormName = $value; |
| 921 | + } elseif ( $param_name == 'link text' ) { |
| 922 | + $inLinkStr = $value; |
| 923 | + } elseif ( $param_name == 'link type' ) { |
| 924 | + $inLinkType = $value; |
| 925 | + } elseif ( $param_name == 'query string' ) { |
| 926 | + // Change HTML-encoded ampersands directly to |
| 927 | + // URL-encoded ampersands, so that the string |
| 928 | + // doesn't get split up on the '&'. |
| 929 | + $inQueryStr = str_replace( '&', '%26', $value ); |
| 930 | + |
| 931 | + $inQueryStr = Sanitizer::decodeCharReferences( $inQueryStr ); |
| 932 | + parse_str($inQueryStr, $arr); |
| 933 | + $inQueryArr = array_merge_recursive( $inQueryArr, $arr ); |
| 934 | + } elseif ( $param_name == 'tooltip' ) { |
| 935 | + $inTooltip = Sanitizer::decodeCharReferences( $value ); |
| 936 | + } elseif ( $param_name == 'target' ) { |
| 937 | + $inTargetName = $value; |
| 938 | + } elseif ( $param_name == null && $value == 'popup' ) { |
| 939 | + self::loadScriptsForPopupForm( $parser ); |
| 940 | + $classStr = 'popupformlink'; |
| 941 | + } elseif ( $param_name !== null ) { |
| 942 | + $value = urlencode($value); |
| 943 | + parse_str("$param_name=$value", $arr); |
| 944 | + $inQueryArr = array_merge_recursive( $inQueryArr, $arr ); |
| 945 | + }elseif ( $i == 0 ) { |
| 946 | + $inFormName = $value; |
| 947 | + } elseif ( $i == 1 ) { |
| 948 | + $inLinkStr = $value; |
| 949 | + } elseif ( $i == 2 ) { |
| 950 | + $inLinkType = $value; |
| 951 | + } elseif ( $i == 3 ) { |
| 952 | + // Change HTML-encoded ampersands directly to |
| 953 | + // URL-encoded ampersands, so that the string |
| 954 | + // doesn't get split up on the '&'. |
| 955 | + $inQueryStr = str_replace( '&', '%26', $value ); |
| 956 | + |
| 957 | + $inQueryStr = Sanitizer::decodeCharReferences( $inQueryStr ); |
| 958 | + parse_str($inQueryStr, $arr); |
| 959 | + $inQueryArr = array_merge_recursive( $inQueryArr, $arr ); |
| 960 | + } |
| 961 | + } |
| 962 | + |
| 963 | + $ad = SFUtils::getSpecialPage( $specialPageName ); |
| 964 | + $link_url = $ad->getTitle()->getLocalURL() . "/$inFormName"; |
| 965 | + if ( ! empty( $inTargetName ) ) { |
| 966 | + $link_url .= "/$inTargetName"; |
| 967 | + } |
| 968 | + $link_url = str_replace( ' ', '_', $link_url ); |
| 969 | + $hidden_inputs = ""; |
| 970 | + if ( ! empty($inQueryArr) ) { |
| 971 | + // Special handling for the buttons - query string |
| 972 | + // has to be turned into hidden inputs. |
| 973 | + if ( $inLinkType == 'button' || $inLinkType == 'post button' ) { |
| 974 | + |
| 975 | + $query_components = explode( '&', http_build_query( $inQueryArr ) ); |
| 976 | + |
| 977 | + foreach ( $query_components as $query_component ) { |
| 978 | + $query_component = urldecode( $query_component ); |
| 979 | + $var_and_val = explode( '=', $query_component, 2 ); |
| 980 | + if ( count( $var_and_val ) == 2 ) { |
| 981 | + $hidden_inputs .= SFFormUtils::hiddenFieldHTML( $var_and_val[0], $var_and_val[1] ); |
| 982 | + } |
| 983 | + } |
| 984 | + } else { |
| 985 | + $link_url .= ( strstr( $link_url, '?' ) ) ? '&' : '?'; |
| 986 | + $link_url .= http_build_query( $inQueryArr ); |
| 987 | + } |
| 988 | + } |
| 989 | + if ( $inLinkType == 'button' || $inLinkType == 'post button' ) { |
| 990 | + $formMethod = ( $inLinkType == 'button' ) ? 'get' : 'post'; |
| 991 | + $str = Html::rawElement( 'form', array( 'action' => $link_url, 'method' => $formMethod, 'class' => $classStr ), |
| 992 | + Html::rawElement( 'button', array( 'type' => 'submit', 'value' => $inLinkStr ), $inLinkStr ) . |
| 993 | + $hidden_inputs |
| 994 | + ); |
| 995 | + } else { |
| 996 | + // If a target page has been specified but it doesn't |
| 997 | + // exist, make it a red link. |
| 998 | + if ( ! empty( $inTargetName ) ) { |
| 999 | + $targetTitle = Title::newFromText( $inTargetName ); |
| 1000 | + if ( is_null( $targetTitle ) || !$targetTitle->exists() ) { |
| 1001 | + $classStr .= " new"; |
| 1002 | + } |
| 1003 | + } |
| 1004 | + $str = Html::rawElement( 'a', array( 'href' => $link_url, 'class' => $classStr, 'title' => $inTooltip ), $inLinkStr ); |
| 1005 | + } |
| 1006 | + |
| 1007 | + return $str; |
| 1008 | + } |
| 1009 | + |
892 | 1010 | } |