including() ) { $this->setHeaders(); } $form_name = $this->including() ? $query : $this->getRequest()->getVal( 'form', $query ); $form_name = str_replace( '_', ' ', $form_name ); $this->printPage( $form_name, $this->including() ); } function printPage( $form_name, $embedded = false ) { global $wgPageFormsFormPrinter, $wgParser, $wgPageFormsRunQueryFormAtTop; $out = $this->getOutput(); $req = $this->getRequest(); $user = $this->getUser(); // Get contents of form-definition page. $form_title = Title::makeTitleSafe( PF_NS_FORM, $form_name ); if ( !$form_title || !$form_title->exists() ) { if ( $form_name === '' ) { $text = Html::element( 'p', array( 'class' => 'error' ), wfMessage( 'pf_runquery_badurl' )->text() ) . "\n"; } else { $text = Html::rawElement( 'p', array( 'class' => 'error' ), wfMessage( 'pf_formstart_badform', PFUtils::linkText( PF_NS_FORM, $form_name ) )->parse() ) . "\n"; } $out->addHTML( $text ); return; } // Initialize variables. $form_definition = PFUtils::getPageText( $form_title ); if ( $embedded ) { $req = $this->getUser()->getRequest(); // @HACK - set $wgRequest so that FormPrinter::formHTML() // can have the right data. Much better would be to // pass this in as a parameter to formHTML(). global $wgRequest; $wgRequest = $req; } else { $req = $this->getRequest(); } // We check that the form name is the same, in case // Special:RunQuery is embedded on the page and there's more // than one of them. // Query/ies on the page can also be run automatically if // "_run" is added to the query string (this was added in // PF 4.3.1; in PF 4.3, there was no such option, and before // 4.3, "wpRunQuery=true" was used). $form_submitted = $req->getCheck( '_run' ) || $req->getVal( 'pfRunQueryFormName' ) == $form_name; $content = $req->getVal( 'wpTextbox1' ); $raw = $req->getBool( 'raw', false ); if ( $raw ) { $out->setArticleBodyOnly( true ); } list( $form_text, $data_text, $form_page_title ) = $wgPageFormsFormPrinter->formHTML( $form_definition, $form_submitted, false, $form_title->getArticleID(), $content, null, null, true, $embedded ); $text = ""; // Get the text of the results. $resultsText = ''; if ( $form_submitted ) { // @TODO - fix RunQuery's parsing so that this check // isn't needed. if ( $wgParser->getOutput() == null ) { $headItems = array(); } else { $headItems = $wgParser->getOutput()->getHeadItems(); } foreach ( $headItems as $key => $item ) { $out->addHeadItem( $key, "\t\t" . $item . "\n" ); } $wgParser->mOptions = ParserOptions::newFromUser( $user ); $resultsText = $wgParser->parse( $data_text, $this->getPageTitle(), $wgParser->mOptions, true, false )->getText(); } // Get the full text of the form. $fullFormText = ''; $additionalQueryHeader = ''; $dividerText = ''; if ( !$raw ) { // Create the "additional query" header, and the // divider text - one of these (depending on whether // the query form is at the top or bottom) is displayed // if the form has already been submitted. if ( $form_submitted ) { $additionalQueryHeader = "\n" . Html::element( 'h2', null, wfMessage( 'pf_runquery_additionalquery' )->text() ) . "\n"; $dividerText = "\n