Index: trunk/extensions/SemanticForms/SemanticForms.php |
— | — | @@ -90,6 +90,7 @@ |
91 | 91 | $wgHooks['ParserFirstCallInit'][] = 'SFParserFunctions::registerFunctions'; |
92 | 92 | $wgHooks['MakeGlobalVariablesScript'][] = 'SFFormUtils::setGlobalJSVariables'; |
93 | 93 | $wgHooks['PageSchemasRegisterHandlers'][] = 'SFPageSchemas::registerClass'; |
| 94 | +$wgHooks['EditPage::importFormData'][] = 'SFUtils::showFormPreview'; |
94 | 95 | |
95 | 96 | $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI'; |
96 | 97 | $wgAPIModules['sfautoedit'] = 'SFAutoeditAPI'; |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -819,4 +819,42 @@ |
820 | 820 | return $hasFactory ? SpecialPageFactory::getPage( $pageName ) : SpecialPage::getPage( $pageName ); |
821 | 821 | } |
822 | 822 | |
| 823 | + /** |
| 824 | + * Appends a preview of the actual form, when a page in the "Form" |
| 825 | + * namespace is previewed. |
| 826 | + * |
| 827 | + * @author Solitarius |
| 828 | + * @since 2.4 |
| 829 | + */ |
| 830 | + public function showFormPreview( $editpage, $request ) { |
| 831 | + global $wgOut, $sfgFormPrinter; |
| 832 | + |
| 833 | + wfDebug( __METHOD__ . ": enter.\n" ); |
| 834 | + wfProfileIn( __METHOD__ ); |
| 835 | + |
| 836 | + // Exit if we're not in preview mode. |
| 837 | + if ( ! $editpage->preview ) { |
| 838 | + return true; |
| 839 | + } |
| 840 | + // Exit if we aren't in the "Form" namespace. |
| 841 | + if ( $editpage->getArticle()->getTitle()->getNamespace() != SF_NS_FORM ) { |
| 842 | + return true; |
| 843 | + } |
| 844 | + |
| 845 | + $editpage->previewTextAfterContent .= Html::element( 'h2', null, wfMsg( 'sf-preview-header' ) ) . "\n" . |
| 846 | + '<div class="previewnote" style="font-weight: bold">' . $wgOut->parse( wfMsg( 'sf-preview-note' ) ) . "</div>\n<hr />\n"; |
| 847 | + |
| 848 | + $form_definition = StringUtils::delimiterReplace( '<noinclude>', '</noinclude>', '', $editpage->textbox1 ); |
| 849 | + list ( $form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name ) = |
| 850 | + $sfgFormPrinter->formHTML( $form_definition, null, false, null, null, "Semantic Forms form preview dummy title", null ); |
| 851 | + |
| 852 | + SFUtils::addJavascriptAndCSS(); |
| 853 | + $editpage->previewTextAfterContent .= |
| 854 | + '<div style="margin-top: 15px">' . $form_text . "</div>"; |
| 855 | + |
| 856 | + wfProfileOut( __METHOD__ ); |
| 857 | + |
| 858 | + return true; |
| 859 | + } |
| 860 | + |
823 | 861 | } |
Index: trunk/extensions/SemanticForms/languages/SF_Messages.php |
— | — | @@ -165,6 +165,8 @@ |
166 | 166 | 'sf_bad_date_error' => 'must be a valid date', |
167 | 167 | 'uploadwindow' => 'Upload window', // Description for Special:UploadWindow |
168 | 168 | 'sf_deletionlog' => 'Deletion log', |
| 169 | + 'sf-preview-header' => 'Form preview', |
| 170 | + 'sf-preview-note' => 'This is what the form will look like when it is in use:', |
169 | 171 | 'sf-pageschemas-pagenameformula' => 'Page name formula:', |
170 | 172 | 'sf-pageschemas-createtitle' => 'Title of form for new pages:', |
171 | 173 | 'sf-pageschemas-edittitle' => 'Title of form for existing pages:', |