Example #1
0
    function execute($category)
    {
        global $wgUser, $wgRequest, $wgOut, $wgPageSchemasHandlerClasses;
        if (!$wgUser->isAllowed('generatepages')) {
            $wgOut->permissionRequired('generatepages');
            return;
        }
        $this->setHeaders();
        $param = $wgRequest->getText('param');
        if (!empty($param) && !empty($category)) {
            // Generate the pages!
            $this->generatePages($param, $wgRequest->getArray('page'));
            $text = Html::element('p', null, wfMessage('ps-generatepages-success')->parse());
            $wgOut->addHTML($text);
            return true;
        }
        if ($category == "") {
            // No category listed.
            // TODO - show an error message.
            return true;
        }
        // Standard "generate pages" form, with category name set.
        // Check for a valid category, with a page schema defined.
        $pageSchemaObj = new PSSchema($category);
        if (!$pageSchemaObj->isPSDefined()) {
            $text = Html::element('p', null, wfMessage('ps-generatepages-noschema')->parse());
            $wgOut->addHTML($text);
            return true;
        }
        $text = Html::element('p', null, wfMessage('ps-generatepages-desc')->parse()) . "\n";
        $text .= '<form method="post">';
        $text .= Html::input('param', $category, 'hidden') . "\n";
        $text .= '<div id="ps_check_all_check_none">
		<input type="button" id="ps_check_all" value="' . wfMessage('powersearch-toggleall')->parse() . '" />
		<input type="button" id="ps_check_none" value="' . wfMessage('powersearch-togglenone')->parse() . '" />
		</div><br/>';
        $wgOut->addModules('ext.pageschemas.generatepages');
        // This hook will set an array of strings, with each value
        // as a title of a page to be created.
        $pageList = array();
        foreach ($wgPageSchemasHandlerClasses as $psHandlerClass) {
            $pagesFromHandler = call_user_func(array($psHandlerClass, "getPagesToGenerate"), $pageSchemaObj);
            foreach ($pagesFromHandler as $page) {
                $pageList[] = $page;
            }
        }
        foreach ($pageList as $page) {
            if (!$page instanceof Title) {
                continue;
            }
            $pageName = PageSchemas::titleString($page);
            $text .= Html::input('page[]', $pageName, 'checkbox', array('checked' => true));
            $text .= "\n" . Linker::link($page) . "<br />\n";
        }
        $text .= "<br />\n";
        $text .= Html::input(null, wfMessage('generatepages')->parse(), 'submit');
        $text .= "\n</form>";
        $wgOut->addHTML($text);
        return true;
    }
Example #2
0
 public static function render($input, $args, $parser, $frame)
 {
     // Disable cache so that CSS will get loaded.
     $parser->disableCache();
     // If this call is contained in a transcluded page or template,
     // or if the input is empty, display nothing.
     if (!$frame->title->equals($parser->getTitle()) || $input == '') {
         return;
     }
     // TODO: Do processing here, like parse to an array
     $error_msg = null;
     // Recreate the top-level <PageSchema> tag, with whatever
     // attributes it contained, because that was actually a tag-
     // function call, as opposed to a real XML tag.
     $input = Xml::tags('PageSchema', $args, $input);
     if ($xml_object = PageSchemas::validateXML($input, $error_msg)) {
         // Store the XML in the page_props table
         $parser->getOutput()->setProperty('PageSchema', $input);
         // Display the schema on the screen
         global $wgOut, $wgScriptPath;
         $wgOut->addStyle($wgScriptPath . '/extensions/PageSchemas/PageSchemas.css');
         $text = PageSchemas::displaySchema($xml_object);
     } else {
         // Store error message in the page_props table
         $parser->getOutput()->setProperty('PageSchema', $error_msg);
         $text = Html::element('p', null, "The (incorrect) XML definition for this template is:") . "\n";
         $text .= Html::element('pre', null, $input);
     }
     return $text;
 }
Example #3
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 #4
0
    function execute($category)
    {
        global $wgRequest, $wgOut, $wgUser, $wgTitle;
        // If a category has been selected (i.e., it's not just
        // Special:EditSchema), only display this if the user is
        // allowed to edit the category page.
        if (!is_null($category) && (!$wgUser->isAllowed('edit') || !$wgTitle->userCan('edit'))) {
            $wgOut->permissionRequired('edit');
            return;
        }
        $this->setHeaders();
        $text = '<p>' . wfMessage('ps-page-desc-edit-schema')->parse() . '</p>';
        PageSchemas::addJavascriptAndCSS();
        $save_page = $wgRequest->getCheck('wpSave');
        if ($save_page) {
            $psXML = self::createPageSchemaXMLFromForm();
            $categoryTitle = Title::newFromText($category, NS_CATEGORY);
            $categoryArticle = new Article($categoryTitle);
            if ($categoryTitle->exists()) {
                $pageText = $categoryArticle->getContent();
                $pageSchemaObj = new PSSchema($category);
                if ($pageSchemaObj->isPSDefined()) {
                    // Do some preg_replace magic.
                    // This is necessary if the <PageSchema> tag
                    // accepts any attributes - which it currently
                    // does not, but it may well in the future.
                    $tag = "PageSchema";
                    $pageText = preg_replace('{<' . $tag . '[^>]*>([^@]*?)</' . $tag . '>' . '}', $psXML, $pageText);
                } else {
                    $pageText = $psXML . $pageText;
                }
            } else {
                $pageText = $psXML;
            }
            $editSummary = $wgRequest->getVal('wpSummary');
            $categoryArticle->doEdit($pageText, $editSummary);
            $redirectURL = $categoryTitle->getLocalURL();
            $text = <<<END
\t\t<script type="text/javascript">
\t\twindow.onload = function() {
\t\t\twindow.location="{$redirectURL}";
\t\t}
\t\t</script>

END;
            $wgOut->addHTML($text);
            return true;
        }
        if ($category == "") {
            // No category was specified - show the list of
            // categories with a page schema defined.
            $text = self::showLinksToCategories();
            $wgOut->addHTML($text);
            return true;
        }
        // We have a category - show a form.
        // See if a page schema has already been defined for this category.
        $title = Title::newFromText($category, NS_CATEGORY);
        $pageId = $title->getArticleID();
        $dbr = wfGetDB(DB_SLAVE);
        $res = $dbr->select('page_props', array('pp_page', 'pp_propname', 'pp_value'), array('pp_page' => $pageId));
        $row = $dbr->fetchRow($res);
        if ($row == null && !$title->exists()) {
            // Category doesn't exist.
            $wgOut->setPageTitle(wfMessage('createschema')->parse());
            $text = '<p>' . wfMessage('ps-page-desc-cat-not-exist')->parse() . '</p>';
            $text .= self::printForm();
        } elseif ($row[1] != 'PageSchema' || $row[2] == null) {
            // Category exists, but has no page schema.
            $text = '<p>' . wfMessage('ps-page-desc-ps-not-exist')->parse() . '</p>';
            $wgOut->setPageTitle(wfMessage('createschema')->parse());
            $text .= self::printForm();
        } else {
            // It's a category with an existing page schema -
            // populate the form with its values.
            $pageSchemaObj = new PSSchema($category);
            $pageXMLstr = $row[2];
            $pageXML = simplexml_load_string($pageXMLstr);
            $text = self::printForm($pageSchemaObj, $pageXML);
        }
        $wgOut->addHTML($text);
        return true;
    }
Example #5
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);
         }
     }
 }
	function execute( $category ) {
		global $wgUser, $wgRequest, $wgOut, $wgPageSchemasHandlerClasses;

		if ( ! $wgUser->isAllowed( 'generatepages' ) ) {
			$wgOut->permissionRequired( 'generatepages' );
			return;
		}

		$this->setHeaders();
		$param = $wgRequest->getText('param');
		if ( !empty( $param ) && !empty( $category ) ) {
			// Generate the pages!
			$this->generatePages( $param, $wgRequest->getArray( 'page' ) );
			$text = Html::element( 'p', null, wfMsg( 'ps-generatepages-success' ) );
			$wgOut->addHTML( $text );
			return true;
		}

		if ( $category == "") {
			// No category listed.
			// TODO - show an error message.
			return true;
		}

		// Standard "generate pages" form, with category name set.
		// Check for a valid category, with a page schema defined.
		$pageSchemaObj = new PSSchema( $category );
		if ( !$pageSchemaObj->isPSDefined() ) {
			$text = Html::element( 'p', null, wfMsg( 'ps-generatepages-noschema' ) );
			$wgOut->addHTML( $text );
			return true;
		}

		$text = Html::element( 'p', null, wfMsg( 'ps-generatepages-desc' ) ) . "\n";
		$text .= '<form method="post">';
		$text .= Html::input( 'param', $category, 'hidden' ) . "\n";

		// This hook will set an array of strings, with each value
		// as a title of a page to be created.
		$pageList = array();
		foreach ( $wgPageSchemasHandlerClasses as $psHandlerClass ) {
			$pagesFromHandler = call_user_func( array( $psHandlerClass, "getPagesToGenerate" ), $pageSchemaObj );
			foreach ( $pagesFromHandler as $page ) {
				$pageList[] = $page;
			}
		}
		// SpecialPage::getSkin() was added in MW 1.18
		if ( is_callable( $this, 'getSkin' ) ) {
			$skin = $this->getSkin();
		} else {
			global $wgUser;
			$skin = $wgUser->getSkin();
		}
		foreach ( $pageList as $page ) {
			if ( !( $page instanceof Title ) ) { continue; }
			$pageName = PageSchemas::titleString( $page );
			$text .= Html::input( 'page[]', $pageName, 'checkbox', array( 'checked' => true ) );
			$text .= "\n" . $skin->link( $page ) . "<br />\n";
		}
		$text .= "<br />\n";
		$text .= Html::input( null, wfMsg( 'generatepages' ), 'submit' );
		$text .= "\n</form>";
		$wgOut->addHTML( $text );
		return true;
	}
Example #7
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 #9
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 #10
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');
 }