/**
  * Check if the given object has already been serialised at sufficient
  * recursion depth.
  * @param SMWDIWikiPage $st specifying the object to check
  *
  * @return boolean
  */
 protected function isPageDone(SMWDIWikiPage $di, $recdepth)
 {
     return $this->isHashDone($di->getHash(), $recdepth);
 }
 /**
  * Helper method to make sure there is a cache entry for the data about
  * the given subject with the given ID.
  *
  * @todo The management of this cache should be revisited.
  *
  * @since 1.8
  */
 protected function initSemanticDataCache($sid, SMWDIWikiPage $subject)
 {
     // *** Prepare the cache ***//
     if (!array_key_exists($sid, $this->store->m_semdata)) {
         // new cache entry
         $this->store->m_semdata[$sid] = new SMWSql3StubSemanticData($subject, $this->store, false);
         $this->store->m_sdstate[$sid] = array();
     }
     // Issue #622
     // If a redirect was cached preceding this request and points to the same
     // subject id ensure that in all cases the requested subject matches with
     // the selected DB id
     if ($this->store->m_semdata[$sid]->getSubject()->getHash() !== $subject->getHash()) {
         $this->store->m_semdata[$sid] = new SMWSql3StubSemanticData($subject, $this->store, false);
         $this->store->m_sdstate[$sid] = array();
     }
     if (count($this->store->m_semdata) > 20 && self::$in_getSemanticData == 1) {
         // prevent memory leak;
         // It is not so easy to find the sweet spot between cache size and performance gains (both memory and time),
         // The value of 20 was chosen by profiling runtimes for large inline queries and heavily annotated pages.
         // However, things might have changed in the meantime ...
         $this->store->m_semdata = array($sid => $this->store->m_semdata[$sid]);
         $this->store->m_sdstate = array($sid => $this->store->m_sdstate[$sid]);
     }
 }
 /**
  * Load results of the given print request and result subject. This is only
  * done when needed.
  */
 protected function loadContent()
 {
     if ($this->mContent !== false) {
         return;
     }
     wfProfileIn('SMWQueryResult::loadContent (SMW)');
     switch ($this->mPrintRequest->getMode()) {
         case SMWPrintRequest::PRINT_THIS:
             // NOTE: The limit is ignored here.
             $this->mContent = array($this->mResult);
             break;
         case SMWPrintRequest::PRINT_CATS:
             // Always recompute cache here to ensure output format is respected.
             self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'), $this->getRequestOptions(false));
             self::$catCacheObj = $this->mResult->getHash();
             $limit = $this->mPrintRequest->getParameter('limit');
             $this->mContent = $limit === false ? self::$catCache : array_slice(self::$catCache, 0, $limit);
             break;
         case SMWPrintRequest::PRINT_PROP:
             $propertyValue = $this->mPrintRequest->getData();
             if ($propertyValue->isValid()) {
                 $this->mContent = $this->mStore->getPropertyValues($this->mResult, $propertyValue->getDataItem(), $this->getRequestOptions());
             } else {
                 $this->mContent = array();
             }
             // Print one component of a multi-valued string.
             // Known limitation: the printrequest still is of type _rec, so if printers check
             // for this then they will not recognize that it returns some more concrete type.
             if ($this->mPrintRequest->getTypeID() == '_rec' && $this->mPrintRequest->getParameter('index') !== false) {
                 $pos = $this->mPrintRequest->getParameter('index') - 1;
                 $newcontent = array();
                 foreach ($this->mContent as $diContainer) {
                     /* SMWRecordValue */
                     $recordValue = SMWDataValueFactory::newDataItemValue($diContainer, $propertyValue->getDataItem());
                     $dataItems = $recordValue->getDataItems();
                     if (array_key_exists($pos, $dataItems) && !is_null($dataItems[$pos])) {
                         $newcontent[] = $dataItems[$pos];
                     }
                 }
                 $this->mContent = $newcontent;
             }
             break;
         case SMWPrintRequest::PRINT_CCAT:
             ///NOTE: The limit is ignored here.
             if (self::$catCacheObj != $this->mResult->getHash()) {
                 self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'));
                 self::$catCacheObj = $this->mResult->getHash();
             }
             $found = false;
             $prkey = $this->mPrintRequest->getData()->getDBkey();
             foreach (self::$catCache as $cat) {
                 if ($cat->getDBkey() == $prkey) {
                     $found = true;
                     break;
                 }
             }
             $this->mContent = array(new SMWDIBoolean($found));
             break;
         default:
             $this->mContent = array();
             // Unknown print request.
     }
     reset($this->mContent);
     wfProfileOut('SMWQueryResult::loadContent (SMW)');
 }
Exemple #4
0
 /**
  * Create an SMWExpElement for some internal resource, given by an
  * SMWDIWikiPage object. This is the one place in the code where URIs
  * of wiki pages and user-defined properties are determined. A modifier
  * can be given to make variants of a URI, typically done for
  * auxiliary properties. In this case, the URI is modiied by appending
  * "-23$modifier" where "-23" is the URI encoding of "#" (a symbol not
  * occuring in MW titles).
  *
  * @param $diWikiPage SMWDIWikiPage or SMWDIProperty
  * @param $modifier string, using only Latin letters and numbers
  * @return SMWExpResource
  */
 public static function getResourceElementForWikiPage(SMWDIWikiPage $diWikiPage, $modifier = '')
 {
     global $wgContLang;
     if ($diWikiPage->getNamespace() == NS_MEDIA) {
         // special handling for linking media files directly (object only)
         $title = Title::makeTitle($diWikiPage->getNamespace(), $diWikiPage->getDBkey());
         $file = wfFindFile($title);
         if ($file !== false) {
             return new SMWExpResource($file->getFullURL());
         }
         // else: Medialink to non-existing file :-/ fall through
     }
     $hash = $diWikiPage->getHash() . $modifier;
     if (self::getResourceElementCache()->contains($hash)) {
         return self::getResourceElementCache()->fetch($hash);
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     if ($modifier === '') {
         $importProperty = new SMWDIProperty('_IMPO');
         $importDis = \SMW\StoreFactory::getStore()->getPropertyValues($diWikiPage, $importProperty);
         $importURI = count($importDis) > 0;
     } else {
         $importURI = false;
     }
     if ($importURI) {
         $importValue = DataValueFactory::getInstance()->newDataItemValue(current($importDis), $importProperty);
         $namespace = $importValue->getNS();
         $namespaceId = $importValue->getNSID();
         $localName = $importValue->getLocalName();
     } else {
         $localName = '';
         if ($diWikiPage->getNamespace() == SMW_NS_PROPERTY) {
             $namespace = self::getNamespaceUri('property');
             $namespaceId = 'property';
             $localName = self::encodeURI(rawurlencode($diWikiPage->getDBkey()));
         }
         if ($localName === '' || in_array($localName[0], array('-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
             $namespace = self::getNamespaceUri('wiki');
             $namespaceId = 'wiki';
             $localName = self::getEncodedPageName($diWikiPage);
         }
         if ($modifier !== '') {
             $localName .= '-23' . self::encodeURI(rawurlencode($modifier));
         }
     }
     $resource = new SMWExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
     self::getResourceElementCache()->save($hash, $resource);
     return $resource;
 }