/**
  * Delete all semantic data stored for the given subject. Used for
  * update purposes.
  *
  * @param $subject SMWDIWikiPage the data of which is deleted
  */
 protected function deleteSemanticData(SMWDIWikiPage $subject)
 {
     if ($subject->getSubobjectName() !== '') {
         return;
     }
     // not needed, and would mess up data
     $db = wfGetDB(DB_MASTER);
     $id = $this->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), '', false);
     if ($id == 0) {
         // not (directly) used anywhere yet, may be a redirect but we do not care here
         wfRunHooks('smwDeleteSemanticData', array($subject));
         return;
     }
     foreach (self::getPropertyTables() as $proptable) {
         if ($proptable->name == 'smw_conc2') {
             continue;
         }
         // skip concepts, since they have chache data in their table which should be kept while the cache is intact
         if ($proptable->idsubject) {
             $db->delete($proptable->name, array('s_id' => $id), __METHOD__);
         } elseif ($proptable->name != 'smw_redi2') {
             /// NOTE: redirects are handled by updateRedirects(), not here!
             $db->delete($proptable->name, array('s_title' => $subject->getDBkey(), 's_namespace' => $subject->getNamespace()), __METHOD__);
         }
     }
     // also find subobjects used by this ID ...
     $res = $db->select('smw_ids', '*', 'smw_title = ' . $db->addQuotes($subject->getDBkey()) . ' AND ' . 'smw_namespace = ' . $db->addQuotes($subject->getNamespace()) . ' AND ' . 'smw_iw = ' . $db->addQuotes($subject->getInterwiki()) . ' AND ' . 'smw_subobject != ' . $db->addQuotes(''), __METHOD__);
     $subobjects = array();
     // ... and delete them as well
     foreach ($res as $row) {
         $subobjects[] = $row->smw_id;
         $this->m_idCache->setId($row->smw_title, $row->smw_namespace, $row->smw_iw, $row->smw_subobject, 0);
         // deleted below
         foreach (self::getPropertyTables() as $proptable) {
             if ($proptable->idsubject) {
                 $db->delete($proptable->name, array('s_id' => $row->smw_id), __METHOD__);
             }
         }
     }
     $db->freeResult($res);
     // free all affected subobjects in one call:
     if (count($subobjects) > 0) {
         $db->delete('smw_ids', array('smw_id' => $subobjects), __METHOD__);
     }
     wfRunHooks('smwDeleteSemanticData', array($subject));
 }
 /**
  * @see SMWStore::getProperties
  *
  * @param SMWDIWikiPage $subject
  * @param SMWRequestOptions $requestoptions
  */
 public function getProperties(SMWDIWikiPage $subject, $requestoptions = null)
 {
     wfProfileIn("SMWSQLStore3::getProperties (SMW)");
     $sid = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName());
     if ($sid == 0) {
         // no id, no page, no properties
         wfProfileOut("SMWSQLStore3::getProperties (SMW)");
         return array();
     }
     $db = wfGetDB(DB_SLAVE);
     $result = array();
     if ($requestoptions !== null) {
         // potentially need to get more results, since options apply to union
         $suboptions = clone $requestoptions;
         $suboptions->limit = $requestoptions->limit + $requestoptions->offset;
         $suboptions->offset = 0;
     } else {
         $suboptions = null;
     }
     foreach (SMWSQLStore3::getPropertyTables() as $proptable) {
         $from = $db->tableName($proptable->name);
         if ($proptable->idsubject) {
             $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 ($proptable->fixedproperty == false) {
             // select all properties
             $from .= " INNER JOIN " . $db->tableName('smw_ids') . " ON smw_id=p_id";
             $res = $db->select($from, 'DISTINCT smw_title,smw_sortkey', $where . $this->store->getSQLConditions($suboptions, 'smw_sortkey', 'smw_sortkey'), 'SMW::getProperties', $this->store->getSQLOptions($suboptions, 'smw_sortkey'));
             foreach ($res as $row) {
                 $result[] = new SMWDIProperty($row->smw_title);
             }
         } else {
             // just check if subject occurs in table
             $res = $db->select($from, '*', $where, 'SMW::getProperties', array('LIMIT' => 1));
             if ($db->numRows($res) > 0) {
                 $result[] = new SMWDIProperty($proptable->fixedproperty);
             }
         }
         $db->freeResult($res);
     }
     $result = $this->store->applyRequestOptions($result, $requestoptions);
     // apply options to overall result
     wfProfileOut("SMWSQLStore3::getProperties (SMW)");
     return $result;
 }
Пример #3
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
     }
     if ($diWikiPage->getSubobjectName() !== '') {
         $modifier = $diWikiPage->getSubobjectName();
     }
     if ($modifier === '') {
         $importProperty = new SMWDIProperty('_IMPO');
         $importDis = smwfGetStore()->getPropertyValues($diWikiPage, $importProperty);
         $importURI = count($importDis) > 0;
     } else {
         $importURI = false;
     }
     if ($importURI) {
         $importValue = SMWDataValueFactory::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';
             if ($diWikiPage->getNamespace() !== 0) {
                 $localName = str_replace(' ', '_', $wgContLang->getNSText($diWikiPage->getNamespace())) . ':' . $diWikiPage->getDBkey();
             } else {
                 $localName = $diWikiPage->getDBkey();
             }
             $localName = self::encodeURI(wfUrlencode($localName));
         }
         if ($modifier !== '') {
             $localName .= '-23' . $modifier;
         }
     }
     return new SMWExpNsResource($localName, $namespace, $namespaceId, $diWikiPage);
 }
Пример #4
0
 /**
  * Method to get all subobjects for a given subject.
  *
  * @since 1.8
  * @param SMWDIWikiPage $subject
  * @param DatabaseBase $dbr only used for reading
  * @return array of smw_id => SMWDIWikiPage
  */
 protected function getSubobjects(SMWDIWikiPage $subject, DatabaseBase $dbr)
 {
     $res = $dbr->select(SMWSql3SmwIds::tableName, 'smw_id,smw_subobject', 'smw_title = ' . $dbr->addQuotes($subject->getDBkey()) . ' AND ' . 'smw_namespace = ' . $dbr->addQuotes($subject->getNamespace()) . ' AND ' . 'smw_iw = ' . $dbr->addQuotes($subject->getInterwiki()) . ' AND ' . 'smw_subobject != ' . $dbr->addQuotes(''), __METHOD__);
     $diHandler = $this->store->getDataItemHandlerForDIType(SMWDataItem::TYPE_WIKIPAGE);
     $subobjects = array();
     foreach ($res as $row) {
         $subobjects[$row->smw_id] = $diHandler->dataItemFromDBKeys(array($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), '', $row->smw_subobject));
     }
     $dbr->freeResult($res);
     return $subobjects;
 }
 /**
  * Delete all semantic data stored for the given subject. Used for
  * update purposes. Handles Subobjects recursively
  *
  * @param $subject SMWDIWikiPage the data of which is deleted
  */
 public function deleteSemanticData(SMWDIWikiPage $subject)
 {
     $db = wfGetDB(DB_MASTER);
     $id = $this->store->smwIds->getSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), false, true);
     if ($id == 0) {
         // not (directly) used anywhere yet, may be a redirect but we do not care here
         wfRunHooks('smwDeleteSemanticData', array($subject));
         return;
     }
     //get oldData for diffing and updating property counts
     $oldData = $this->store->getSemanticData($subject);
     $this->doDiffandUpdateCount($oldData);
     $oldHashes = $this->store->smwIds->getPropertyTableHashes($id);
     foreach (SMWSQLStore3::getPropertyTables() as $tableId => $tableDeclaration) {
         $tableName = $tableDeclaration->name;
         if (array_key_exists($tableName, $oldHashes)) {
             $this->deleteTableSemanticData($id, $tableDeclaration);
         }
     }
     if ($subject->getSubobjectName() !== '') {
         wfRunHooks('smwDeleteSemanticData', array($subject));
         return;
         // Subobjects don't have subsubobjects
     }
     // also find subobjects used by this ID ...
     $oldSubobjects = $this->getSubobjects($subject);
     // ... and delete their data as well recursively
     foreach ($oldSubobjects as $subobject) {
         $this->deleteSemanticData($subobject);
     }
     //TODO: delete all unused subobjects
     wfRunHooks('smwDeleteSemanticData', array($subject));
 }
Пример #6
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;
 }