r76468 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76467‎ | r76468 | r76469 >
Date:20:37, 10 November 2010
Author:yaron
Status:deferred
Tags:
Comment:
Improved some formatting, layout and comments
Modified paths:
  • /trunk/extensions/SemanticForms/specials/SF_RunQuery.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/specials/SF_RunQuery.php
@@ -23,91 +23,107 @@
2424 $this->setHeaders();
2525 $form_name = $this->including() ? $query : $wgRequest->getVal( 'form', $query );
2626
27 - self::printQueryForm( $form_name, $this->including() );
 27+ self::printPage( $form_name, $this->including() );
2828 }
2929
30 - static function printQueryForm( $form_name, $embedded = false ) {
 30+ static function printPage( $form_name, $embedded = false ) {
3131 global $wgOut, $wgRequest, $wgScriptPath, $sfgScriptPath, $sfgFormPrinter, $wgParser;
3232
33 - // get contents of form definition file
 33+ // Get contents of form-definition page.
3434 $form_title = Title::makeTitleSafe( SF_NS_FORM, $form_name );
3535
3636 if ( ! $form_title || ! $form_title->exists() ) {
3737 $javascript_text = "";
38 - if ( $form_name == '' )
 38+ if ( $form_name == '' ) {
3939 $text = '<p class="error">' . wfMsg( 'sf_runquery_badurl' ) . "</p>\n";
40 - else
 40+ } else {
4141 $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;
4255 } 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() );
4585 $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 );
5786 }
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();
6995 } else {
70 - $edit_content = null;
71 - $is_text_source = true;
 96+ $headItems = $wgParser->getOutput()->mHeadItems;
7297 }
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" );
80100 }
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+ }
95102
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
103118 <form id="sfForm" name="createbox" action="$action" method="post" class="createbox">
104119 <input type="hidden" name="query" value="true" />
105120
106121 END;
107 - $text .= $form_text;
108 - }
 122+ $text .= $form_text;
109123 }
110124 if ( $embedded )
111125 $text = "<div class='runQueryEmbedded'>$text</div>";
 126+
 127+ // Now write everything to the screen.
112128 $wgOut->addHTML( $text );
113129 SFUtils::addJavascriptAndCSS( $embedded ? $wgParser:null );
114130 $script = ' <script type="text/javascript">' . "\n" . $javascript_text . '</script>' . "\n";

Status & tagging log