/** * Handle the onDataChanged hook of SMW >1.6, which gets called * every time the value of a propery changes somewhere. * * @since 0.1 * * @param SMWStore $store * @param SMWChangeSet $changes * * @return true */ public static function onDataUpdate( SMWStore $store, SMWSemanticData $newData ) { $subject = $newData->getSubject(); $oldData = $store->getSemanticData( $subject ); $title = Title::makeTitle( $subject->getNamespace(), $subject->getDBkey() ); $groups = SWLGroups::getMatchingWatchGroups( $title ); $edit = false; foreach ( $groups as /* SWLGroup */ $group ) { $changeSet = SWLChangeSet::newFromSemanticData( $oldData, $newData, $group->getProperties() ); if ( $changeSet->hasUserDefinedProperties() ) { if ( $edit === false ) { $edit = new SWLEdit( $title->getArticleID(), $GLOBALS['wgUser']->getName(), wfTimestampNow() ); $edit->writeToDB(); } $changeSet->setEdit( $edit ); $setId = $changeSet->writeToStore( $groups, $edit->getId() ); if ( $setId != 0 ) { $group->notifyWatchingUsers( $changeSet ); } } } return true; }
/** * Helper function to handle getPropertyValues(). * * @param SMWStore $store * @param string $pageName * @param integer $pageNamespace * @param string $propID * @param null|SMWRequestOptions $requestOptions * * @return array of SMWDataItem */ public static function getSMWPropertyValues(SMWStore $store, $pageName, $pageNamespace, $propID, $requestOptions = null) { $pageName = str_replace(' ', '_', $pageName); $page = new SMWDIWikiPage($pageName, $pageNamespace, ''); $property = new SMWDIProperty($propID); return $store->getPropertyValues($page, $property, $requestOptions); }
/** * Helper function to handle getPropertyValues() in both SMW 1.6 * and earlier versions. * * @param SMWStore $store * @param string $pageName * @param integer $pageNamespace * @param string $propID * @param null|SMWRequestOptions $requestOptions * * @return array of SMWDataItem */ public static function getSMWPropertyValues( SMWStore $store, $pageName, $pageNamespace, $propID, $requestOptions = null ) { // SMWDIProperty was added in SMW 1.6 if ( class_exists( 'SMWDIProperty' ) ) { $pageName = str_replace( ' ', '_', $pageName ); $page = new SMWDIWikiPage( $pageName, $pageNamespace, null ); $property = new SMWDIProperty( $propID ); return $store->getPropertyValues( $page, $property, $requestOptions ); } else { $title = Title::makeTitleSafe( $pageNamespace, $pageName ); $property = SMWPropertyValue::makeProperty( $propID ); return $store->getPropertyValues( $title, $property, $requestOptions ); } }
public function execute() { // TODO It would be good if this script would work with SMW not being enable (yet). // Then one could setup the store without first enabling SMW (which will break the wiki until the store is setup). if (!defined('SMW_VERSION')) { $this->output("You need to have SMW enabled in order to use this maintenance script!\n\n"); exit; } $this->loadGlobalFunctions(); $store = $this->getStore(); if ($this->hasOption('delete')) { $this->dropStore($store); } else { SMWStore::setupStore(!$this->isQuiet()); } }
public function execute() { global $smwgDefaultStore; $alternativestore = $this->getArg('backend', false); $alternativestore = $alternativestore !== false && $alternativestore !== $smwgDefaultStore; if ($alternativestore !== false) { $smwgDefaultStore = $this->getArg('backend', false); print "\nSelected storage " . $smwgDefaultStore . " for update!\n\n"; } global $smwgIP; if (!isset($smwgIP)) { $smwgIP = dirname(__FILE__) . '/../'; } require_once $smwgIP . 'includes/SMW_GlobalFunctions.php'; if ($this->hasOption('delete')) { print "\n Deleting all stored data for {$smwgDefaultStore} completely!\n \n\n"; if ($alternativestore) { print " This store is currently not used by SMW. Deleting it\n should not cause problems in the wiki.\n\n"; $delay = 5; } else { print " WARNING: This store is currently used by SMW! Deleting it\n will cause problems in the wiki if SMW is enabled.\n\n"; $delay = 20; } print "Abort with CTRL-C in the next {$delay} seconds ... "; wfCountDown($delay); smwfGetStore()->drop(true); wfRunHooks('smwDropTables'); print "\n"; while (ob_get_level() > 0) { // be sure to have some buffer, otherwise some PHPs complain ob_end_flush(); } echo "\n All storage structures for {$smwgDefaultStore} have been deleted.\n You can recreate them with this script, and then use\n SMW_refreshData.php to rebuild their contents."; } else { SMWStore::setupStore(); } }
/** * @since 2.1 * * @param string $connectionTypeId * * @return mixed */ public function getConnection($connectionTypeId = 'mw.db') { return parent::getConnection($connectionTypeId); }
/** * Get the output string for a query in debugging mode. * * @param $query SMWQuery * @return string */ public function getDebugQueryResult(SMWQuery $query) { $this->m_sortkeys = $query->sortkeys; $sparqlCondition = $this->getSparqlCondition($query->getDescription()); $entries = array(); if ($sparqlCondition instanceof SMWSparqlSingletonCondition) { if ($sparqlCondition->condition === '') { // all URIs exist, no querying $sparql = 'None (no conditions).'; } else { $condition = $this->getSparqlConditionString($sparqlCondition); $namespaces = $sparqlCondition->namespaces; $sparql = smwfGetSparqlDatabase()->getSparqlForAsk($condition, $namespaces); } } elseif ($sparqlCondition instanceof SMWSparqlFalseCondition) { $sparql = 'None (conditions can not be satisfied by anything).'; } else { $condition = $this->getSparqlConditionString($sparqlCondition); $namespaces = $sparqlCondition->namespaces; $options = $this->getSparqlOptions($query, $sparqlCondition); $options['DISTINCT'] = true; $sparql = smwfGetSparqlDatabase()->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces); } $sparql = str_replace(array('[', ':', ' '), array('[', ':', ' '), $sparql); $entries['SPARQL Query'] = "<pre>{$sparql}</pre>"; return SMWStore::formatDebugOutput('SMWSparqlStore', $entries, $query); }
/** * Using a preprocessed internal query description referenced by $rootid, compute * the proper debug output for the given query. * * @param SMWQuery $query * @param integer $rootid * * @return string */ protected function getDebugQueryResult(SMWQuery $query, $rootid) { $qobj = $this->m_queries[$rootid]; $entries = array(); $sql_options = $this->getSQLOptions($query, $rootid); list($startOpts, $useIndex, $tailOpts) = $this->m_dbs->makeSelectOptions($sql_options); if ($qobj->joinfield !== '') { $entries['SQL Query'] = "<tt>SELECT DISTINCT {$qobj->alias}.smw_title AS t,{$qobj->alias}.smw_namespace AS ns FROM " . $this->m_dbs->tableName($qobj->jointable) . " AS {$qobj->alias}" . $qobj->from . ($qobj->where === '' ? '' : ' WHERE ') . $qobj->where . "{$tailOpts} LIMIT " . $sql_options['LIMIT'] . ' OFFSET ' . $sql_options['OFFSET'] . ';</tt>'; } else { $entries['SQL Query'] = 'Empty result, no SQL query created.'; } $auxtables = ''; foreach ($this->m_querylog as $table => $log) { $auxtables .= "<li>Temporary table {$table}"; foreach ($log as $q) { $auxtables .= "<br />  <tt>{$q}</tt>"; } $auxtables .= '</li>'; } if ($auxtables) { $entries['Auxilliary Tables Used'] = "<ul>{$auxtables}</ul>"; } else { $entries['Auxilliary Tables Used'] = 'No auxilliary tables used.'; } return SMWStore::formatDebugOutput('SMWSQLStore3', $entries, $query); }
/** * @since 1.9.1.1 */ public function setConfiguration(Settings $configuration) { self::$configuration = $configuration; }
/** * 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)'); }
/** * @see SMWStore::refreshData() * @since 1.8 */ public function refreshData(&$index, $count, $namespaces = false, $usejobs = true) { return $this->baseStore->refreshData($index, $count, $namespaces, $usejobs); }
protected function doUpdateTables() { if ($GLOBALS['wgRequest']->getText('udsure') == 'yes') { $this->printRawOutput(function () { $result = SMWStore::setupStore(); if ($result === true) { print '<p><b>' . wfMessage('smw_smwadmin_setupsuccess')->text() . "</b></p>\n"; } }); } }
public function execute($par) { global $wgOut, $wgRequest, $wgServer, $wgArticlePath, $wgUser, $smwgAdminRefreshStore; if (!$this->userCanExecute($wgUser)) { // If the user is not authorized, show an error. $this->displayRestrictionError(); return; } $this->setHeaders(); /**** Get status of refresh job, if any ****/ $dbr = wfGetDB(DB_SLAVE); $row = $dbr->selectRow('job', '*', array('job_cmd' => 'SMWRefreshJob'), __METHOD__); if ($row !== false) { // similar to Job::pop_type, but without deleting the job $title = Title::makeTitleSafe($row->job_namespace, $row->job_title); $blob = (string) $row->job_params !== '' ? unserialize($row->job_params) : false; $refreshjob = Job::factory($row->job_cmd, $title, $blob, $row->job_id); } else { $refreshjob = null; } /**** Execute actions if any ****/ $action = $wgRequest->getText('action'); if ($action == 'updatetables') { $sure = $wgRequest->getText('udsure'); if ($sure == 'yes') { $wgOut->disable(); // raw output ob_start(); print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\">\n<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Setting up Storage for Semantic MediaWiki</title></head><body><p><pre>"; header("Content-type: text/html; charset=UTF-8"); $result = SMWStore::setupStore(); print '</pre></p>'; if ($result === true) { print '<p><b>' . wfMessage('smw_smwadmin_setupsuccess')->text() . "</b></p>\n"; } $returntitle = SpecialPage::getTitleFor('SMWAdmin'); print '<p> ' . wfMessage('smw_smwadmin_return', '<a href="' . htmlspecialchars($returntitle->getFullURL()) . '">Special:SMWAdmin</a>')->text() . "</p>\n"; print '</body></html>'; ob_flush(); flush(); return; } } elseif ($smwgAdminRefreshStore && $action == 'refreshstore') { // managing refresh jobs for the store $sure = $wgRequest->getText('rfsure'); $title = SpecialPage::getTitleFor('SMWAdmin'); if ($sure == 'yes') { if (is_null($refreshjob)) { // careful, there might be race conditions here $newjob = new SMWRefreshJob($title, array('spos' => 1, 'prog' => 0, 'rc' => 2)); $newjob->insert(); $wgOut->addHTML('<p>' . wfMessage('smw_smwadmin_updatestarted', '<a href="' . htmlspecialchars($title->getFullURL()) . '">Special:SMWAdmin</a>')->text() . '</p>'); } else { $wgOut->addHTML('<p>' . wfMessage('smw_smwadmin_updatenotstarted', '<a href="' . htmlspecialchars($title->getFullURL()) . '">Special:SMWAdmin</a>')->text() . '</p>'); } } elseif ($sure == 'stop') { $dbw = wfGetDB(DB_MASTER); // delete (all) existing iteration jobs $dbw->delete('job', array('job_cmd' => 'SMWRefreshJob'), __METHOD__); $wgOut->addHTML('<p>' . wfMessage('smw_smwadmin_updatestopped', '<a href="' . htmlspecialchars($title->getFullURL()) . '">Special:SMWAdmin</a>')->text() . '</p>'); } else { $wgOut->addHTML('<p>' . wfMessage('smw_smwadmin_updatenotstopped', '<a href="' . htmlspecialchars($title->getFullURL()) . '">Special:SMWAdmin</a>')->text() . '</p>'); } return; } /**** Normal output ****/ $html = '<p>' . wfMessage('smw_smwadmin_docu')->text() . "</p>\n"; // creating tables and converting contents from older versions $html .= '<form name="buildtables" action="" method="POST">' . "\n" . '<input type="hidden" name="action" value="updatetables" />' . "\n"; $html .= '<br /><h2>' . wfMessage('smw_smwadmin_db')->text() . "</h2>\n" . '<p>' . wfMessage('smw_smwadmin_dbdocu')->text() . "</p>\n"; $html .= '<p>' . wfMessage('smw_smwadmin_permissionswarn')->text() . "</p>\n" . '<input type="hidden" name="udsure" value="yes"/>' . '<input type="submit" value="' . wfMessage('smw_smwadmin_dbbutton')->text() . '"/></form>' . "\n"; $html .= '<br /><h2>' . wfMessage('smw_smwadmin_datarefresh')->text() . "</h2>\n" . '<p>' . wfMessage('smw_smwadmin_datarefreshdocu')->text() . "</p>\n"; if (!is_null($refreshjob)) { $prog = $refreshjob->getProgress(); $html .= '<p>' . wfMessage('smw_smwadmin_datarefreshprogress')->text() . "</p>\n" . '<p><div style="float: left; background: #DDDDDD; border: 1px solid grey; width: 300px; "><div style="background: #AAF; width: ' . round($prog * 300) . 'px; height: 20px; "> </div></div>  ' . round($prog * 100, 4) . '%</p><br /><br />'; if ($smwgAdminRefreshStore) { $html .= '<form name="refreshwiki" action="" method="POST">' . '<input type="hidden" name="action" value="refreshstore" />' . '<input type="submit" value="' . wfMessage('smw_smwadmin_datarefreshstop')->escaped() . '" /> ' . ' <input type="checkbox" name="rfsure" value="stop"/> ' . wfMessage('smw_smwadmin_datarefreshstopconfirm')->escaped() . '</form>' . "\n"; } } elseif ($smwgAdminRefreshStore) { $html .= '<form name="refreshwiki" action="" method="POST">' . '<input type="hidden" name="action" value="refreshstore" />' . '<input type="hidden" name="rfsure" value="yes"/>' . '<input type="submit" value="' . wfMessage('smw_smwadmin_datarefreshbutton')->text() . '"/>' . '</form>' . "\n"; } $html .= '<br /><h2>' . wfMessage('smw_smwadmin_announce')->text() . "</h2>\n" . '<p>' . wfMessage('smw_smwadmin_announcedocu')->text() . "</p>\n" . '<p>' . wfMessage('smw_smwadmin_announcebutton')->text() . "</p>\n" . '<form name="announcewiki" action="http://semantic-mediawiki.org/wiki/Special:SMWRegistry" method="GET">' . '<input type="hidden" name="url" value="' . $wgServer . str_replace('$1', '', $wgArticlePath) . '" />' . '<input type="hidden" name="return" value="Special:SMWAdmin" />' . '<input type="submit" value="' . wfMessage('smw_smwadmin_announce')->text() . '"/></form>' . "\n"; $html .= '<br /><h2>' . wfMessage('smw_smwadmin_support')->text() . "</h2>\n" . '<p>' . wfMessage('smw_smwadmin_supportdocu')->text() . "</p>\n" . "<ul>\n" . '<li>' . wfMessage('smw_smwadmin_installfile')->text() . "</li>\n" . '<li>' . wfMessage('smw_smwadmin_smwhomepage')->text() . "</li>\n" . '<li>' . wfMessage('smw_smwadmin_mediazilla')->text() . "</li>\n" . '<li>' . wfMessage('smw_smwadmin_questions')->text() . "</li>\n" . "</ul>\n"; $wgOut->addHTML($html); }
} if (array_key_exists('t', $options)) { $filterarray[] = SMW_NS_TYPE; } $filter = count($filterarray) > 0 ? $filterarray : false; if (array_key_exists('f', $options)) { print "\n Deleting all stored data completely and rebuilding it again later!\n Semantic data in the wiki might be incomplete for some time while this operation runs.\n\n NOTE: It is usually necessary to run this script ONE MORE TIME after this operation,\n since some properties' types are not stored yet in the first run.\n The first run can normally use the parameter -p to refresh only properties.\n\n"; if (array_key_exists('s', $options) || array_key_exists('e', $options)) { print " WARNING: -s or -e are used, so some pages will not be refreshed at all!\n Data for those pages will only be available again when they have been\n refreshed as well!\n\n"; } print 'Abort with control-c in the next five seconds ... '; wfCountDown(6); smwfGetStore()->drop($verbose); wfRunHooks('smwDropTables'); print "\n"; SMWStore::setupStore($verbose); while (ob_get_level() > 0) { // be sure to have some buffer, otherwise some PHPs complain ob_end_flush(); } echo "\nAll storage structures have been deleted and recreated.\n\n"; } $linkCache = LinkCache::singleton(); $num_files = 0; if ($pages == false) { print "Refreshing all semantic data in the database!\n---\n" . " Some versions of PHP suffer from memory leaks in long-running scripts.\n" . " If your machine gets very slow after many pages (typically more than\n" . " 1000) were refreshed, please abort with CTRL-C and resume this script\n" . " at the last processed page id using the parameter -s (use -v to display\n" . " page ids during refresh). Continue this until all pages were refreshed.\n---\n"; print "Processing all IDs from {$start} to " . ($end ? "{$end}" : 'last ID') . " ...\n"; $id = $start; while ((!$end || $id <= $end) && $id > 0) { if ($verbose) { print "({$num_files}) Processing ID " . $id . " ...\n";