function getPageHeader() { global $wgUser; $sk = $wgUser->getSkin(); $create_form_link = SFUtils::linkForSpecialPage($sk, 'CreateForm'); $header = "<p>" . $create_form_link . ".</p>\n"; $header .= '<p>' . wfMsg('sf_forms_docu') . "</p><br />\n"; return $header; }
function execute( $query ) { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; global $wgLang, $smwgContLang; # Check permissions if ( !$wgUser->isAllowed( 'createclass' ) ) { $this->displayRestrictionError(); return; } $this->setHeaders(); $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); $numStartingRows = 10; self::addJavascript( $numStartingRows ); $property_name_error_str = ''; $save_page = $wgRequest->getCheck( 'save' ); if ( $save_page ) { $template_name = trim( $wgRequest->getVal( "template_name" ) ); $form_name = trim( $wgRequest->getVal( "form_name" ) ); $category_name = trim( $wgRequest->getVal( "category_name" ) ); if ( $template_name === '' | $form_name === '' || $category_name === '' ) { $wgOut->addWikiMsg( 'sf_createclass_missingvalues' ); return; } $fields = array(); $jobs = array(); // cycle through all the rows passed in for ( $i = 1; $wgRequest->getCheck( "property_name_$i" ); $i++ ) { // go through the query values, setting the appropriate local variables $property_name = trim( $wgRequest->getVal( "property_name_$i" ) ); if ( empty( $property_name ) ) continue; $field_name = trim( $wgRequest->getVal( "field_name_$i" ) ); if ( $field_name === '' ) $field_name = $property_name; $property_type = $wgRequest->getVal( "property_type_$i" ); $allowed_values = $wgRequest->getVal( "allowed_values_$i" ); $is_list = $wgRequest->getCheck( "is_list_$i" ); // create an SFTemplateField based on these // values, and add it to the $fields array $field = SFTemplateField::create( $field_name, $field_name, $property_name, $is_list ); $fields[] = $field; // create the property, and make a job for it $full_text = SFCreateProperty::createPropertyText( $property_type, '', $allowed_values ); $property_title = Title::makeTitleSafe( SMW_NS_PROPERTY, $property_name ); $params = array(); $params['user_id'] = $wgUser->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob( $property_title, $params ); } // create the template, and save it $full_text = SFTemplateField::createTemplateText( $template_name, $fields, null, $category_name, null, null, null ); $template_title = Title::makeTitleSafe( NS_TEMPLATE, $template_name ); $template_article = new Article( $template_title, 0 ); $edit_summary = ''; $template_article->doEdit( $full_text, $edit_summary ); // create the form, and make a job for it $form_template = SFTemplateInForm::create( $template_name, '', false ); $form_templates = array( $form_template ); $form = SFForm::create( $form_name, $form_templates ); $full_text = $form->createMarkup(); $form_title = Title::makeTitleSafe( SF_NS_FORM, $form_name ); $params = array(); $params['user_id'] = $wgUser->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob( $form_title, $params ); // create the category, and make a job for it $full_text = SFCreateCategory::createCategoryText( $form_name, $category_name, '' ); $category_title = Title::makeTitleSafe( NS_CATEGORY, $category_name ); $params = array(); $params['user_id'] = $wgUser->getId(); $params['page_text'] = $full_text; $jobs[] = new SFCreatePageJob( $category_title, $params ); Job::batchInsert( $jobs ); $wgOut->addWikiMsg( 'sf_createclass_success' ); return; } $datatype_labels = $smwgContLang->getDatatypeLabels(); // make links to all the other 'Create...' pages, in order to // link to them at the top of the page $sk = $wgUser->getSkin(); $creation_links = array(); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateProperty' ); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateTemplate' ); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateForm' ); $creation_links[] = SFUtils::linkForSpecialPage( $sk, 'CreateCategory' ); $create_class_docu = wfMsg( 'sf_createclass_docu', $wgLang->listToText( $creation_links ) ); $leave_field_blank = wfMsg( 'sf_createclass_leavefieldblank' ); $form_name_label = wfMsg( 'sf_createclass_nameinput' ); $template_name_label = wfMsg( 'sf_createtemplate_namelabel' ); $category_name_label = wfMsg( 'sf_createcategory_name' ); $property_name_label = wfMsg( 'sf_createproperty_propname' ); $field_name_label = wfMsg( 'sf_createtemplate_fieldname' ); $type_label = wfMsg( 'sf_createproperty_proptype' ); $allowed_values_label = wfMsg( 'sf_createclass_allowedvalues' ); $list_of_values_label = wfMsg( 'sf_createclass_listofvalues' ); $text = <<<END <form action="" method="post"> <p>$create_class_docu</p> <p>$leave_field_blank</p> <p>$template_name_label <input type="text" size="30" name="template_name"></p> <p>$form_name_label <input type="text" size="30" name="form_name"></p> <p>$category_name_label <input type="text" size="30" name="category_name"></p> <div> <table id="mainTable"> <tr> <th colspan="2">$property_name_label</th> <th>$field_name_label</th> <th>$type_label</th> <th>$allowed_values_label</th> <th>$list_of_values_label</th> </tr> END; // Make one more row than what we're displaying - use the // last row as a "starter row", to be cloned when the // "Add another" button is pressed. for ( $i = 1; $i <= $numStartingRows + 1; $i++ ) { if ( $i == $numStartingRows + 1 ) { $rowString = 'id="starterRow" style="display: none"'; $n = 'starter'; } else { $rowString = ''; $n = $i; } $text .= <<<END <tr $rowString> <td>$n.</td> <td><input type="text" size="25" name="property_name_$n" /></td> <td><input type="text" size="25" name="field_name_$n" /></td> <td> <select name="property_type_$n"> END; $optionsStr =""; foreach ( $datatype_labels as $label ) { $text .= " <option>$label</option>\n"; $optionsStr .= $label . ","; } $text .= <<<END </select> </td> <td><input type="text" size="25" name="allowed_values_$n" /></td> <td><input type="checkbox" name="is_list_$n" /></td> END; } $text .= <<<END </tr> </table> </div> END; $add_another_button = Html::element( 'input', array( 'type' => 'button', 'value' => wfMsg( 'sf_formedit_addanother' ), 'onclick' => "createClassAddRow()" ) ); $text .= Html::rawElement( 'p', null, $add_another_button ) . "\n"; // Set 'title' as hidden field, in case there's no URL niceness $cc = $this->getTitle(); $text .= SFFormUtils::hiddenFieldHTML( 'title', SFUtils::titleURLString( $cc ) ); $text .= Html::element( 'input', array( 'type' => 'submit', 'name' => 'save', 'value' => wfMsg( 'sf_createclass_create' ) ) ); $text .= "</form>\n"; $wgOut->addHTML( $text ); }
function doSpecialCreateForm() { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; $db = wfGetDB( DB_SLAVE ); // Create Javascript to populate fields to let the user input // parameters for the field, based on the input type selected // in the dropdown. $skin = $wgUser->getSkin(); $url = $skin->makeSpecialUrl( 'CreateForm', "showinputtypeoptions=' + this.val() + '&formfield=' + this.attr('formfieldid') + '" ); foreach ( $wgRequest->getValues() as $param => $value ) { $url .= '¶ms[' . Xml::escapeJsString( $param ) . ']=' . Xml::escapeJsString( $value ); } // Only add 'collapsible' ability if the ResourceLoader exists, // i.e. for MW 1.17 - adding backwards compatibility doesn't // seem worth it for this relatively minor piece of // functionality. if ( method_exists( $wgOut, 'addModules' ) ) { $wgOut->addModules( 'ext.semanticforms.collapsible' ); } $wgOut->addScript("<script> jQuery.fn.displayInputParams = function() { inputParamsDiv = this.closest('.formField').find('.otherInputParams'); jQuery.ajax({ url: '$url', context: document.body, success: function(data){ inputParamsDiv.html(data); } }); }; jQuery(document).ready(function() { jQuery('.inputTypeSelector').change( function() { jQuery(this).displayInputParams(); }); }); </script>"); // Get the names of all templates on this site. $all_templates = array(); $res = $db->select( 'page', 'page_title', array( 'page_namespace' => NS_TEMPLATE, 'page_is_redirect' => 0 ), array( 'ORDER BY' => 'page_title' ) ); if ( $db->numRows( $res ) > 0 ) { while ( $row = $db->fetchRow( $res ) ) { $template_name = str_replace( '_', ' ', $row[0] ); $all_templates[] = $template_name; } } $form_templates = array(); $i = 1; $deleted_template_loc = null; # handle inputs $form_name = $wgRequest->getVal( 'form_name' ); foreach ( $wgRequest->getValues() as $var => $val ) { # ignore variables that are not of the right form if ( strpos( $var, "_" ) != false ) { # get the template declarations and work from there list ( $action, $id ) = explode( "_", $var, 2 ); if ( $action == "template" ) { // If the button was pressed to remove // this template, just don't add it to // the array. if ( $wgRequest->getVal( "del_$id" ) != null ) { $deleted_template_loc = $id; } else { $form_template = SFTemplateInForm::create( $val, $wgRequest->getVal( "label_$id" ), $wgRequest->getVal( "allow_multiple_$id" ) ); $form_templates[] = $form_template; } } } } if ( $wgRequest->getVal( 'add_field' ) != null ) { $form_template = SFTemplateInForm::create( $wgRequest->getVal( 'new_template' ), "", false ); $new_template_loc = $wgRequest->getVal( 'before_template' ); if ( $new_template_loc === null ) { $new_template_loc = 0; } // @HACK - array_splice() doesn't work for objects, so // we have to first insert a stub element into the // array, then replace that with the actual object. array_splice( $form_templates, $new_template_loc, 0, "stub" ); $form_templates[$new_template_loc] = $form_template; } else { $new_template_loc = null; } // Now cycle through the templates and fields, modifying each // one per the query variables. foreach ( $form_templates as $i => $ft ) { foreach ( $ft->getFields() as $j => $field ) { // handle the change in indexing if a new template was // inserted before the end, or one was deleted $old_i = $i; if ( $new_template_loc != null ) { if ( $i > $new_template_loc ) { $old_i = $i - 1; } elseif ( $i == $new_template_loc ) { // it's the new template; it shouldn't // get any query-string data $old_i = - 1; } } elseif ( $deleted_template_loc != null ) { if ( $i >= $deleted_template_loc ) { $old_i = $i + 1; } } foreach ( $wgRequest->getValues() as $key => $value ) { if ( ( $pos = strpos( $key, '_' . $old_i . '_' . $j ) ) != false ) { $paramName = substr( $key, 0, $pos ); // Spaces got replaced by // underlines in the query. $paramName = str_replace( '_', ' ', $paramName ); } else { continue; } if ( $paramName == 'label' ) { $field->template_field->setLabel( $value ); } elseif ( $paramName == 'input type' ) { $input_type = $wgRequest->getVal( "input_type_" . $old_i . "_" . $j ); if ( $input_type == 'hidden' ) { $field->template_field->setInputType( $input_type ); $field->setIsHidden( true ); } elseif ( substr( $input_type, 0, 1 ) == '.' ) { // It's the default input type - // don't do anything. } else { $field->template_field->setInputType( $input_type ); } } else { if ( ! empty( $value ) ) { if ( $value == 'on' ) { $value = true; } $field->setFieldArg( $paramName, $value ); } } } } } $form = SFForm::create( $form_name, $form_templates ); // If a submit button was pressed, create the form-definition // file, then redirect. $save_page = $wgRequest->getCheck( 'wpSave' ); $preview_page = $wgRequest->getCheck( 'wpPreview' ); if ( $save_page || $preview_page ) { // Validate form name if ( $form->getFormName() == "" ) { $form_name_error_str = wfMsg( 'sf_blank_error' ); } else { // Redirect to wiki interface $wgOut->setArticleBodyOnly( true ); $title = Title::makeTitleSafe( SF_NS_FORM, $form->getFormName() ); $full_text = $form->createMarkup(); $text = SFUtils::printRedirectForm( $title, $full_text, "", $save_page, $preview_page, false, false, false, null, null ); $wgOut->addHTML( $text ); return; } } $text = "\t" . '<form action="" method="post">' . "\n"; // Set 'title' field, in case there's no URL niceness $text .= SFFormUtils::hiddenFieldHTML( 'title', $this->getTitle()->getPrefixedText() ); $text .= "\t<p>" . wfMsg( 'sf_createform_nameinput' ) . ' ' . wfMsg( 'sf_createform_nameinputdesc' ) . ' <input size=25 name="form_name" value="' . $form_name . '" />'; if ( ! empty( $form_name_error_str ) ) $text .= "\t" . Html::element( 'font', array( 'color' => 'red' ), $form_name_error_str ); $text .= "</p>\n"; $text .= $form->creationHTML(); $text .= "\t<p>" . wfMsg( 'sf_createform_addtemplate' ) . "\n"; $select_body = ""; foreach ( $all_templates as $template ) { $select_body .= " " . Html::element( 'option', array( 'value' => $template ), $template ) . "\n"; } $text .= "\t" . Html::rawElement( 'select', array( 'name' => 'new_template' ), $select_body ) . "\n"; // If a template has already been added, show a dropdown letting // the user choose where in the list to add a new dropdown. if ( count( $form_templates ) > 0 ) { $before_template_msg = wfMsg( 'sf_createform_beforetemplate' ); $text .= $before_template_msg; $select_body = ""; foreach ( $form_templates as $i => $ft ) { $select_body .= "\t" . Html::element( 'option', array( 'value' => $i ), $ft->getTemplateName() ) . "\n"; } $final_index = count( $form_templates ); $at_end_msg = wfMsg( 'sf_createform_atend' ); $select_body .= "\t" . Html::element( 'option', array( 'value' => $final_index, 'selected' => 'selected' ), $at_end_msg ); $text .= Html::rawElement( 'select', array( 'name' => 'before_template' ), $select_body ) . "\n"; } // Disable 'save' and 'preview' buttons if user has not yet // added any templates. $disabled_text = ( count( $form_templates ) == 0 ) ? "disabled" : ""; $add_button_text = wfMsg( 'sf_createform_add' ); $sk = $wgUser->getSkin(); $create_template_link = SFUtils::linkForSpecialPage( $sk, 'CreateTemplate' ); $text .= "\t" . Html::input( 'add_field', $add_button_text, 'submit' ); $text .= <<<END </p> <br /> END; $saveAttrs = array( 'id' => 'wpSave' ); if ( count( $form_templates ) == 0 ) { $saveAttrs['disabled'] = true; } $editButtonsText = "\t" . Html::input( 'wpSave', wfMsg( 'savearticle' ), 'submit', $saveAttrs ) . "\n"; $previewAttrs = array( 'id' => 'wpPreview' ); if ( count( $form_templates ) == 0 ) { $previewAttrs['disabled'] = true; } $editButtonsText .= "\t" . Html::input( 'wpPreview', wfMsg( 'preview' ), 'submit', $previewAttrs ) . "\n"; $text .= "\t" . Html::rawElement( 'div', array( 'class' => 'editButtons' ), Html::rawElement( 'p', array(), $editButtonsText ) . "\n" ) . "\n"; // Explanatory message if buttons are disabled because no // templates have been added. if ( count( $form_templates ) == 0 ) { $text .= "\t" . Html::element( 'p', null, "(" . wfMsg( 'sf_createtemplate_addtemplatebeforesave' ) . ")" ); } $text .= <<<END </form> <hr /><br /> END; $text .= "\t" . Html::rawElement( 'p', null, $create_template_link . '.' ); $wgOut->addExtensionStyle( $sfgScriptPath . "/skins/SemanticForms.css" ); $wgOut->addHTML( $text ); }
function execute($query) { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; $this->setHeaders(); // Cycle through the query values, setting the appropriate // local variables. $category_name = $wgRequest->getVal('category_name'); $default_form = $wgRequest->getVal('default_form'); $parent_category = $wgRequest->getVal('parent_category'); $category_name_error_str = null; $save_page = $wgRequest->getCheck('wpSave'); $preview_page = $wgRequest->getCheck('wpPreview'); if ($save_page || $preview_page) { // Validate category name if ($category_name === '') { $category_name_error_str = wfMsg('sf_blank_error'); } else { // Redirect to wiki interface $wgOut->setArticleBodyOnly(true); $title = Title::makeTitleSafe(NS_CATEGORY, $category_name); $full_text = SFCreateCategory::createCategoryText($default_form, $category_name, $parent_category); $text = SFUtils::printRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null); $wgOut->addHTML($text); return; } } $all_forms = SFUtils::getAllForms(); // Set 'title' as hidden field, in case there's no URL niceness global $wgContLang; $mw_namespace_labels = $wgContLang->getNamespaces(); $special_namespace = $mw_namespace_labels[NS_SPECIAL]; $text = <<<END \t<form action="" method="get"> END; $text .= "\t" . Html::hidden('title', "{$special_namespace}:CreateCategory") . "\n"; $firstRow = wfMsg('sf_createcategory_name') . ' ' . Html::input('category_name', null, 'text', array('size' => 25)) . "\n"; if (!is_null($category_name_error_str)) { $firstRow .= Html::element('span', array('style' => 'color: red;'), $category_name_error_str) . "\n"; } $firstRow .= "\t" . wfMsg('sf_createcategory_defaultform') . "\n"; $formSelector = "\t" . Html::element('option', null, null) . "\n"; foreach ($all_forms as $form) { $formSelector .= "\t" . Html::element('option', null, $form) . "\n"; } $firstRow .= Html::rawElement('select', array('id' => 'form_dropdown', 'name' => 'default_form'), $formSelector); $text .= Html::rawElement('p', null, $firstRow); $subcategory_label = wfMsg('sf_createcategory_makesubcategory'); $text .= <<<END \t<p>{$subcategory_label} \t<select id="category_dropdown" name="parent_category"> \t<option></option> END; $categories = SFUtils::getCategoriesForPage(); foreach ($categories as $category) { $category = str_replace('_', ' ', $category); $text .= "\t" . Html::element('option', null, $category) . "\n"; } $text .= "\t</select>\n"; $editButtonsText = "\t" . Html::input('wpSave', wfMsg('savearticle'), 'submit', array('id' => 'wpSave')) . "\n"; $editButtonsText .= "\t" . Html::input('wpPreview', wfMsg('preview'), 'submit', array('id' => 'wpPreview')) . "\n"; $text .= "\t" . Html::rawElement('div', array('class' => 'editButtons'), $editButtonsText) . "\n"; $text .= <<<END \t<br /><hr /<br /> END; $sk = $wgUser->getSkin(); $create_form_link = SFUtils::linkForSpecialPage($sk, 'CreateForm'); $text .= "\t" . Html::rawElement('p', null, $create_form_link . '.') . "\n"; $text .= "\t</form>\n"; $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css"); $wgOut->addHTML($text); }
function printCreateTemplateForm() { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; self::addJavascript(); $text = ''; $save_page = $wgRequest->getCheck('wpSave'); $preview_page = $wgRequest->getCheck('wpPreview'); if ($save_page || $preview_page) { $validToken = $this->getUser()->matchEditToken($wgRequest->getVal('csrf'), 'CreateTemplate'); if (!$validToken) { $text = "This appears to be a cross-site request forgery; canceling save."; $wgOut->addHTML($text); return; } $fields = array(); // Cycle through the query values, setting the // appropriate local variables. foreach ($wgRequest->getValues() as $var => $val) { $var_elements = explode("_", $var); // we only care about query variables of the form "a_b" if (count($var_elements) != 2) { continue; } list($field_field, $id) = $var_elements; if ($field_field == 'name' && $id != 'starter') { $field = SFTemplateField::create($val, $wgRequest->getVal('label_' . $id), $wgRequest->getVal('semantic_property_' . $id), $wgRequest->getCheck('is_list_' . $id)); $fields[] = $field; } } // Assemble the template text, and submit it as a wiki // page. $wgOut->setArticleBodyOnly(true); $template_name = $wgRequest->getVal('template_name'); $title = Title::makeTitleSafe(NS_TEMPLATE, $template_name); $category = $wgRequest->getVal('category'); $aggregating_property = $wgRequest->getVal('semantic_property_aggregation'); $aggregation_label = $wgRequest->getVal('aggregation_label'); $template_format = $wgRequest->getVal('template_format'); $full_text = SFTemplateField::createTemplateText($template_name, $fields, null, $category, $aggregating_property, $aggregation_label, $template_format); $text = SFUtils::printRedirectForm($title, $full_text, "", $save_page, $preview_page, false, false, false, null, null); $wgOut->addHTML($text); return; } $text .= ' <form id="createTemplateForm" action="" method="post">' . "\n"; // Set 'title' field, in case there's no URL niceness $text .= Html::hidden('title', $this->getTitle()->getPrefixedText()) . "\n"; $text .= "\t<p id=\"template_name_p\">" . wfMsg('sf_createtemplate_namelabel') . ' <input size="25" id="template_name" name="template_name" /></p>' . "\n"; $text .= "\t<p>" . wfMsg('sf_createtemplate_categorylabel') . ' <input size="25" name="category" /></p>' . "\n"; $text .= "\t<fieldset>\n"; $text .= "\t" . Html::element('legend', null, wfMsg('sf_createtemplate_templatefields')) . "\n"; $text .= "\t" . Html::element('p', null, wfMsg('sf_createtemplate_fieldsdesc')) . "\n"; $all_properties = self::getAllPropertyNames(); $text .= '<div id="fieldsList">' . "\n"; $text .= self::printFieldEntryBox("1", $all_properties); $text .= self::printFieldEntryBox("starter", $all_properties, false); $text .= "</div>\n"; $add_field_button = Html::input(null, wfMsg('sf_createtemplate_addfield'), 'button', array('onclick' => "createTemplateAddField()")); $text .= Html::rawElement('p', null, $add_field_button) . "\n"; $text .= "\t</fieldset>\n"; $text .= "\t<fieldset>\n"; $text .= "\t" . Html::element('legend', null, wfMsg('sf_createtemplate_aggregation')) . "\n"; $text .= "\t" . Html::element('p', null, wfMsg('sf_createtemplate_aggregationdesc')) . "\n"; $text .= "\t<p>" . wfMsg('sf_createtemplate_semanticproperty') . ' ' . self::printPropertiesDropdown($all_properties, "aggregation") . "</p>\n"; $text .= "\t<p>" . wfMsg('sf_createtemplate_aggregationlabel') . ' ' . Html::input('aggregation_label', null, 'text', array('size' => '25')) . "</p>\n"; $text .= "\t</fieldset>\n"; $text .= "\t<p>" . wfMsg('sf_createtemplate_outputformat') . "\n"; $text .= "\t" . Html::input('template_format', 'standard', 'radio', array('checked' => true), null) . ' ' . wfMsg('sf_createtemplate_standardformat') . "\n"; $text .= "\t" . Html::input('template_format', 'infobox', 'radio', null) . ' ' . wfMsg('sf_createtemplate_infoboxformat') . "</p>\n"; $text .= "\t" . Html::hidden('csrf', $this->getUser()->getEditToken('CreateTemplate')) . "\n"; $save_button_text = wfMsg('savearticle'); $preview_button_text = wfMsg('preview'); $text .= <<<END \t<div class="editButtons"> \t<input type="submit" id="wpSave" name="wpSave" value="{$save_button_text}" /> \t<input type="submit" id="wpPreview" name="wpPreview" value="{$preview_button_text}" /> \t</div> \t</form> END; $sk = $wgUser->getSkin(); $create_property_link = SFUtils::linkForSpecialPage($sk, 'CreateProperty'); $text .= "\t<br /><hr /><br />\n"; $text .= "\t" . Html::rawElement('p', null, $create_property_link . '.') . "\n"; $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css"); $wgOut->addHTML($text); }
function execute($query) { global $wgLang, $smwgContLang; $out = $this->getOutput(); $req = $this->getRequest(); // Check permissions. if (!$this->getUser()->isAllowed('createclass')) { $this->displayRestrictionError(); return; } $this->setHeaders(); $numStartingRows = 5; $out->addJsConfigVars('$numStartingRows', $numStartingRows); $out->addModules(array('ext.semanticforms.SF_CreateClass')); $createAll = $req->getCheck('createAll'); if ($createAll) { // Guard against cross-site request forgeries (CSRF). $validToken = $this->getUser()->matchEditToken($req->getVal('csrf'), 'CreateClass'); if (!$validToken) { $text = "This appears to be a cross-site request forgery; canceling save."; $out->addHTML($text); return; } $this->createAllPages(); return; } $specialBGColor = '#eeffcc'; if (defined('SMW_VERSION')) { $possibleTypes = $smwgContLang->getDatatypeLabels(); } elseif (defined('CARGO_VERSION')) { global $wgCargoFieldTypes; $possibleTypes = $wgCargoFieldTypes; $specialBGColor = ''; } else { $possibleTypes = array(); } // Make links to all the other 'Create...' pages, in order to // link to them at the top of the page. $creation_links = array(); if (defined('SMW_VERSION')) { $creation_links[] = SFUtils::linkForSpecialPage('CreateProperty'); } $creation_links[] = SFUtils::linkForSpecialPage('CreateTemplate'); $creation_links[] = SFUtils::linkForSpecialPage('CreateForm'); $creation_links[] = SFUtils::linkForSpecialPage('CreateCategory'); $text = '<form action="" method="post">' . "\n"; $text .= "\t" . Html::rawElement('p', null, wfMessage('sf_createclass_docu')->rawParams($wgLang->listToText($creation_links))->escaped()) . "\n"; $templateNameLabel = wfMessage('sf_createtemplate_namelabel')->escaped(); $templateNameInput = Html::input('template_name', null, 'text', array('size' => 30)); $text .= "\t" . Html::rawElement('p', null, $templateNameLabel . ' ' . $templateNameInput) . "\n"; $templateInfo = SFCreateTemplate::printTemplateStyleInput('template_format'); $templateInfo .= Html::rawElement('p', null, Html::element('input', array('type' => 'checkbox', 'name' => 'template_multiple', 'id' => 'template_multiple', 'class' => "disableFormAndCategoryInputs")) . ' ' . wfMessage('sf_createtemplate_multipleinstance')->escaped()) . "\n"; // Either #set_internal or #subobject will be added to the // template, depending on whether Semantic Internal Objects is // installed. global $smwgDefaultStore; if (defined('SIO_VERSION') || $smwgDefaultStore == "SMWSQLStore3") { $templateInfo .= Html::rawElement('div', array('id' => 'connecting_property_div', 'style' => 'display: none;'), wfMessage('sf_createtemplate_connectingproperty')->escaped() . "\n" . Html::element('input', array('type' => 'text', 'name' => 'connecting_property'))) . "\n"; } $text .= Html::rawElement('blockquote', null, $templateInfo); $form_name_label = wfMessage('sf_createclass_nameinput')->text(); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'form_name'), $form_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'form_name', 'id' => 'form_name'), null)) . "\n"; $category_name_label = wfMessage('sf_createcategory_name')->text(); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'category_name'), $category_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'category_name', 'id' => 'category_name'), null)) . "\n"; if (defined('CARGO_VERSION') && !defined('SMW_VERSION')) { $cargo_table_label = wfMessage('sf_createtemplate_cargotablelabel')->escaped(); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'cargo_table'), $cargo_table_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'cargo_table', 'id' => 'cargo_table'), null)) . "\n"; } $text .= "\t" . Html::element('br', null, null) . "\n"; $text .= <<<END \t<div> \t\t<table id="mainTable" style="border-collapse: collapse;"> END; if (defined('SMW_VERSION')) { $property_label = wfMessage('smw_pp_type')->escaped(); $text .= <<<END \t\t<tr> \t\t\t<th colspan="3" /> \t\t\t<th colspan="3" style="background: #ddeebb; padding: 4px;">{$property_label}</th> \t\t</tr> END; } $field_name_label = wfMessage('sf_createtemplate_fieldname')->escaped(); $list_of_values_label = wfMessage('sf_createclass_listofvalues')->escaped(); $text .= <<<END \t\t<tr> \t\t\t<th colspan="2">{$field_name_label}</th> \t\t\t<th style="padding: 4px;">{$list_of_values_label}</th> END; if (defined('SMW_VERSION')) { $property_name_label = wfMessage('sf_createproperty_propname')->escaped(); $text .= <<<END \t\t\t<th style="background: {$specialBGColor}; padding: 4px;">{$property_name_label}</th> END; } $type_label = wfMessage('sf_createproperty_proptype')->escaped(); $allowed_values_label = wfMessage('sf_createclass_allowedvalues')->escaped(); $text .= <<<END \t\t\t<th style="background: {$specialBGColor}; padding: 4px;">{$type_label}</th> \t\t\t<th style="background: {$specialBGColor}; padding: 4px;">{$allowed_values_label}</th> \t\t</tr> END; // Make one more row than what we're displaying - use the // last row as a "starter row", to be cloned when the // "Add another" button is pressed. for ($i = 1; $i <= $numStartingRows + 1; $i++) { if ($i == $numStartingRows + 1) { $rowString = 'id="starterRow" style="display: none"'; $n = 'starter'; } else { $rowString = ''; $n = $i; } $text .= <<<END \t\t<tr {$rowString} style="margin: 4px;"> \t\t\t<td>{$n}.</td> \t\t\t<td><input type="text" size="25" name="field_name_{$n}" /></td> \t\t\t<td style="text-align: center;"><input type="checkbox" name="is_list_{$n}" /></td> END; if (defined('SMW_VERSION')) { $text .= <<<END \t\t\t<td style="background: {$specialBGColor}; padding: 4px;"><input type="text" size="25" name="property_name_{$n}" /></td> END; } $text .= <<<END \t\t\t<td style="background: {$specialBGColor}; padding: 4px;"> END; $typeDropdownBody = ''; foreach ($possibleTypes as $typeName) { $typeDropdownBody .= "\t\t\t\t<option>{$typeName}</option>\n"; } $text .= "\t\t\t\t" . Html::rawElement('select', array('name' => "property_type_{$n}"), $typeDropdownBody) . "\n"; $text .= <<<END \t\t\t</td> \t\t\t<td style="background: {$specialBGColor}; padding: 4px;"><input type="text" size="25" name="allowed_values_{$n}" /></td> END; } $text .= <<<END \t\t</tr> \t\t</table> \t</div> END; $add_another_button = Html::element('input', array('type' => 'button', 'value' => wfMessage('sf_formedit_addanother')->text(), 'class' => "createClassAddRow")); $text .= Html::rawElement('p', null, $add_another_button) . "\n"; // Set 'title' as hidden field, in case there's no URL niceness $cc = $this->getTitle(); $text .= Html::hidden('title', SFUtils::titleURLString($cc)); $text .= "\t" . Html::hidden('csrf', $this->getUser()->getEditToken('CreateClass')) . "\n"; $text .= Html::element('input', array('type' => 'submit', 'name' => 'createAll', 'value' => wfMessage('sf_createclass_create')->text())); $text .= "</form>\n"; $out->addHTML($text); }
function execute($query) { global $wgOut, $wgRequest, $wgUser, $sfgScriptPath; global $wgLang, $smwgContLang; // Check permissions. if (!$wgUser->isAllowed('createclass')) { $this->displayRestrictionError(); return; } $this->setHeaders(); $wgOut->addExtensionStyle($sfgScriptPath . "/skins/SemanticForms.css"); $numStartingRows = 5; self::addJavascript($numStartingRows); $createAll = $wgRequest->getCheck('createAll'); if ($createAll) { self::createAllPages(); return; } $datatypeLabels = $smwgContLang->getDatatypeLabels(); // Make links to all the other 'Create...' pages, in order to // link to them at the top of the page. $creation_links = array(); $creation_links[] = SFUtils::linkForSpecialPage('CreateProperty'); $creation_links[] = SFUtils::linkForSpecialPage('CreateTemplate'); $creation_links[] = SFUtils::linkForSpecialPage('CreateForm'); $creation_links[] = SFUtils::linkForSpecialPage('CreateCategory'); $form_name_label = wfMessage('sf_createclass_nameinput')->text(); $category_name_label = wfMessage('sf_createcategory_name')->text(); $field_name_label = wfMessage('sf_createtemplate_fieldname')->text(); $list_of_values_label = wfMessage('sf_createclass_listofvalues')->text(); $property_name_label = wfMessage('sf_createproperty_propname')->text(); $type_label = wfMessage('sf_createproperty_proptype')->text(); $allowed_values_label = wfMessage('sf_createclass_allowedvalues')->text(); $text = '<form action="" method="post">' . "\n"; $text .= "\t" . Html::rawElement('p', null, wfMessage('sf_createclass_docu', $wgLang->listToText($creation_links))->text()) . "\n"; $templateNameLabel = wfMessage('sf_createtemplate_namelabel')->text(); $templateNameInput = Html::input('template_name', null, 'text', array('size' => 30)); $text .= "\t" . Html::rawElement('p', null, $templateNameLabel . ' ' . $templateNameInput) . "\n"; $templateInfo = SFCreateTemplate::printTemplateStyleInput('template_format'); $templateInfo .= Html::rawElement('p', null, Html::element('input', array('type' => 'checkbox', 'name' => 'template_multiple', 'id' => 'template_multiple', 'onclick' => "disableFormAndCategoryInputs()")) . ' ' . wfMessage('sf_createtemplate_multipleinstance')->text()) . "\n"; $text .= Html::rawElement('blockquote', null, $templateInfo); $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'form_name'), $form_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'form_name', 'id' => 'form_name'), null)) . "\n"; $text .= "\t" . Html::rawElement('p', null, Html::element('label', array('for' => 'category_name'), $category_name_label) . ' ' . Html::element('input', array('size' => '30', 'name' => 'category_name', 'id' => 'category_name'), null)) . "\n"; $text .= "\t" . Html::element('br', null, null) . "\n"; $property_label = wfMessage('smw_pp_type')->text(); $text .= <<<END \t<div> \t\t<table id="mainTable" style="border-collapse: collapse;"> \t\t<tr> \t\t\t<th colspan="3" /> \t\t\t<th colspan="3" style="background: #ddeebb; padding: 4px;">{$property_label}</th> \t\t</tr> \t\t<tr> \t\t\t<th colspan="2">{$field_name_label}</th> \t\t\t<th style="padding: 4px;">{$list_of_values_label}</th> \t\t\t<th style="background: #eeffcc; padding: 4px;">{$property_name_label}</th> \t\t\t<th style="background: #eeffcc; padding: 4px;">{$type_label}</th> \t\t\t<th style="background: #eeffcc; padding: 4px;">{$allowed_values_label}</th> \t\t</tr> END; // Make one more row than what we're displaying - use the // last row as a "starter row", to be cloned when the // "Add another" button is pressed. for ($i = 1; $i <= $numStartingRows + 1; $i++) { if ($i == $numStartingRows + 1) { $rowString = 'id="starterRow" style="display: none"'; $n = 'starter'; } else { $rowString = ''; $n = $i; } $text .= <<<END \t\t<tr {$rowString} style="margin: 4px;"> \t\t\t<td>{$n}.</td> \t\t\t<td><input type="text" size="25" name="field_name_{$n}" /></td> \t\t\t<td style="text-align: center;"><input type="checkbox" name="is_list_{$n}" /></td> \t\t\t<td style="background: #eeffcc; padding: 4px;"><input type="text" size="25" name="property_name_{$n}" /></td> \t\t\t<td style="background: #eeffcc; padding: 4px;"> END; $typeDropdownBody = ''; foreach ($datatypeLabels as $label) { $typeDropdownBody .= "\t\t\t\t<option>{$label}</option>\n"; } $text .= "\t\t\t\t" . Html::rawElement('select', array('name' => "property_type_{$n}"), $typeDropdownBody) . "\n"; $text .= <<<END \t\t\t</td> \t\t\t<td style="background: #eeffcc; padding: 4px;"><input type="text" size="25" name="allowed_values_{$n}" /></td> END; } $text .= <<<END \t\t</tr> \t\t</table> \t</div> END; $add_another_button = Html::element('input', array('type' => 'button', 'value' => wfMessage('sf_formedit_addanother')->text(), 'onclick' => "createClassAddRow()")); $text .= Html::rawElement('p', null, $add_another_button) . "\n"; // Set 'title' as hidden field, in case there's no URL niceness $cc = $this->getTitle(); $text .= Html::hidden('title', SFUtils::titleURLString($cc)); $text .= Html::element('input', array('type' => 'submit', 'name' => 'createAll', 'value' => wfMessage('sf_createclass_create')->text())); $text .= "</form>\n"; $wgOut->addHTML($text); }