Example #1
0
	public static function displayTabs( $obj, &$content_actions ) {
		global $wgUser;

		$title = $obj->getTitle();
		if ( $title->getNamespace() != NS_CATEGORY ){
			return true;
		}

		$category = $title->getText();
		$pageSchemaObj = new PSSchema( $category );
		$isPSDefined = $pageSchemaObj->isPSDefined();

		global $wgTitle, $wgRequest;

		if ( $wgUser->isAllowed( 'edit' ) && $wgTitle->userCan( 'edit' ) ) {
			$content_actions['editschema'] = array(
				'text' => ( $isPSDefined ) ? wfMsg( 'editschema' ) : wfMsg( 'createschema' ),
				'class' => $wgRequest->getVal( 'action' ) == 'editschema' ? 'selected' : '',
				'href' => $title->getLocalURL( 'action=editschema' )
			);
		}

		if ( $isPSDefined && $wgUser->isAllowed( 'generatepages' ) ) {
			$content_actions['generatepages'] = array(
				'text' => wfMsg( 'generatepages' ),
				'class' => $wgRequest->getVal( 'action' ) == 'generatepages' ? 'selected' : '',
				'href' => $title->getLocalURL( 'action=generatepages' )
			);
		}

		return true;
	}
Example #2
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;
    }
 /**
  * Get the form(s) used to edit this page - either:
  * - the default form(s) for the page itself, if there are any; or
  * - the default form(s) for a category that this article belongs to,
  * if there are any; or
  * - the default form(s) for the article's namespace, if there are any.
  */
 static function getDefaultFormsForPage($title)
 {
     // See if the page itself has a default form (or forms), and
     // return it/them if so.
     // (Disregard category pages for this check.)
     if ($title->getNamespace() != NS_CATEGORY) {
         $default_form = self::getDefaultForm($title);
         if ($default_form != '') {
             return array($default_form);
         }
     }
     $default_forms = self::getFormsThatPagePointsTo($title->getText(), $title->getNamespace(), self::PAGE_DEFAULT_FORM);
     if (count($default_forms) > 0) {
         return $default_forms;
     }
     // If this is not a category page, look for a default form
     // for its parent category or categories.
     $namespace = $title->getNamespace();
     if (NS_CATEGORY !== $namespace) {
         $default_forms = array();
         $categories = SFUtils::getCategoriesForPage($title);
         foreach ($categories as $category) {
             if (class_exists('PSSchema')) {
                 // Check the Page Schema, if one exists.
                 $psSchema = new PSSchema($category);
                 if ($psSchema->isPSDefined()) {
                     $formName = SFPageSchemas::getFormName($psSchema);
                     if (!is_null($formName)) {
                         $default_forms[] = $formName;
                     }
                 }
             }
             $categoryPage = Title::makeTitleSafe(NS_CATEGORY, $category);
             $defaultFormForCategory = self::getDefaultForm($categoryPage);
             if ($defaultFormForCategory != '') {
                 $default_forms[] = $defaultFormForCategory;
             }
             $default_forms = array_merge($default_forms, self::getFormsThatPagePointsTo($category, NS_CATEGORY, self::DEFAULT_FORM));
         }
         if (count($default_forms) > 0) {
             // It is possible for two categories to have the same default form, so purge any
             // duplicates from the array to avoid a "more than one default form" warning.
             return array_unique($default_forms);
         }
     }
     // All that's left is checking for the namespace. If this is
     // a subpage, exit out - default forms for namespaces don't
     // apply to subpages.
     if ($title->isSubpage()) {
         return array();
     }
     // If we're still here, just return the default form for the
     // namespace, which may well be null.
     if (NS_MAIN === $namespace) {
         // If it's in the main (blank) namespace, check for the
         // file named with the word for "Main" in this language.
         $namespace_label = wfMessage('sf_blank_namespace')->inContentLanguage()->text();
     } else {
         global $wgContLang;
         $namespace_labels = $wgContLang->getNamespaces();
         $namespace_label = $namespace_labels[$namespace];
     }
     $namespacePage = Title::makeTitleSafe(NS_PROJECT, $namespace_label);
     $default_form = self::getDefaultForm($namespacePage);
     if ($default_form != '') {
         return array($default_form);
     }
     $default_forms = self::getFormsThatPagePointsTo($namespace_label, NS_PROJECT, self::DEFAULT_FORM);
     return $default_forms;
 }
	/**
	 * Get the form(s) used to edit this page - either:
	 * - the default form(s) for the page itself, if there are any; or
	 * - the default form(s) for a category that this article belongs to,
	 * if there are any; or
	 * - the default form(s) for the article's namespace, if there are any.
	 */
	static function getDefaultFormsForPage( $title ) {
		// See if the page itself has a default form (or forms), and
		// return it/them if so.
		$default_forms = self::getFormsThatPagePointsTo( $title->getText(), $title->getNamespace(), self::PAGE_DEFAULT_FORM );
		if ( count( $default_forms ) > 0 ) {
			return $default_forms;
		}
		// If this is not a category page, look for a default form
		// for its parent category or categories.
		$namespace = $title->getNamespace();
		if ( NS_CATEGORY !== $namespace ) {
			$default_forms = array();
			$categories = SFUtils::getCategoriesForPage( $title );
			foreach ( $categories as $category ) {
				if ( class_exists( 'PSSchema' ) ) {
					// Check the Page Schema, if one exists.
					$psSchema = new PSSchema( $category );
					if ( $psSchema->isPSDefined() ) {
						$formName = SFPageSchemas::getFormName( $psSchema );
						if ( !is_null( $formName ) ) {
							$default_forms[] = $formName;
						}
					}
				}
				$default_forms = array_merge( $default_forms, self::getFormsThatPagePointsTo( $category, NS_CATEGORY, self::DEFAULT_FORM ) );
			}
			if ( count( $default_forms ) > 0 ) {
				return $default_forms;
			}
		}

		// All that's left is checking for the namespace. If this is
		// a subpage, exit out - default forms for namespaces don't
		// apply to subpages.
		if ( $title->isSubpage() ) {
			return array();
		}

		// If we're still here, just return the default form for the
		// namespace, which may well be null.
		if ( NS_MAIN === $namespace ) {
			// If it's in the main (blank) namespace, check for the
			// file named with the word for "Main" in this language.
			$namespace_label = wfMsgForContent( 'sf_blank_namespace' );
		} else {
			global $wgContLang;
			$namespace_labels = $wgContLang->getNamespaces();
			$namespace_label = $namespace_labels[$namespace];
		}
		$default_forms = self::getFormsThatPagePointsTo( $namespace_label, NS_PROJECT, self::DEFAULT_FORM );
		return $default_forms;
	}
	/**
	 * Creates all the pages that the user specified.
	 */
	function generatePages( $categoryName, $selectedPageList ) {
		$pageSchema = new PSSchema( $categoryName );
		$pageSchema->generateAllPages( $selectedPageList );
	}
Example #6
0
 /**
  * Gets all the filters specified for a category.
  */
 static function loadFiltersForCategory($category)
 {
     $filters = array();
     $title = Title::newFromText($category, NS_CATEGORY);
     $pageId = $title->getArticleID();
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('page_props', array('pp_value'), array('pp_page' => $pageId, 'pp_propname' => 'SDFilters'));
     while ($row = $dbr->fetchRow($res)) {
         // There should only be one row.
         $filtersStr = $row['pp_value'];
         $filtersInfo = unserialize($filtersStr);
         foreach ($filtersInfo as $filterName => $filterValues) {
             $curFilter = new SDFilter();
             $curFilter->setName($filterName);
             foreach ($filterValues as $key => $value) {
                 if ($key == 'property') {
                     $curFilter->setProperty($value);
                     $curFilter->loadPropertyTypeFromProperty();
                 } elseif ($key == 'category') {
                     $curFilter->setCategory($value);
                 } elseif ($key == 'requires') {
                     $curFilter->addRequiredFilter($value);
                 }
             }
             $filters[] = $curFilter;
         }
     }
     // Get "legacy" filters defined via the SMW special property
     // "Has filter" and the Filter: namespace.
     $filter_names = SDUtils::getValuesForProperty(str_replace(' ', '_', $category), NS_CATEGORY, '_SD_F');
     foreach ($filter_names as $filter_name) {
         $filter = SDFilter::load($filter_name);
         $filter->required_filters = SDUtils::getValuesForProperty($filter_name, SD_NS_FILTER, '_SD_RF', SD_SP_REQUIRES_FILTER, SD_NS_FILTER);
         $filters[] = $filter;
     }
     // Read from the Page Schemas schema for this category, if
     // it exists, and add any filters defined there.
     if (class_exists('PSSchema')) {
         $pageSchemaObj = new PSSchema($category);
         if ($pageSchemaObj->isPSDefined()) {
             $filters_ps = SDFilter::loadAllFromPageSchema($pageSchemaObj);
             $result_filters = array_merge($filters, $filters_ps);
             return $result_filters;
         }
     }
     return $filters;
 }
	function __construct( $templateXML ) {
		$this->mTemplateXML = $templateXML;
		$this->mTemplateName = (string) $templateXML->attributes()->name;
		if( ((string) $templateXML->attributes()->multiple) == "multiple" ) {
			$this->mMultipleAllowed = true;
		}
		// Index for template objects
		$i = 0 ;
		$inherited_fields = array();
		foreach ($templateXML->children() as $child) {
			if ( $child->getName() == 'InheritsFrom' ) {
				$schema_to_inherit = (string) $child->attributes()->schema;
				$template_to_inherit = (string) $child->attributes()->template;
				if ( $schema_to_inherit != null && $template_to_inherit != null ) {
					$inheritedSchemaObj = new PSSchema( $schema_to_inherit );
					$inherited_templates = $inheritedSchemaObj->getTemplates();
					foreach( $inherited_templates as $inherited_template ) {
						if( $template_to_inherit == $inherited_template->getName() ){
							$inherited_fields = $inherited_template->getFields();
						}
					}
				}
			} elseif ( $child->getName() == "Field" ) {
				$ignore = (string) $child->attributes()->ignore;
				if ( count($child->children()) > 0 ) { //@TODO :Can be dealt more efficiently
					$fieldObj = new PSTemplateField( $child );
					$this->mFields[$i++]= $fieldObj;
				} elseif ( $ignore != "true" ) {
					// Code to add fields from inherited templates
					$field_name = (string) $child->attributes()->name;
					foreach ( $inherited_fields as $inherited_field ) {
						if ( $field_name == $inherited_field->getName() ) {
							$this->mFields[$i++]= $inherited_field;
						}
					}
				}
			}
		}
	}
	/**
	 * Gets all the filters specified for a category.
	 */
	static function loadFiltersForCategory( $category ) {
		$filters = array();
		$filters_ps = array();
		$filter_names = SDUtils::getValuesForProperty( str_replace( ' ', '_', $category ), NS_CATEGORY, '_SD_F' );
		foreach ( $filter_names as $filter_name ) {
			$filters[] = SDFilter::load( $filter_name );
		}
		// Read from the Page Schemas schema for this category, if
		// it exists, and add any filters defined there.
		if ( class_exists( 'PSSchema' ) ) {
			$pageSchemaObj = new PSSchema( $category );
			if ( $pageSchemaObj->isPSDefined() ) {
				$filters_ps = SDFilter::loadAllFromPageSchema( $pageSchemaObj );
				$result_filters = array_merge( $filters, $filters_ps );
				return $result_filters;
			}
		}
		return $filters;
	}