/** * 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->descriptionProcessor->addErrorWithMsgKey('smw_misplacedsubquery'); 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->descriptionProcessor->constructDisjunctiveCompoundDescriptionFrom($result, new NamespaceDescription($idx)); } } else { $result = $this->descriptionProcessor->constructDisjunctiveCompoundDescriptionFrom($result, $this->descriptionProcessor->constructDescriptionForWikiPageValueChunk($chunk)); } $chunk = $this->readChunk('\\[\\[|\\]\\]|\\|\\||\\|'); if ($chunk == '||') { $chunk = $this->readChunk('\\[\\[|\\]\\]|\\|\\||\\|'); $continue = true; } else { $continue = false; } } return $this->finishLinkDescription($chunk, true, $result, $setNS); }
public function testTryToGetConjunctiveCompoundDescriptionForNullCurrentDescription() { $instance = new DescriptionProcessor(); $newDescription = $instance->constructDescriptionForWikiPageValueChunk('bar'); $this->assertInstanceOf('SMW\\Query\\Language\\ValueDescription', $instance->constructConjunctiveCompoundDescriptionFrom(null, $newDescription)); }