Skip to content

Commit

Permalink
reolve URLs in page id as external link (implements dokufreaks#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
lprobsth committed Dec 4, 2023
1 parent 5480776 commit ec0cd4f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
40 changes: 29 additions & 11 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,26 +636,44 @@ public function finishList()
*/
protected function printPageCell($id)
{
$external = False;

if(preg_match("/\b(?:https?:\/\/|www\.)\S+\b/i", $id)) {
$external = True;
}

// check for page existence if internal page
if (!$external) {
// handle image and text titles
if (!empty($this->page['titleimage'])) {
$title = '<img src="' . ml($this->page['titleimage']) . '" class="media"';
if (!empty($this->page['title'])) {
$title .= ' title="' . hsc($this->page['title']) . '" alt="' . hsc($this->page['title']) . '"';
}
$title .= ' />';
} else {
$title = hsc($this->page['title']);
}
} else {
$this->page['exists'] = true;
}

if ($this->page['exists']) {
$class = 'wikilink1';
} else {
$class = 'wikilink2';
}

// handle image and text titles
if (!empty($this->page['titleimage'])) {
$title = '<img src="' . ml($this->page['titleimage']) . '" class="media"';
if (!empty($this->page['title'])) {
$title .= ' title="' . hsc($this->page['title']) . '" alt="' . hsc($this->page['title']) . '"';
}
$title .= ' />';
// produce output
if (!$external) {
// produce output
$section = !empty($this->page['section']) ? '#' . $this->page['section'] : '';
$content = '<a href="' . wl($id) . $section . '" class="' . $class . '" title="' . $id . '" data-wiki-id="' . $id . '">' . $title . '</a>';
} else {
$title = hsc($this->page['title']);
$content = '<a href="'.$id.
'" class="'.$class.'" title="'.$id.'">'.$this->page['title'].'</a>';
}

// produce output
$section = !empty($this->page['section']) ? '#' . $this->page['section'] : '';
$content = '<a href="' . wl($id) . $section . '" class="' . $class . '" title="' . $id . '" data-wiki-id="' . $id . '">' . $title . '</a>';
if ($this->style == 'list') {
$content = '<ul><li>' . $content . '</li></ul>';
}
Expand Down
18 changes: 11 additions & 7 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ public function handle($match, $state, $pos, Doku_Handler $handler)
list($id, $section) = array_pad(explode('#', $id, 2), 2, null);
if (!$id) $id = $ID;

$external = False;

// Igor and later
if (class_exists('dokuwiki\File\PageResolver')) {
$resolver = new dokuwiki\File\PageResolver($ID);
$id = $resolver->resolveId($id);
$exists = page_exists($id);
} else {
// Compatibility with older releases
resolve_pageid(getNS($ID), $id, $exists);
if(!preg_match("/\b(?:https?:\/\/|www\.)\S+\b/i", $id)) {
if (class_exists('dokuwiki\File\PageResolver')) {
$resolver = new dokuwiki\File\PageResolver($ID);
$id = $resolver->resolveId($id);
$exists = page_exists($id);
} else {
// Compatibility with older releases
resolve_pageid(getNS($ID), $id, $exists);
}
}

// page has an image title
Expand Down

0 comments on commit ec0cd4f

Please sign in to comment.