Exemplo n.º 1
0
 /**
  * @param $link MediaWiki link target
  */
 public static function parse($link)
 {
     PhpUtil::assertString($link, 'link');
     self::init();
     $link = urldecode($link);
     if (strpos($link, '#') !== false) {
         throw new WikiParserException('Invalid title: "' . $link . '" (Contains #)');
     }
     $parts = explode(':', $link, 2);
     if (count($parts) === 2) {
         $prefix = mb_strtolower(WikiUtil::cleanSpace($parts[0]));
         // TODO: handle interwiki links like [[:de:Foo]]
         if (strlen($prefix) === 0) {
             throw new WikiParserException('cannot handle link [' . $link . ']');
         }
         // TODO: handle special prefixes, e.g. [[q:Foo]] links to WikiQuotes
         if (isset(self::$nsCodes[$prefix])) {
             $code = self::$nsCodes[$prefix];
             $name = StringUtil::mb_ucfirst(WikiUtil::cleanSpace($parts[1]));
             return new WikiTitle($code, $name);
         }
     }
     $name = StringUtil::mb_ucfirst(WikiUtil::cleanSpace($link));
     return new WikiTitle(self::NS_MAIN, $name);
 }