/** * @since 2.0 */ public static function clear() { if (self::$instance !== null) { self::$instance->getSettings()->clear(); } self::$instance = null; }
/** * @since 2.2 * * @return ConnectionManager */ public function newConnectionManager() { $connectionManager = new ConnectionManager(); $repositoryConnectionProvider = new RepositoryConnectionProvider(); $repositoryConnectionProvider->setHttpVersionTo($this->applicationFactory->getSettings()->get('smwgSparqlRepositoryConnectorForcedHttpVersion')); $connectionManager->registerConnectionProvider('sparql', $repositoryConnectionProvider); return $connectionManager; }
private function doFetchResultsForRawParameters(array $rawParams) { // FIXME QueryDuration should be a property of the QueryProcessor or // QueryEngine but since we don't want to open the pandora's box and // increase issues within the current QueryProcessor implementation // we will track the time outside of the actual execution framework $queryDuration = 0; $start = microtime(true); list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode); $this->query->setSubject(DIWIkiPage::newFromTitle($this->parserData->getTitle())); $queryHash = $this->query->getHash(); $this->circularReferenceGuard->mark($queryHash); // If we caught in a circular loop (due to a template referencing to itself) // then we stop here before the next query execution to avoid an infinite // self-reference if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) { return ''; } $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); $format = $this->params['format']->getValue(); // FIXME Parser should be injected into the ResultPrinter // Enables specific formats to import its annotation data from // a recursive parse process in the result format // e.g. using ask query to search/set an invert property value if (isset($this->params['import-annotation']) && $this->params['import-annotation']->getValue()) { $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput()); } if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) { $queryDuration = microtime(true) - $start; } $this->circularReferenceGuard->unmark($queryHash); $this->createQueryProfile($this->query, $format, $queryDuration); return $result; }
private function doFetchResultsForRawParameters(array $rawParams) { // FIXME QueryDuration should be a property of the QueryProcessor or // QueryEngine but since we don't want to open the pandora's box and // increase issues within the current QueryProcessor implementation // we will track the time outside of the actual execution framework $queryDuration = 0; $start = microtime(true); list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode); $queryHash = $this->query->getHash(); $this->circularReferenceGuard->mark($queryHash); // If we caught in a circular loop (due to a template referencing to itself) // then we stop here before the next query execution to avoid an infinite // self-reference if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) { return ''; } $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); // FIXME Should be injected // A printer run its own isolated wgParser process therefore if the printer // or a template inclusion is used by a printer, possible extra annotations // need to be imported for further usage $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput()); if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) { $queryDuration = microtime(true) - $start; } $this->circularReferenceGuard->unmark($queryHash); $this->createQueryProfile($this->query, $this->params['format']->getValue(), $queryDuration); return $result; }
/** * @note Comparison must happen *before* the storage update; * even finding uses of a property fails after its type changed. */ private function inspectPropertySpecification() { if (!$this->enabledWithUpdateJobs) { return; } $propertySpecificationChangeNotifier = new PropertySpecificationChangeNotifier($this->store, $this->semanticData); $propertySpecificationChangeNotifier->compareWith($this->applicationFactory->getSettings()->get('smwgDeclarationProperties')); }
/** * @since 2.3 * * @return PropertyTableInfoFetcher */ public function newPropertyTableInfoFetcher() { $settings = $this->applicationFactory->getSettings(); $propertyTableInfoFetcher = new PropertyTableInfoFetcher(); $propertyTableInfoFetcher->setCustomFixedPropertyList($settings->get('smwgFixedProperties')); $propertyTableInfoFetcher->setCustomSpecialPropertyList($settings->get('smwgPageSpecialProperties')); return $propertyTableInfoFetcher; }
/** * @see PropertyAnnotatorDecorator::addPropertyValues */ protected function addPropertyValues() { $this->applicationFactory = ApplicationFactory::getInstance(); $settings = $this->applicationFactory->getSettings(); $namespace = $this->getSemanticData()->getSubject()->getNamespace(); foreach ($this->categories as $catname) { if (!$settings->get('smwgShowHiddenCategories') && $this->isHiddenCategory($catname)) { continue; } if ($settings->get('smwgCategoriesAsInstances') && $namespace !== NS_CATEGORY) { $this->getSemanticData()->addPropertyObjectValue(new DIProperty(DIProperty::TYPE_CATEGORY), new DIWikiPage($catname, NS_CATEGORY, '')); } if ($settings->get('smwgUseCategoryHierarchy') && $namespace === NS_CATEGORY) { $this->getSemanticData()->addPropertyObjectValue(new DIProperty(DIProperty::TYPE_SUBCATEGORY), new DIWikiPage($catname, NS_CATEGORY, '')); } } }
/** * @see https://www.mediawiki.org/wiki/Manual:$wgExtensionMessagesFiles */ private function registerI18n() { $smwgIP = $this->applicationFactory->getSettings()->get('smwgIP'); $this->globalVars['wgMessagesDirs']['SemanticMediaWiki'] = $smwgIP . 'i18n'; $this->globalVars['wgExtensionMessagesFiles']['SemanticMediaWiki'] = $smwgIP . 'languages/SMW_Messages.php'; $this->globalVars['wgExtensionMessagesFiles']['SemanticMediaWikiAlias'] = $smwgIP . 'languages/SMW_Aliases.php'; $this->globalVars['wgExtensionMessagesFiles']['SemanticMediaWikiMagic'] = $smwgIP . 'languages/SMW_Magic.php'; $this->globalVars['wgExtensionMessagesFiles']['SemanticMediaWikiNamespaces'] = $smwgIP . 'languages/SemanticMediaWiki.namespaces.php'; }
/** * @since 2.4 */ public function tearDown() { foreach ($this->configuration as $key => $value) { $GLOBALS[$key] = $value; $this->applicationFactory->getSettings()->set($key, $value); } $this->applicationFactory->clear(); $this->dataValueFactory->clear(); }
/** * @note Comparison must happen *before* the storage update; * even finding uses of a property fails after its type changed. */ private function inspectPropertySpecification() { if (!$this->updateJobsEnabledState) { return; } $propertySpecDiffFinder = new PropertySpecDiffFinder($this->store, $this->semanticData); $propertySpecDiffFinder->setPropertiesToCompare($this->applicationFactory->getSettings()->get('smwgDeclarationProperties')); $propertySpecDiffFinder->findDiff(); }
private function newHtmlContentBuilder($webRequest) { $htmlContentBuilder = new HtmlContentBuilder($this->applicationFactory->getStore(), $this->subjectDV->getDataItem()); $htmlContentBuilder->setOption('dir', $webRequest->getVal('dir')); $htmlContentBuilder->setOption('printable', $webRequest->getVal('printable')); $htmlContentBuilder->setOption('offset', $webRequest->getVal('offset')); $htmlContentBuilder->setOption('showInverse', $this->applicationFactory->getSettings()->get('smwgBrowseShowInverse')); $htmlContentBuilder->setOption('showAll', $this->applicationFactory->getSettings()->get('smwgBrowseShowAll')); $htmlContentBuilder->setOption('byApi', $this->applicationFactory->getSettings()->get('smwgBrowseByApi')); return $htmlContentBuilder; }
/** * @see https://www.mediawiki.org/wiki/Manual:$wgHooks * * @note $wgHooks contains a list of hooks which specifies for every event an * array of functions to be called. */ private function registerHooks() { $hookRegistry = new HookRegistry($this->globalVars, $this->directory); $hookRegistry->register(); if (!$this->applicationFactory->getSettings()->get('smwgSemanticsEnabled')) { return; } // Old-style registration $this->globalVars['wgHooks']['AdminLinks'][] = 'SMWExternalHooks::addToAdminLinks'; $this->globalVars['wgHooks']['PageSchemasRegisterHandlers'][] = 'SMWExternalHooks::onPageSchemasRegistration'; }
private function createQueryProfile($query, $format) { // If the smwgQueryProfiler is marked with FALSE then just don't create a profile. if ($this->applicationFactory->getSettings()->get('smwgQueryProfiler') === false) { return; } $query->setOption('smwgQueryDurationEnabled', $this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')); $profileAnnotatorFactory = $this->applicationFactory->getQueryFactory()->newProfileAnnotatorFactory(); $combinedProfileAnnotator = $profileAnnotatorFactory->newCombinedProfileAnnotator($query, $format); $combinedProfileAnnotator->pushAnnotationsTo($this->parserData->getSemanticData()); }
private function canPerformUpdate() { if ($this->getRedirectTarget() !== null) { return true; } // ParserOptions::getInterfaceMessage is being used to identify whether a // parse was initiated by `Message::parse` if ($this->text === '' || $this->parser->getOptions()->getInterfaceMessage()) { return false; } if (!$this->parser->getTitle()->isSpecialPage()) { return true; } $isEnabledSpecialPage = $this->applicationFactory->getSettings()->get('smwgEnabledSpecialPage'); foreach ($isEnabledSpecialPage as $specialPage) { if ($this->parser->getTitle()->isSpecial($specialPage)) { return true; } } return false; }
/** * Parsing text before an article is displayed or previewed, strip out * semantic properties and add them to the ParserOutput object * * @since 1.9 * * @param string &$text */ public function parse(&$text) { $title = $this->parserData->getTitle(); $this->settings = $this->applicationFactory->getSettings(); $this->doStripMagicWordsFromText($text); $this->setSemanticEnabledNamespaceState($title); $this->addRedirectTargetAnnotation($text); $linksInValues = $this->settings->get('smwgLinksInValues'); $text = preg_replace_callback($this->getRegexpPattern($linksInValues), $linksInValues ? 'self::process' : 'self::preprocess', $text); $this->parserData->getOutput()->addModules($this->getModules()); $this->parserData->pushSemanticDataToParserOutput(); SMWOutputs::commitToParserOutput($this->parserData->getOutput()); }
/** * @note Make sure to have a valid revision (null means delete etc.) and * check if semantic data should be processed and displayed for a page in * the given namespace */ private function performUpdate() { Profiler::In(); $this->applicationFactory = ApplicationFactory::getInstance(); if ($this->updateJobsEnabledState === null) { $this->setUpdateJobsEnabledState($this->applicationFactory->getSettings()->get('smwgEnableUpdateJobs')); } $title = $this->getSubject()->getTitle(); $wikiPage = $this->applicationFactory->newPageCreator()->createPage($title); $revision = $wikiPage->getRevision(); $this->updateSemanticData($title, $wikiPage, $revision); Profiler::Out(); return $this->doRealUpdate($this->inspectPropertyType()); }
private function doFetchResultsForRawParameters(array $rawParams) { // FIXME QueryDuration should be a property of the QueryProcessor or // QueryEngine but since we don't want to open the pandora's box and // increase issues within the current QueryProcessor implementation // we will track the time outside of the actual execution framework $queryDuration = 0; $start = microtime(true); list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode); $this->result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY); if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) { $queryDuration = microtime(true) - $start; } $this->createQueryProfile($this->query, $this->params['format']->getValue(), $queryDuration); }
/** * Parsing text before an article is displayed or previewed, strip out * semantic properties and add them to the ParserOutput object * * @since 1.9 * * @param string &$text */ public function parse(&$text) { $title = $this->parserData->getTitle(); $this->settings = $this->applicationFactory->getSettings(); // Identifies the current parser run (especially when called recursively) $this->parserData->getSubject()->setContextReference('intp:' . uniqid()); $this->doStripMagicWordsFromText($text); $this->setSemanticEnabledNamespaceState($title); $this->addRedirectTargetAnnotation($text); $linksInValues = $this->settings->get('smwgLinksInValues'); $text = preg_replace_callback($this->getRegexpPattern($linksInValues), $linksInValues ? 'self::process' : 'self::preprocess', $text); if ($this->isEnabledNamespace) { $this->parserData->getOutput()->addModules($this->getModules()); } $this->parserData->pushSemanticDataToParserOutput(); SMWOutputs::commitToParserOutput($this->parserData->getOutput()); }
/** * Parsing text before an article is displayed or previewed, strip out * semantic properties and add them to the ParserOutput object * * @since 1.9 * * @param string &$text */ public function parse(&$text) { $title = $this->parserData->getTitle(); $this->settings = $this->applicationFactory->getSettings(); $start = microtime(true); // Identifies the current parser run (especially when called recursively) $this->parserData->getSubject()->setContextReference('intp:' . uniqid()); $this->doStripMagicWordsFromText($text); $this->isEnabledNamespace = $this->isSemanticEnabledForNamespace($title); $this->addRedirectTargetAnnotationFromText($text); $linksInValues = $this->settings->get('smwgLinksInValues'); $text = preg_replace_callback($this->getRegexpPattern($linksInValues), $linksInValues ? 'self::process' : 'self::preprocess', $text); if ($this->isEnabledNamespace) { $this->parserData->getOutput()->addModules($this->getModules()); if (method_exists($this->parserData->getOutput(), 'recordOption')) { $this->parserData->getOutput()->recordOption('userlang'); } } $this->parserData->pushSemanticDataToParserOutput(); $this->parserData->addLimitReport('intext-parsertime', number_format(microtime(true) - $start, 3)); SMWOutputs::commitToParserOutput($this->parserData->getOutput()); }
/** * Returns magic words attached to the ParserOutput object * * @since 1.9 * * @return string|null */ protected function getMagicWords() { $settings = $this->applicationFactory->getSettings(); $parserOutput = $this->parserData->getOutput(); // Prior MW 1.21 mSMWMagicWords is used (see SMW\ParserTextProcessor) if (method_exists($parserOutput, 'getExtensionData')) { $smwMagicWords = $parserOutput->getExtensionData('smwmagicwords'); $mws = $smwMagicWords === null ? array() : $smwMagicWords; } else { // @codeCoverageIgnoreStart $mws = isset($parserOutput->mSMWMagicWords) ? $parserOutput->mSMWMagicWords : array(); // @codeCoverageIgnoreEnd } if (in_array('SMW_SHOWFACTBOX', $mws)) { $showfactbox = SMW_FACTBOX_NONEMPTY; } elseif (in_array('SMW_NOFACTBOX', $mws)) { $showfactbox = SMW_FACTBOX_HIDDEN; } elseif ($this->useInPreview) { $showfactbox = $settings->get('smwgShowFactboxEdit'); } else { $showfactbox = $settings->get('smwgShowFactbox'); } return $showfactbox; }
private function newTemporaryTableBuilder() { $temporaryTableBuilder = new TemporaryTableBuilder($this->store->getConnection('mw.db.queryengine')); $temporaryTableBuilder->withAutoCommit($this->applicationFactory->getSettings()->get('smwgQTemporaryTablesAutoCommitMode')); return $temporaryTableBuilder; }
/** * @see Job::insert * * @since 1.9 * @codeCoverageIgnore */ public function insert() { if ($this->applicationFactory->getSettings()->get('smwgEnableUpdateJobs')) { parent::insert(); } }
private function canAddHelpForm() { return $this->applicationFactory->getSettings()->get('smwgEnabledEditPageHelp'); }