Esempio n. 1
0
 /**
  * Run job
  * @return boolean success
  */
 function run()
 {
     wfProfileIn('SMWUpdateJob::run (SMW)');
     global $wgParser;
     LinkCache::singleton()->clear();
     if (is_null($this->title)) {
         $this->error = "SMWUpdateJob: Invalid title";
         wfProfileOut('SMWUpdateJob::run (SMW)');
         return false;
     } elseif (!$this->title->exists()) {
         smwfGetStore()->deleteSubject($this->title);
         // be sure to clear the data
         wfProfileOut('SMWUpdateJob::run (SMW)');
         return true;
     }
     $revision = Revision::newFromTitle($this->title);
     if (!$revision) {
         $this->error = 'SMWUpdateJob: Page exists but no revision was found for "' . $this->title->getPrefixedDBkey() . '"';
         wfProfileOut('SMWUpdateJob::run (SMW)');
         return false;
     }
     wfProfileIn(__METHOD__ . '-parse');
     $options = new ParserOptions();
     $output = $wgParser->parse($revision->getText(), $this->title, $options, true, true, $revision->getID());
     wfProfileOut(__METHOD__ . '-parse');
     wfProfileIn(__METHOD__ . '-update');
     SMWParseData::storeData($output, $this->title, false);
     wfProfileOut(__METHOD__ . '-update');
     wfProfileOut('SMWUpdateJob::run (SMW)');
     return true;
 }
Esempio n. 2
0
 /**
  * Method for handling the subobject parser function.
  *
  * @since 1.7
  *
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     self::$m_errors = array();
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     $subobjectName = str_replace(' ', '_', trim(array_shift($params)));
     $mainSemanticData = SMWParseData::getSMWData($parser);
     $subject = $mainSemanticData->getSubject();
     $diSubWikiPage = new SMWDIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName);
     $semanticData = new SMWContainerSemanticData($diSubWikiPage);
     foreach ($params as $param) {
         $parts = explode('=', trim($param), 2);
         // Only add the property when there is both a name
         // and a non-empty value.
         if (count($parts) == 2 && $parts[1] != '') {
             self::addPropertyValueToSemanticData($parts[0], $parts[1], $semanticData);
         } else {
             //self::$m_errors[] = wfMsgForContent( 'smw_noinvannot' );
         }
     }
     $propertyDi = new SMWDIProperty('_SOBJ');
     $subObjectDi = new SMWDIContainer($semanticData);
     SMWParseData::getSMWData($parser)->addPropertyObjectValue($propertyDi, $subObjectDi);
     return smwfEncodeMessages(self::$m_errors);
 }
Esempio n. 3
0
 /**
  * Method for handling the subobject parser function.
  *
  * @since 1.7
  *
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     self::$m_errors = array();
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     $subobjectName = str_replace(' ', '_', trim(array_shift($params)));
     // For objects that don't come with there own idenifier, use a value
     // dependant md4 hash key
     if ($subobjectName === '' || $subobjectName === '-') {
         $subobjectName = '_' . hash('md4', implode('|', $params), false);
     }
     $mainSemanticData = SMWParseData::getSMWData($parser);
     $subject = $mainSemanticData->getSubject();
     $diSubWikiPage = new SMWDIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName);
     $semanticData = new SMWContainerSemanticData($diSubWikiPage);
     $previousPropertyDi = null;
     foreach ($params as $param) {
         $parts = explode('=', trim($param), 2);
         // Only add the property when there is both a name
         // and a non-empty value.
         if (count($parts) == 2 && $parts[1] != '') {
             $previousPropertyDi = self::addPropertyValueToSemanticData($parts[0], $parts[1], $semanticData);
         } elseif (count($parts) == 1 && !is_null($previousPropertyDi)) {
             self::addPropertyDiValueToSemanticData($previousPropertyDi, $parts[0], $semanticData);
         } else {
             //self::$m_errors[] = wfMessage( 'smw_noinvannot' )->inContentLanguage()->text();
         }
     }
     $propertyDi = new SMWDIProperty('_SOBJ');
     $subObjectDi = new SMWDIContainer($semanticData);
     SMWParseData::getSMWData($parser)->addPropertyObjectValue($propertyDi, $subObjectDi);
     return smwfEncodeMessages(self::$m_errors);
 }
	/**
	 * Method for handling the set_recurring_event parser function.
	 * 
	 * @since 1.5.3
	 * 
	 * @param Parser $parser
	 */
	public static function render( Parser &$parser ) {
		$params = func_get_args();
		array_shift( $params ); // We already know the $parser ...

		// Almost all of the work gets done by
		// getDatesForRecurringEvent().
		$results = self::getDatesForRecurringEvent( $params );
		if ( $results == null ) {
			return null;
		}

		list( $property_name, $all_date_strings, $unused_params ) = $results;

		// Do the actual saving of the data.
		foreach ( $all_date_strings as $date_str ) {
			SMWParseData::addProperty( $property_name, $date_str, false, $parser, true );
		}

		global $wgTitle;
		if ( !is_null( $wgTitle ) && $wgTitle->isSpecialPage() ) {
			global $wgOut;
			SMWOutputs::commitToOutputPage( $wgOut );
		}
		else {
			SMWOutputs::commitToParser( $parser );
		}	
	}
Esempio n. 5
0
 /**
  * Method for handling the declare parser function.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  * @param PPFrame $frame
  * @param array $args
  */
 public static function render(Parser &$parser, PPFrame $frame, array $args)
 {
     if ($frame->isTemplate()) {
         foreach ($args as $arg) {
             if (trim($arg) !== '') {
                 $expanded = trim($frame->expand($arg));
                 $parts = explode('=', $expanded, 2);
                 if (count($parts) == 1) {
                     $propertystring = $expanded;
                     $argumentname = $expanded;
                 } else {
                     $propertystring = $parts[0];
                     $argumentname = $parts[1];
                 }
                 $property = SMWPropertyValue::makeUserProperty($propertystring);
                 $argument = $frame->getArgument($argumentname);
                 $valuestring = $frame->expand($argument);
                 if ($property->isValid()) {
                     $type = $property->getPropertyTypeID();
                     if ($type == '_wpg') {
                         $matches = array();
                         preg_match_all('/\\[\\[([^\\[\\]]*)\\]\\]/u', $valuestring, $matches);
                         $objects = $matches[1];
                         if (count($objects) == 0) {
                             if (trim($valuestring) !== '') {
                                 SMWParseData::addProperty($propertystring, $valuestring, false, $parser, true);
                             }
                         } else {
                             foreach ($objects as $object) {
                                 SMWParseData::addProperty($propertystring, $object, false, $parser, true);
                             }
                         }
                     } elseif (trim($valuestring) !== '') {
                         SMWParseData::addProperty($propertystring, $valuestring, false, $parser, true);
                     }
                     // $value = SMWDataValueFactory::newPropertyObjectValue( $property->getDataItem(), $valuestring );
                     // if (!$value->isValid()) continue;
                 }
             }
         }
     } else {
         // @todo Save as metadata
     }
     global $wgTitle;
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return '';
 }
Esempio n. 6
0
 /**
  * Method for handling the set parser function.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     foreach ($params as $param) {
         $parts = explode('=', trim($param), 2);
         // Only add the property when there is both a name and a value.
         if (count($parts) == 2) {
             SMWParseData::addProperty($parts[0], $parts[1], false, $parser, true);
         }
     }
     return '';
 }
Esempio n. 7
0
 /**
  * Method for handling the ask concept function.
  * 
  * @todo The possible use of this in an HTML or Specal page context needs to be revisited. The code mentions it, but can this actually happen?
  * @todo The escaping of symbols in concept queries needs to be revisited.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     global $wgContLang, $wgTitle;
     $title = $parser->getTitle();
     $pconc = new SMWDIProperty('_CONC');
     if ($title->getNamespace() != SMW_NS_CONCEPT) {
         $result = smwfEncodeMessages(array(wfMsgForContent('smw_no_concept_namespace')));
         SMWOutputs::commitToParser($parser);
         return $result;
     } elseif (count(SMWParseData::getSMWdata($parser)->getPropertyValues($pconc)) > 0) {
         $result = smwfEncodeMessages(array(wfMsgForContent('smw_multiple_concepts')));
         SMWOutputs::commitToParser($parser);
         return $result;
     }
     // process input:
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     // Use first parameter as concept (query) string.
     $concept_input = str_replace(array('&gt;', '&lt;'), array('>', '<'), array_shift($params));
     // second parameter, if any, might be a description
     $concept_docu = array_shift($params);
     // NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14
     $query = SMWQueryProcessor::createQuery($concept_input, SMWQueryProcessor::getProcessedParams(array('limit' => 20, 'format' => 'list')), SMWQueryProcessor::CONCEPT_DESC);
     $concept_text = $query->getDescription()->getQueryString();
     if (!is_null(SMWParseData::getSMWData($parser))) {
         $diConcept = new SMWDIConcept($concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth());
         SMWParseData::getSMWData($parser)->addPropertyObjectValue($pconc, $diConcept);
     }
     // display concept box:
     $rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink');
     SMWOutputs::requireResource('ext.smw.style');
     // TODO: escape output, preferably via Html or Xml class.
     $result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent('smw_concept_description', $title->getText()) . (count($query->getErrors()) > 0 ? ' ' . smwfEncodeMessages($query->getErrors()) : '') . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' . ($concept_docu ? "<p>{$concept_docu}</p>" : '') . '<pre>' . str_replace('[', '&#x005B;', $concept_text) . "</pre>\n</div>";
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return $result;
 }
Esempio n. 8
0
 /**
  * This function creates wiki text suitable for rendering a Factbox based on the
  * information found in a given ParserOutput object. If the required custom data
  * is not found in the given ParserOutput, then semantic data for the provided Title
  * object is retreived from the store.
  * 
  * @param ParserOutput $parseroutput
  * @param Title $title
  * 
  * @return string
  */
 public static function getFactboxTextFromOutput(ParserOutput $parseroutput, Title $title)
 {
     global $wgRequest, $smwgShowFactboxEdit, $smwgShowFactbox;
     $mws = isset($parseroutput->mSMWMagicWords) ? $parseroutput->mSMWMagicWords : array();
     if (in_array('SMW_SHOWFACTBOX', $mws)) {
         $showfactbox = SMW_FACTBOX_NONEMPTY;
     } elseif (in_array('SMW_NOFACTBOX', $mws)) {
         $showfactbox = SMW_FACTBOX_HIDDEN;
     } elseif ($wgRequest->getCheck('wpPreview')) {
         $showfactbox = $smwgShowFactboxEdit;
     } else {
         $showfactbox = $smwgShowFactbox;
     }
     if ($showfactbox == SMW_FACTBOX_HIDDEN) {
         // use shortcut
         return '';
     }
     // Deal with complete dataset only if needed:
     $smwData = SMWParseData::getSMWDataFromParserOutput($parseroutput);
     if ($smwData === null || $smwData->stubObject) {
         $smwData = smwfGetStore()->getSemanticData(SMWDIWikiPage::newFromTitle($title));
     }
     return SMWFactbox::getFactboxText($smwData, $showfactbox);
 }
	/**
	 * This callback function strips out the semantic attributes from a wiki
	 * link. Expected parameter: array(linktext, properties, value, caption)
	 */
	static public function parsePropertiesCallback( $semanticLink ) {
		global $smwgInlineErrors, $smwgStoreAnnotations;

		wfProfileIn( 'smwfParsePropertiesCallback (SMW)' );

		if ( array_key_exists( 1, $semanticLink ) ) {
			$property = $semanticLink[1];
		} else {
			$property = '';
		}

		if ( array_key_exists( 2, $semanticLink ) ) {
			$value = $semanticLink[2];
		} else {
			$value = '';
		}

		if ( $value === '' ) { // silently ignore empty values
			wfProfileOut( 'smwfParsePropertiesCallback (SMW)' );
			return '';
		}

		if ( $property == 'SMW' ) {
			switch ( $value ) {
				case 'on':
					SMWParserExtensions::$mTempStoreAnnotations = true;
					break;
				case 'off':
					SMWParserExtensions::$mTempStoreAnnotations = false;
					break;
			}
			wfProfileOut( 'smwfParsePropertiesCallback (SMW)' );
			return '';
		}

		if ( array_key_exists( 3, $semanticLink ) ) {
			$valueCaption = $semanticLink[3];
		} else {
			$valueCaption = false;
		}

		// Extract annotations and create tooltip.
		$properties = preg_split( '/:[=:]/u', $property );

		foreach ( $properties as $singleprop ) {
			$dv = SMWParseData::addProperty( $singleprop, $value, $valueCaption, SMWParserExtensions::$mTempParser, $smwgStoreAnnotations && SMWParserExtensions::$mTempStoreAnnotations );
		}

		$result = $dv->getShortWikitext( true );

		if ( ( $smwgInlineErrors && $smwgStoreAnnotations && SMWParserExtensions::$mTempStoreAnnotations ) && ( !$dv->isValid() ) ) {
			$result .= $dv->getErrorText();
		}

		wfProfileOut( 'smwfParsePropertiesCallback (SMW)' );

		return $result;
	}
	static function getOutputData( $title, $rid = 0 ) {
		// normal page
		global $wgTitle, $wgUser;
		$wgTitle = $title;
		$revision = Revision::newFromTitle( $title, $rid );
		if ( $revision === NULL ) {
			throw new MWException( __METHOD__ . ": Page not exist '{$page_name} ({$rid})'" );
		}
		$text = $revision->getText();
		$wom = WOMProcessor::parseToWOM( $text );

		global $wgOMOutputHookedParserFunctions;
		$pfs = $wom->getObjectsByTypeID( WOM_TYPE_PARSERFUNCTION );
		foreach ( $pfs as $id => $obj ) {
			self::removeSubWOMIds( $obj );
			foreach ( $wgOMOutputHookedParserFunctions as $function_key ) {
				if ( $obj->getFunctionKey() == $function_key ) {
					// add wom id to parser function, with specified parameter 'wom_id'
					$param = new WOMParameterModel( 'wom_id' );
					$pv = new WOMParamValueModel();
					$param->insertObject( $pv );
					$pv->insertObject( new WOMTextModel( $id ) );
					$obj->insertObject( $param );
				}
			}
		}
		// FIXME: template values may have object ids
		$tmpls = $wom->getObjectsByTypeID( WOM_TYPE_TEMPLATE );
		foreach ( $tmpls as $id => $obj ) {
			self::removeSubWOMIds( $obj );
		}

		global $wgParser, $wgOut, $wgWOMOutputHooked;
		$wgWOMOutputHooked = true;
		$options = ParserOptions::newFromUser( $wgUser );

		self::$queryProps = array();
		self::$queryId = 1;
		$wgParser->parse( $wom->getWikiText(), $title, $options );

		$output = SMWParseData::getSMWdata( $wgParser );

		if ( !isset( $output ) ) {
			$semdata = smwfGetStore()->getSemanticData( $title );
		} else {
			$semdata = $output;
		}

		$tmp_id = 0;
		// fill in semantic properties
		$properties = array();
		foreach ( $semdata->getProperties() as $property ) {
			$label = '';
			if ( !$property->isShown() ) { // showing this is not desired, hide
				continue;
			} elseif ( $property->isUserDefined() ) { // user defined property
				if ( version_compare ( SMW_VERSION, '1.6', '>=' ) ) {
					$label = $property->getLabel();
				} else {
					$property->setCaption( preg_replace( '/[ ]/u', '&nbsp;', $property->getWikiValue(), 2 ) );
					// / NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow
					$label = $property->getWikiValue();
				}
			} else {
				if ( version_compare ( SMW_VERSION, '1.6', '>=' ) ) {
					$label = $property->getLabel();
				} else {
					if ( $property->isVisible() ) { // predefined property
						$label = $property->getWikiValue();
					} else { // predefined, internal property
						continue;
					}
				}
			}
			$properties[$label] = array();

			$propvalues = $semdata->getPropertyValues( $property );
			foreach ( $propvalues as $propvalue ) {
				if ( version_compare ( SMW_VERSION, '1.6', '>=' ) ) {
					if ( $propvalue->getDIType() == SMWDataItem::TYPE_ERROR ) continue;
					$properties[$label][$propvalue->getSerialization()] = false;
				} else {
					$properties[$label][$propvalue->getWikiValue()] = false;
				}
			}
		}
		$props = $wom->getObjectsByTypeID( WOM_TYPE_PROPERTY );
		foreach ( $props as $prop ) {
			$id = $prop->getObjectID();
			if ( $id == '' ) continue;
			$name = $prop->getPropertyName();
			$value = $prop->getPropertyValue();
			if ( !isset( $properties[$name][$value] ) ) {
				// remove category not match to output
				$wom->removePageObject( $id );
			} else {
				$properties[$name][$value] = true;
			}
		}
		foreach ( $properties as $name => $values ) {
			foreach ( $values as $val => $flag ) {
				if ( $flag !== true ) {
					$p = new WOMPropertyModel( $name, $val );
					$p->setObjectID( 'output' . ( $tmp_id ++ ) );
					$wom->insertObject( $p );
					$wom->addToPageObjectSet( $p );
				}
			}
		}

		// fill in ask query results
		foreach ( self::$queryProps as $wom_id => $queries ) {
			$query_res = new WOMQueryResult();
			if ( $wom_id != '' ) {
				$parent = $wom->getObject( $wom_id );
			} else {
				$parent = new WOMParserFunctionModel( 'ask' );
				$parent->setObjectID( 'output' . ( $tmp_id ++ ) );
				$wom->insertObject( $parent );
				$wom->addToPageObjectSet( $parent );
			}
			$parent->insertObject( $query_res );
			$query_res->setObjectID( 'output' . ( $tmp_id ++ ) );
			$wom->addToPageObjectSet( $query_res );
			foreach ( $queries as $label => $vals ) {
				$vals = array_unique( $vals );
				foreach ( $vals as $val ) {
					$query_res->insertObject( new WOMPropertyModel( $label, $val ) );
				}
			}
		}

		// fill in categories
		$categories = $title->getParentCategories();
		$cates = $wom->getObjectsByTypeID( WOM_TYPE_CATEGORY );
		foreach ( $cates as $cate ) {
			$id = $cate->getObjectID();
			if ( $id == '' ) continue;
			$name = Title::newFromText( $cate->getName(), NS_CATEGORY )->getFullText();
			if ( !isset( $categories[$name] ) ) {
				// remove category not match to output
				$wom->removePageObject( $id );
			} else {
				$categories[$name] = true;
			}
		}
		foreach ( $categories as $cate => $flag ) {
			if ( $flag !== true ) {
				$c = new WOMCategoryModel( Title::newFromText( $cate )->getText() );
				$c->setObjectID( 'output' . ( $tmp_id ++ ) );
				$wom->insertObject( $c );
				$wom->addToPageObjectSet( $c );
			}
		}

		return $wom;
	}
Esempio n. 11
0
 public static function onParserAfterTidy(&$parser, &$text)
 {
     $title = $parser->getTitle();
     // make sure this isn't some title we didn't wanted to purge in the first place:
     if (self::hasUpdateTitle($title)) {
         /* 
          * Note: don't use SMWUpdateJob here because it would parse the whole article again and 
          * could cause some problems with very dynamic extensions like Extension:Variables.
          */
         $output = $parser->getOutput();
         // only update if the page contains semantic data:
         if (isset($output->mSMWData)) {
             SMWParseData::storeData($output, $title, true);
         }
         self::removeUpdateTitle($title);
     }
     return true;
 }
Esempio n. 12
0
 /**
  * Add data about the query and its parameters to the semantic data of
  * the given parser. The $queryKey is a string key that uniquely
  * identifies the query; this is difficult to create in a stable way
  * from the processed query object and parameters, but easy to get from
  * the raw user input.
  *
  * @param string $queryKey
  * @param SMWQuery $query
  * @param array $params
  * @param Parser $parser
  *
  * @since 1.8
  */
 public static function addQueryData($queryKey, SMWQuery $query, array $params, Parser $parser)
 {
     $mainSemanticData = SMWParseData::getSMWData($parser);
     $subject = $mainSemanticData->getSubject();
     $diSubWikiPage = new SMWDIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), "_QUERY" . $queryKey);
     $semanticData = new SMWContainerSemanticData($diSubWikiPage);
     $description = $query->getDescription();
     // Add query string
     $propertyDi = new SMWDIProperty('_ASKST');
     $valueDi = new SMWDIBlob($description->getQueryString());
     $semanticData->addPropertyObjectValue($propertyDi, $valueDi);
     // Add query size
     $propertyDi = new SMWDIProperty('_ASKSI');
     $valueDi = new SMWDINumber($description->getSize());
     $semanticData->addPropertyObjectValue($propertyDi, $valueDi);
     // Add query depth
     $propertyDi = new SMWDIProperty('_ASKDE');
     $valueDi = new SMWDINumber($description->getDepth());
     $semanticData->addPropertyObjectValue($propertyDi, $valueDi);
     // Add query format
     $propertyDi = new SMWDIProperty('_ASKFO');
     $valueDi = new SMWDIString($params['format']->getValue());
     $semanticData->addPropertyObjectValue($propertyDi, $valueDi);
     $propertyDi = new SMWDIProperty('_ASK');
     $subObjectDi = new SMWDIContainer($semanticData);
     SMWParseData::getSMWData($parser)->addPropertyObjectValue($propertyDi, $subObjectDi);
 }