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 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);
    }
Exemple #3
0
 /**
  * Generate pages (form and templates) specified in the list.
  */
 public static function generatePages($pageSchemaObj, $selectedPages)
 {
     global $wgUser;
     $psTemplates = $pageSchemaObj->getTemplates();
     $form_templates = array();
     $jobs = array();
     foreach ($psTemplates as $psTemplate) {
         // Generate every specified template
         $templateName = $psTemplate->getName();
         $templateTitle = Title::makeTitleSafe(NS_TEMPLATE, $templateName);
         $fullTemplateName = PageSchemas::titleString($templateTitle);
         $template_fields = self::getFieldsFromTemplateSchema($psTemplate);
         if (class_exists('SIOPageSchemas')) {
             $internalObjProperty = SIOPageSchemas::getInternalObjectPropertyName($psTemplate);
         } else {
             $internalObjProperty = null;
         }
         // TODO - actually, the category-setting should be
         // smarter than this: if there's more than one
         // template in the schema, it should probably be only
         // the first non-multiple template that includes the
         // category tag.
         if ($psTemplate->isMultiple()) {
             $categoryName = null;
         } else {
             $categoryName = $pageSchemaObj->getCategoryName();
         }
         $templateText = SFTemplateField::createTemplateText($templateName, $template_fields, $internalObjProperty, $categoryName, null, null, null);
         if (in_array($fullTemplateName, $selectedPages)) {
             $params = array();
             $params['user_id'] = $wgUser->getId();
             $params['page_text'] = $templateText;
             $jobs[] = new PSCreatePageJob($templateTitle, $params);
         }
         $templateValues = self::getTemplateValues($psTemplate);
         if (array_key_exists('Label', $templateValues)) {
             $templateLabel = $templateValues['Label'];
         } else {
             $templateLabel = null;
         }
         $form_fields = self::getFormFieldInfo($psTemplate, $template_fields);
         // Create template info for form, for use in generating
         // the form (if it will be generated).
         $form_template = SFTemplateInForm::create($templateName, $templateLabel, $psTemplate->isMultiple(), null, $form_fields);
         $form_templates[] = $form_template;
     }
     Job::batchInsert($jobs);
     // Create form, if it's specified.
     $formName = self::getFormName($pageSchemaObj);
     if (!empty($formName)) {
         $formInfo = self::getMainFormInfo($pageSchemaObj);
         $formTitle = Title::makeTitleSafe(SF_NS_FORM, $formName);
         $fullFormName = PageSchemas::titleString($formTitle);
         if (in_array($fullFormName, $selectedPages)) {
             self::generateForm($formName, $formTitle, $form_templates, $formInfo, $categoryName);
         }
     }
 }
Exemple #4
0
 static function createAllPages()
 {
     global $wgOut, $wgRequest, $wgUser;
     $template_name = trim($wgRequest->getVal("template_name"));
     $template_multiple = $wgRequest->getBool("template_multiple");
     // If this is a multiple-instance template, there
     // shouldn't be a corresponding form or category.
     if ($template_multiple) {
         $form_name = null;
         $category_name = null;
     } else {
         $form_name = trim($wgRequest->getVal("form_name"));
         $category_name = trim($wgRequest->getVal("category_name"));
     }
     if ($template_name === '' || !$template_multiple && ($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("field_name_{$i}"); $i++) {
         // go through the query values, setting the appropriate local variables
         $property_name = trim($wgRequest->getVal("property_name_{$i}"));
         $field_name = trim($wgRequest->getVal("field_name_{$i}"));
         $property_type = $wgRequest->getVal("property_type_{$i}");
         $allowed_values = $wgRequest->getVal("allowed_values_{$i}");
         $is_list = $wgRequest->getCheck("is_list_{$i}");
         // Create an SFTemplateField object 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.
         if (!empty($property_name)) {
             $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 (might as well save
     // one page, instead of just creating jobs for all of them).
     $template_format = $wgRequest->getVal("template_format");
     $full_text = SFTemplateField::createTemplateText($template_name, $fields, null, $category_name, null, null, $template_format);
     $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');
 }