/**
  * @since 2.1
  */
 public function setupDependencies(Store $store)
 {
     // This needs to happen before access to a property object is granted
     // $pageCreator = UtilityFactory::getInstance()->newPageCreator();
     foreach ($this->getListOfPropertyInstances() as $propertyInstance) {
         $store->updateData($propertyInstance->getDependencies());
     }
 }
 /**
  * @since 2.2
  *
  * @param Store $store
  * @param Callable|null $reporterCallback
  *
  * @return PropertyStatisticsRebuilder
  */
 public function newPropertyStatisticsRebuilder(Store $store, $reporterCallback = null)
 {
     $messageReporter = MessageReporterFactory::getInstance()->newObservableMessageReporter();
     $messageReporter->registerReporterCallback($reporterCallback);
     $propertyStatisticsTable = new PropertyStatisticsTable($store->getConnection('mw.db'), SQLStore::PROPERTY_STATISTICS_TABLE);
     $propertyStatisticsRebuilder = new PropertyStatisticsRebuilder($store, $propertyStatisticsTable);
     $propertyStatisticsRebuilder->setMessageReporter($messageReporter);
     return $propertyStatisticsRebuilder;
 }
Пример #3
0
 /**
  * Returns wanted properties
  *
  * @note This function is very resource intensive and needs to be cached on
  * medium/large wikis.
  *
  * @since 1.9
  *
  * @return DIProperty[]
  */
 protected function doQuery()
 {
     Profiler::In(__METHOD__);
     $options = $this->store->getSQLOptions($this->requestOptions, 'title');
     $options['ORDER BY'] = 'count DESC';
     // TODO: this is not how JOINS should be specified in the select function
     $res = $this->dbConnection->select($this->dbConnection->tableName($this->propertyTable->getName()) . ' INNER JOIN ' . $this->dbConnection->tableName($this->store->getObjectIds()->getIdTable()) . ' ON p_id=smw_id LEFT JOIN ' . $this->dbConnection->tableName('page') . ' ON (page_namespace=' . $this->dbConnection->addQuotes(SMW_NS_PROPERTY) . ' AND page_title=smw_title)', 'smw_title, COUNT(*) as count', 'smw_id > 50 AND page_id IS NULL GROUP BY smw_title', __METHOD__, $options);
     Profiler::Out(__METHOD__);
     return $res;
 }
 private function compareWithKey($propertyKey)
 {
     if ($this->hasDiff()) {
         return;
     }
     $property = new DIProperty($propertyKey);
     $newValues = $this->semanticData->getPropertyValues($property);
     $oldValues = $this->store->getPropertyValues($this->semanticData->getSubject(), $property);
     $this->notifyDispatcher(!$this->isEqual($oldValues, $newValues));
 }
 private function hasMatchFor($id, $key, DIWikiPage $subject)
 {
     $key = $id . '#' . $key;
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     $requestOptions = new RequestOptions();
     $requestOptions->limit = 1;
     $result = $this->store->getPropertySubjects(new DIProperty($id), $subject, $requestOptions);
     $this->cache->save($key, $result !== array());
     return $result !== array();
 }
 /**
  * @since 2.5
  *
  * @param $dataItem
  *
  * @return DataItem
  */
 public function findRedirectTarget($dataItem)
 {
     if (!$dataItem instanceof DIWikiPage && !$dataItem instanceof DIProperty) {
         return $dataItem;
     }
     $hash = $dataItem->getSerialization();
     // Guard against a dataItem that points to itself
     $this->circularReferenceGuard->mark($hash);
     if (!$this->circularReferenceGuard->isCircularByRecursionFor($hash)) {
         $dataItem = $this->store->getRedirectTarget($dataItem);
     }
     $this->circularReferenceGuard->unmark($hash);
     return $dataItem;
 }
 /**
  * @since 2.0
  *
  * @return SemanticData
  */
 public function getSemanticData(DIWikiPage $subject)
 {
     $requestOptions = new RequestOptions();
     $requestOptions->sort = true;
     $semanticData = new SemanticData($subject);
     $incomingProperties = $this->store->getInProperties($subject, $requestOptions);
     foreach ($incomingProperties as $property) {
         $values = $this->store->getPropertySubjects($property, null);
         foreach ($values as $value) {
             $semanticData->addPropertyObjectValue($property, $value);
         }
     }
     return $semanticData;
 }
 /**
  * @since 2.4
  *
  * @param string $property
  *
  * @return boolean
  */
 public function findPropertyListFor($property = '')
 {
     $this->meta = array();
     $this->propertyList = array();
     $this->namespaces = array();
     $this->requestOptions->limit++;
     // increase by one to look ahead
     $this->continueOffset = 1;
     if ($property !== '') {
         $property = str_replace("_", " ", $property);
         $this->requestOptions->addStringCondition($property, StringCondition::STRCOND_MID);
         // Disjunctive condition to allow for auto searches of foaf OR Foaf
         $this->requestOptions->addStringCondition(ucfirst($property), StringCondition::STRCOND_MID, true);
     }
     $propertyListLookup = $this->store->getPropertiesSpecial($this->requestOptions);
     $this->requestOptions->limit--;
     foreach ($propertyListLookup->fetchList() as $value) {
         if ($this->continueOffset > $this->requestOptions->limit) {
             break;
         }
         $this->addPropertyToList($value);
         $this->continueOffset++;
     }
     $this->continueOffset = $this->continueOffset > $this->requestOptions->limit ? $this->requestOptions->limit : 0;
     $this->namespaces = array_keys($this->namespaces);
     $this->meta = array('limit' => $this->requestOptions->limit, 'count' => count($this->propertyList), 'isCached' => $propertyListLookup->isCached());
     return true;
 }
 private function tryToMatchDataItemForUnmatchedWikiNamespaceUri($uri)
 {
     $dataItem = null;
     // Sesame: Not a valid (absolute) URI: _node1abjt1k9bx17
     if (filter_var($uri, FILTER_VALIDATE_URL) === false) {
         return $dataItem;
     }
     $respositoryResult = $this->store->getConnection('sparql')->select('?v1 ?v2', "<{$uri}> rdfs:label ?v1 . <{$uri}> swivt:wikiNamespace ?v2", array('LIMIT' => 1));
     $expElements = $respositoryResult->current();
     if ($expElements !== false) {
         // ?v1
         if (isset($expElements[0])) {
             $dbKey = $expElements[0]->getLexicalForm();
         } else {
             $dbKey = 'UNKNOWN';
         }
         // ?v2
         if (isset($expElements[1])) {
             $namespace = strval($expElements[1]->getLexicalForm());
         } else {
             $namespace = NS_MAIN;
         }
         $dataItem = new DIWikiPage($this->getFittingKeyByCapitalLinks($dbKey, $namespace), $namespace);
     }
     return $dataItem;
 }
 /**
  * @since 2.4
  *
  * @param string $property
  *
  * @return boolean
  */
 public function findPropertyListBy($property = '')
 {
     $requestOptions = new RequestOptions();
     $requestOptions->sort = true;
     $requestOptions->limit = $this->limit;
     $isFromCache = false;
     //
     $this->matchPropertiesToPreferredLabelBy($property);
     // Increase by one to look ahead
     $requestOptions->limit++;
     $requestOptions = $this->doModifyRequestOptionsWith($property, $requestOptions);
     $propertyListLookup = $this->store->getPropertiesSpecial($requestOptions);
     $isFromCache = $propertyListLookup->isFromCache();
     // Restore original limit
     $requestOptions->limit--;
     foreach ($propertyListLookup->fetchList() as $value) {
         if ($this->continueOffset > $requestOptions->limit) {
             break;
         }
         $this->addPropertyToList($value);
         $this->continueOffset++;
     }
     $this->continueOffset = $this->continueOffset > $requestOptions->limit ? $requestOptions->limit : 0;
     $this->namespaces = array_keys($this->namespaces);
     $this->meta = array('limit' => $requestOptions->limit, 'count' => count($this->propertyList), 'isCached' => $isFromCache);
     return true;
 }
Пример #11
0
 /**
  * @since 1.9
  *
  * @return number
  */
 public function getUsedPropertiesCount()
 {
     $count = 0;
     $row = $this->dbConnection->selectRow(array($this->store->getStatisticsTable()), 'Count( * ) AS count', array('usage_count > 0'), __METHOD__);
     $count = $row ? $row->count : $count;
     return (int) $count;
 }
 /**
  * @since 2.3
  *
  * @param DIWikiPage $subject, $subobjectName
  * @param string $subobjectName
  */
 public function tryToMakeIdForSubject(DIWikiPage $subject, $subobjectName = '')
 {
     if ($subject->getNamespace() !== NS_CATEGORY && $subject->getNamespace() !== SMW_NS_PROPERTY) {
         return 0;
     }
     $id = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false);
     wfDebugLog('smw', __METHOD__ . " add new {$id} ID for " . $subject->getHash() . " \n");
     return $id;
 }
 private function getPropertyTableForType($type)
 {
     $propertyTables = $this->store->getPropertyTables();
     $tableIdForType = $this->store->findTypeTableId($type);
     if (isset($propertyTables[$tableIdForType])) {
         return $propertyTables[$tableIdForType];
     }
     throw new RuntimeException("Tried to access a table that doesn't exist for {$type}.");
 }
Пример #14
0
 protected function getPagesFromFilters()
 {
     $pages = array();
     $titleLookup = new TitleLookup($this->store->getConnection('mw.db'));
     foreach ($this->filters as $namespace) {
         $pages = array_merge($pages, $titleLookup->setNamespace($namespace)->selectAll());
     }
     return $pages;
 }
 private function getConceptDescription(DIWikiPage $concept)
 {
     $value = $this->store->getPropertyValues($concept, new DIProperty('_CONC'));
     if ($value === null || $value === array()) {
         return new ThingDescription();
     }
     $value = end($value);
     return ApplicationFactory::getInstance()->newQueryParser()->getQueryDescription($value->getConceptQuery());
 }
Пример #16
0
 private function doRealUpdate()
 {
     $this->store->setUpdateJobsEnabledState($this->updateJobsEnabledState);
     if ($this->processSemantics) {
         $this->store->updateData($this->semanticData);
     } else {
         $this->store->clearData($this->semanticData->getSubject());
     }
     return true;
 }
 private function findMatchesWith($id, $key, DIWikiPage $subject, $requestOptions)
 {
     $key = $id . '#' . $key . '#' . $requestOptions->getHash();
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     $result = $this->store->getPropertySubjects(new DIProperty($id), $subject, $requestOptions);
     $this->cache->save($key, $result);
     wfDebugLog('smw', __METHOD__ . " {$id} and " . $subject->getDBKey() . "\n");
     return $result;
 }
 /**
  * Figures out the label of the property to be used. For outgoing ones it is just
  * the text, for incoming ones we try to figure out the inverse one if needed,
  * either by looking for an explicitly stated one or by creating a default one.
  *
  * @param[in] $property SMWPropertyValue  The property of interest
  * @param[in] $incoming bool  If it is an incoming property
  *
  * @return string  The label of the property
  */
 private function getPropertyLabel(\SMWPropertyValue $property, $incoming = false)
 {
     if ($incoming && $this->getOption('showInverse')) {
         $oppositeprop = \SMWPropertyValue::makeUserProperty(wfMessage('smw_inverse_label_property')->text());
         $labelarray = $this->store->getPropertyValues($property->getDataItem()->getDiWikiPage(), $oppositeprop->getDataItem());
         $rv = count($labelarray) > 0 ? $labelarray[0]->getLongWikiText() : wfMessage('smw_inverse_label_default', $property->getWikiValue())->text();
     } else {
         $rv = $property->getWikiValue();
     }
     return $this->unbreak($rv);
 }
 private function tryToFindImportDataItem(DIWikiPage $diWikiPage, $modifier)
 {
     $importDataItems = null;
     // Only try to find an import vocab for a matchable entity
     if ($diWikiPage->getNamespace() === NS_CATEGORY || $diWikiPage->getNamespace() === SMW_NS_PROPERTY) {
         $importDataItems = $this->store->getPropertyValues($diWikiPage, new DIProperty('_IMPO'));
     }
     if ($importDataItems !== null && $importDataItems !== array()) {
         $importDataItems = current($importDataItems);
     }
     return $importDataItems;
 }
 private function tryToFindImportDataItem(DIWikiPage $diWikiPage, $modifier)
 {
     $importDataItems = null;
     // Only try to match an import vocab to an user-defined property
     if ($modifier === '' && $this->isUserDefinedPropertyPage($diWikiPage)) {
         $importDataItems = $this->store->getPropertyValues($diWikiPage, new DIProperty('_IMPO'));
     }
     if ($importDataItems !== null && $importDataItems !== array()) {
         $importDataItems = current($importDataItems);
     }
     return $importDataItems;
 }
Пример #21
0
 private function findMatchesFor($id, $key, DIWikiPage $subject)
 {
     $key = 'f#' . $id . '#' . $key;
     if ($this->cache->contains($key)) {
         return unserialize($this->cache->fetch($key));
     }
     $requestOptions = new RequestOptions();
     $result = $this->store->getPropertySubjects(new DIProperty($id), $subject, $requestOptions);
     $this->cache->save($key, serialize($result));
     wfDebugLog('smw', __METHOD__ . " {$id} and " . $subject->getDBKey() . "\n");
     return $result;
 }
Пример #22
0
 protected function createMultipleConcepts()
 {
     $titleLookup = new TitleLookup($this->store->getConnection('mw.db'));
     $titleLookup->setNamespace(SMW_NS_CONCEPT);
     if ($this->endId == 0 && $this->startId == 0) {
         return $titleLookup->selectAll();
     }
     $endId = $titleLookup->getMaxId();
     if ($this->endId > 0) {
         $endId = min($this->endId, $endId);
     }
     return $titleLookup->selectByIdRange($this->startId, $endId);
 }
Пример #23
0
 private function findNextIdPosition(&$id, $emptyrange)
 {
     $nextpos = $id + $this->iterationLimit;
     $db = $this->store->getConnection('mw.db');
     // nothing found, check if there will be more pages later on
     if ($emptyrange && $nextpos > \SMWSql3SmwIds::FXD_PROP_BORDER_ID) {
         $nextByPageId = (int) $db->selectField('page', 'page_id', "page_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "page_id ASC"));
         $nextBySmwId = (int) $db->selectField(\SMWSql3SmwIds::TABLE_NAME, 'smw_id', "smw_id >= {$nextpos}", __METHOD__, array('ORDER BY' => "smw_id ASC"));
         // Next position is determined by the pool with the maxId
         $nextpos = $nextBySmwId != 0 && $nextBySmwId > $nextByPageId ? $nextBySmwId : $nextByPageId;
     }
     $id = $nextpos ? $nextpos : -1;
 }
 private function doFetchPropertyValues($dataItems, $dataValue)
 {
     $propertyValues = array();
     foreach ($dataItems as $dataItem) {
         if (!$dataItem instanceof DIWikiPage) {
             continue;
         }
         $pv = $this->store->getPropertyValues($dataItem, $dataValue->getDataItem(), $this->getRequestOptions());
         $propertyValues = array_merge($propertyValues, $pv);
         unset($pv);
     }
     return $propertyValues;
 }
 private function selectPropertiesFromTable()
 {
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     if ($this->requestOptions->limit > 0) {
         $options['LIMIT'] = $this->requestOptions->limit;
         $options['OFFSET'] = max($this->requestOptions->offset, 0);
     }
     $conditions = array('smw_id > ' . SQLStore::FIXED_PROPERTY_ID_UPPERBOUND, 'smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '', 'smw_subobject' => '');
     $conditions['usage_count'] = 0;
     $idTable = $this->store->getObjectIds()->getIdTable();
     $res = $this->store->getConnection('mw.db')->select(array($idTable, $this->propertyStatisticsStore->getStatisticsTable()), array('smw_title', 'usage_count'), $conditions, __METHOD__, $options, array($idTable => array('INNER JOIN', array('smw_id=p_id'))));
     return $res;
 }
Пример #26
0
 private function selectPropertiesFromTable()
 {
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     $conditions = array('smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '');
     if ($this->requestOptions->limit > 0) {
         $options['LIMIT'] = $this->requestOptions->limit;
         $options['OFFSET'] = max($this->requestOptions->offset, 0);
     }
     if ($this->requestOptions->getStringConditions()) {
         $conditions[] = $this->store->getSQLConditions($this->requestOptions, '', 'smw_title', false);
     }
     $res = $this->store->getConnection('mw.db')->select($this->store->getObjectIds()->getIdTable(), array('smw_id', 'smw_title'), $conditions, __METHOD__, $options);
     return $res;
 }
 private function doQueryPropertyTable()
 {
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     $conditions = array('smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '');
     if ($this->requestOptions->limit > 0) {
         $options['LIMIT'] = $this->requestOptions->limit;
         $options['OFFSET'] = max($this->requestOptions->offset, 0);
     }
     if ($this->requestOptions->getStringConditions()) {
         $conditions[] = $this->store->getSQLConditions($this->requestOptions, '', 'smw_sortkey', false);
     }
     $db = $this->store->getConnection('mw.db');
     $res = $db->select(array($db->tableName(SQLStore::ID_TABLE), $db->tableName(SQLStore::PROPERTY_STATISTICS_TABLE)), array('smw_title', 'usage_count'), $conditions, __METHOD__, $options, array($db->tableName(SQLStore::ID_TABLE) => array('INNER JOIN', array('smw_id=p_id'))));
     return $res;
 }
Пример #28
0
 /**
  * @since 2.0
  */
 public function execute()
 {
     // TODO It would be good if this script would work with SMW not being enable (yet).
     // Then one could setup the store without first enabling SMW (which will break the wiki until the store is setup).
     if (!defined('SMW_VERSION')) {
         $this->output("You need to have SMW enabled in order to use this maintenance script!\n\n");
         exit;
     }
     $this->loadGlobalFunctions();
     $store = $this->getStore();
     if ($this->hasOption('delete')) {
         $this->dropStore($store);
     } else {
         Store::setupStore(!$this->isQuiet());
     }
 }
Пример #29
0
 /**
  * @since 1.9
  *
  * @return array
  */
 protected function doQuery()
 {
     Profiler::In(__METHOD__);
     // the query needs to do the filtering of internal properties, else LIMIT is wrong
     $options = array('ORDER BY' => 'smw_sortkey');
     if ($this->requestOptions !== null) {
         if ($this->requestOptions->limit > 0) {
             $options['LIMIT'] = $this->requestOptions->limit;
             $options['OFFSET'] = max($this->requestOptions->offset, 0);
         }
     }
     $conditions = array('smw_namespace' => SMW_NS_PROPERTY, 'smw_iw' => '');
     $conditions['usage_count'] = 0;
     $res = $this->dbConnection->select(array($this->store->getObjectIds()->getIdTable(), $this->store->getStatisticsTable()), array('smw_title', 'usage_count'), $conditions, __METHOD__, $options, array($this->store->getObjectIds()->getIdTable() => array('INNER JOIN', array('smw_id=p_id'))));
     Profiler::Out(__METHOD__);
     return $res;
 }
Пример #30
0
 private function handleYetUnknownRedirectTarget(SemanticData $semanticData, DIWikiPage $target)
 {
     // Only keep the reference to safeguard that even in case of a text keeping
     // its annotations there are removed from the Store. A redirect is not
     // expected to contain any other annotation other than that of the redirect
     // target
     $subject = $semanticData->getSubject();
     $semanticData = new SemanticData($subject);
     $semanticData->addPropertyObjectValue(new DIProperty('_REDI'), $target);
     // Force a manual changeTitle before the general update otherwise
     // #redirect can cause an inconsistent data container as observed in #895
     $this->store->changeTitle($subject->getTitle(), $target->getTitle(), $subject->getTitle()->getArticleID(), $target->getTitle()->getArticleID());
     $dispatchContext = EventHandler::getInstance()->newDispatchContext();
     $dispatchContext->set('title', $subject->getTitle());
     EventHandler::getInstance()->getEventDispatcher()->dispatch('factbox.cache.delete', $dispatchContext);
     return $semanticData;
 }