/** * @see DataValue::getShortWikiText * * @param string $value */ public function getShortWikiText($linker = null) { if (!$this->isValid()) { return ''; } return '[[' . Localizer::getInstance()->getNamespaceTextById(NS_MEDIAWIKI) . ':smw allows pattern' . '|' . $this->getDataItem()->getString() . ' ]]'; }
public function textProvider() { #0 $provider[] = array('Foo', false, 'Foo', PrintRequest::PRINT_PROP, PropertyValue::class, ''); #1 $provider[] = array('-Foo', false, '-Foo', PrintRequest::PRINT_PROP, PropertyValue::class, ''); #2 $provider[] = array('-Foo=Bar', false, 'Bar', PrintRequest::PRINT_PROP, PropertyValue::class, ''); #3 // Category $categoryName = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY); $provider[] = array('Category', false, $categoryName, PrintRequest::PRINT_CATS, null, ''); #4 $provider[] = array('Bar#foobar', false, 'Bar', PrintRequest::PRINT_PROP, PropertyValue::class, 'foobar'); #5 $provider[] = array('Foo#', false, 'Foo', PrintRequest::PRINT_PROP, PropertyValue::class, '-'); #6, 1464 $provider[] = array('Has boolean#<span style="color: green; font-size: 120%;">✓</span>,<span style="color: #AA0000; font-size: 120%;">✕</span>=Label on (✓,✕)', false, 'Label on (✓,✕)', PrintRequest::PRINT_PROP, PropertyValue::class, '<span style="color: green; font-size: 120%;">✓</span>,<span style="color: #AA0000; font-size: 120%;">✕</span>'); #7 $provider[] = array('Foo.Bar', false, 'Bar', PrintRequest::PRINT_CHAIN, PropertyChainValue::class, ''); #8 $provider[] = array('Foo.Bar#foobar', false, 'Bar', PrintRequest::PRINT_CHAIN, PropertyChainValue::class, 'foobar'); #9 ... $provider[] = array('Foo = <span style="color: green; font-size: 120%;">Label</span>', false, '<span style="color: green; font-size: 120%;">Label</span>', PrintRequest::PRINT_PROP, PropertyValue::class, ''); #10 ... $provider[] = array('Foo#Bar = <span style="color: green; font-size: 120%;">Label</span>', false, '<span style="color: green; font-size: 120%;">Label</span>', PrintRequest::PRINT_PROP, PropertyValue::class, 'Bar'); return $provider; }
public function queryDataProvider() { $categoryNS = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY); $provider = array(); // #0 // {{#ask: [[Modification date::+]] // |?Modification date // |format=list // }} $provider[] = array(array('', '[[Modification date::+]]', '?Modification date', 'format=list'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('list', 1, 1, '[[Modification date::+]]'))); // #1 // {{#ask: [[Modification date::+]][[Category:Foo]] // |?Modification date // |?Has title // |format=list // }} $provider[] = array(array('', '[[Modification date::+]][[Category:Foo]]', '?Modification date', '?Has title', 'format=list'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('list', 2, 1, "[[Modification date::+]] [[{$categoryNS}:Foo]]"))); // #2 Unknown format, default table // {{#ask: [[Modification date::+]][[Category:Foo]] // |?Modification date // |?Has title // |format=bar // }} $provider[] = array(array('', '[[Modification date::+]][[Category:Foo]]', '?Modification date', '?Has title', 'format=bar'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('table', 2, 1, "[[Modification date::+]] [[{$categoryNS}:Foo]]"))); return $provider; }
public function testAddDescription() { $ns = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY); $instance = new ClassDescription(new DIWikiPage('Foo', NS_CATEGORY)); $instance->addDescription(new ClassDescription(new DIWikiPage('Bar', NS_CATEGORY))); $this->assertEquals("[[{$ns}:Foo||Bar]]", $instance->getQueryString()); $this->assertEquals(" <q>[[{$ns}:Foo||Bar]]</q> ", $instance->getQueryString(true)); }
public function testGetQueryStringForCategoryNamespace() { $namespace = NS_CATEGORY; $ns = Localizer::getInstance()->getNamespaceTextById($namespace); $instance = new NamespaceDescription($namespace); $this->assertEquals("[[:{$ns}:+]]", $instance->getQueryString()); $this->assertEquals(" <q>[[:{$ns}:+]]</q> ", $instance->getQueryString(true)); }
public function testAddPropertyValue() { $instance = new SemanticData(DIWikiPage::newFromTitle(Title::newFromText(__METHOD__))); $instance->addPropertyValue('addPropertyValue', DIWikiPage::doUnserialize('Foo#0#')); $key = Localizer::getInstance()->getNamespaceTextById(SMW_NS_PROPERTY) . ':' . 'addPropertyValue'; $expected = array('propertyCount' => 1, 'propertyLabels' => array($key), 'propertyValues' => array('Foo')); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $instance); }
public function testGetContentLanguage() { $language = $this->getMockBuilder('\\Language')->disableOriginalConstructor()->getMock(); $instance = new Localizer($language); $this->assertSame($language, $instance->getContentLanguage()); $this->assertSame($GLOBALS['wgContLang'], Localizer::getInstance()->getContentLanguage()); Localizer::clear(); }
public function conjunctionProvider() { $nsHelp = Localizer::getInstance()->getNamespaceTextById(NS_HELP); $descriptions = array(new NamespaceDescription(NS_MAIN), new NamespaceDescription(NS_HELP)); $provider[] = array($descriptions, array('descriptions' => $descriptions, 'queryString' => "[[:+]] [[{$nsHelp}:+]]", 'queryStringAsValue' => " <q>[[:+]] [[{$nsHelp}:+]]</q> ", 'isSingleton' => false, 'queryFeatures' => 24, 'size' => 2, 'depth' => 0)); $descriptions = array(new ValueDescription(new DIWikiPage('Foo', NS_MAIN)), new Conjunction(array(new ValueDescription(new DIWikiPage('Bar', NS_MAIN)), new ValueDescription(new DIWikiPage('Yim', NS_MAIN))))); $provider[] = array($descriptions, array('descriptions' => $descriptions, 'queryString' => '[[:Foo]] [[:Bar]] [[:Yim]]', 'queryStringAsValue' => ' <q>[[:Foo]] [[:Bar]] [[:Yim]]</q> ', 'isSingleton' => true, 'queryFeatures' => 16, 'size' => 3, 'depth' => 0)); return $provider; }
public function getQueryString($asValue = false) { $localizedNamespaceText = Localizer::getInstance()->getNamespaceTextById($this->namespace); $prefix = $this->namespace == NS_CATEGORY ? ':' : ''; if ($asValue) { return ' <q>[[' . $prefix . $localizedNamespaceText . ':+]]</q> '; } return '[[' . $prefix . $localizedNamespaceText . ':+]]'; }
private static function doSerializeCat($printRequest, $parameters) { $catlabel = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY); $result = '?' . $catlabel; if ($printRequest->getLabel() != $catlabel) { $result .= '=' . $printRequest->getLabel(); } return $result . $parameters; }
public function testFileUploadForDummyTextFile() { $subject = new DIWikiPage('Foo.txt', NS_FILE); $fileNS = Localizer::getInstance()->getNamespaceTextById(NS_FILE); $dummyTextFile = $this->fixturesFileProvider->newUploadForDummyTextFile('Foo.txt'); $this->assertTrue($dummyTextFile->doUpload('[[HasFile::File:Foo.txt]]')); $expected = array('propertyCount' => 4, 'propertyKeys' => array('HasFile', '_MEDIA', '_MIME', '_SKEY'), 'propertyValues' => array("{$fileNS}:Foo.txt", 'TEXT', 'text/plain', 'Foo.txt')); $this->semanticDataValidator->assertThatPropertiesAreSet($expected, $this->getStore()->getSemanticData($subject)); }
public function testParseUserValueWhereContentPageHasSpecificContentLanguage() { $language = Localizer::getInstance()->getLanguage('ja'); $title = $this->getMockBuilder('Title')->disableOriginalConstructor()->getMock(); $title->expects($this->once())->method('getPageLanguage')->will($this->returnValue($language)); $subject = $this->getMockBuilder('\\SMW\\DIWikiPage')->disableOriginalConstructor()->getMock(); $subject->expects($this->once())->method('getTitle')->will($this->returnValue($title)); $instance = new BooleanValue(); $instance->setContextPage($subject); $instance->setUserValue('уюЪ'); $this->assertTrue($instance->getBoolean()); $this->assertInternalType('string', $instance->getWikiValue()); }
public function testCommonMethods() { $ns = Localizer::getInstance()->getNamespaceTextById(SMW_NS_CONCEPT); $concept = new DIWikiPage('Foo', SMW_NS_CONCEPT); $instance = new ConceptDescription($concept); $this->assertEquals($concept, $instance->getConcept()); $this->assertEquals("[[{$ns}:Foo]]", $instance->getQueryString()); $this->assertEquals(" <q>[[{$ns}:Foo]]</q> ", $instance->getQueryString(true)); $this->assertEquals(false, $instance->isSingleton()); $this->assertEquals(array(), $instance->getPrintRequests()); $this->assertEquals(1, $instance->getSize()); $this->assertEquals(0, $instance->getDepth()); $this->assertEquals(4, $instance->getQueryFeatures()); }
public function testFileUploadForDummyTextFile() { $subject = new DIWikiPage('RdfLinkedFile.txt', NS_FILE); $fileNS = Localizer::getInstance()->getNamespaceTextById(NS_FILE); $dummyTextFile = $this->fixturesFileProvider->newUploadForDummyTextFile('RdfLinkedFile.txt'); $dummyTextFile->doUpload('[[HasFile::File:RdfLinkedFile.txt]]'); $exportController = new ExportController(new RDFXMLSerializer()); $exportController->enableBacklinks(false); ob_start(); $exportController->printPages(array($subject->getTitle()->getPrefixedDBKey())); $output = ob_get_clean(); $expected = array("<rdfs:label>{$fileNS}:RdfLinkedFile.txt</rdfs:label>", '<swivt:file rdf:resource="' . $dummyTextFile->getLocalFile()->getFullURL() . '"/>', '<property:Media_type-23aux rdf:datatype="http://www.w3.org/2001/XMLSchema#string">TEXT</property:Media_type-23aux>', '<property:MIME_type-23aux rdf:datatype="http://www.w3.org/2001/XMLSchema#string">text/plain</property:MIME_type-23aux>'); $this->stringValidator->assertThatStringContains($expected, $output); }
public function textProvider() { $category = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY); $provider['print-cats'] = array(new PrintRequest(PrintRequest::PRINT_CATS, 'Foo'), false, "?{$category}=Foo"); $provider['print-ccat'] = array(new PrintRequest(PrintRequest::PRINT_CCAT, 'Foo', DIWikiPage::newFromText('Bar')->getTitle()), false, '?Bar=Foo'); $provider['print-this'] = array(new PrintRequest(PrintRequest::PRINT_THIS, 'Foo'), false, '?=Foo#'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar'); $provider['print-prop'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data), false, '?Bar#=Foo'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar'); $provider['print-prop-output'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar'), false, '?Bar#foobar=Foo'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar'); $provider['print-prop-output-parameters-no-show'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar', array('index' => 2)), false, '?Bar#foobar=Foo'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Bar'); $provider['print-prop-output-parameters-show'] = array(new PrintRequest(PrintRequest::PRINT_PROP, 'Foo', $data, 'foobar', array('index' => 2)), true, '?Bar#foobar=Foo|+index=2'); $data = DataValueFactory::getInstance()->newPropertyValueByLabel('Modification date'); $provider['predefined-property'] = array(new PrintRequest(PrintRequest::PRINT_PROP, '', $data), false, '?Modification date#'); return $provider; }
public function specialPropertiesDataProvider() { $provider = array(); #0 Unknown $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('UNKNOWN')), 'settings' => array('smwgPageSpecialProperties' => array('Lala', '_Lula', '-Lila', '')), 'pageInfo' => array()), array('propertyCount' => 0)); #1 TYPE_MODIFICATION_DATE $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('withModificationDate')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MODIFICATION_DATE)), 'pageInfo' => array('getModificationDate' => 1272508903)), array('propertyCount' => 1, 'propertyKeys' => '_MDAT', 'propertyValues' => array('2010-04-29T02:41:43'))); #2 TYPE_CREATION_DATE $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('withCreationDate')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_CREATION_DATE)), 'pageInfo' => array('getCreationDate' => 1272508903)), array('propertyCount' => 1, 'propertyKeys' => '_CDAT', 'propertyValues' => array('2010-04-29T02:41:43'))); #3 TYPE_NEW_PAGE $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('NEW_PAGE_isNew')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_NEW_PAGE)), 'pageInfo' => array('isNewPage' => true)), array('propertyCount' => 1, 'propertyKeys' => '_NEWP', 'propertyValues' => array(true))); #4 $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('NEW_PAGE_isNotNew')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_NEW_PAGE)), 'pageInfo' => array('isNewPage' => false)), array('propertyCount' => 1, 'propertyKeys' => '_NEWP', 'propertyValues' => array(false))); #5 TYPE_LAST_EDITOR $userPage = MockTitle::buildMock('Lula'); $userNS = Localizer::getInstance()->getNamespaceTextById(NS_USER); $userPage->expects($this->any())->method('getNamespace')->will($this->returnValue(NS_USER)); $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('withLastEditor')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_LAST_EDITOR)), 'pageInfo' => array('getLastEditor' => $userPage)), array('propertyCount' => 1, 'propertyKeys' => '_LEDT', 'propertyValues' => array(":{$userNS}:Lula"))); #6 Combined entries $userPage = MockTitle::buildMock('Lula'); $userNS = Localizer::getInstance()->getNamespaceTextById(NS_USER); $userPage->expects($this->any())->method('getNamespace')->will($this->returnValue(NS_USER)); $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('withCombinedEntries')), 'settings' => array('smwgPageSpecialProperties' => array('_MDAT', '_LEDT')), 'pageInfo' => array('getModificationDate' => 1272508903, 'getLastEditor' => $userPage)), array('propertyCount' => 2, 'propertyKeys' => array('_MDAT', '_LEDT'), 'propertyValues' => array('2010-04-29T02:41:43', ":{$userNS}:Lula"))); #7 TYPE_MEDIA $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('MimePropertyForFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MEDIA)), 'pageInfo' => array('isFilePage' => true, 'getMediaType' => 'FooMedia')), array('propertyCount' => 1, 'propertyKeys' => '_MEDIA', 'propertyValues' => array('FooMedia'))); #8 $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('MediaPropertyForNonFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MEDIA)), 'pageInfo' => array('isFilePage' => false, 'getMediaType' => 'FooMedia')), array('propertyCount' => 0)); #9 TYPE_MIME $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('MimePropertyForFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MIME)), 'pageInfo' => array('isFilePage' => true, 'getMimeType' => 'FooMime')), array('propertyCount' => 1, 'propertyKeys' => '_MIME', 'propertyValues' => array('FooMime'))); #10 $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('MimePropertyForNonFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MIME)), 'pageInfo' => array('isFilePage' => false, 'getMimeType' => 'FooMime')), array('propertyCount' => 0)); #11 Empty TYPE_MIME $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('EmptyMimePropertyFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MIME)), 'pageInfo' => array('isFilePage' => true, 'getMimeType' => '')), array('propertyCount' => 0)); #12 Empty TYPE_MEDIA $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('EmptyMediaPropertyFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MEDIA)), 'pageInfo' => array('isFilePage' => true, 'getMediaType' => '')), array('propertyCount' => 0)); #13 Null TYPE_MIME $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('NullMimePropertyFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MIME)), 'pageInfo' => array('isFilePage' => true, 'getMimeType' => null)), array('propertyCount' => 0)); #14 Null TYPE_MEDIA $provider[] = array(array('subject' => DIWikiPage::newFromTitle(Title::newFromText('NullMediaPropertyFilePage')), 'settings' => array('smwgPageSpecialProperties' => array(DIProperty::TYPE_MEDIA)), 'pageInfo' => array('isFilePage' => true, 'getMimeType' => null)), array('propertyCount' => 0)); return $provider; }
/** * @since 2.4 * * @param integer $formatFlag * * @return string|boolean */ public function getLocalizedFormat($formatFlag = self::LOCL_DEFAULT) { $dateTime = $this->dataItem->asDateTime(); $timezoneLiteral = ''; if (!$dateTime) { return false; } if ($formatFlag === self::LOCL_TIMEZONE) { $timezoneLiteral = $this->getTimezoneLiteralWithModifiedDateTime($dateTime); } $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage($this->language); $precision = $this->dataItem->getPrecision(); // Look for the Z precision which indicates the position of the TZ if ($precision === SMW_PREC_YMDT && $timezoneLiteral !== '') { $precision = SMW_PREC_YMDTZ; } $preferredDateFormatByPrecision = $extraneousLanguage->getPreferredDateFormatByPrecision($precision); // Mark the position since we cannot use DateTime::setTimezone in case // it is a military zone $preferredDateFormatByPrecision = str_replace('T', '**', $preferredDateFormatByPrecision); $dateString = $this->formatWithLocalizedTextReplacement($dateTime, $preferredDateFormatByPrecision); return str_replace('**', $timezoneLiteral, $dateString); }
/** * @see EntityLookup::getSemanticData * * @since 2.5 * * {@inheritDoc} */ public function getSemanticData(DIWikiPage $subject, $filter = false) { if (!$this->blobStore->canUse() || !$this->canUseValueLookupFeature(SMW_VL_SD)) { return $this->entityLookup->getSemanticData($subject, $filter); } // Use a separate container otherwise large serializations of subobjects // will decrease performance when combined with other lists $sid = $this->getHashFrom($subject, $subject->getSubobjectName()); $container = $this->blobStore->read($sid); // Make sure that when switching user languages, user labels etc. // are appropriately generated $userLang = Localizer::getInstance()->getUserLanguage()->getCode(); $sdid = HashBuilder::createHashIdForContent(array((array) $filter, self::VERSION), 'sd:' . $userLang . ':'); if ($container->has($sdid)) { return $container->get($sdid); } $semanticData = $this->entityLookup->getSemanticData($subject, $filter); $semanticData->setLastModified(wfTimestamp(TS_UNIX)); $container->set($sdid, $semanticData); $this->blobStore->save($container); $this->appendToList($sid, $subject); return $semanticData; }
/** * Parse an article description (the part of an inline query that * is in between "[[" and the closing "]]" assuming it is not specifying * a category or property) and create a suitable description. * The first chunk behind the "[[" has already been read and is * passed as a parameter. */ private function getArticleDescription($firstChunk, &$setNS) { $chunk = $firstChunk; $result = null; $continue = true; while ($continue) { if ($chunk == '<q>') { // no subqueries of the form [[<q>...</q>]] (not needed) $this->errorMessages[] = wfMessage('smw_misplacedsubquery')->inContentLanguage()->text(); return null; } $list = preg_split('/:/', $chunk, 3); // ":Category:Foo" "User:bar" ":baz" ":+" if ($list[0] === '' && count($list) == 3) { $list = array_slice($list, 1); } if (count($list) == 2 && $list[1] == '+') { // try namespace restriction $idx = \SMW\Localizer::getInstance()->getNamespaceIndexByName($list[0]); if ($idx !== false) { $result = $this->addDescription($result, new NamespaceDescription($idx), false); } } else { $value = \SMW\DataValueFactory::getInstance()->newTypeIDValue('_wpg', $chunk); $value->setQueryConditionUsage(true); if ($value->isValid()) { $result = $this->addDescription($result, new ValueDescription($value->getDataItem(), null), false); } } $chunk = $this->readChunk('\\[\\[|\\]\\]|\\|\\||\\|'); if ($chunk == '||') { $chunk = $this->readChunk('\\[\\[|\\]\\]|\\|\\||\\|'); $continue = true; } else { $continue = false; } } return $this->finishLinkDescription($chunk, true, $result, $setNS); }
public function queryDataProvider() { $categoryNS = Localizer::getInstance()->getNamespaceTextById(NS_CATEGORY); $fileNS = Localizer::getInstance()->getNamespaceTextById(NS_FILE); $provider = array(); // #0 // {{#ask: [[Modification date::+]] // |?Modification date // |format=list // }} $provider[] = array(array('[[Modification date::+]]', '?Modification date', 'format=list'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('list', 1, 1, '[[Modification date::+]]')), array('smwgQueryDurationEnabled' => false)); // #1 Query string with spaces // {{#ask: [[Modification date::+]] [[Category:Foo bar]] [[Has title::!Foo bar]] // |?Modification date // |?Has title // |format=list // }} $provider[] = array(array('[[Modification date::+]] [[Category:Foo bar]] [[Has title::!Foo bar]]', '?Modification date', '?Has title', 'format=list'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('list', 4, 1, "[[Modification date::+]] [[{$categoryNS}:Foo bar]] [[Has title::!Foo bar]]")), array('smwgQueryDurationEnabled' => false)); // #2 // {{#ask: [[Modification date::+]][[Category:Foo]] // |?Modification date // |?Has title // |format=list // }} $provider[] = array(array('[[Modification date::+]][[Category:Foo]]', '?Modification date', '?Has title', 'format=list'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('list', 2, 1, "[[Modification date::+]] [[{$categoryNS}:Foo]]")), array('smwgQueryDurationEnabled' => false)); // #3 Known format // {{#ask: [[File:Fooo]] // |?Modification date // |default=no results // |format=feed // }} $provider[] = array(array('[[File:Fooo]]', '?Modification date', 'default=no results', 'format=feed'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('feed', 1, 1, "[[:{$fileNS}:Fooo]]")), array('smwgQueryDurationEnabled' => false)); // #4 Unknown format, default table // {{#ask: [[Modification date::+]][[Category:Foo]] // |?Modification date // |?Has title // |format=bar // }} $provider[] = array(array('[[Modification date::+]][[Category:Foo]]', '?Modification date', '?Has title', 'format=lula'), array('propertyCount' => 4, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO'), 'propertyValues' => array('table', 2, 1, "[[Modification date::+]] [[{$categoryNS}:Foo]]")), array('smwgQueryDurationEnabled' => false)); // #5 QueryTime enabled $provider[] = array(array('[[Modification date::+]][[Category:Foo]]', '?Modification date', '?Has title', 'format=lula'), array('propertyCount' => 5, 'propertyKeys' => array('_ASKST', '_ASKSI', '_ASKDE', '_ASKFO', '_ASKDU')), array('smwgQueryDurationEnabled' => true)); return $provider; }
/** * Get the prefixed text for this value, including a localized namespace * prefix. * * @return string */ public function getPrefixedText() { if ($this->m_prefixedtext !== '') { return $this->m_prefixedtext; } $this->m_prefixedtext = 'NO_VALID_VALUE'; if ($this->isValid()) { $nstext = Localizer::getInstance()->getNamespaceTextById($this->m_dataitem->getNamespace()); $this->m_prefixedtext = ($this->m_dataitem->getInterwiki() !== '' ? $this->m_dataitem->getInterwiki() . ':' : '') . ($nstext !== '' ? "{$nstext}:" : '') . $this->getText(); } return $this->m_prefixedtext; }
/** * @since 2.5 * * @param integer $index * @param string $url * * @return string */ public function getLocalizedTextByNamespace($index, $text) { $namespace = Localizer::getInstance()->getNamespaceTextById($index); return str_replace(Localizer::getInstance()->getCanonicalNamespaceTextById($index) . ':', $namespace . ':', $text); }
/** * @dataProvider localizedFormatProvider */ public function testGetLocalizedFormat($serialization, $languageCode, $flag, $expected) { $instance = new IntlTimeFormatter(DITime::doUnserialize($serialization), Localizer::getInstance()->getLanguage($languageCode)); $this->assertEquals($expected, $instance->getLocalizedFormat($flag)); }
/** * Displays a value, including all relevant links (browse and search by property) * * @param[in] $property SMWPropertyValue The property this value is linked to the subject with * @param[in] $value DataValue The actual value * @param[in] $incoming bool If this is an incoming or outgoing link * * @return string HTML with the link to the article, browse, and search pages */ private function displayValue(\SMWPropertyValue $property, DataValue $dataValue, $incoming) { $linker = smwfGetLinker(); // Allow the DV formatter to access a specific language code $dataValue->setOption(DataValue::OPT_CONTENT_LANGUAGE, Localizer::getInstance()->getPreferredContentLanguage($this->subject->getDataItem())->getCode()); $dataValue->setOption(DataValue::OPT_USER_LANGUAGE, Localizer::getInstance()->getUserLanguage()->getCode()); $dataValue->setContextPage($this->subject->getDataItem()); // Use LOCL formatting where appropriate (date) $dataValue->setOutputFormat('LOCL'); $html = $dataValue->getLongHTMLText($linker); if ($dataValue->getTypeID() === '_wpg' || $dataValue->getTypeID() === '__sob') { $html .= " " . \SMWInfolink::newBrowsingLink('+', $dataValue->getLongWikiText())->getHTML($linker); } elseif ($incoming && $property->isVisible()) { $html .= " " . \SMWInfolink::newInversePropertySearchLink('+', $dataValue->getTitle(), $property->getDataItem()->getLabel(), 'smwsearch')->getHTML($linker); } elseif ($dataValue->getProperty() instanceof DIProperty && $dataValue->getProperty()->getKey() !== '_INST') { $html .= $dataValue->getInfolinkText(SMW_OUTPUT_HTML, $linker); } return $html; }
/** * @since 2.2 * * @return array|integer|string|boolean * @throws RuntimeException */ public function getSettingsFor($key) { $settings = $this->getFileContentsFor('settings'); if (($key === 'wgContLang' || $key === 'wgLang') && isset($settings[$key])) { \RequestContext::getMain()->setLanguage($settings[$key]); Localizer::getInstance()->clear(); return \Language::factory($settings[$key]); } // Needs special attention due to NS constant usage if ($key === 'smwgNamespacesWithSemanticLinks' && isset($settings[$key])) { $smwgNamespacesWithSemanticLinks = array(); foreach ($settings[$key] as $ns => $value) { $smwgNamespacesWithSemanticLinks[constant($ns)] = (bool) $value; } return $smwgNamespacesWithSemanticLinks; } if ($key === 'smwgDVFeatures' && isset($settings[$key])) { $smwgDVFeatures = ''; foreach ($settings[$key] as $value) { $smwgDVFeatures = constant($value) | $smwgDVFeatures; } return $smwgDVFeatures; } if ($key === 'wgDefaultUserOptions' && isset($settings[$key])) { return array_merge($GLOBALS['wgDefaultUserOptions'], $settings[$key]); } // Needs special attention due to constant usage if ($key === 'smwgQConceptCaching' && isset($settings[$key])) { return constant($settings[$key]); } // Needs special attention due to constant usage if (strpos($key, 'CacheType') !== false && isset($settings[$key])) { return $settings[$key] === false ? CACHE_NONE : defined($settings[$key]) ? constant($settings[$key]) : $settings[$key]; } if (isset($settings[$key])) { return $settings[$key]; } // Set default values if (isset($GLOBALS[$key]) || array_key_exists($key, $GLOBALS)) { return $GLOBALS[$key]; } throw new RuntimeException("{$key} is unknown"); }
public function parameterDataProvider() { $helpNS = Localizer::getInstance()->getNamespaceTextById(NS_HELP); $provider = array(); #0 Anonymous identifier // {{#subobject: // |Foo=bar // }} $provider[] = array(array('', 'Foo=bar'), array('hasErrors' => false, 'identifier' => '_', 'propertyCount' => 1, 'propertyLabels' => 'Foo', 'propertyValues' => 'Bar')); #1 Anonymous identifier // {{#subobject:- // |Foo=1001 9009 // }} $provider[] = array(array('-', 'Foo=1001 9009'), array('hasErrors' => false, 'identifier' => '_', 'propertyCount' => 1, 'propertyLabels' => 'Foo', 'propertyValues' => '1001 9009')); #2 Named identifier // {{#subobject:FooBar // |FooBar=Bar foo // }} $provider[] = array(array('FooBar', 'FooBar=Bar foo'), array('hasErrors' => false, 'identifier' => 'FooBar', 'propertyCount' => 1, 'propertyLabels' => 'FooBar', 'propertyValues' => 'Bar foo')); #3 Named identifier // {{#subobject:Foo bar // |Foo=Help:Bar // }} $provider[] = array(array('Foo bar', 'Foo=Help:Bar'), array('hasErrors' => false, 'identifier' => 'Foo_bar', 'propertyCount' => 1, 'propertyLabels' => 'Foo', 'propertyValues' => "{$helpNS}:Bar")); #4 Named identifier // {{#subobject: Foo bar foo // |Bar=foo Bar // }} $provider[] = array(array(' Foo bar foo ', 'Bar=foo Bar'), array('hasErrors' => false, 'identifier' => 'Foo_bar_foo', 'propertyCount' => 1, 'propertyLabels' => 'Bar', 'propertyValues' => 'Foo Bar')); #5 Named identifier // {{#subobject: Foo bar foo // |状況=超やばい // |Bar=http://www.semantic-mediawiki.org/w/index.php?title=Subobject // }} $provider[] = array(array(' Foo bar foo ', '状況=超やばい', 'Bar=http://www.semantic-mediawiki.org/w/index.php?title=Subobject'), array('hasErrors' => false, 'identifier' => 'Foo_bar_foo', 'propertyCount' => 2, 'propertyLabels' => array('状況', 'Bar'), 'propertyValues' => array('超やばい', 'Http://www.semantic-mediawiki.org/w/index.php?title=Subobject'))); #6 {{#subobject: Foo bar foo // |Bar=foo Bar // |Modification date=foo Bar // }} $provider[] = array(array(' Foo bar foo ', 'Bar=foo Bar', 'Modification date=foo Bar'), array('hasErrors' => true, 'identifier' => 'Foo_bar_foo', 'propertyCount' => 1, 'propertyLabels' => array('Bar'), 'propertyValues' => array('Foo Bar'))); #7 {{#subobject: Foo bar foo // |Bar=foo Bar // |-Foo=foo Bar // }} $provider[] = array(array(' Foo bar foo ', 'Bar=foo Bar', '-Foo=foo Bar'), array('hasErrors' => true, 'identifier' => 'Foo_bar_foo', 'propertyCount' => 1, 'propertyLabels' => array('Bar'), 'propertyValues' => array('Foo Bar'))); // An empty subobject is not being classified as valid (to create an object) #8 {{#subobject: Foo bar foo // |Bar=foo Bar // |Modification date=1 Jan 1970 // }} $provider[] = array(array(' Foo bar foo ', 'Modification date=1 Jan 1970'), array('hasErrors' => true, 'identifier' => 'Foo_bar_foo', 'propertyCount' => 0)); // Get the right language for an error object $diPropertyError = new DIProperty(DIProperty::TYPE_ERROR); #9 {{#subobject: Foo bar foo // |Bar=foo Bar // |Date=Foo // }} $provider[] = array(array(' Foo bar foo ', 'Date=Foo'), array('hasErrors' => true, 'identifier' => 'Foo_bar_foo', 'propertyCount' => 1, 'propertyLabels' => array($diPropertyError->getLabel()), 'propertyValues' => array('Date'))); return $provider; }
private function registerCallbackHandlersByConstructedInstance($callbackLoader) { /** * @var BlobStore */ $callbackLoader->registerCallback('BlobStore', function ($namespace, $cacheType = null, $ttl = 0) use($callbackLoader) { $callbackLoader->registerExpectedReturnType('BlobStore', '\\Onoi\\BlobStore\\BlobStore'); $cacheFactory = $callbackLoader->load('CacheFactory'); $blobStore = new BlobStore($namespace, $cacheFactory->newMediaWikiCompositeCache($cacheType)); $blobStore->setNamespacePrefix($cacheFactory->getCachePrefix()); $blobStore->setExpiryInSeconds($ttl); $blobStore->setUsageState($cacheType !== CACHE_NONE && $cacheType !== false); return $blobStore; }); /** * @var CachedQueryResultPrefetcher */ $callbackLoader->registerCallback('CachedQueryResultPrefetcher', function ($cacheType = null) use($callbackLoader) { $callbackLoader->registerExpectedReturnType('CachedQueryResultPrefetcher', '\\SMW\\CachedQueryResultPrefetcher'); $settings = $callbackLoader->load('Settings'); $cacheType = $cacheType === null ? $settings->get('smwgQueryResultCacheType') : $cacheType; $cachedQueryResultPrefetcher = new CachedQueryResultPrefetcher($callbackLoader->load('Store'), $callbackLoader->singleton('QueryFactory'), $callbackLoader->create('BlobStore', CachedQueryResultPrefetcher::CACHE_NAMESPACE, $cacheType, $settings->get('smwgQueryResultCacheLifetime')), $callbackLoader->singleton('TransientStatsdCollector', CachedQueryResultPrefetcher::STATSD_ID)); $cachedQueryResultPrefetcher->setLogger($callbackLoader->singleton('MediaWikiLogger')); $cachedQueryResultPrefetcher->setNonEmbeddedCacheLifetime($settings->get('smwgQueryResultNonEmbeddedCacheLifetime')); return $cachedQueryResultPrefetcher; }); /** * @var CachedPropertyValuesPrefetcher */ $callbackLoader->registerCallback('CachedPropertyValuesPrefetcher', function ($cacheType = null, $ttl = 604800) use($callbackLoader) { $callbackLoader->registerExpectedReturnType('CachedPropertyValuesPrefetcher', '\\SMW\\CachedPropertyValuesPrefetcher'); $cachedPropertyValuesPrefetcher = new CachedPropertyValuesPrefetcher($callbackLoader->load('Store'), $callbackLoader->load('BlobStore', CachedPropertyValuesPrefetcher::CACHE_NAMESPACE, $cacheType, $ttl)); return $cachedPropertyValuesPrefetcher; }); /** * @var TransientStatsdCollector */ $callbackLoader->registerCallback('TransientStatsdCollector', function ($id) use($callbackLoader) { $callbackLoader->registerExpectedReturnType('TransientStatsdCollector', '\\SMW\\TransientStatsdCollector'); // Explicitly use the DB to access a SqlBagOstuff instance $cacheType = CACHE_DB; $ttl = 0; $transientStatsdCollector = new TransientStatsdCollector($callbackLoader->create('BlobStore', TransientStatsdCollector::CACHE_NAMESPACE, $cacheType, $ttl), $id); return $transientStatsdCollector; }); /** * @var PropertySpecificationLookup */ $callbackLoader->registerCallback('PropertySpecificationLookup', function () use($callbackLoader) { $callbackLoader->registerExpectedReturnType('PropertySpecificationLookup', '\\SMW\\PropertySpecificationLookup'); $propertySpecificationLookup = new PropertySpecificationLookup($callbackLoader->singleton('CachedPropertyValuesPrefetcher'), $callbackLoader->singleton('InMemoryPoolCache')->getPoolCacheById(PropertySpecificationLookup::POOLCACHE_ID)); // Uses the language object selected in user preferences. It is one // of two global language objects $propertySpecificationLookup->setLanguageCode(Localizer::getInstance()->getUserLanguage()->getCode()); return $propertySpecificationLookup; }); /** * @var PropertyHierarchyLookup */ $callbackLoader->registerCallback('PropertyHierarchyLookup', function () use($callbackLoader) { $callbackLoader->registerExpectedReturnType('PropertyHierarchyLookup', '\\SMW\\PropertyHierarchyLookup'); $propertyHierarchyLookup = new PropertyHierarchyLookup($callbackLoader->load('Store'), $callbackLoader->singleton('InMemoryPoolCache')->getPoolCacheById(PropertyHierarchyLookup::POOLCACHE_ID)); $propertyHierarchyLookup->setSubcategoryDepth($callbackLoader->load('Settings')->get('smwgQSubcategoryDepth')); $propertyHierarchyLookup->setSubpropertyDepth($callbackLoader->load('Settings')->get('smwgQSubpropertyDepth')); return $propertyHierarchyLookup; }); /** * @var PropertyLabelFinder */ $callbackLoader->registerCallback('PropertyLabelFinder', function () use($callbackLoader) { $callbackLoader->registerExpectedReturnType('PropertyLabelFinder', '\\SMW\\PropertyLabelFinder'); $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage(); $propertyLabelFinder = new PropertyLabelFinder($callbackLoader->load('Store'), $extraneousLanguage->getPropertyLabels(), $extraneousLanguage->getCanonicalPropertyLabels()); return $propertyLabelFinder; }); /** * @var TransitionalDiffStore */ $callbackLoader->registerCallback('TransitionalDiffStore', function () use($callbackLoader) { $callbackLoader->registerExpectedReturnType('TransitionalDiffStore', '\\SMW\\SQLStore\\TransitionalDiffStore'); $cacheFactory = $callbackLoader->load('CacheFactory'); $cacheType = null; $transitionalDiffStore = new TransitionalDiffStore($cacheFactory->newMediaWikiCompositeCache($cacheType), $cacheFactory->getCachePrefix()); $transitionalDiffStore->setLogger($callbackLoader->singleton('MediaWikiLogger')); return $transitionalDiffStore; }); }
/** * Specify the wiki page to which this value refers. This information is * used to parse user values such as "#subsection" which only make sense * when used on a certain page. * * @since 1.7 * * @param SMWDIWikiPage|null $contextPage */ public function setContextPage(SMWDIWikiPage $contextPage = null) { $this->m_contextPage = $contextPage; $this->setOption(self::OPT_CONTENT_LANGUAGE, Localizer::getInstance()->getPreferredContentLanguage($contextPage)->getCode()); }
/** * Anonymous user with default preferences and content language */ private function makeCanonicalParserOptions() { return ParserOptions::newFromUserAndLang(new User(), Localizer::getInstance()->getContentLanguage()); }
/** * Formatting rule set: * - preferred goes before translation * - displayTitle goes before translation * - translation goes before "normal" label */ private function getFormattedLabel($linker = null) { $property = $this->dataValue->getDataItem(); $output = ''; $displayTitle = ''; $preferredLabel = $property->getPreferredLabel($this->dataValue->getOptionBy(PropertyValue::OPT_USER_LANGUAGE)); $label = $preferredLabel; if ($preferredLabel === '' && ($label = $this->findTranslatedPropertyLabel($property)) === '') { $label = $property->getLabel(); } if ($this->dataValue->getWikiPageValue() !== null) { $displayTitle = $this->dataValue->getWikiPageValue()->getDisplayTitle(); } $canonicalLabel = $property->getCanonicalLabel(); // Display title goes before a translated label (but not preferred) if ($displayTitle !== '' && !$property->isUserDefined()) { $label = $displayTitle; $canonicalLabel = $displayTitle; } // Internal format only used by PropertyValue $format = $this->getOptionBy(PropertyValue::FORMAT_LABEL); $this->dataValue->setCaption($label); if ($format === self::VALUE) { $output = $this->dataValue->getWikiValue(); } if ($format === self::WIKI_LONG && $linker !== null) { $output = $this->dataValue->getLongWikiText($linker); } elseif ($format === self::WIKI_LONG && $preferredLabel === '' && $displayTitle !== '') { $output = $displayTitle; } elseif ($format === self::WIKI_LONG) { // Avoid Title::getPrefixedText as it transforms the text to have a // leading capital letter in some configurations $output = Localizer::getInstance()->createTextWithNamespacePrefix(SMW_NS_PROPERTY, $label); } if ($format === self::HTML_SHORT && $linker !== null) { $output = $this->dataValue->getShortHTMLText($linker); } // Output both according to the formatting rule set forth by if ($canonicalLabel !== $label) { $output = Message::get(array('smw-property-preferred-title-format', $output, $canonicalLabel)); } return $output; }