protected function parseUserValue($value)
 {
     global $wgContLang;
     $this->m_diProperties = array();
     $stringValue = '';
     $valueList = preg_split('/[\\s]*;[\\s]*/u', trim($value));
     foreach ($valueList as $propertyName) {
         $propertyNameParts = explode(':', $propertyName, 2);
         if (count($propertyNameParts) > 1) {
             $namespace = smwfNormalTitleText($propertyNameParts[0]);
             $propertyName = $propertyNameParts[1];
             $propertyNamespace = $wgContLang->getNsText(SMW_NS_PROPERTY);
             if ($namespace != $propertyNamespace) {
                 $this->addError(wfMessage('smw_wrong_namespace', $propertyNamespace)->inContentLanguage()->text());
             }
         }
         $propertyName = smwfNormalTitleText($propertyName);
         try {
             $diProperty = SMWDIProperty::newFromUserLabel($propertyName);
         } catch (SMWDataItemException $e) {
             $diProperty = new SMWDIProperty('Error');
             $this->addError(wfMessage('smw_noproperty', $propertyName)->inContentLanguage()->text());
         }
         $this->m_diProperties[] = $diProperty;
         $stringValue .= ($stringValue ? ';' : '') . $diProperty->getKey();
     }
     $this->m_dataitem = new SMWDIBlob($stringValue);
 }
 /**
  * Creates and returns a new SWLPropertyChange instance from a serialization.
  *
  * @param string|null $oldValue
  * @param string|null $newValue
  *
  * @return SWLPropertyChange
  */
 public static function newFromSerialization(SMWDIProperty $property, $oldValue, $newValue)
 {
     $diType = SMWDataValueFactory::getDataItemId($property->findPropertyTypeID());
     //var_dump($property);
     //if($diType!=7) {throw new Exception();exit;}
     return new self(is_null($oldValue) ? null : SMWDataItem::newFromSerialization($diType, $oldValue), is_null($newValue) ? null : SMWDataItem::newFromSerialization($diType, $newValue));
 }
	/**
	 * Creates and returns a new SWLPropertyChange instance from a serialization.
	 *
	 * @param string|null $oldValue
	 * @param string|null $newValue
	 *
	 * @return SWLPropertyChange
	 */
	public static function newFromSerialization( SMWDIProperty $property, $oldValue, $newValue ) {
		$diType = SMWDataValueFactory::getDataItemId( $property->findPropertyTypeID() );

		return new self(
			is_null( $oldValue ) ? null : SMWDataItem::newFromSerialization( $diType, $oldValue ),
			is_null( $newValue ) ? null : SMWDataItem::newFromSerialization( $diType, $newValue )
		);
	}
 /**
  * Returns an array of CustomTexts set by the admin in WatchlistConditions
  * for this group and property.
  *
  * @since 0.2
  *
  * @param SMWDIProperty $property
  * @param String $newValue
  *
  * @return String or false
  */
 public function getPropertyCustomText(SMWDIProperty $property, $newValue)
 {
     $this->initCustomTexts();
     if (array_key_exists($property->getLabel(), $this->customTexts) && array_key_exists($newValue, $this->customTexts[$property->getLabel()])) {
         return $this->customTexts[$property->getLabel()][$newValue];
     } else {
         return false;
     }
 }
Beispiel #5
0
function SemanticGlossaryRegisterPropertyAliases()
{
    SMWDIProperty::registerPropertyAlias('___glt', wfMsg('semanticglossary-prop-glt'));
    SMWDIProperty::registerPropertyAlias('___gld', wfMsg('semanticglossary-prop-gld'));
    SMWDIProperty::registerPropertyAlias('___gll', wfMsg('semanticglossary-prop-gll'));
    return true;
}
 /**
  * Check if property is range restricted and, if so, whether the current value is allowed.
  * Creates an error if the value is illegal.
  */
 protected function checkAllowedValues()
 {
     if (!is_null($this->m_property)) {
         $propertyDiWikiPage = $this->m_property->getDiWikiPage();
     }
     if (is_null($this->m_property) || is_null($propertyDiWikiPage) || !isset($this->m_dataitem)) {
         return;
         // no property known, or no data to check
     }
     $allowedvalues = \SMW\StoreFactory::getStore()->getPropertyValues($propertyDiWikiPage, new SMWDIProperty('_PVAL'));
     if (count($allowedvalues) == 0) {
         return;
     }
     $hash = $this->m_dataitem->getHash();
     $testdv = DataValueFactory::getInstance()->newTypeIDValue($this->getTypeID());
     $accept = false;
     $valuestring = '';
     foreach ($allowedvalues as $di) {
         if ($di instanceof SMWDIBlob) {
             $testdv->setUserValue($di->getString());
             if ($hash === $testdv->getDataItem()->getHash()) {
                 $accept = true;
                 break;
             } else {
                 if ($valuestring !== '') {
                     $valuestring .= ', ';
                 }
                 $valuestring .= $di->getString();
             }
         }
     }
     if (!$accept) {
         $this->addError(wfMessage('smw_notinenum', $this->getWikiValue(), $valuestring)->inContentLanguage()->text());
     }
 }
Beispiel #7
0
 /**
  * @see SMWOrderedListPage::initParameters()
  * @note We use a smaller limit here; property pages might become large.
  */
 protected function initParameters()
 {
     global $smwgPropertyPagingLimit;
     $this->limit = $smwgPropertyPagingLimit;
     $this->mProperty = SMWDIProperty::newFromUserLabel($this->mTitle->getText());
     return true;
 }
 function setTypeAndPossibleValues()
 {
     // The presence of "-" at the beginning of a property name
     // (which happens if SF tries to parse an inverse query)
     // leads to an error in SMW - just exit if that's the case.
     if (strpos($this->mSemanticProperty, '-') === 0) {
         return;
     }
     $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty);
     if ($proptitle === null) {
         return;
     }
     $store = SFUtils::getSMWStore();
     // this returns an array of objects
     $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value");
     $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format");
     $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty);
     $this->mPropertyType = $propValue->findPropertyTypeID();
     foreach ($allowed_values as $allowed_value) {
         // HTML-unencode each value
         $this->mPossibleValues[] = html_entity_decode($allowed_value);
         if (count($label_formats) > 0) {
             $label_format = $label_formats[0];
             $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType);
             $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value);
             $label_value->setOutputFormat($label_format);
             $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue());
         }
     }
     // HACK - if there were any possible values, set the property
     // type to be 'enumeration', regardless of what the actual type is
     if (count($this->mPossibleValues) > 0) {
         $this->mPropertyType = 'enumeration';
     }
 }
Beispiel #9
0
 function setTypeAndPossibleValues()
 {
     $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty);
     if ($proptitle === null) {
         return;
     }
     $store = smwfGetStore();
     // this returns an array of objects
     $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value");
     $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format");
     $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty);
     $this->mPropertyType = $propValue->findPropertyTypeID();
     foreach ($allowed_values as $allowed_value) {
         // HTML-unencode each value
         $this->mPossibleValues[] = html_entity_decode($allowed_value);
         if (count($label_formats) > 0) {
             $label_format = $label_formats[0];
             $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType);
             $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value);
             $label_value->setOutputFormat($label_format);
             $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue());
         }
     }
     // HACK - if there were any possible values, set the property
     // type to be 'enumeration', regardless of what the actual type is
     if (count($this->mPossibleValues) > 0) {
         $this->mPropertyType = 'enumeration';
     }
 }
 /**
  * @see SMWOrderedListPage::initParameters()
  * @note We use a smaller limit here; property pages might become large.
  */
 protected function initParameters()
 {
     global $smwgPropertyPagingLimit;
     $this->limit = $smwgPropertyPagingLimit;
     $this->mProperty = SMWDIProperty::newFromUserLabel($this->mTitle->getText());
     $this->store = ApplicationFactory::getInstance()->getStore();
     return true;
 }
 /**
  * Produce a formatted string representation for showing a property and
  * its usage count in the list of used properties.
  *
  * @since 1.8
  *
  * @param SMWDIProperty $property
  * @param integer $useCount
  * @return string
  */
 protected function formatPropertyItem(SMWDIProperty $property, $useCount)
 {
     global $wgLang;
     $linker = smwfGetLinker();
     $errors = array();
     $diWikiPage = $property->getDiWikiPage();
     $title = !is_null($diWikiPage) ? $diWikiPage->getTitle() : null;
     if ($property->isUserDefined() && is_null($title)) {
         // Show even messed up property names.
         $typestring = '';
         $proplink = $property->getLabel();
         $errors[] = wfMessage('smw_notitle', $property->getLabel())->escaped();
     } elseif ($property->isUserDefined()) {
         if ($useCount <= 5) {
             $errors[] = wfMessage('smw_propertyhardlyused')->escaped();
         }
         // User defined types default to Page
         global $smwgPDefaultType;
         $typeDataValue = SMWTypesValue::newFromTypeId($smwgPDefaultType);
         $typestring = $typeDataValue->getLongHTMLText($linker);
         $label = htmlspecialchars($property->getLabel());
         if ($title->exists()) {
             $typeProperty = new SMWDIProperty('_TYPE');
             $types = smwfGetStore()->getPropertyValues($diWikiPage, $typeProperty);
             if (count($types) >= 1) {
                 $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), $typeProperty);
                 $typestring = $typeDataValue->getLongHTMLText($linker);
             } else {
                 $errors[] = wfMessage('smw_propertylackstype')->rawParams($typestring)->escaped();
             }
             $proplink = $linker->link($title, $label);
         } else {
             $errors[] = wfMessage('smw_propertylackspage')->escaped();
             $proplink = $linker->link($title, $label, array(), array('action' => 'view'));
         }
     } else {
         // predefined property
         $typeid = $property->findPropertyTypeID();
         $typeDataValue = SMWTypesValue::newFromTypeId($typeid);
         $typestring = $typeDataValue->getLongHTMLText($linker);
         $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null);
         $proplink = $propertyDataValue->getShortHtmlText($linker);
     }
     $warnings = smwfEncodeMessages($errors, 'warning', '', false);
     $useCount = $wgLang->formatNum($useCount);
     if ($typestring === '') {
         // Builtins have no type
         // @todo Should use numParams for $useCount?
         return wfMessage('smw_property_template_notype')->rawParams($proplink)->params($useCount)->text() . ' ' . $warnings;
     } else {
         // @todo Should use numParams for $useCount?
         return wfMessage('smw_property_template')->rawParams($proplink, $typestring)->params($useCount)->escaped() . ' ' . $warnings;
     }
 }
	public function addPropertyAndValue( $propName, $value ) {
		// SMW 1.6+
		if ( class_exists( 'SMWDIProperty' ) ) {
			$property = SMWDIProperty::newFromUserLabel( $propName );
		} else {
			$property = SMWPropertyValue::makeUserProperty( $propName );
		}
		$dataValue = SMWDataValueFactory::newPropertyObjectValue( $property, $value );

		if ( $dataValue->isValid() ) {
			$this->mPropertyValuePairs[] = array( $property, $dataValue );
		} // else - show an error message?
	}
 /**
  * @see SMWDataValue::loadDataItem()
  *
  * @param $dataitem SMWDataItem
  *
  * @return boolean
  */
 protected function loadDataItem(SMWDataItem $dataItem)
 {
     if (!$dataItem instanceof SMWDIBlob) {
         return false;
     }
     $this->m_dataitem = $dataItem;
     $this->m_diProperties = array();
     foreach (explode(';', $dataItem->getString()) as $propertyKey) {
         $property = null;
         try {
             $property = new SMWDIProperty($propertyKey);
         } catch (SMWDataItemException $e) {
             $property = new SMWDIProperty('Error');
             $this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text());
         }
         if ($property instanceof SMWDIProperty) {
             // Find a possible redirect
             $this->m_diProperties[] = $property->getRedirectTarget();
         }
     }
     $this->m_caption = false;
     return true;
 }
function initProperties()
{
    if (class_exists('SMWDIProperty')) {
        SMWDIProperty::registerProperty("__SIA_RECTCOORDS", '_str', "SIArectangleCoordinates", true);
        SMWDIProperty::registerProperty("__SIA_IMG_URL", '_str', "SIAimageURL", true);
        SMWDIProperty::registerProperty("__SIA_ANNOTATED", '_str', "SIAannotatedImage", true);
        SMWDIProperty::registerProperty("__SIA_CREATED_BY", '_str', "SIAcreatedBy", true);
    } else {
        SMWPropertyValue::registerProperty("__SIA_RECTCOORDS", '_str', "SIArectangleCoordinates", true);
        SMWPropertyValue::registerProperty("__SIA_IMG_URL", '_str', "SIAimageURL", true);
        SMWPropertyValue::registerProperty("__SIA_ANNOTATED", '_str', "SIAannotatedImage", true);
        SMWPropertyValue::registerProperty("__SIA_CREATED_BY", '_str', "SIAcreatedBy", true);
    }
    return true;
}
    /**
     * Write (or delte, if $delete is set to true) the data in the object
     * variables, to the wiki page corresponding to this page handler
     * @param boolean $delete
     */
    public function writeOrDeleteDataToWiki( $delete = false ) {
        if ( $delete ) {
            if ( $this->checkWikiPageExists() ) {
                $this->initSMWWriter( $delete = true );
            } else {
                return;
            }
        } else {
            $this->ensureWikiPageExists();
            $this->initSMWWriter();
        }

        $properties = $this->m_properties;
        foreach ( $properties as $cur_prop ) {
            $propertystring = $cur_prop['p'];
            // TODO: Remove old code:
            // $property = SMWPropertyValue::makeUserProperty( $propertystring );
            $property_di = SMWDIProperty::newFromUserLabel($propertystring);
            $valuestring = RDFIOUtils::sanitizeSMWValue( $cur_prop['v'] );
            $value    = SMWDataValueFactory::newPropertyObjectValue( $property_di, $valuestring );

            $propertyErrorText = $property->getErrorText();
            $propertyHasError = ( $propertyErrorText != '' );
            if ( $propertyHasError ) {
                $this->addError( "<p>In RDFIOPageHandler::writeOrDeleteDataToWiki(): " . $property->getErrorText() . "</p>" );
            }

            $valueErrorText = $value->getErrorText();
            $valueHasError = ( $valueErrorText != '' );
            if ( $valueHasError ) {
                $this->addError( "<p>Error creating property value object in RDFIOPageHandler::writeOrDeleteDataToWiki():</p><p>" . $value->getErrorText() . "</p>" );
            }
            if ( $delete ) {
                $this->m_smwwriter_remove->addPropertyObjectValue( $property, $value );
                $editmessage = "Deleting properties. Last property delete: " . $propertystring . " : " . $valuestring;
            } else {
                $this->m_smwwriter_add->addPropertyObjectValue( $property, $value );
                $editmessage = "Importing properties. Last property added: " . $propertystring . " : " . $valuestring;
            }
        }

        $this->m_smwwriter->update( $this->m_smwwriter_remove, $this->m_smwwriter_add, $editmessage );
        $smwWriterError = $this->m_smwwriter->getError();
        $smwWriterHasError = ( $smwWriterError != '' );
        if ( $smwWriterHasError ) {
            $this->addError( "<p>SMWWriter Error: " . $smwWriterError . "</p>" );
        }
    }
Beispiel #16
0
function saclInitProperties()
{
    // Read restriction properties
    SMWDIProperty::registerProperty('___VISIBLE', '_str', wfMsgForContent('sacl-property-visibility'));
    SMWDIProperty::registerProperty('___VISIBLE_WL_GROUP', '_str', wfMsgForContent('sacl-property-visibility-wl-group'));
    SMWDIProperty::registerProperty('___VISIBLE_WL_USER', '_wpg', wfMsgForContent('sacl-property-visibility-wl-user'));
    SMWDIProperty::registerPropertyAlias('___VISIBLE', 'Visible to');
    SMWDIProperty::registerPropertyAlias('___VISIBLE_WL_GROUP', 'Visible to group');
    SMWDIProperty::registerPropertyAlias('___VISIBLE_WL_USER', 'Visible to user');
    // Write restriction properties
    SMWDIProperty::registerProperty('___EDITABLE', '_str', wfMsgForContent('sacl-property-editable'));
    SMWDIProperty::registerProperty('___EDITABLE_WL_GROUP', '_str', wfMsgForContent('sacl-property-editable-wl-group'));
    SMWDIProperty::registerProperty('___EDITABLE_WL_USER', '_wpg', wfMsgForContent('sacl-property-editable-wl-user'));
    SMWDIProperty::registerPropertyAlias('___EDITABLE_BY', 'Editable by');
    SMWDIProperty::registerPropertyAlias('___EDITABLE_WL_GROUP', 'Editable by group');
    SMWDIProperty::registerPropertyAlias('___EDITABLE_WL_USER', 'Editable by user');
    return true;
}
 /**
  * Get an array key => value of genealogical properties as SMWDIProperty
  * @throws MWException
  */
 public static function getProperties()
 {
     static $properties;
     if ($properties !== null) {
         return $properties;
     }
     global $wgGenealogicalProperties, $wgOut;
     $properties = array();
     if (!is_array($wgGenealogicalProperties)) {
         throw new MWException('Configuration variable $wgGenealogicalProperties must be an array !');
     }
     foreach ($wgGenealogicalProperties as $key => $value) {
         if ($value) {
             $properties[$key] = SMWDIProperty::newFromUserLabel($value);
         }
     }
     return $properties;
 }
 /**
  * @brief  Initializes all properties, hooks into smwInitProperties.
  *
  * @return true
  */
 public static function sespInitProperties()
 {
     // Page author
     SMWDIProperty::registerProperty('___EUSER', '_wpg', wfMsgForContent('sesp-property-author'));
     SMWDIProperty::registerPropertyAlias('___EUSER', 'Page author');
     // Page creator
     SMWDIProperty::registerProperty('___CUSER', '_wpg', wfMsgForContent('sesp-property-first-author'));
     SMWDIProperty::registerPropertyAlias('___CUSER', 'Page creator');
     // Revision ID
     SMWDIProperty::registerProperty('___REVID', '_num', wfMsgForContent('sesp-property-revision-id'));
     SMWDIProperty::registerPropertyAlias('___REVID', 'Revision ID');
     //View count
     SMWDIProperty::registerProperty('___VIEWS', '_num', wfMsgForContent('sesp-property-view-count'));
     SMWDIProperty::registerPropertyAlias('___VIEWS', 'Number of page views');
     //Sub pages
     SMWDIProperty::registerProperty('___SUBP', '_wpg', wfMsgForContent('sesp-property-subpages'));
     SMWDIProperty::registerPropertyAlias('___SUBP', 'Subpage');
     //Number of revisions
     SMWDIProperty::registerProperty('___NREV', '_num', wfMsgForContent('sesp-property-revisions'));
     SMWDIProperty::registerPropertyAlias('___NREV', 'Number of revisions');
     //Number of talk page revisions
     SMWDIProperty::registerProperty('___NTREV', '_num', wfMsgForContent('sesp-property-talk-revisions'));
     SMWDIProperty::registerPropertyAlias('___NTREV', 'Number of talk page revisions');
     // MIME type
     SMWDIProperty::registerProperty('___MIMETYPE', '_str', wfMsgForContent('sesp-property-mimetype'));
     SMWDIProperty::registerPropertyAlias('___MIMETYPE', 'MIME type');
     // MIME type
     SMWDIProperty::registerProperty('___MEDIATYPE', '_str', wfMsgForContent('sesp-property-mediatype'));
     SMWDIProperty::registerPropertyAlias('___MEDIATYPE', 'Media type');
     // SHORTURL type
     SMWDIProperty::registerProperty('___SHORTURL', '_uri', wfMsgForContent('sesp-property-shorturl'));
     SMWDIProperty::registerPropertyAlias('___SHORTURL', 'Short URL');
     // METADATA types
     SMWDIProperty::registerProperty('___EXIFDATETIME', '_dat', wfMsgForContent('exif-datetimeoriginal'));
     SMWDIProperty::registerPropertyAlias('___EXIFDATETIME', 'Exposure date');
     SMWDIProperty::registerProperty('___EXIFSOFTWARE', '_str', wfMsgForContent('exif-software'));
     SMWDIProperty::registerPropertyAlias('___EXIFSOFTWARE', 'Software');
     return true;
 }
Beispiel #19
0
 /**
  * Return the array of predefined property table declarations, initialising
  * it if necessary. The result is an array of SMWSQLStore3Table objects
  * indexed by table ids.
  *
  * It is ensured that the keys of the returned array agree with the name of
  * the table that they refer to.
  *
  * @since 1.8
  * @return SMWSQLStore3Table[]
  */
 public static function getPropertyTables()
 {
     if (isset(self::$prop_tables)) {
         return self::$prop_tables;
         // Don't initialise twice.
     }
     /**
      * @var SMWSQLStore3Table[] $propertyTables
      */
     $propertyTables = array();
     //tables for each DI type
     foreach (self::$di_type_tables as $tableDIType => $tableName) {
         $propertyTables[$tableName] = new SMWSQLStore3Table($tableDIType, $tableName);
     }
     //tables for special properties
     foreach (self::$special_tables as $propertyKey) {
         $typeId = SMWDIProperty::getPredefinedPropertyTypeId($propertyKey);
         $diType = SMWDataValueFactory::getDataItemId($typeId);
         $tableName = 'smw_fpt' . strtolower($propertyKey);
         $propertyTables[$tableName] = new SMWSQLStore3Table($diType, $tableName, $propertyKey);
     }
     // Redirect table uses another subject scheme for historic reasons
     // TODO This should be changed if possible
     $propertyTables['smw_fpt_redi']->setUsesIdSubject(false);
     // Get all the tables for the properties that are declared as fixed
     // (overly used and thus having separate tables)
     foreach (self::$fixedProperties as $propertyKey => $tableDIType) {
         $tableName = 'smw_fpt_' . md5($propertyKey);
         $propertyTables[$tableName] = new SMWSQLStore3Table($tableDIType, $tableName, $propertyKey);
     }
     wfRunHooks('SMWPropertyTables', array(&$propertyTables));
     self::$prop_tables = $propertyTables;
     // Build index for finding property tables
     self::$fixedPropertyTableIds = array();
     foreach (self::$prop_tables as $tid => $propTable) {
         if ($propTable->isFixedPropertyTable()) {
             self::$fixedPropertyTableIds[$propTable->getFixedProperty()] = $tid;
         }
     }
     // Specifically set properties that must not be stored in any
     // property table to null here. Any function that hits this
     // null unprepared is doing something wrong anyway.
     self::$fixedPropertyTableIds['_SKEY'] = null;
     return self::$prop_tables;
 }
 /**
  * @see SMWStore::getPropertySubjects
  *
  * @param SMWDIProperty $property
  * @param mixed $value SMWDataItem or null
  * @param SMWRequestOptions $requestoptions
  *
  * @return array of SMWDIWikiPage
  */
 public function getPropertySubjects(SMWDIProperty $property, $value, $requestoptions = null)
 {
     /// TODO: should we share code with #ask query computation here? Just use queries?
     wfProfileIn("SMWSQLStore3::getPropertySubjects (SMW)");
     if ($property->isInverse()) {
         // inverses are working differently
         $noninverse = new SMWDIProperty($property->getKey(), false);
         $result = $this->getPropertyValues($value, $noninverse, $requestoptions);
         wfProfileOut("SMWSQLStore3::getPropertySubjects (SMW)");
         return $result;
     }
     // First build $select, $from, and $where for the DB query
     $where = $from = '';
     $pid = $this->store->smwIds->getSMWPropertyID($property);
     $tableid = SMWSQLStore3::findPropertyTableID($property);
     if ($pid == 0 || $tableid === '') {
         wfProfileOut("SMWSQLStoreLight::getPropertySubjects (SMW)");
         return array();
     }
     $proptables = SMWSQLStore3::getPropertyTables();
     $proptable = $proptables[$tableid];
     $db = wfGetDB(DB_SLAVE);
     if ($proptable->idsubject) {
         // join in smw_ids to get title data
         $from = $db->tableName('smw_ids') . " INNER JOIN " . $db->tableName($proptable->name) . " AS t1 ON t1.s_id=smw_id";
         $select = 'smw_title, smw_namespace, smw_sortkey, smw_iw, smw_subobject';
     } else {
         // no join needed, title+namespace as given in proptable
         $from = $db->tableName($proptable->name) . " AS t1";
         $select = 's_title AS smw_title, s_namespace AS smw_namespace, s_title AS smw_sortkey, \'\' AS smw_iw, \'\' AS smw_subobject';
     }
     if ($proptable->fixedproperty == false) {
         $where .= ($where ? ' AND ' : '') . "t1.p_id=" . $db->addQuotes($pid);
     }
     $this->prepareValueQuery($from, $where, $proptable, $value, 1);
     // ***  Now execute the query and read the results  ***//
     $result = array();
     $res = $db->select($from, 'DISTINCT ' . $select, $where . $this->store->getSQLConditions($requestoptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), 'SMW::getPropertySubjects', $this->store->getSQLOptions($requestoptions, 'smw_sortkey'));
     foreach ($res as $row) {
         try {
             if ($row->smw_iw === '' || $row->smw_iw[0] != ':') {
                 // filter special objects
                 $result[] = new SMWDIWikiPage($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject);
             }
         } catch (SMWDataItemException $e) {
             // silently drop data, should be extremely rare and will usually fix itself at next edit
         }
     }
     $db->freeResult($res);
     wfProfileOut("SMWSQLStore3::getPropertySubjects (SMW)");
     return $result;
 }
Beispiel #21
0
 /**
  * Create an SMWExpElement for some internal resource, given by an
  * SMWDIProperty object.
  * This code is only applied to user-defined properties, since the
  * code for special properties in
  * SMWExporter::getSpecialPropertyResource() may require information
  * about the namespace in which some special property is used.
  *
  * @param $diProperty SMWDIProperty
  * @param $helperProperty boolean determines if an auxiliary property resource to store a helper value (see SMWExporter::getDataItemHelperExpElement()) should be generated
  * @return SMWExpResource
  */
 public static function getResourceElementForProperty(SMWDIProperty $diProperty, $helperProperty = false)
 {
     $diWikiPage = $diProperty->getDiWikiPage();
     if (is_null($diWikiPage)) {
         throw new Exception('SMWExporter::getResourceElementForProperty() can only be used for non-inverse, user-defined properties.');
     } elseif ($helperProperty) {
         return self::getResourceElementForWikiPage($diWikiPage, 'aux');
     } else {
         return self::getResourceElementForWikiPage($diWikiPage);
     }
 }
Beispiel #22
0
 /**
  * Add a new alias label to an existing datatype id. Note that every ID should have a primary
  * label, either provided by SMW or registered with registerDatatype. This function should be
  * called from within the hook 'smwInitDatatypes'.
  *
  * @deprecated Use SMWDIProperty::registerPropertyAlias(). Will vanish before SMW 1.7.
  */
 public static function registerPropertyAlias($id, $label)
 {
     SMWDIProperty::registerPropertyAlias($id, $label);
 }
Beispiel #23
0
 public function execute()
 {
     global $wgDBtype;
     if ($this->hasOption('setup')) {
         $store = new SMWSQLStore3();
         // Lets do a drop to ensure the user doesn't has any Store3 tables already (happens when running this script twice)
         $tables = array('smw_stats');
         foreach (SMWSQLStore3::getPropertyTables() as $proptable) {
             $tables[] = $proptable->name;
         }
         $dbw = wfGetDB(DB_MASTER);
         foreach ($tables as $table) {
             $name = $dbw->tableName($table);
             $dbw->query('DROP TABLE ' . ($wgDBtype == 'postgres' ? '' : 'IF EXISTS ') . $name, 'SMWMigrate::drop');
         }
         $store->setup();
         //enter user defined properties into smw_stats (internal ones are handled by setup already )
         $query = 'Replace into ' . $dbw->tableName('smw_stats') . ' (pid,usage_count) Select smw_id,0 from ' . $dbw->tableName('smw_ids') . ' where smw_namespace = ' . SMW_NS_PROPERTY . ' and smw_iw = "" ';
         $dbw->query($query, 'SMWMigrate:commandLine');
     } elseif ($this->hasOption('migrate')) {
         $options = array();
         if ($this->hasArg(0)) {
             if ($this->hasArg(1)) {
                 $options['LIMIT'] = $this->getArg(0);
                 $options['OFFSET'] = $this->getArg(1);
             }
         }
         $dbw = wfGetDB(DB_MASTER);
         $oldStore = new SMWSQLStore2();
         $newStore = new SMWSQLStore3();
         $proptables = SMWSQLStore3::getPropertyTables();
         //get properties
         $res = $dbw->select('smw_ids', array('smw_id', 'smw_title', 'smw_namespace'), array('smw_namespace' => SMW_NS_PROPERTY), __METHOD__, $options);
         foreach ($res as $row) {
             $property = new SMWDIProperty($row->smw_title);
             echo 'Now migrating data for Property ' . $property->getLabel() . " into Store3 \n";
             //get the table
             $tableId = SMWSQLStore3::findPropertyTableID($property);
             $proptable = $proptables[$tableId];
             //get the DIHandler
             $dataItemId = SMWDataValueFactory::getDataItemId($property->findPropertyTypeId());
             $diHandler = $newStore->getDataItemHandlerForDIType($dataItemId);
             $subjects = $oldStore->getPropertySubjects($property, null);
             $insertions = array();
             foreach ($subjects as $subject) {
                 $sid = $newStore->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), true, str_replace('_', ' ', $subject->getDBkey()) . $subject->getSubobjectName());
                 //now prepare udpates
                 $propvals = $oldStore->getPropertyValues($subject, $property);
                 $uvals = $proptable->idsubject ? array('s_id' => $sid) : array('s_title' => $subject->getDBkey(), 's_namespace' => $subject->getNamespace());
                 if ($proptable->fixedproperty == false) {
                     $uvals['p_id'] = $newStore->makeSMWPropertyID($property);
                 }
                 foreach ($propvals as $propval) {
                     $uvals = array_merge($uvals, $diHandler->getInsertValues($propval));
                     $insertions[] = $uvals;
                 }
             }
             // now write to the DB for all subjects (is this too much?)
             $dbw->insert($proptable->name, $insertions, "SMW::migrate{$proptable->name}");
         }
         $dbw->freeResult($res);
     } else {
         echo "Sorry I refuse to work without any options currently";
     }
 }
 /**
  * Extend a given SMWExpData element by adding export data for the
  * specified property data itme. This method is called when
  * constructing export data structures from SMWSemanticData objects.
  *
  * @param $property SMWDIProperty
  * @param $dataItems array of SMWDataItem objects for the given property
  * @param $data SMWExpData to add the data to
  */
 public static function addPropertyValues(SMWDIProperty $property, array $dataItems, SMWExpData &$expData)
 {
     if ($property->isUserDefined()) {
         $pe = self::getResourceElementForProperty($property);
         $peHelper = self::getResourceElementForProperty($property, true);
         foreach ($dataItems as $dataItem) {
             $ed = self::getDataItemExpElement($dataItem);
             if (!is_null($ed)) {
                 $expData->addPropertyObjectValue($pe, $ed);
             }
             $edHelper = self::getDataItemHelperExpElement($dataItem);
             if (!is_null($edHelper)) {
                 $expData->addPropertyObjectValue($peHelper, $edHelper);
             }
         }
     } else {
         // pre-defined property, only exported if known
         $diSubject = $expData->getSubject()->getDataItem();
         // subject wikipage required for disambiguating special properties:
         if (is_null($diSubject) || $diSubject->getDIType() != SMWDataItem::TYPE_WIKIPAGE) {
             return;
         }
         $pe = self::getSpecialPropertyResource($property->getKey(), $diSubject->getNamespace());
         if (is_null($pe)) {
             return;
             // unknown special property, not exported
         }
         // have helper property ready before entering the for loop, even if not needed:
         $peHelper = self::getResourceElementForProperty($property, true);
         $filterNamespace = $property->getKey() == '_REDI' || $property->getKey() == '_URI';
         foreach ($dataItems as $dataItem) {
             // Basic namespace filtering to ensure that types match for redirects etc.
             /// TODO: currently no full check for avoiding OWL DL illegal redirects is done (OWL property type ignored)
             if ($filterNamespace && !$dataItem instanceof SMWDIUri && (!$dataItem instanceof SMWDIWikiPage || $dataItem->getNamespace() != $diSubject->getNamespace())) {
                 continue;
             }
             $ed = self::getDataItemExpElement($dataItem);
             if (!is_null($ed)) {
                 if ($property->getKey() == '_CONC' && $ed->getSubject()->getUri() === '') {
                     // equivalent to anonymous class -> simplify description
                     foreach ($ed->getProperties() as $subp) {
                         if ($subp->getUri() != self::getSpecialNsResource('rdf', 'type')->getUri()) {
                             foreach ($ed->getValues($subp) as $subval) {
                                 $expData->addPropertyObjectValue($subp, $subval);
                             }
                         }
                     }
                 } elseif ($property->getKey() == '_IMPO') {
                     $dataValue = DataValueFactory::getInstance()->newDataItemValue($dataItem, $property);
                     if (!$dataValue instanceof \SMWImportValue) {
                         continue;
                     }
                     $expData->addPropertyObjectValue($pe, self::getDataItemExpElement(new SMWDIBlob($dataValue->getImportReference())));
                 } elseif ($property->getKey() == '_REDI') {
                     $expData->addPropertyObjectValue($pe, $ed);
                     $expData->addPropertyObjectValue(self::getSpecialPropertyResource('_URI'), $ed);
                 } elseif (!$property->isUserDefined() && !self::hasSpecialPropertyResource($property)) {
                     $expData->addPropertyObjectValue(self::getResourceElementForProperty($property, true), $ed);
                 } else {
                     $expData->addPropertyObjectValue($pe, $ed);
                 }
             }
             $edHelper = self::getDataItemHelperExpElement($dataItem);
             if ($edHelper !== null) {
                 $expData->addPropertyObjectValue($peHelper, $edHelper);
             }
         }
     }
 }
Beispiel #25
0
 /**
  * Create a value for the given property, provided as an SMWDIProperty
  * object. If no value is given, an empty container is created, the
  * value of which can be set later on.
  *
  * @param $property SMWDIProperty property object for which this value is made
  * @param $valueString mixed user value string, or false if unknown
  * @param $caption mixed user-defined caption, or false if none given
  * @param $contextPage SMWDIWikiPage that provides a context for parsing the value string, or null
  *
  * @return SMWDataValue
  */
 public static function newPropertyObjectValue(SMWDIProperty $property, $valueString = false, $caption = false, $contextPage = null)
 {
     $typeId = $property->isInverse() ? '_wpg' : $property->findPropertyTypeID();
     return self::newTypeIdValue($typeId, $valueString, $caption, $property, $contextPage);
 }
Beispiel #26
0
 /**
  * Set up predefined properties, including their label, aliases, and
  * typing information.
  */
 protected static function initPropertyRegistration()
 {
     if (is_array(SMWDIProperty::$m_prop_types)) {
         return;
         // init happened before
     }
     global $smwgContLang, $smwgUseCategoryHierarchy;
     $datatypeLabels = $smwgContLang->getDatatypeLabels();
     SMWDIProperty::$m_prop_labels = $smwgContLang->getPropertyLabels() + $datatypeLabels;
     SMWDIProperty::$m_prop_aliases = $smwgContLang->getPropertyAliases() + $smwgContLang->getDatatypeAliases();
     // Setup built-in predefined properties.
     // NOTE: all ids must start with underscores. The translation
     // for each ID, if any, is defined in the language files.
     // Properties without translation cannot be entered by or
     // displayed to users, whatever their "show" value below.
     SMWDIProperty::$m_prop_types = array('_TYPE' => array('__typ', true), '_URI' => array('__spu', true), '_INST' => array('__sin', false), '_UNIT' => array('__sps', true), '_IMPO' => array('__imp', true), '_CONV' => array('__sps', true), '_SERV' => array('__sps', true), '_PVAL' => array('__sps', true), '_REDI' => array('__red', true), '_SUBP' => array('__sup', true), '_SUBC' => array('__suc', !$smwgUseCategoryHierarchy), '_CONC' => array('__con', false), '_MDAT' => array('_dat', false), '_CDAT' => array('_dat', false), '_NEWP' => array('_boo', false), '_LEDT' => array('_wpg', false), '_ERRP' => array('_wpp', false), '_LIST' => array('__pls', true), '_SKEY' => array('__key', false), '_SF_DF' => array('__spf', true), '_SF_AF' => array('__spf', true), '_SOBJ' => array('_wpg', true), '_ASK' => array('_wpg', false), '_ASKST' => array('_cod', true), '_ASKFO' => array('_str', true), '_ASKSI' => array('_num', true), '_ASKDE' => array('_num', true));
     foreach ($datatypeLabels as $typeid => $label) {
         SMWDIProperty::$m_prop_types[$typeid] = array($typeid, true);
     }
     wfRunHooks('smwInitProperties');
 }
 /**
  * This function does the same as makeSMWPageID() but takes into account
  * that properties might be predefined.
  */
 protected function makeSMWPropertyID(SMWDIProperty $property)
 {
     if (!$property->isUserDefined() && array_key_exists($property->getKey(), self::$special_ids)) {
         return self::$special_ids[$property->getKey()];
         // very important property with fixed id
     } else {
         return $this->makeSMWPageID($property->getKey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki($property), '', true);
     }
 }
Beispiel #28
0
 public static function registerProperty($id, $typeid, $label)
 {
     if (class_exists('SMWDIProperty')) {
         SMWDIProperty::registerProperty($id, $typeid, $label, true);
     } else {
         SMWPropertyValue::registerProperty($id, $typeid, $label, true);
     }
 }
 /**
  * Creates and returns a new SWLChangeSet instance from a database result
  * obtained by doing a select on swl_sets. 
  * 
  * @since 0.1
  * 
  * @param array $changeSetArray
  * 
  * @return SWLChangeSet
  */
 public static function newFromArray(array $changeSetArray)
 {
     $changeSet = new SWLChangeSet(SMWDIWikiPage::newFromTitle(Title::newFromID($changeSetArray['page_id'])), null, null, null, $changeSetArray['id'], new SWLEdit($changeSetArray['page_id'], $changeSetArray['user_name'], $changeSetArray['time'], $changeSetArray['editid']));
     foreach ($changeSetArray['changes'] as $propName => $changes) {
         $property = SMWDIProperty::doUnserialize($propName, '__pro');
         foreach ($changes as $change) {
             $changeSet->addChange($property, SWLPropertyChange::newFromSerialization($property, array_key_exists('old', $change) ? $change['old'] : null, array_key_exists('new', $change) ? $change['new'] : null));
         }
     }
     return $changeSet;
 }
 /**
  * @see SMWStore::getPropertySubjects
  *
  * @todo This method cannot retrieve subjects for sortkeys, i.e., for
  * property _SKEY. Only empty arrays will be returned there.
  *
  * @param SMWDIProperty $property
  * @param SMWDataItem|null $value
  * @param SMWRequestOptions|null $requestOptions
  *
  * @return array of DIWikiPage
  */
 public function getPropertySubjects(SMWDIProperty $property, SMWDataItem $value = null, SMWRequestOptions $requestOptions = null)
 {
     /// TODO: should we share code with #ask query computation here? Just use queries?
     if ($property->isInverse()) {
         // inverses are working differently
         $noninverse = new SMW\DIProperty($property->getKey(), false);
         $result = $this->getPropertyValues($value, $noninverse, $requestOptions);
         return $result;
     }
     // #1222, Filter those where types don't match (e.g property = _txt
     // and value = _wpg)
     if ($value !== null && DataTypeRegistry::getInstance()->getDataItemId($property->findPropertyTypeID()) !== $value->getDIType()) {
         return array();
     }
     // First build $select, $from, and $where for the DB query
     $where = $from = '';
     $pid = $this->store->smwIds->getSMWPropertyID($property);
     $tableid = $this->store->findPropertyTableID($property);
     if ($pid == 0 || $tableid === '') {
         return array();
     }
     $proptables = $this->store->getPropertyTables();
     $proptable = $proptables[$tableid];
     $db = $this->store->getConnection();
     if ($proptable->usesIdSubject()) {
         // join with ID table to get title data
         $from = $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " INNER JOIN " . $db->tableName($proptable->getName()) . " AS t1 ON t1.s_id=smw_id";
         $select = 'smw_title, smw_namespace, smw_iw, smw_sortkey, smw_subobject';
     } else {
         // no join needed, title+namespace as given in proptable
         $from = $db->tableName($proptable->getName()) . " AS t1";
         $select = 's_title AS smw_title, s_namespace AS smw_namespace, \'\' AS smw_iw, s_title AS smw_sortkey, \'\' AS smw_subobject';
     }
     if (!$proptable->isFixedPropertyTable()) {
         $where .= ($where ? ' AND ' : '') . "t1.p_id=" . $db->addQuotes($pid);
     }
     $this->prepareValueQuery($from, $where, $proptable, $value, 1);
     // ***  Now execute the query and read the results  ***//
     $result = array();
     if (!$proptable->isFixedPropertyTable()) {
         if ($where !== '' && strpos(SMW_SQL3_SMWIW_OUTDATED, $where) === false) {
             $where .= " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW);
         } else {
             $where .= " smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWIW_OUTDATED) . " AND smw_iw!=" . $db->addQuotes(SMW_SQL3_SMWDELETEIW);
         }
     }
     $res = $db->select($from, 'DISTINCT ' . $select, $where . $this->store->getSQLConditions($requestOptions, 'smw_sortkey', 'smw_sortkey', $where !== ''), __METHOD__, $this->store->getSQLOptions($requestOptions, 'smw_sortkey'));
     $diHandler = $this->store->getDataItemHandlerForDIType(SMWDataItem::TYPE_WIKIPAGE);
     foreach ($res as $row) {
         try {
             if ($row->smw_iw === '' || $row->smw_iw[0] != ':') {
                 // filter special objects
                 $result[] = $diHandler->dataItemFromDBKeys(array_values((array) $row));
             }
         } catch (DataItemHandlerException $e) {
             // silently drop data, should be extremely rare and will usually fix itself at next edit
         }
     }
     $db->freeResult($res);
     return $result;
 }