/** * Serialize data associated to a specific page. This method works on the * level of pages, i.e. it serialises parts of SMW content and implements * features like recursive export or backlinks that are available for this * type of data. * * The recursion depth means the following. Depth of 1 or above means * the object is serialised with all property values, and referenced * objects are serialised with depth reduced by 1. Depth 0 means that only * minimal declarations are serialised, so no dependencies are added. A * depth of -1 encodes "infinite" depth, i.e. a complete recursive * serialisation without limit. * * @param SMWDIWikiPage $diWikiPage specifying the page to be exported * @param integer $recursiondepth specifying the depth of recursion */ protected function serializePage(SMWDIWikiPage $diWikiPage, $recursiondepth = 1) { if ($this->isPageDone($diWikiPage, $recursiondepth)) { return; // do not export twice } $this->markPageAsDone($diWikiPage, $recursiondepth); $semData = $this->getSemanticData($diWikiPage, $recursiondepth == 0); // Don't try to serialize an empty page that cause an incomplete exp-data set // (e.g. _REDI as no property page hence DBKey is empty) if ($semData === null || $diWikiPage->getDBKey() === '') { return null; } $expData = SMWExporter::getInstance()->makeExportData($semData); $this->serializer->serializeExpData($expData, $recursiondepth); foreach ($semData->getSubSemanticData() as $subobjectSemData) { $this->serializer->serializeExpData(SMWExporter::getInstance()->makeExportData($subobjectSemData)); } // let other extensions add additional RDF data for this page $additionalDataArray = array(); \Hooks::run('smwAddToRDFExport', array($diWikiPage, &$additionalDataArray, $recursiondepth != 0, $this->add_backlinks)); foreach ($additionalDataArray as $additionalData) { $this->serializer->serializeExpData($additionalData); // serialise } if ($recursiondepth != 0) { $subrecdepth = $recursiondepth > 0 ? $recursiondepth - 1 : ($recursiondepth == 0 ? 0 : -1); foreach ($expData->getProperties() as $property) { if ($property->getDataItem() instanceof SMWWikiPageValue) { $this->queuePage($property->getDataItem(), 0); // no real recursion along properties } $wikipagevalues = false; foreach ($expData->getValues($property) as $valueExpElement) { $valueResource = $valueExpElement instanceof SMWExpData ? $valueExpElement->getSubject() : $valueExpElement; if (!$wikipagevalues && $valueResource->getDataItem() instanceof SMWWikiPageValue) { $wikipagevalues = true; } elseif (!$wikipagevalues) { break; } $this->queuePage($valueResource->getDataItem(), $subrecdepth); } } // Add backlinks: // Note: Backlinks are different from recursive serialisations, since // stub declarations (recdepth==0) still need to have the property that // links back to the object. So objects that would be exported with // recdepth 0 cannot be put into the main queue but must be done right // away. They also might be required many times, if they link back to // many different objects in many ways (we cannot consider them "Done" // if they were serialised at recdepth 0 only). if ($this->add_backlinks) { $inprops = \SMW\StoreFactory::getStore()->getInProperties($diWikiPage); foreach ($inprops as $inprop) { $propWikiPage = $inprop->getCanonicalDiWikiPage(); if (!is_null($propWikiPage)) { $this->queuePage($propWikiPage, 0); // no real recursion along properties } $inSubs = \SMW\StoreFactory::getStore()->getPropertySubjects($inprop, $diWikiPage); foreach ($inSubs as $inSub) { if (!$this->isPageDone($inSub, $subrecdepth)) { $semdata = $this->getSemanticData($inSub, true); if (!$semdata instanceof SMWSemanticData) { continue; } $semdata->addPropertyObjectValue($inprop, $diWikiPage); $expData = SMWExporter::getInstance()->makeExportData($semdata); $this->serializer->serializeExpData($expData, $subrecdepth); } } } if (NS_CATEGORY === $diWikiPage->getNamespace()) { // also print elements of categories $options = new SMWRequestOptions(); $options->limit = 100; // Categories can be large, always use limit $instances = \SMW\StoreFactory::getStore()->getPropertySubjects(new SMW\DIProperty('_INST'), $diWikiPage, $options); $pinst = new SMW\DIProperty('_INST'); foreach ($instances as $instance) { if (!array_key_exists($instance->getHash(), $this->element_done)) { $semdata = $this->getSemanticData($instance, true); if (!$semdata instanceof SMWSemanticData) { continue; } $semdata->addPropertyObjectValue($pinst, $diWikiPage); $expData = SMWExporter::getInstance()->makeExportData($semdata); $this->serializer->serializeExpData($expData, $subrecdepth); } } } elseif (SMW_NS_CONCEPT === $diWikiPage->getNamespace()) { // print concept members (slightly different code) $desc = new SMWConceptDescription($diWikiPage); $desc->addPrintRequest(new PrintRequest(PrintRequest::PRINT_THIS, '')); $query = new SMWQuery($desc); $query->setLimit(100); $res = \SMW\StoreFactory::getStore()->getQueryResult($query); $resarray = $res->getNext(); $pinst = new SMW\DIProperty('_INST'); while ($resarray !== false) { $instance = end($resarray)->getNextDataItem(); if (!$instance instanceof \SMWDataItem) { $resarray = $res->getNext(); continue; } if (!array_key_exists($instance->getHash(), $this->element_done)) { $semdata = $this->getSemanticData($instance, true); if (!$semdata instanceof \SMW\SemanticData) { $resarray = $res->getNext(); continue; } $semdata->addPropertyObjectValue($pinst, $diWikiPage); $expData = SMWExporter::getInstance()->makeExportData($semdata); $this->serializer->serializeExpData($expData); } $resarray = $res->getNext(); } } } } }
public static function getAllPagesForConcept($conceptName, $substring = null) { global $sfgMaxAutocompleteValues, $sfgAutocompleteOnAllChars; $store = smwfGetStore(); $conceptTitle = Title::makeTitleSafe(SMW_NS_CONCEPT, $conceptName); if (!is_null($substring)) { $substring = strtolower($substring); } // Escape if there's no such concept. if ($conceptTitle == null || !$conceptTitle->exists()) { return "Could not find concept: {$conceptName}"; } $conceptDI = SMWDIWikiPage::newFromTitle($conceptTitle); $desc = new SMWConceptDescription($conceptDI); $printout = new SMWPrintRequest(SMWPrintRequest::PRINT_THIS, ""); $desc->addPrintRequest($printout); $query = new SMWQuery($desc); $query->setLimit($sfgMaxAutocompleteValues); $query_result = $store->getQueryResult($query); $pages = array(); while ($res = $query_result->getNext()) { $pageName = $res[0]->getNextText(SMW_OUTPUT_WIKI); if (is_null($substring)) { $pages[] = $pageName; } else { // Filter on the substring manually. It would // be better to do this filtering in the // original SMW query, but that doesn't seem // possible yet. $lowercasePageName = strtolower($pageName); if ($sfgAutocompleteOnAllChars) { if (strpos($lowercasePageName, $substring) >= 0) { $pages[] = $pageName; } } else { if (strpos($lowercasePageName, $substring) === 0 || strpos($lowercasePageName, ' ' . $substring) > 0) { $pages[] = $pageName; } } } } sort($pages); return $pages; }