Index: trunk/extensions/SemanticForms/specials/SF_RunQuery.php |
— | — | @@ -23,91 +23,107 @@ |
24 | 24 | $this->setHeaders(); |
25 | 25 | $form_name = $this->including() ? $query : $wgRequest->getVal( 'form', $query ); |
26 | 26 | |
27 | | - self::printQueryForm( $form_name, $this->including() ); |
| 27 | + self::printPage( $form_name, $this->including() ); |
28 | 28 | } |
29 | 29 | |
30 | | - static function printQueryForm( $form_name, $embedded = false ) { |
| 30 | + static function printPage( $form_name, $embedded = false ) { |
31 | 31 | global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter, $wgParser; |
32 | 32 | |
33 | | - // get contents of form definition file |
| 33 | + // Get contents of form-definition page. |
34 | 34 | $form_title = Title::makeTitleSafe( SF_NS_FORM, $form_name ); |
35 | 35 | |
36 | 36 | if ( ! $form_title || ! $form_title->exists() ) { |
37 | 37 | $javascript_text = ""; |
38 | | - if ( $form_name == '' ) |
| 38 | + if ( $form_name == '' ) { |
39 | 39 | $text = '<p class="error">' . wfMsg( 'sf_runquery_badurl' ) . "</p>\n"; |
40 | | - else |
| 40 | + } else { |
41 | 41 | $text = '<p class="error">Error: No form page was found at ' . SFUtils::linkText( SF_NS_FORM, $form_name ) . ".</p>\n"; |
| 42 | + } |
| 43 | + $wgOut->addHTML( $text ); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + // Initialize variables. |
| 48 | + $form_article = new Article( $form_title ); |
| 49 | + $form_definition = $form_article->getContent(); |
| 50 | + $submit_url = $form_title->getLocalURL( 'action=submit' ); |
| 51 | + if ( $embedded ) { |
| 52 | + $run_query = false; |
| 53 | + $content = null; |
| 54 | + $raw = false; |
42 | 55 | } else { |
43 | | - $s = wfMsg( 'sf_runquery_title', $form_title->getText() ); |
44 | | - if ( !$embedded ) |
| 56 | + $run_query = $wgRequest->getCheck( 'wpRunQuery' ); |
| 57 | + $content = $wgRequest->getVal( 'wpTextbox1' ); |
| 58 | + $raw = $wgRequest->getBool( 'raw', false ); |
| 59 | + } |
| 60 | + $form_submitted = ( $run_query ); |
| 61 | + if ( $raw ) |
| 62 | + $wgOut->setArticleBodyOnly( true ); |
| 63 | + // if user already made some action, ignore the edited |
| 64 | + // page and just get data from the query string |
| 65 | + if ( !$embedded && $wgRequest->getVal( 'query' ) == 'true' ) { |
| 66 | + $edit_content = null; |
| 67 | + $is_text_source = false; |
| 68 | + } elseif ( $content != null ) { |
| 69 | + $edit_content = $content; |
| 70 | + $is_text_source = true; |
| 71 | + } else { |
| 72 | + $edit_content = null; |
| 73 | + $is_text_source = true; |
| 74 | + } |
| 75 | + list ( $form_text, $javascript_text, $data_text, $form_page_title ) = |
| 76 | + $sfgFormPrinter->formHTML( $form_definition, $form_submitted, $is_text_source, $form_article->getID(), $edit_content, null, null, true, $embedded ); |
| 77 | + $text = ""; |
| 78 | + |
| 79 | + // Set the page title. |
| 80 | + if ( !$embedded ) { |
| 81 | + if ( $form_page_title != null ) { |
| 82 | + $wgOut->setPageTitle( $form_page_title ); |
| 83 | + } else { |
| 84 | + $s = wfMsg( 'sf_runquery_title', $form_title->getText() ); |
45 | 85 | $wgOut->setPageTitle( $s ); |
46 | | - $form_article = new Article( $form_title ); |
47 | | - $form_definition = $form_article->getContent(); |
48 | | - $submit_url = $form_title->getLocalURL( 'action=submit' ); |
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 | 86 | } |
58 | | - $form_submitted = ( $run_query ); |
59 | | - if ( $raw ) |
60 | | - $wgOut->setArticleBodyOnly( true ); |
61 | | - // if user already made some action, ignore the edited |
62 | | - // page and just get data from the query string |
63 | | - if ( !$embedded && $wgRequest->getVal( 'query' ) == 'true' ) { |
64 | | - $edit_content = null; |
65 | | - $is_text_source = false; |
66 | | - } elseif ( $content != null ) { |
67 | | - $edit_content = $content; |
68 | | - $is_text_source = true; |
| 87 | + } |
| 88 | + if ( $form_submitted ) { |
| 89 | + global $wgUser, $wgTitle, $wgOut; |
| 90 | + $wgParser->mOptions = new ParserOptions(); |
| 91 | + $wgParser->mOptions->initialiseFromUser( $wgUser ); |
| 92 | + // method was added in MW 1.16 |
| 93 | + if ( method_exists( $wgParser->getOutput(), 'getHeadItems' ) ) { |
| 94 | + $headItems = $wgParser->getOutput()->getHeadItems(); |
69 | 95 | } else { |
70 | | - $edit_content = null; |
71 | | - $is_text_source = true; |
| 96 | + $headItems = $wgParser->getOutput()->mHeadItems; |
72 | 97 | } |
73 | | - list ( $form_text, $javascript_text, $data_text, $form_page_title ) = |
74 | | - $sfgFormPrinter->formHTML( $form_definition, $form_submitted, $is_text_source, $form_article->getID(), $edit_content, null, null, true, $embedded ); |
75 | | - $text = ""; |
76 | | - // override the default title for this page if |
77 | | - // a title was specified in the form |
78 | | - if ( $form_page_title != null && !$embedded ) { |
79 | | - $wgOut->setPageTitle( $form_page_title ); |
| 98 | + foreach ( $headItems as $key => $item ) { |
| 99 | + $wgOut->addHeadItem( $key, "\t\t" . $item . "\n" ); |
80 | 100 | } |
81 | | - if ( $form_submitted ) { |
82 | | - global $wgUser, $wgTitle, $wgOut; |
83 | | - $wgParser->mOptions = new ParserOptions(); |
84 | | - $wgParser->mOptions->initialiseFromUser( $wgUser ); |
85 | | - $text = $wgParser->parse( $data_text, $wgTitle, $wgParser->mOptions )->getText(); |
86 | | - // method was added in MW 1.16 |
87 | | - if ( method_exists( $wgParser->getOutput(), 'getHeadItems' ) ) { |
88 | | - $headItems = $wgParser->getOutput()->getHeadItems(); |
89 | | - } else { |
90 | | - $headItems = $wgParser->getOutput()->mHeadItems; |
91 | | - } |
92 | | - foreach ( $headItems as $key => $item ) { |
93 | | - $wgOut->addHeadItem( $key, "\t\t" . $item . "\n" ); |
94 | | - } |
| 101 | + } |
95 | 102 | |
96 | | - $additional_query = wfMsg( 'sf_runquery_additionalquery' ); |
97 | | - if ( !$raw ) |
98 | | - $text .= "\n<h2>$additional_query</h2>\n"; |
99 | | - } |
100 | | - if ( !$raw ) { |
101 | | - $action = htmlspecialchars( SpecialPage::getTitleFor( "RunQuery", $form_name )->getLocalURL() ); |
102 | | - $text .= <<<END |
| 103 | + // Display the text of the results. |
| 104 | + if ( $form_submitted ) { |
| 105 | + $text = $wgParser->parse( $data_text, $wgTitle, $wgParser->mOptions )->getText(); |
| 106 | + } |
| 107 | + |
| 108 | + // Display the "additional query" header, if the form has |
| 109 | + // already been submitted. |
| 110 | + if ( $form_submitted ) { |
| 111 | + $additional_query = wfMsg( 'sf_runquery_additionalquery' ); |
| 112 | + if ( !$raw ) |
| 113 | + $text .= "\n<h2>$additional_query</h2>\n"; |
| 114 | + } |
| 115 | + if ( !$raw ) { |
| 116 | + $action = htmlspecialchars( SpecialPage::getTitleFor( "RunQuery", $form_name )->getLocalURL() ); |
| 117 | + $text .= <<<END |
103 | 118 | <form id="sfForm" name="createbox" action="$action" method="post" class="createbox"> |
104 | 119 | <input type="hidden" name="query" value="true" /> |
105 | 120 | |
106 | 121 | END; |
107 | | - $text .= $form_text; |
108 | | - } |
| 122 | + $text .= $form_text; |
109 | 123 | } |
110 | 124 | if ( $embedded ) |
111 | 125 | $text = "<div class='runQueryEmbedded'>$text</div>"; |
| 126 | + |
| 127 | + // Now write everything to the screen. |
112 | 128 | $wgOut->addHTML( $text ); |
113 | 129 | SFUtils::addJavascriptAndCSS( $embedded ? $wgParser:null ); |
114 | 130 | $script = ' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n"; |