/** * @param $nsCode namespace code * @param $decoded decoded page name. URL-decoded, using normalized spaces (not underscores), first letter uppercase. */ public function __construct($nsCode, $decoded) { PhpUtil::assertInteger($nsCode, 'namespace code'); if (!isset(self::$nsNames[$nsCode])) { throw new \InvalidArgumentException('unknown namespace code ' . $nsCode); } PhpUtil::assertString($decoded, 'page name'); if (strlen($decoded) === 0) { throw new WikiParserException('page name must not be empty'); } $this->nsCode = $nsCode; $this->nsName = self::$nsNames[$nsCode][0]; $this->encoded = WikiUtil::wikiEncode($decoded); // re-decode to make sure name is normalized $this->decoded = WikiUtil::wikiDecode($this->encoded); }
private function parseTemplate($templateNode, $source) { while (true) { $propertyNode = new PropertyNode($source->getLine()); $this->parseProperty($propertyNode, $source); //The first entry denotes the name of the template if ($templateNode->getTitle() == null) { $templateName = $propertyNode->getText(); if (!$templateName) { throw new WikiParserException("Template name contains invalid elements", $templateNode->getLine(), $source->findLine($templateNode->getLine())); } $templateNode->setTitle(new WikiTitle(WikiTitle::NS_TEMPLATE, WikiUtil::wikiDecode(trim($templateName)))); } else { $templateNode->addProperty($propertyNode); } //Reached template end? if ($source->lastTag('}}')) { return $templateNode; } } }