Example #1
0
 /**
  * Returns the HTML for setting the filter options, for the
  * Semantic Drilldown section in Page Schemas' "edit schema" page
  */
 public static function getFieldEditingHTML($psField)
 {
     //$require_filter_label = wfMessage( 'sd_createfilter_requirefilter' )->text();
     $filter_array = array();
     $hasExistingValues = false;
     if (!is_null($psField)) {
         $filter_array = $psField->getObject('semanticdrilldown_Filter');
         if (!is_null($filter_array)) {
             $hasExistingValues = true;
         }
     }
     $filterName = PageSchemas::getValueFromObject($filter_array, 'name');
     $selectedCategory = PageSchemas::getValueFromObject($filter_array, 'ValuesFromCategory');
     $fromCategoryAttrs = array();
     if (!is_null($selectedCategory)) {
         $fromCategoryAttrs['checked'] = true;
     }
     // Have the first radiobutton ("Use all values of this
     // property for the filter") checked if none of the other
     // options have been selected - unlike the others, there's
     // no XML to define this option.
     $usePropertyValuesAttr = array();
     if (empty($selectedCategory)) {
         $usePropertyValuesAttr['checked'] = true;
     }
     $html_text = '<div class="editSchemaMinorFields">' . "\n";
     $html_text .= '<p>' . wfMessage('ps-optional-name')->text() . ' ';
     $html_text .= Html::input('sd_filter_name_num', $filterName, 'text', array('size' => 25)) . "</p>\n";
     $html_text .= wfMessage('sd-pageschemas-values')->text() . ":\n";
     $html_text .= Html::input('sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr) . ' ';
     $html_text .= wfMessage('sd_createfilter_usepropertyvalues')->text() . "\n";
     $html_text .= Html::input('sd_values_source_num', 'category', 'radio', $fromCategoryAttrs) . "\n";
     $html_text .= "\t" . wfMessage('sd_createfilter_usecategoryvalues')->text() . "\n";
     $categories = SDUtils::getTopLevelCategories();
     $categoriesHTML = "";
     foreach ($categories as $category) {
         $categoryOptionAttrs = array();
         $category = str_replace('_', ' ', $category);
         if ($category == $selectedCategory) {
             $categoryOptionAttrs['selected'] = true;
         }
         $categoriesHTML .= "\t" . Html::element('option', $categoryOptionAttrs, $category) . "\n";
     }
     $html_text .= "\t" . Html::rawElement('select', array('id' => 'category_dropdown', 'name' => 'sd_category_name_num'), "\n" . $categoriesHTML) . "\n";
     $html_text .= "\t</p>\n";
     $html_text .= "\t</div>\n";
     return array($html_text, $hasExistingValues);
 }
Example #2
0
 /**
  * Returns an array of SFTemplateField objects, representing the fields
  * of a template, based on the contents of a <PageSchema> tag.
  */
 public static function getFieldsFromTemplateSchema($psTemplate)
 {
     $psFields = $psTemplate->getFields();
     $templateFields = array();
     foreach ($psFields as $psField) {
         $prop_array = $psField->getObject('semanticmediawiki_Property');
         $propertyName = PageSchemas::getValueFromObject($prop_array, 'name');
         if ($psField->getLabel() === '') {
             $fieldLabel = $psField->getName();
         } else {
             $fieldLabel = $psField->getLabel();
         }
         $templateField = SFTemplateField::create($psField->getName(), $fieldLabel, $propertyName, $psField->isList(), $psField->getDelimiter(), $psField->getDisplay());
         $templateFields[] = $templateField;
     }
     return $templateFields;
 }
Example #3
0
 /**
  * Returns the HTML necessary for getting information about the
  * semantic property within the Page Schemas 'editschema' page.
  */
 public static function getFieldEditingHTML($psTemplateField)
 {
     global $smwgContLang;
     $prop_array = array();
     $hasExistingValues = false;
     if (!is_null($psTemplateField)) {
         $prop_array = $psTemplateField->getObject('semanticmediawiki_Property');
         if (!is_null($prop_array)) {
             $hasExistingValues = true;
         }
     }
     $html_text = '<p>' . wfMessage('ps-optional-name')->text() . ' ';
     $propName = PageSchemas::getValueFromObject($prop_array, 'name');
     $html_text .= Html::input('smw_property_name_num', $propName, array('size' => 15)) . "\n";
     $propType = PageSchemas::getValueFromObject($prop_array, 'Type');
     $select_body = "";
     $datatype_labels = $smwgContLang->getDatatypeLabels();
     foreach ($datatype_labels as $label) {
         $optionAttrs = array();
         if ($label == $propType) {
             $optionAttrs['selected'] = 'selected';
         }
         $select_body .= "\t" . Xml::element('option', $optionAttrs, $label) . "\n";
     }
     $propertyDropdownAttrs = array('id' => 'property_dropdown', 'name' => 'smw_property_type_num', 'value' => $propType);
     $html_text .= "Type: " . Xml::tags('select', $propertyDropdownAttrs, $select_body) . "</p>\n";
     $html_text .= '<p>If you want this property to only be allowed to have certain values, enter the list of allowed values, separated by commas (if a value contains a comma, replace it with "\\,"):</p>';
     $allowedValsInputAttrs = array('size' => 80);
     $allowedValues = PageSchemas::getValueFromObject($prop_array, 'allowed_values');
     if (is_null($allowedValues)) {
         $allowed_val_string = '';
     } else {
         $allowed_val_string = implode(', ', $allowedValues);
     }
     $html_text .= '<p>' . Html::input('smw_values_num', $allowed_val_string, 'text', $allowedValsInputAttrs) . "</p>\n";
     return array($html_text, $hasExistingValues);
 }
	/**
	 * Returns the HTML for setting the filter options, for the
	 * Semantic Drilldown section in Page Schemas' "edit schema" page
	 */
	public static function getFieldEditingHTML( $psField ){
		//$require_filter_label = wfMsg( 'sd_createfilter_requirefilter' );

		$filter_array = array();
		$hasExistingValues = false;
		if ( !is_null( $psField ) ) {
			$filter_array = $psField->getObject( 'semanticdrilldown_Filter' );
			if ( !is_null( $filter_array ) ) {
				$hasExistingValues = true;
			}
		}

		$filterName = PageSchemas::getValueFromObject( $filter_array, 'name' );
		$selectedCategory = PageSchemas::getValueFromObject( $filter_array, 'ValuesFromCategory' );
		$fromCategoryAttrs = array();
		if ( !is_null( $selectedCategory ) ) {
			$fromCategoryAttrs['checked'] = true;
		}
		$dateRangesAttrs = array();
		$year_value = wfMsgForContent( 'sd_filter_year' );
		$yearOptionAttrs = array( 'value' => $year_value );
		$month_value = wfMsgForContent( 'sd_filter_month' );
		$monthOptionAttrs = array( 'value' => $month_value );
		$filterTimePeriod = PageSchemas::getValueFromObject( $filter_array, 'TimePeriod' );
		if ( !is_null( $filterTimePeriod ) ) {
			$dateRangesAttrs['checked'] = true;
			if ( $filterTimePeriod == $year_value ) {
				$yearOptionAttrs['selected'] = true;
			} else {
				$monthOptionAttrs['selected'] = true;
			}
		}
		$manualSourceAttrs = array();
		$filterValuesAttrs = array( 'size' => 40 );
		$values_array = PageSchemas::getValueFromObject( $filter_array, 'Values' );
		if ( !is_null( $values_array ) ) {
			$manualSourceAttrs['checked'] = true;
			$filterValuesStr = implode( ', ', $values_array );
		} else {
			$filterValuesStr = '';
		}
		// Have the first radiobutton ("Use all values of this
		// property for the filter") checked if none of the other
		// options have been selected - unlike the others, there's
		// no XML to define this option.
		$usePropertyValuesAttr = array();
		if ( empty( $selectedCategory ) && empty( $filterTimePeriod ) && empty( $filterValuesStr ) ) {
			$usePropertyValuesAttr['checked'] = true;
		}

		// The "input type" field.
		$combo_box_value = wfMsgForContent( 'sd_filter_combobox' );
		$date_range_value = wfMsgForContent( 'sd_filter_daterange' );
		$valuesListAttrs = array( 'value' => '' );
		$comboBoxAttrs = array( 'value' => $combo_box_value );
		$dateRangeAttrs = array( 'value' => $date_range_value );
		$input_type_val = PageSchemas::getValueFromObject( $filter_array, 'InputType' );
		if ( $input_type_val == $combo_box_value ) {
			$comboBoxAttrs['selected'] = true;
		} elseif ( $input_type_val == $date_range_value ) {
			$dateRangeAttrs['selected'] = true;
		} else {
			$valuesListAttrs['selected'] = true;
		}

		$html_text = '<p>' . wfMsg( 'ps-optional-name' ) . ' ';
		$html_text .= Html::input( 'sd_filter_name_num', $filterName, 'text', array( 'size' => 25 ) ) . "</p>\n";
		$html_text .= '<fieldset><legend>' . wfMsg( 'sd-pageschemas-values' ) . '</legend>' . "\n";
		$html_text .= '<p>' . Html::input( 'sd_values_source_num', 'property', 'radio', $usePropertyValuesAttr ) . ' ';
		$html_text .= wfMsg( 'sd_createfilter_usepropertyvalues' ) . "</p>\n";
		$html_text .= "\t<p>\n";
		$html_text .= Html::input( 'sd_values_source_num', 'category', 'radio', $fromCategoryAttrs ) . "\n";
		$html_text .= "\t" . wfMsg( 'sd_createfilter_usecategoryvalues' ) . "\n";
		$categories = SDUtils::getTopLevelCategories();
		$categoriesHTML = "";
		foreach ( $categories as $category ) {
			$categoryOptionAttrs = array();
			$category = str_replace( '_', ' ', $category );
			if ( $category == $selectedCategory) {
				$categoryOptionAttrs['selected'] = true;
			}
			$categoriesHTML .= "\t" . Html::element( 'option', $categoryOptionAttrs, $category ) . "\n";
		}
		$html_text .= "\t" . Html::rawElement( 'select', array( 'id' => 'category_dropdown', 'name' => 'sd_category_name_num' ), "\n" . $categoriesHTML ) . "\n";
		$html_text .= "\t</p>\n";

		$html_text .= "\t<p>\n";
		$html_text .= "\t" . Html::input( 'sd_values_source_num', 'dates', 'radio', $dateRangesAttrs ) . "\n";
		$html_text .= "\t" . wfMsg( 'sd_createfilter_usedatevalues' ) . "\n";
		$dateRangeDropdown = Html::element( 'option', $yearOptionAttrs, wfMsg( 'sd_filter_year' ) ) . "\n";
		$dateRangeDropdown .= Html::element( 'option', $monthOptionAttrs, wfMsg( 'sd_filter_month' ) ) . "\n";
		$html_text .= Html::rawElement( 'select', array( 'name' => 'sd_time_period_num', 'id' => 'time_period_dropdown' ), "\n" . $dateRangeDropdown ) . "\n";
		$html_text .= "</p>\n<p>\n";
		$html_text .= "\t" . Html::input( 'sd_values_source_num', 'manual', 'radio', $manualSourceAttrs ) . "\n";
		$html_text .= "\t" . wfMsg( 'sd_createfilter_entervalues' ) . "\n";
		$html_text .= "\t" . Html::input( 'sd_filter_values_num', $filterValuesStr, 'text', $filterValuesAttrs ) . "\n";
		$html_text .= "\t</p>\n";
		$html_text .= "</fieldset>\n";

		$html_text .= '<p>' . wfMsg( 'sd_createfilter_inputtype' ) . "\n";
		$inputTypeOptionsHTML = "\t" . Html::element( 'option', $valuesListAttrs, wfMsg( 'sd_createfilter_listofvalues' ) ) . "\n";
		$inputTypeOptionsHTML .= "\t" . Html::element( 'option', $comboBoxAttrs, wfMsg( 'sd_filter_combobox' ) ) . "\n";
		$inputTypeOptionsHTML .= "\t" . Html::element( 'option', $dateRangeAttrs, wfMsg( 'sd_filter_daterange' ) ) . "\n";
		$html_text .= Html::rawElement( 'select', array( 'name' => 'sd_input_type_num', 'id' => 'input_type_dropdown' ), $inputTypeOptionsHTML ) . "\n";
		$html_text .= "</p>\n";

		return array( $html_text, $hasExistingValues );
	}
Example #5
0
 /**
  * Generate pages (form and templates) specified in the list.
  */
 public static function generatePages($pageSchemaObj, $selectedPages)
 {
     global $wgUser;
     $psFormItems = $pageSchemaObj->getFormItemsList();
     $form_items = array();
     $jobs = array();
     $templateHackUsed = false;
     $isCategoryNameSet = false;
     // Generate every specified template
     foreach ($psFormItems as $psFormItem) {
         if ($psFormItem['type'] == 'Template') {
             $psTemplate = $psFormItem['item'];
             $templateName = $psTemplate->getName();
             $templateTitle = Title::makeTitleSafe(NS_TEMPLATE, $templateName);
             $fullTemplateName = PageSchemas::titleString($templateTitle);
             $template_fields = self::getFieldsFromTemplateSchema($psTemplate);
             // Get property for use in either #set_internal
             // or #subobject, defined by either SIO's or
             // SMW's Page Schemas portion. We don't need
             // to record which one it came from, because
             // SF's code to generate the template runs its
             // own, similar check.
             // @TODO - $internalObjProperty should probably
             // have a more generic name.
             if (class_exists('SIOPageSchemas')) {
                 $internalObjProperty = SIOPageSchemas::getInternalObjectPropertyName($psTemplate);
             } elseif (method_exists('SMWPageSchemas', 'getConnectingPropertyName')) {
                 $internalObjProperty = SMWPageSchemas::getConnectingPropertyName($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 {
                 if ($isCategoryNameSet == false) {
                     $categoryName = $pageSchemaObj->getCategoryName();
                     $isCategoryNameSet = true;
                 } else {
                     $categoryName = null;
                 }
             }
             if (method_exists($psTemplate, 'getFormat')) {
                 $templateFormat = $psTemplate->getFormat();
             } else {
                 $templateFormat = null;
             }
             $sfTemplate = new SFTemplate($templateName, $template_fields);
             $sfTemplate->setConnectingProperty($internalObjProperty);
             $sfTemplate->setCategoryName($categoryName);
             $sfTemplate->setFormat($templateFormat);
             // Set Cargo table, if one was set in the schema.
             $cargoArray = $psTemplate->getObject('cargo_TemplateDetails');
             if (!is_null($cargoArray)) {
                 $sfTemplate->mCargoTable = PageSchemas::getValueFromObject($cargoArray, 'Table');
             }
             $templateText = $sfTemplate->createText();
             if (in_array($fullTemplateName, $selectedPages)) {
                 $params = array();
                 $params['user_id'] = $wgUser->getId();
                 $params['page_text'] = $templateText;
                 $jobs[] = new PSCreatePageJob($templateTitle, $params);
                 if (strpos($templateText, '{{!}}') > 0) {
                     $templateHackUsed = true;
                 }
             }
             $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_items[] = array('type' => 'template', 'name' => $form_template->getTemplateName(), 'item' => $form_template);
         } elseif ($psFormItem['type'] == 'Section') {
             $psPageSection = $psFormItem['item'];
             $form_section = self::getPageSection($psPageSection);
             $form_section->setSectionLevel($psPageSection->getSectionLevel());
             $form_items[] = array('type' => 'section', 'name' => $form_section->getSectionName(), 'item' => $form_section);
         }
     }
     // Create the "!" hack template, if it's necessary
     if ($templateHackUsed) {
         $templateTitle = Title::makeTitleSafe(NS_TEMPLATE, '!');
         if (!$templateTitle->exists()) {
             $params = array();
             $params['user_id'] = $wgUser->getId();
             $params['page_text'] = '|';
             $jobs[] = new PSCreatePageJob($templateTitle, $params);
         }
     }
     if (class_exists('JobQueueGroup')) {
         JobQueueGroup::singleton()->push($jobs);
     } else {
         // MW <= 1.20
         Job::batchInsert($jobs);
     }
     // Create form, if it's specified.
     $formName = self::getFormName($pageSchemaObj);
     $categoryName = $pageSchemaObj->getCategoryName();
     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_items, $formInfo, $categoryName);
         }
     }
 }
Example #6
0
 static function getInternalObjectPropertyName($psTemplate)
 {
     // TODO - there should be a more direct way to get
     // this data.
     $sioPropertyArray = $psTemplate->getObject('semanticinternalobjects_MainProperty');
     return PageSchemas::getValueFromObject($sioPropertyArray, 'name');
 }