1be906b56SAndreas Gohr<?php 2be906b56SAndreas Gohr 3be906b56SAndreas Gohrnamespace dokuwiki\Parsing\ParserMode; 4be906b56SAndreas Gohr 571096e46SAndreas Gohruse dokuwiki\Parsing\Handler; 6*3440a8c0SAndreas Gohruse dokuwiki\Parsing\Helpers; 771096e46SAndreas Gohr 8be906b56SAndreas Gohrclass Internallink extends AbstractMode 9be906b56SAndreas Gohr{ 10be906b56SAndreas Gohr /** @inheritdoc */ 1171096e46SAndreas Gohr public function getSort() 1271096e46SAndreas Gohr { 1371096e46SAndreas Gohr return 300; 1471096e46SAndreas Gohr } 1571096e46SAndreas Gohr 1671096e46SAndreas Gohr /** @inheritdoc */ 17be906b56SAndreas Gohr public function connectTo($mode) 18be906b56SAndreas Gohr { 19be906b56SAndreas Gohr // Word boundaries? 20be906b56SAndreas Gohr $this->Lexer->addSpecialPattern("\[\[.*?\]\](?!\])", $mode, 'internallink'); 21be906b56SAndreas Gohr } 22be906b56SAndreas Gohr 23be906b56SAndreas Gohr /** @inheritdoc */ 2471096e46SAndreas Gohr public function handle($match, $state, $pos, Handler $handler) 25be906b56SAndreas Gohr { 2671096e46SAndreas Gohr // Strip the opening and closing markup 2771096e46SAndreas Gohr $link = preg_replace(['/^\[\[/', '/\]\]$/u'], '', $match); 2871096e46SAndreas Gohr 2971096e46SAndreas Gohr // Split title from URL 3071096e46SAndreas Gohr $link = sexplode('|', $link, 2); 3171096e46SAndreas Gohr if ($link[1] !== null && preg_match('/^\{\{[^\}]+\}\}$/', $link[1])) { 3271096e46SAndreas Gohr // If the title is an image, convert it to an array containing the image details 3371096e46SAndreas Gohr $link[1] = Media::parseMedia($link[1]); 3471096e46SAndreas Gohr } 3571096e46SAndreas Gohr $link[0] = trim($link[0]); 3671096e46SAndreas Gohr 37*3440a8c0SAndreas Gohr [$call, $args] = Helpers::classifyLink($link[0], $link[1]); 38*3440a8c0SAndreas Gohr $handler->addCall($call, $args, $pos); 3971096e46SAndreas Gohr return true; 40be906b56SAndreas Gohr } 41be906b56SAndreas Gohr} 42