コード例 #1
0
 /**
  * @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));
 }
コード例 #2
0
 /**
  * @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));
 }
コード例 #3
0
 /**
  * @since  1.0
  *
  * @param DIWikiPage $subject
  */
 public function tryToFindLinksFor(DIWikiPage $subject)
 {
     if (!isset($this->propertySearchPatternByNamespace[$subject->getNamespace()])) {
         return;
     }
     $propertySearchPattern = $this->propertySearchPatternByNamespace[$subject->getNamespace()];
     $requestOptions = new RequestOptions();
     $requestOptions->sort = true;
     // Use 3 as buffer to broaden match possibilities
     $requestOptions->limit = 3;
     $this->doResolveAntecedentHierarchyRecursively($subject, $propertySearchPattern, $requestOptions);
     krsort($this->antecedentHierarchyLinks);
     if (!$this->findClosestDescendant) {
         return;
     }
     $this->doFindClosestDescendantByInverseLink($subject, $propertySearchPattern, $requestOptions);
 }
コード例 #4
0
 /**
  * #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);
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 /**
  * @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;
 }
コード例 #7
0
 /**
  * @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;
 }
コード例 #8
0
 /**
  * @since  2.1
  *
  * @param integer $sid
  * @param DIWikiPage $subject
  * @param integer|string|null $interWiki
  */
 public function updateInterwikiField($sid, DIWikiPage $subject, $interWiki = null)
 {
     $this->store->getConnection()->update(self::tableName, array('smw_iw' => $interWiki !== null ? $interWiki : $subject->getInterWiki()), array('smw_id' => $sid), __METHOD__);
     $this->setCache($subject->getDBKey(), $subject->getNamespace(), $subject->getInterWiki(), $subject->getSubobjectName(), $sid, $subject->getSortKey());
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 private function tryToInvalidateCachedListLookupEntryFor(DIWikiPage $subject)
 {
     if ($subject->getNamespace() !== SMW_NS_PROPERTY) {
         return null;
     }
     $this->factory->newPropertyUsageCachedListLookup()->deleteCache();
     $this->factory->newUnusedPropertyCachedListLookup()->deleteCache();
     $this->factory->newUndeclaredPropertyCachedListLookup()->deleteCache();
     $this->factory->newUsageStatisticsCachedListLookup()->deleteCache();
 }
コード例 #11
0
 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;
 }
コード例 #12
0
 /**
  * @since 2.1
  *
  * @param DIWikiPage $dataItem
  *
  * @return string
  */
 public static function getHashIdForDiWikiPage(DIWikiPage $dataItem)
 {
     return self::createFromSegments($dataItem->getDBKey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSubobjectName());
 }
コード例 #13
0
 private function doDeferredCachedListLookupUpdate(DIWikiPage $subject)
 {
     if ($subject->getNamespace() !== SMW_NS_PROPERTY) {
         return null;
     }
     $deferredCallableUpdate = $this->factory->newDeferredCallableCachedListLookupUpdate();
     $deferredCallableUpdate->setOrigin(__METHOD__);
     $deferredCallableUpdate->pushToUpdateQueue();
 }
コード例 #14
0
 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;
 }
コード例 #16
0
 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);
 }
コード例 #17
0
ファイル: DataValueFactory.php プロジェクト: Rikuforever/wiki
 /**
  * This factory method returns a data value object from a given property,
  * value string. It is intended to be used on user input to allow to
  * turn a property and value string into a data value object.
  *
  * @since 1.9
  *
  * @param string $propertyName property string
  * @param string $valueString user value string
  * @param mixed $caption user-defined caption
  * @param SMWDIWikiPage|null $contextPage context for parsing the value string
  *
  * @return DataValue
  */
 public function newPropertyValue($propertyName, $valueString, $caption = false, DIWikiPage $contextPage = null)
 {
     // Enforce upper case for the first character on annotations that are used
     // within the property namespace in order to avoid confusion when
     // $wgCapitalLinks setting is disabled
     if ($contextPage !== null && $contextPage->getNamespace() === SMW_NS_PROPERTY) {
         $propertyName = ucfirst($propertyName);
     }
     $propertyDV = SMWPropertyValue::makeUserProperty($propertyName);
     if (!$propertyDV->isValid()) {
         return $propertyDV;
     }
     if (!$propertyDV->canUse()) {
         return new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw-datavalue-property-restricted-use', $propertyName)->inContentLanguage()->text(), $valueString, $caption);
     }
     $propertyDI = $propertyDV->getDataItem();
     if ($propertyDI instanceof SMWDIError) {
         return $propertyDV;
     }
     if ($propertyDI instanceof DIProperty && !$propertyDI->isInverse()) {
         $dataValue = $this->newPropertyObjectValue($propertyDI, $valueString, $caption, $contextPage);
     } elseif ($propertyDI instanceof DIProperty && $propertyDI->isInverse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw_noinvannot')->inContentLanguage()->text(), $valueString, $caption);
     } else {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw-property-name-invalid', $propertyName)->inContentLanguage()->text(), $valueString, $caption);
     }
     if ($dataValue->isValid() && !$dataValue->canUse()) {
         $dataValue = new ErrorValue($propertyDV->getPropertyTypeID(), wfMessage('smw-datavalue-restricted-use', implode(',', $datavalue->getErrors()))->inContentLanguage()->text(), $valueString, $caption);
     }
     return $dataValue;
 }
コード例 #18
0
 /**
  * @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;
 }
コード例 #19
0
 /**
  * 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);
 }
コード例 #20
0
 private function tryToFindAtLeastOnePropertyTableReferenceFor(DIProperty $property)
 {
     $resultList = '';
     $resultMessage = '';
     $resultCount = 0;
     $extra = '';
     $dataItem = ApplicationFactory::getInstance()->getStore()->getPropertyTableIdReferenceFinder()->tryToFindAtLeastOneReferenceForProperty($property);
     if (!$dataItem instanceof DIWikiPage) {
         $resultMessage = 'No reference found.';
         return array($resultMessage, $resultList, $resultCount);
     }
     // In case the item has already been marked as deleted but is yet pending
     // for removal
     if ($dataItem->getInterWiki() === ':smw-delete') {
         $resultMessage = 'Item reference "' . $dataItem->getSubobjectName() . '" has already been marked for removal.';
         $dataItem = new DIWikiPage($dataItem->getDBKey(), $dataItem->getNamespace());
     }
     $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem);
     $dataValue->setOutputFormat('LOCL');
     if ($dataValue->isValid()) {
         //$resultMessage = 'Item reference for a zero-marked property.';
         $resultList = $dataValue->getShortHtmlText($this->linker) . ' ' . $extra;
         $resultCount++;
         $resultList .= '  ' . Infolink::newBrowsingLink('+', $dataValue->getLongWikiText())->getHTML($this->linker);
     }
     return array($resultMessage, $resultList, $resultCount);
 }