/**
  * @since  1.9
  */
 protected function loadAtInstantiation()
 {
     /**
      * Settings object definition
      *
      * @since  1.9
      *
      * @return Settings
      */
     $this->registerObject('Settings', function () {
         return Settings::newFromGlobals();
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * Store object definition
      *
      * @since  1.9
      *
      * @return Store
      */
     $this->registerObject('Store', function (DependencyBuilder $builder) {
         return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore'));
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * CacheHandler object definition
      *
      * @since  1.9
      *
      * @return CacheHandler
      */
     $this->registerObject('CacheHandler', function (DependencyBuilder $builder) {
         return CacheHandler::newFromId($builder->newObject('Settings')->get('smwgCacheType'));
     }, DependencyObject::SCOPE_SINGLETON);
 }
 protected function getTypeProperties($typeLabel)
 {
     global $wgRequest, $smwgTypePagingLimit;
     if ($smwgTypePagingLimit <= 0) {
         return '';
         // not too useful, but we comply to this request
     }
     $from = $wgRequest->getVal('from');
     $until = $wgRequest->getVal('until');
     $typeValue = DataValueFactory::getInstance()->newTypeIDValue('__typ', $typeLabel);
     if (!$typeValue->isValid()) {
         return $this->msg('smw-special-types-no-such-type')->escaped();
     }
     $store = \SMW\StoreFactory::getStore();
     $options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
     $diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
     if (!$options->ascending) {
         $diWikiPages = array_reverse($diWikiPages);
     }
     $result = '';
     if (count($diWikiPages) > 0) {
         $pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
         $title = $this->getTitleFor('Types', $typeLabel);
         $title->setFragment('#SMWResults');
         // Make navigation point to the result list.
         $navigation = $pageLister->getNavigationLinks($title);
         $resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
         $typeName = $typeValue->getLongWikiText();
         $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMessage('smw_type_header', $typeName)->text() . "</h2>\n<p>" . wfMessage('smw_typearticlecount')->numParams($resultNumber)->text() . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
     }
     return $result;
 }
 /**
  * @since  1.9
  */
 protected function loadAtInstantiation()
 {
     /**
      * Settings object definition
      *
      * @since  1.9
      *
      * @return Settings
      */
     $this->registerObject('Settings', function () {
         return Settings::newFromGlobals();
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * Store object definition
      *
      * @since  1.9
      *
      * @return Store
      */
     $this->registerObject('Store', function (DependencyBuilder $builder) {
         return StoreFactory::getStore($builder->newObject('Settings')->get('smwgDefaultStore'));
     }, DependencyObject::SCOPE_SINGLETON);
     /**
      * @since  1.9
      *
      * @return Cache
      */
     $this->registerObject('Cache', function (DependencyBuilder $builder) {
         return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache();
     }, DependencyObject::SCOPE_SINGLETON);
 }
Example #4
0
 /**
  * Returns the HTML which is added to $wgOut after the article text.
  *
  * @return string
  */
 protected function getHtml()
 {
     if ($this->limit > 0) {
         // limit==0: configuration setting to disable this completely
         $store = StoreFactory::getStore();
         $concept = $store->getConceptCacheStatus($this->getDataItem());
         $description = new ConceptDescription($this->getDataItem());
         $query = SMWPageLister::getQuery($description, $this->limit, $this->from, $this->until);
         $queryResult = $store->getQueryResult($query);
         $diWikiPages = $queryResult->getResults();
         if ($this->until !== '') {
             $diWikiPages = array_reverse($diWikiPages);
         }
         $errors = $queryResult->getErrors();
     } else {
         $diWikiPages = array();
         $errors = array();
     }
     $pageLister = new SMWPageLister($diWikiPages, null, $this->limit, $this->from, $this->until);
     $this->mTitle->setFragment('#SMWResults');
     // Make navigation point to the result list.
     $navigation = $pageLister->getNavigationLinks($this->mTitle);
     $titleText = htmlspecialchars($this->mTitle->getText());
     $resultNumber = min($this->limit, count($diWikiPages));
     // Concept cache information
     if ($concept instanceof DIConcept && $concept->getCacheStatus() === 'full') {
         $cacheInformation = Html::element('span', array('class' => 'smw-concept-cache-information'), ' ' . $this->getContext()->msg('smw-concept-cache-text', $this->getContext()->getLanguage()->formatNum($concept->getCacheCount()), $this->getContext()->getLanguage()->date($concept->getCacheDate()), $this->getContext()->getLanguage()->time($concept->getCacheDate()))->text());
     } else {
         $cacheInformation = '';
     }
     return Html::element('br', array('id' => 'smwfootbr')) . Html::element('a', array('name' => 'SMWResults'), null) . Html::rawElement('div', array('id' => 'mw-pages'), Html::rawElement('h2', array(), $this->getContext()->msg('smw_concept_header', $titleText)->text()) . Html::element('span', array(), $this->getContext()->msg('smw_conceptarticlecount', $resultNumber)->parse()) . smwfEncodeMessages($errors) . ' ' . $navigation . $cacheInformation . $pageLister->formatList());
 }
 public function testGetters()
 {
     $diType = SMWDataItem::TYPE_NUMBER;
     $name = 'smw_di_number';
     $instance = new TableDefinition($diType, $name);
     $this->assertInternalType('array', $instance->getFields(StoreFactory::getStore('SMWSQLStore3')));
     $this->assertEquals($diType, $instance->getDiType());
     $this->assertEquals($name, $instance->getName());
 }
Example #6
0
 /**
  * Helper function to get the SMW data store for different versions
  * of SMW.
  */
 public static function getSMWStore()
 {
     if (class_exists('\\SMW\\StoreFactory')) {
         // SMW 1.9+
         return \SMW\StoreFactory::getStore();
     } else {
         return smwfGetStore();
     }
 }
 /**
  * @dataProvider propertyObjectProvider
  */
 public function testPhpSerialization($property, $dataItem)
 {
     $instance = StubSemanticData::newFromSemanticData(new SemanticData(new DIWikiPage('Foo', NS_MAIN)), $this->store);
     $instance->addPropertyObjectValue($property, $dataItem);
     StoreFactory::setDefaultStoreForUnitTest($this->store);
     $serialization = serialize($instance);
     $this->assertEquals($instance->getHash(), unserialize($serialization)->getHash());
     StoreFactory::clear();
 }
Example #8
0
 /**
  * @test TableDefinition::getFields
  * @test TableDefinition::getDiType
  * @test TableDefinition::getName
  *
  * @since 1.9
  */
 public function testGetters()
 {
     $diType = SMWDataItem::TYPE_NUMBER;
     $name = 'smw_di_number';
     $instance = $this->newInstance($diType, $name);
     $this->assertInternalType('array', $instance->getFields(StoreFactory::getStore('SMWSQLStore3')), 'Asserts that getFields() returns an array');
     $this->assertEquals($diType, $instance->getDiType(), 'Asserts that getDiType() returns the corret object');
     $this->assertEquals($name, $instance->getName(), 'Asserts that getName() returns the corret object');
 }
 /**
  * @dataProvider getCacheNonCacheDataProvider
  */
 public function testCacheNoCacheOnSQLStore(array $test, array $expected, array $info)
 {
     $store = StoreFactory::getStore('SMWSQLStore3');
     // Sample A
     $instance = $this->newInstance($store, $test['A']['property'], $test['A']['count'], $test['cacheEnabled']);
     $this->assertEquals($expected['A'], $instance->getResults(), $info['msg']);
     // Sample B
     $instance = $this->newInstance($store, $test['B']['property'], $test['B']['count'], $test['cacheEnabled']);
     $this->assertEquals($expected['B'], $instance->getResults(), $info['msg']);
     $this->assertEquals($test['cacheEnabled'], $instance->isCached());
 }
 protected function setUp()
 {
     $this->store = StoreFactory::getStore();
     if (!$this->store instanceof SPARQLStore) {
         $this->markTestSkipped("Requires a SPARQLStore instance");
     }
     $this->sparqlDatabase = $this->store->getConnection();
     if (!$this->sparqlDatabase->setConnectionTimeoutInSeconds(5)->ping()) {
         $this->markTestSkipped("Can't connect to the SparlDatabase");
     }
 }
 protected function setupStore($source, $expectedToRun = 0)
 {
     $storeId = isset($GLOBALS['smwgQuerySources'][$source]) ? $GLOBALS['smwgQuerySources'][$source] : null;
     $queryResult = $this->getMockBuilder('SMWQueryResult')->disableOriginalConstructor()->getMock();
     $queryResult->expects($this->exactly($expectedToRun))->method('getCount')->will($this->returnValue(0));
     $queryResult->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
     $store = StoreFactory::getStore($storeId);
     if (method_exists($store, 'setQueryResult')) {
         $store->setQueryResult($queryResult);
     }
     return $store;
 }
 public function testProcessOnSQLStore()
 {
     $userLanguage = $this->getMockBuilder('\\Language')->disableOriginalConstructor()->getMock();
     ApplicationFactory::getInstance()->registerObject('Store', StoreFactory::getStore());
     $extraStats = array();
     $version = '1.21';
     $instance = new SpecialStatsAddExtra($extraStats, $version, $userLanguage);
     $this->assertTrue($instance->process());
     // This is a "cheap" check against the SQLStore as it could return any
     // value therefore we use a message key as only known constant to verify
     // that the matching process was successful
     $this->assertTrue($this->matchArray($extraStats, 'smw-statistics-property-instance'));
 }
 private function registerCallbackHandlers($callbackLoader)
 {
     $callbackLoader->registerExpectedReturnType('Settings', '\\SMW\\Settings');
     $callbackLoader->registerCallback('Settings', function () use($callbackLoader) {
         return Settings::newFromGlobals();
     });
     $callbackLoader->registerExpectedReturnType('Store', '\\SMW\\Store');
     $callbackLoader->registerCallback('Store', function () use($callbackLoader) {
         return StoreFactory::getStore($callbackLoader->singleton('Settings')->get('smwgDefaultStore'));
     });
     $callbackLoader->registerExpectedReturnType('Cache', '\\Onoi\\Cache\\Cache');
     $callbackLoader->registerCallback('Cache', function () {
         return ApplicationFactory::getInstance()->newCacheFactory()->newMediaWikiCompositeCache();
     });
     $callbackLoader->registerCallback('NamespaceExaminer', function () use($callbackLoader) {
         return NamespaceExaminer::newFromArray($callbackLoader->singleton('Settings')->get('smwgNamespacesWithSemanticLinks'));
     });
     $callbackLoader->registerExpectedReturnType('ParserData', '\\SMW\\ParserData');
     $callbackLoader->registerCallback('ParserData', function (\Title $title, \ParserOutput $parserOutput) {
         return new ParserData($title, $parserOutput);
     });
     $callbackLoader->registerCallback('MessageFormatter', function (\Language $language) {
         return new MessageFormatter($language);
     });
     $callbackLoader->registerExpectedReturnType('PageCreator', '\\SMW\\MediaWiki\\PageCreator');
     $callbackLoader->registerCallback('PageCreator', function () {
         return new PageCreator();
     });
     $callbackLoader->registerExpectedReturnType('TitleCreator', '\\SMW\\MediaWiki\\TitleCreator');
     $callbackLoader->registerCallback('TitleCreator', function () {
         return new TitleCreator();
     });
     $callbackLoader->registerExpectedReturnType('WikiPage', '\\WikiPage');
     $callbackLoader->registerCallback('WikiPage', function (\Title $title) {
         return \WikiPage::factory($title);
     });
     $callbackLoader->registerExpectedReturnType('ContentParser', '\\SMW\\ContentParser');
     $callbackLoader->registerCallback('ContentParser', function (\Title $title) {
         return new ContentParser($title);
     });
     $callbackLoader->registerExpectedReturnType('JobFactory', '\\SMW\\MediaWiki\\Jobs\\JobFactory');
     $callbackLoader->registerCallback('JobFactory', function () {
         return new JobFactory();
     });
     $callbackLoader->registerExpectedReturnType('FactboxFactory', '\\SMW\\Factbox\\FactboxFactory');
     $callbackLoader->registerCallback('FactboxFactory', function () {
         return new FactboxFactory();
     });
 }
 /**
  * @see Maintenance::execute
  */
 public function execute()
 {
     if (!defined('SMW_VERSION')) {
         $this->output("You need to have SMW enabled in order to use this maintenance script!\n\n");
         exit;
     }
     $store = StoreFactory::getStore();
     $statsTable = new PropertyStatisticsTable($store->getConnection('mw.db'), \SMWSQLStore3::PROPERTY_STATISTICS_TABLE);
     // Need to instantiate an extra object here since we cannot make this class itself
     // into a MessageReporter since the maintenance script does not load the interface in time.
     $reporter = new ObservableMessageReporter();
     $reporter->registerReporterCallback(array($this, 'reportMessage'));
     $statisticsRebuilder = new SimplePropertyStatisticsRebuilder($store, $reporter);
     $statisticsRebuilder->rebuild($statsTable);
 }
 protected function setUp()
 {
     $this->store = StoreFactory::getStore();
     if (!$this->store instanceof SPARQLStore) {
         $this->markTestSkipped("Requires a SPARQLStore instance");
     }
     $sparqlDatabase = $this->store->getConnection();
     if (!$sparqlDatabase->setConnectionTimeoutInSeconds(5)->ping()) {
         $this->markTestSkipped("Can't connect to the SPARQL database");
     }
     $sparqlDatabase->deleteAll();
     $this->queryResultValidator = new QueryResultValidator();
     $this->semanticDataFactory = new SemanticDataFactory();
     $this->dataValueFactory = DataValueFactory::getInstance();
 }
 protected function getTypeProperties($typeLabel)
 {
     global $wgRequest, $smwgTypePagingLimit;
     if ($smwgTypePagingLimit <= 0) {
         return '';
         // not too useful, but we comply to this request
     }
     $from = $wgRequest->getVal('from');
     $until = $wgRequest->getVal('until');
     $typeValue = DataValueFactory::getInstance()->newTypeIDValue('__typ', $typeLabel);
     $this->getOutput()->prependHTML($this->getTypesLink());
     if (!$typeValue->isValid()) {
         return $this->msg('smw-special-types-no-such-type')->escaped();
     }
     $store = \SMW\StoreFactory::getStore();
     $options = SMWPageLister::getRequestOptions($smwgTypePagingLimit, $from, $until);
     $diWikiPages = $store->getPropertySubjects(new SMWDIProperty('_TYPE'), $typeValue->getDataItem(), $options);
     if (!$options->ascending) {
         $diWikiPages = array_reverse($diWikiPages);
     }
     $escapedTypeLabel = htmlspecialchars($typeValue->getWikiValue());
     $canonicalLabel = DataTypeRegistry::getInstance()->findCanonicalLabelById($typeValue->getDataItem()->getFragment());
     $typeKey = 'smw-sp-types' . strtolower($typeValue->getDataItem()->getFragment());
     $messageKey = wfMessage($typeKey)->exists() ? $typeKey : 'smw-sp-types-default';
     $result = \Html::rawElement('div', array('class' => 'smw-sp-types-intro' . $typeKey), wfMessage($messageKey, str_replace('_', ' ', $escapedTypeLabel))->parse() . ' ' . wfMessage('smw-sp-types-help', str_replace(' ', '_', $canonicalLabel))->parse());
     $result .= $this->displayExtraInformationAbout($typeValue);
     if (count($diWikiPages) > 0) {
         $pageLister = new SMWPageLister($diWikiPages, null, $smwgTypePagingLimit, $from, $until);
         $title = $this->getTitleFor('Types', $typeLabel);
         $title->setFragment('#SMWResults');
         // Make navigation point to the result list.
         $navigation = $pageLister->getNavigationLinks($title);
         $resultNumber = min($smwgTypePagingLimit, count($diWikiPages));
         $typeName = $typeValue->getLongWikiText();
         $result .= "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMessage('smw_type_header', $typeName)->text() . "</h2>\n<p>" . wfMessage('smw_typearticlecount')->numParams($resultNumber)->text() . "</p>\n" . $navigation . $pageLister->formatList() . $navigation . "\n</div>";
     }
     return $result;
 }
 /**
  * @see SMWDataValue::loadDataItem()
  *
  * @param $dataitem SMWDataItem
  *
  * @return boolean
  */
 protected function loadDataItem(SMWDataItem $dataItem)
 {
     if (!$dataItem instanceof SMWDIBlob) {
         return false;
     }
     $this->m_dataitem = $dataItem;
     $this->m_diProperties = array();
     foreach (explode(';', $dataItem->getString()) as $propertyKey) {
         $property = null;
         try {
             $property = new SMWDIProperty($propertyKey);
         } catch (SMWDataItemException $e) {
             $property = new SMWDIProperty('Error');
             $this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text());
         }
         if ($property instanceof SMWDIProperty) {
             // Find a possible redirect
             $this->m_diProperties[] = StoreFactory::getStore()->getRedirectTarget($property);
         }
     }
     $this->m_caption = false;
     return true;
 }
 /**
  * Retrieve a copy of the semantic data for a wiki page, possibly filtering
  * it so that only essential properties are included (in some cases, we only
  * want to export stub information about a page).
  * We make a copy of the object since we may want to add more data later on
  * and we do not want to modify the store's result which may be used for
  * caching purposes elsewhere.
  */
 protected function getSemanticData(SMWDIWikiPage $diWikiPage, $core_props_only)
 {
     // Issue 619
     // Resolve the redirect target and return a container with information
     // about the redirect
     if ($diWikiPage->getTitle() !== null && $diWikiPage->getTitle()->isRedirect()) {
         try {
             $redirectTarget = $this->getDeepRedirectTargetResolver()->findRedirectTargetFor($diWikiPage->getTitle());
         } catch (\Exception $e) {
             $redirectTarget = null;
         }
         // Couldn't resolve the redirect which is most likely caused by a
         // circular redirect therefore we give up
         if ($redirectTarget === null) {
             return null;
         }
         $semData = new SemanticData($diWikiPage);
         $semData->addPropertyObjectValue(new DIProperty('_REDI'), DIWikiPage::newFromTitle($redirectTarget));
         return $semData;
     }
     $semdata = \SMW\StoreFactory::getStore()->getSemanticData($diWikiPage, $core_props_only ? array('__spu', '__typ', '__imp') : false);
     // advise store to retrieve only core things
     if ($core_props_only) {
         // be sure to filter all non-relevant things that may still be present in the retrieved
         $result = new SMWSemanticData($diWikiPage);
         foreach (array('_URI', '_TYPE', '_IMPO') as $propid) {
             $prop = new SMW\DIProperty($propid);
             $values = $semdata->getPropertyValues($prop);
             foreach ($values as $dv) {
                 $result->addPropertyObjectValue($prop, $dv);
             }
         }
     } else {
         $result = clone $semdata;
     }
     return $result;
 }
Example #19
0
 protected function tearDown()
 {
     StoreFactory::clear();
 }
 /**
  * Find the property's type ID, either by looking up its predefined ID
  * (if any) or by retrieving the relevant information from the store.
  * If no type is stored for a user defined property, the global default
  * type will be used.
  *
  * @return string type ID
  */
 public function findPropertyTypeID()
 {
     global $smwgPDefaultType;
     if (!isset($this->m_proptypeid)) {
         if ($this->isUserDefined()) {
             // normal property
             $diWikiPage = new SMWDIWikiPage($this->getKey(), SMW_NS_PROPERTY, '');
             $typearray = StoreFactory::getStore()->getPropertyValues($diWikiPage, new self('_TYPE'));
             if (count($typearray) >= 1) {
                 // some types given, pick one (hopefully unique)
                 $typeDataItem = reset($typearray);
                 if ($typeDataItem instanceof SMWDIUri) {
                     $this->m_proptypeid = $typeDataItem->getFragment();
                 } else {
                     $this->m_proptypeid = $smwgPDefaultType;
                     // This is important. If a page has an invalid assignment to "has type", no
                     // value will be stored, so the elseif case below occurs. But if the value
                     // is retrieved within the same run, then the error value for "has type" is
                     // cached and thus this case occurs. This is why it is important to tolerate
                     // this case -- it is not necessarily a DB error.
                 }
             } elseif (count($typearray) == 0) {
                 // no type given
                 $this->m_proptypeid = $smwgPDefaultType;
             }
         } else {
             // pre-defined property
             $this->m_proptypeid = PropertyRegistry::getInstance()->getPredefinedPropertyTypeId($this->m_key);
         }
     }
     return $this->m_proptypeid;
 }
 /**
  * Helper method that returns a SMWDIHandlerWikiPage object
  *
  * @since 1.9
  *
  * @return SMWDIHandlerWikiPage
  */
 private function getInstance()
 {
     return new SMWDIHandlerWikiPage(StoreFactory::getStore('SMWSQLStore3'));
 }
Example #22
0
 /**
  * Find the sortkey for this object.
  *
  * @deprecated Use SMWStore::getWikiPageSortKey(). Will vanish before SMW 1.7
  *
  * @return string sortkey
  */
 public function getSortKey()
 {
     return \SMW\StoreFactory::getStore()->getWikiPageSortKey($this->m_dataitem);
 }
 /**
  * Return the array (list) of properties that the individual entries of
  * this datatype consist of.
  *
  * @since 1.6
  *
  * @param $diProperty mixed null or SMWDIProperty object for which to retrieve the types
  *
  * @return array of SMWDIProperty
  */
 public static function findPropertyDataItems($diProperty)
 {
     if (!is_null($diProperty)) {
         $propertyDiWikiPage = $diProperty->getDiWikiPage();
         if (!is_null($propertyDiWikiPage)) {
             $listDiProperty = new SMWDIProperty('_LIST');
             $dataItems = \SMW\StoreFactory::getStore()->getPropertyValues($propertyDiWikiPage, $listDiProperty);
             if (count($dataItems) == 1) {
                 $propertyListValue = new SMWPropertyListValue('__pls');
                 $propertyListValue->setDataItem(reset($dataItems));
                 if ($propertyListValue->isValid()) {
                     return $propertyListValue->getPropertyDataItems();
                 }
             }
         }
     }
     return array();
 }
 /**
  * Check if property is range restricted and, if so, whether the current value is allowed.
  * Creates an error if the value is illegal.
  */
 protected function checkAllowedValues()
 {
     if (!is_null($this->m_property)) {
         $propertyDiWikiPage = $this->m_property->getDiWikiPage();
     }
     if (is_null($this->m_property) || is_null($propertyDiWikiPage) || !isset($this->m_dataitem)) {
         return;
         // no property known, or no data to check
     }
     $allowedvalues = \SMW\StoreFactory::getStore()->getPropertyValues($propertyDiWikiPage, new SMWDIProperty('_PVAL'));
     if (count($allowedvalues) == 0) {
         return;
     }
     $hash = $this->m_dataitem->getHash();
     $testdv = DataValueFactory::getInstance()->newTypeIDValue($this->getTypeID());
     $accept = false;
     $valuestring = '';
     foreach ($allowedvalues as $di) {
         if ($di instanceof SMWDIBlob) {
             $testdv->setUserValue($di->getString());
             if ($hash === $testdv->getDataItem()->getHash()) {
                 $accept = true;
                 break;
             } else {
                 if ($valuestring !== '') {
                     $valuestring .= ', ';
                 }
                 $valuestring .= $di->getString();
             }
         }
     }
     if (!$accept) {
         $this->addError(wfMessage('smw_notinenum', $this->getWikiValue(), $valuestring)->inContentLanguage()->text());
     }
 }
 protected function getStore()
 {
     return StoreFactory::getStore();
 }
 /**
  * Setup the store.
  *
  * @since 1.8
  *
  * @param bool $verbose
  *
  * @return boolean Success indicator
  */
 public static function setupStore($verbose = true)
 {
     $result = StoreFactory::getStore()->setup($verbose);
     wfRunHooks('smwInitializeTables');
     return $result;
 }
Example #27
0
 /**
  * Format a list of diWikiPages chunked by letter in a bullet list.
  * 
  * @param $start integer
  * @param $end integer
  * @param $diWikiPages array of SMWDataItem
  * @param $diProperty SMWDIProperty that the wikipages are values of, or null
  * 
  * @return string
  */
 public static function getShortList($start, $end, array $diWikiPages, $diProperty)
 {
     global $wgContLang;
     $startDv = \SMW\DataValueFactory::getInstance()->newDataItemValue($diWikiPages[$start], $diProperty);
     $sortkey = \SMW\StoreFactory::getStore()->getWikiPageSortKey($diWikiPages[$start]);
     $startChar = $wgContLang->convert($wgContLang->firstChar($sortkey));
     $r = '<h3>' . htmlspecialchars($startChar) . "</h3>\n" . '<ul><li>' . $startDv->getLongHTMLText(smwfGetLinker()) . '</li>';
     $prevStartChar = $startChar;
     for ($index = $start + 1; $index < $end; $index++) {
         $dataValue = \SMW\DataValueFactory::getInstance()->newDataItemValue($diWikiPages[$index], $diProperty);
         $sortkey = \SMW\StoreFactory::getStore()->getWikiPageSortKey($diWikiPages[$index]);
         $startChar = $wgContLang->convert($wgContLang->firstChar($sortkey));
         if ($startChar != $prevStartChar) {
             $r .= "</ul><h3>" . htmlspecialchars($startChar) . "</h3>\n<ul>";
             $prevStartChar = $startChar;
         }
         $r .= '<li>' . $dataValue->getLongHTMLText(smwfGetLinker()) . '</li>';
     }
     $r .= '</ul>';
     return $r;
 }
 /**
  * TODO: document
  */
 protected function makeHTMLResult()
 {
     global $wgOut;
     // TODO: hold into account $smwgAutocompleteInSpecialAsk
     $result = '';
     // build parameter strings for URLs, based on current settings
     $urlArgs['q'] = $this->m_querystring;
     $tmp_parray = array();
     foreach ($this->m_params as $key => $value) {
         if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) {
             $tmp_parray[$key] = $value;
         }
     }
     $urlArgs['p'] = SMWInfolink::encodeParameters($tmp_parray);
     $printoutstring = '';
     /**
      * @var PrintRequest $printout
      */
     foreach ($this->m_printouts as $printout) {
         $printoutstring .= $printout->getSerialisation() . "\n";
     }
     if ($printoutstring !== '') {
         $urlArgs['po'] = $printoutstring;
     }
     if (array_key_exists('sort', $this->m_params)) {
         $urlArgs['sort'] = $this->m_params['sort'];
     }
     if (array_key_exists('order', $this->m_params)) {
         $urlArgs['order'] = $this->m_params['order'];
     }
     if ($this->m_querystring !== '') {
         // FIXME: this is a hack
         SMWQueryProcessor::addThisPrintout($this->m_printouts, $this->m_params);
         $params = SMWQueryProcessor::getProcessedParams($this->m_params, $this->m_printouts);
         $this->m_params['format'] = $params['format']->getValue();
         $this->params = $params;
         $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts);
         /**
          * @var SMWQueryResult $res
          */
         // Determine query results
         $res = $this->getStoreFromParams($params)->getQueryResult($queryobj);
         // Try to be smart for rss/ical if no description/title is given and we have a concept query:
         if ($this->m_params['format'] == 'rss') {
             $desckey = 'rssdescription';
             $titlekey = 'rsstitle';
         } elseif ($this->m_params['format'] == 'icalendar') {
             $desckey = 'icalendardescription';
             $titlekey = 'icalendartitle';
         } else {
             $desckey = false;
         }
         if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) {
             $concept = $queryobj->getDescription()->getConcept();
             if (!isset($this->m_params[$titlekey])) {
                 $this->m_params[$titlekey] = $concept->getText();
             }
             if (!isset($this->m_params[$desckey])) {
                 // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
                 $dv = end(\SMW\StoreFactory::getStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), new SMWDIProperty('_CONC')));
                 if ($dv instanceof SMWConceptValue) {
                     $this->m_params[$desckey] = $dv->getDocu();
                 }
             }
         }
         $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE);
         global $wgRequest;
         $hidequery = $wgRequest->getVal('eq') == 'no';
         if (!$printer->isExportFormat()) {
             if ($res->getCount() > 0) {
                 if ($this->m_editquery) {
                     $urlArgs['eq'] = 'yes';
                 } elseif ($hidequery) {
                     $urlArgs['eq'] = 'no';
                 }
                 $navigation = $this->getNavigationBar($res, $urlArgs);
                 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
                 $query_result = $printer->getResult($res, $params, SMW_OUTPUT_HTML);
                 if (is_array($query_result)) {
                     $result .= $query_result[0];
                 } else {
                     $result .= $query_result;
                 }
                 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
             } else {
                 $result = '<div style="text-align: center;">' . wfMessage('smw_result_noresults')->escaped() . '</div>';
             }
         }
     }
     if (isset($printer) && $printer->isExportFormat()) {
         $wgOut->disable();
         /**
          * @var SMWIExportPrinter $printer
          */
         $printer->outputAsFile($res, $params);
     } else {
         if ($this->m_querystring) {
             $wgOut->setHTMLtitle($this->m_querystring);
         } else {
             $wgOut->setHTMLtitle(wfMessage('ask')->text());
         }
         $urlArgs['offset'] = $this->m_params['offset'];
         $urlArgs['limit'] = $this->m_params['limit'];
         $result = $this->getInputForm($printoutstring, wfArrayToCGI($urlArgs)) . $result;
         $wgOut->addHTML($result);
     }
 }
 private static function getStoreFromParams(array $params)
 {
     $storeId = null;
     $source = $params['source']->getValue();
     if ($source !== '') {
         $storeId = $GLOBALS['smwgQuerySources'][$source];
     }
     return \SMW\StoreFactory::getStore($storeId);
 }
 public function testStoreWithInvalidClassThrowsException()
 {
     $this->setExpectedException('RuntimeException');
     StoreFactory::getStore('foo');
 }