r110032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110031‎ | r110032 | r110033 >
Date:22:03, 25 January 2012
Author:yaron
Status:ok
Tags:
Comment:
Added preview of actual form when a "Form:" page is being previewed, using new 'SFUtils::showFormPreview() method - based on a patch from Solitarius
Modified paths:
  • /trunk/extensions/SemanticForms/SemanticForms.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_Utils.php (modified) (history)
  • /trunk/extensions/SemanticForms/languages/SF_Messages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/SemanticForms.php
@@ -90,6 +90,7 @@
9191 $wgHooks['ParserFirstCallInit'][] = 'SFParserFunctions::registerFunctions';
9292 $wgHooks['MakeGlobalVariablesScript'][] = 'SFFormUtils::setGlobalJSVariables';
9393 $wgHooks['PageSchemasRegisterHandlers'][] = 'SFPageSchemas::registerClass';
 94+$wgHooks['EditPage::importFormData'][] = 'SFUtils::showFormPreview';
9495
9596 $wgAPIModules['sfautocomplete'] = 'SFAutocompleteAPI';
9697 $wgAPIModules['sfautoedit'] = 'SFAutoeditAPI';
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php
@@ -819,4 +819,42 @@
820820 return $hasFactory ? SpecialPageFactory::getPage( $pageName ) : SpecialPage::getPage( $pageName );
821821 }
822822
 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+
823861 }
Index: trunk/extensions/SemanticForms/languages/SF_Messages.php
@@ -165,6 +165,8 @@
166166 'sf_bad_date_error' => 'must be a valid date',
167167 'uploadwindow' => 'Upload window', // Description for Special:UploadWindow
168168 '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:',
169171 'sf-pageschemas-pagenameformula' => 'Page name formula:',
170172 'sf-pageschemas-createtitle' => 'Title of form for new pages:',
171173 'sf-pageschemas-edittitle' => 'Title of form for existing pages:',

Status & tagging log