r51071 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51070‎ | r51071 | r51072 >
Date:15:54, 27 May 2009
Author:yaron
Status:deferred
Tags:
Comment:
New special page
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_RunQuery.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_RunQuery.php
@@ -0,0 +1,99 @@
 2+<?php
 3+/**
 4+ * Displays a pre-defined form that a user can run a query with.
 5+ *
 6+ * @author Yaron Koren
 7+ */
 8+
 9+if (!defined('MEDIAWIKI')) die();
 10+
 11+class SFRunQuery extends SpecialPage {
 12+
 13+ /**
 14+ * Constructor
 15+ */
 16+ function SFRunQuery() {
 17+ SpecialPage::SpecialPage('RunQuery');
 18+ wfLoadExtensionMessages('SemanticForms');
 19+ }
 20+
 21+ function execute($query) {
 22+ global $wgRequest;
 23+ $this->setHeaders();
 24+ $form_name = $wgRequest->getVal('form');
 25+
 26+ // if query string did not contain this variable, try the URL
 27+ if (! $form_name) {
 28+ $form_name = $query;
 29+ }
 30+
 31+ self::printQueryForm($form_name);
 32+ }
 33+
 34+ static function printQueryForm($form_name) {
 35+ global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter, $sfgYUIBase;
 36+
 37+ wfLoadExtensionMessages('SemanticForms');
 38+
 39+ // get contents of form definition file
 40+ $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name);
 41+
 42+ if (! $form_title || ! $form_title->exists() ) {
 43+ if ($form_name == '')
 44+ $text = '<p class="error">' . wfMsg('sf_runquery_badurl') . "</p>\n";
 45+ else
 46+ $text = '<p class="error">Error: No form page was found at ' . SFUtils::linkText(SF_NS_FORM, $form_name) . ".</p>\n";
 47+ } else {
 48+ $s = wfMsg('sf_runquery_title', $form_title->getText());
 49+ $wgOut->setPageTitle($s);
 50+ $form_article = new Article($form_title);
 51+ $form_definition = $form_article->getContent();
 52+ $submit_url = $form_title->getLocalURL('action=submit');
 53+ $run_query = $wgRequest->getCheck('wpRunQuery');
 54+ $content = $wgRequest->getVal('wpTextbox1');
 55+ $form_submitted = ($run_query);
 56+ // if user already made some action, ignore the edited
 57+ // page and just get data from the query string
 58+ if ($wgRequest->getVal('query') == 'true') {
 59+ $edit_content = null;
 60+ $is_text_source = false;
 61+ } elseif ($content != null) {
 62+ $edit_content = $content;
 63+ $is_text_source = true;
 64+ } else {
 65+ $is_text_source = true;
 66+ }
 67+ list ($form_text, $javascript_text, $data_text, $form_page_title) =
 68+ $sfgFormPrinter->formHTML($form_definition, $form_submitted, $is_text_source, $edit_content, null, null, true);
 69+ if ($form_submitted) {
 70+ $wgOut->setArticleBodyOnly( true );
 71+ global $wgTitle;
 72+ $new_url = $wgTitle->getLocalURL() . "/$form_name";
 73+ $text = SFUtils::printRedirectForm($new_url, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime'));
 74+ } else {
 75+ // override the default title for this page if
 76+ // a title was specified in the form
 77+ if ($form_page_title != NULL) {
 78+ $wgOut->setPageTitle($form_page_title);
 79+ }
 80+ if ($wgRequest->getCheck('wpTextbox1')) {
 81+ global $wgParser, $wgTitle;
 82+ $wgParser->mOptions = new ParserOptions();
 83+ $wgParser->mOptions->initialiseFromUser($wgUser);
 84+ $text = $wgParser->parse($content, $wgTitle, $wgParser->mOptions)->getText();
 85+ $additional_query = wfMsg('sf_runquery_additionalquery');
 86+ $text .= "\n<h2>$additional_query</h2>\n";
 87+ }
 88+ $text .=<<<END
 89+ <form name="createbox" onsubmit="return validate_all()" action="" method="post" class="createbox">
 90+ <input type="hidden" name="query" value="true" />
 91+
 92+END;
 93+ $text .= $form_text;
 94+ }
 95+ }
 96+ SFUtils::addJavascriptAndCSS();
 97+ $wgOut->addScript(' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n");
 98+ $wgOut->addHTML($text);
 99+ }
 100+}

Status & tagging log