/** * @since 2.4 * * @param DIProperty $property * @param array|string $errorMsg * * @return DIContainer */ public function getContainerFor(DIProperty $property = null, $errorMsg = '') { if ($property !== null && $property->isInverse()) { $property = new DIProperty($property->getKey()); } $errorMsg = is_array($errorMsg) ? implode(' ', $errorMsg) : $errorMsg; $subject = new DIWikiPage($this->subject->getDBkey(), $this->subject->getNamespace(), $this->subject->getInterwiki(), '_ERR' . md5(($property !== null ? $property->getKey() : 'UNKNOWN') . $errorMsg)); // Encode brackets to avoid an annotion is created/included return $this->newDiContainer($subject, $property, InTextAnnotationParser::obscureAnnotation($errorMsg)); }
/** * @since 2.2 * * @param DIWikiPage $diWikiPage * * @return string */ public static function encodePage(DIWikiPage $diWikiPage) { $localName = ''; if ($diWikiPage->getInterwiki() !== '') { $localName = $diWikiPage->getInterwiki() . ':'; } if ($diWikiPage->getNamespace() !== 0) { $localName .= str_replace(' ', '_', $GLOBALS['wgContLang']->getNSText($diWikiPage->getNamespace())) . ':' . $diWikiPage->getDBkey(); } else { $localName .= $diWikiPage->getDBkey(); } return self::encodeUri(wfUrlencode($localName)); }
/** * #1416 create container manually to avoid any issues that may arise from * a failed Title::makeTitleSafe. */ private function newDIContainer(Query $query) { $subject = $query->getContextPage(); if ($subject === null) { $containerSemanticData = ContainerSemanticData::makeAnonymousContainer(); } else { $subject = new DIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $query->getQueryId()); $containerSemanticData = new ContainerSemanticData($subject); } return new DIContainer($containerSemanticData); }
private function newContainerSemanticData($hash) { if ($this->subject === null) { $containerSemanticData = ContainerSemanticData::makeAnonymousContainer(); $containerSemanticData->skipAnonymousCheck(); } else { $subobjectName = '_ERR' . md5($hash); $subject = new DIWikiPage($this->subject->getDBkey(), $this->subject->getNamespace(), $this->subject->getInterwiki(), $subobjectName); $containerSemanticData = new ContainerSemanticData($subject); } return $containerSemanticData; }
/** * The subobject is attached to a root subject therefore using the root as * identifier to allow it to be invalidated at once with all other subobjects * that relate to a subject */ private function getHashFrom(DIWikiPage $subject, $suffix = '') { return md5(HashBuilder::createHashIdFromSegments($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki()) . $suffix); }
private function defineElementsForDiWikiPage(DIWikiPage $diWikiPage, $modifier) { $localName = ''; if ($diWikiPage->getNamespace() === SMW_NS_PROPERTY) { $namespace = Exporter::getInstance()->getNamespaceUri('property'); $namespaceId = 'property'; $localName = Escaper::encodeUri(rawurlencode($diWikiPage->getDBkey())); } if ($localName === '' || in_array($localName[0], array('-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) { $namespace = Exporter::getInstance()->getNamespaceUri('wiki'); $namespaceId = 'wiki'; $localName = Escaper::encodePage($diWikiPage); } // "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not // occuring in MW titles). if ($modifier !== '') { $localName .= '-23' . Escaper::encodeUri(rawurlencode($modifier)); } return array($localName, $namespace, $namespaceId); }
/** * @see Store::getProperties * * @param DIWikiPage $subject * @param SMWRequestOptions|null $requestOptions * * @return SMWDataItem[] */ public function getProperties(DIWikiPage $subject, SMWRequestOptions $requestOptions = null) { $sid = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName()); if ($sid == 0) { // no id, no page, no properties return array(); } $db = $this->store->getConnection(); $result = array(); // potentially need to get more results, since options apply to union if ($requestOptions !== null) { $suboptions = clone $requestOptions; $suboptions->limit = $requestOptions->limit + $requestOptions->offset; $suboptions->offset = 0; } else { $suboptions = null; } foreach ($this->store->getPropertyTables() as $propertyTable) { if ($propertyTable->usesIdSubject()) { $where = 's_id=' . $db->addQuotes($sid); } elseif ($subject->getInterwiki() === '') { $where = 's_title=' . $db->addQuotes($subject->getDBkey()) . ' AND s_namespace=' . $db->addQuotes($subject->getNamespace()); } else { // subjects with non-emtpy interwiki cannot have properties continue; } if ($propertyTable->isFixedPropertyTable()) { // just check if subject occurs in table $res = $db->select($propertyTable->getName(), '*', $where, __METHOD__, array('LIMIT' => 1)); if ($db->numRows($res) > 0) { $result[] = new SMW\DIProperty($propertyTable->getFixedProperty()); } } else { // select all properties $from = $db->tableName($propertyTable->getName()); $from .= " INNER JOIN " . $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " ON smw_id=p_id"; $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey', $where . $this->store->getSQLConditions($suboptions, 'smw_sortkey', 'smw_sortkey'), __METHOD__, $this->store->getSQLOptions($suboptions, 'smw_sortkey')); foreach ($res as $row) { $result[] = new SMW\DIProperty($row->smw_title); } } $db->freeResult($res); } // apply options to overall result $result = $this->store->applyRequestOptions($result, $requestOptions); return $result; }
/** * @param Title|SMWWikiPageValue|DIWikiPage $concept * * @return DIConcept|null */ public function getStatus($concept) { $db = $this->store->getConnection(); $cid = $this->store->smwIds->getSMWPageID($concept->getDBkey(), $concept->getNamespace(), '', '', false); // TODO: catch db exception $row = $db->selectRow('smw_fpt_conc', array('concept_txt', 'concept_features', 'concept_size', 'concept_depth', 'cache_date', 'cache_count'), array('s_id' => $cid), __METHOD__); if ($row === false) { return null; } $dataItem = new DIConcept($concept, null, $row->concept_features, $row->concept_size, $row->concept_depth); if ($row->cache_date) { $dataItem->setCacheStatus('full'); $dataItem->setCacheDate($row->cache_date); $dataItem->setCacheCount($row->cache_count); } else { $dataItem->setCacheStatus('empty'); } return $dataItem; }
/** * @since 2.4 * * @param DIWikiPage $subject, $subobjectName * @param string $subobjectName */ public function createId(DIWikiPage $subject, $subobjectName = '') { $id = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false); wfDebugLog('smw', __METHOD__ . " add new {$id} ID for " . $subject->getHash() . " {$subobjectName}"); return $id; }
public function getIdForSubject(DIWikiPage $subject, $subobjectName = '') { return $this->store->getObjectIds()->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName, false); }
/** * @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 newResultIterator(DIWikiPage $subject) { $connection = $this->store->getConnection('mw.db'); $dbKey = $subject->getDBkey(); // #1955 Ensure to match a possible predefined property // (Modification date -> _MDAT) if ($subject->getNamespace() === SMW_NS_PROPERTY) { $dbKey = DIProperty::newFromUserLabel($subject->getDBkey())->getKey(); } $condition = 'smw_title = ' . $connection->addQuotes($dbKey) . ' AND ' . 'smw_namespace = ' . $connection->addQuotes($subject->getNamespace()) . ' AND ' . 'smw_iw = ' . $connection->addQuotes($subject->getInterwiki()) . ' AND ' . 'smw_subobject != ' . $connection->addQuotes(''); foreach ($this->skipOn as $skipOn) { $condition .= ' AND smw_subobject != ' . $connection->addQuotes($skipOn); } $res = $connection->select($connection->tablename(SQLStore::ID_TABLE), array('smw_id', 'smw_subobject', 'smw_sortkey'), $condition, __METHOD__); return $this->iteratorFactory->newResultIterator($res); }