r59277 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59276‎ | r59277 | r59278 >
Date:05:31, 20 November 2009
Author:dantman
Status:deferred
Tags:
Comment:
SemanticForms: Add a raw=true mode for use via ajax and fix up the use of $wgRequest so it does not have side effects while on a page the special page was embedded into.
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_RunQuery.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_RunQuery.php
@@ -20,13 +20,8 @@
2121 function execute($query) {
2222 global $wgRequest;
2323 $this->setHeaders();
24 - $form_name = $wgRequest->getVal('form');
 24+ $form_name = $this->including() ? $query : $wgRequest->getVal('form', $query);
2525
26 - // if query string did not contain this variable, try the URL
27 - if (! $form_name) {
28 - $form_name = $query;
29 - }
30 -
3126 self::printQueryForm($form_name, $this->including());
3227 }
3328
@@ -50,12 +45,21 @@
5146 $form_article = new Article($form_title);
5247 $form_definition = $form_article->getContent();
5348 $submit_url = $form_title->getLocalURL('action=submit');
54 - $run_query = $wgRequest->getCheck('wpRunQuery');
55 - $content = $wgRequest->getVal('wpTextbox1');
 49+ if ( $embedded ) {
 50+ $run_query = false;
 51+ $content = NULL;
 52+ $raw = false;
 53+ } else {
 54+ $run_query = $wgRequest->getCheck('wpRunQuery');
 55+ $content = $wgRequest->getVal('wpTextbox1');
 56+ $raw = $wgRequest->getBool('raw', false);
 57+ }
5658 $form_submitted = ($run_query);
 59+ if ( $raw )
 60+ $wgOut->setArticleBodyOnly( true );
5761 // if user already made some action, ignore the edited
5862 // page and just get data from the query string
59 - if ($wgRequest->getVal('query') == 'true') {
 63+ if (!$embedded && $wgRequest->getVal('query') == 'true') {
6064 $edit_content = null;
6165 $is_text_source = false;
6266 } elseif ($content != null) {
@@ -79,15 +83,18 @@
8084 $wgParser->mOptions->initialiseFromUser($wgUser);
8185 $text = $wgParser->parse($data_text, $wgTitle, $wgParser->mOptions)->getText();
8286 $additional_query = wfMsg('sf_runquery_additionalquery');
83 - $text .= "\n<h2>$additional_query</h2>\n";
 87+ if ( !$raw )
 88+ $text .= "\n<h2>$additional_query</h2>\n";
8489 }
85 - $action = htmlspecialchars(SpecialPage::getTitleFor("RunQuery", $form_name)->getLocalURL());
86 - $text .=<<<END
 90+ if ( !$raw ) {
 91+ $action = htmlspecialchars(SpecialPage::getTitleFor("RunQuery", $form_name)->getLocalURL());
 92+ $text .=<<<END
8793 <form name="createbox" onsubmit="return validate_all()" action="$action" method="post" class="createbox">
8894 <input type="hidden" name="query" value="true" />
8995
9096 END;
91 - $text .= $form_text;
 97+ $text .= $form_text;
 98+ }
9299 }
93100 SFUtils::addJavascriptAndCSS();
94101 $wgOut->addScript(' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n");

Status & tagging log