Extract Pagelink functionality

This commit is contained in:
2026-02-03 08:00:09 +01:00
parent 1b6df4a9e4
commit 70a9f30336
4 changed files with 172 additions and 278 deletions

View File

@@ -2,7 +2,7 @@
use dokuwiki\Extension\SyntaxPlugin;
use dokuwiki\plugin\luxtools\Path;
use dokuwiki\plugin\luxtools\PageLink;
use dokuwiki\plugin\luxtools\PageLinkTrait;
use dokuwiki\plugin\luxtools\ThumbnailHelper;
require_once(__DIR__ . '/../autoload.php');
@@ -16,6 +16,7 @@ require_once(__DIR__ . '/../autoload.php');
*/
class syntax_plugin_luxtools_image extends SyntaxPlugin
{
use PageLinkTrait;
/** @inheritdoc */
public function getType()
{
@@ -139,12 +140,7 @@ class syntax_plugin_luxtools_image extends SyntaxPlugin
return true;
}
$pathConfig = (string)$this->getConf('paths');
if ($blobsRoot !== '') {
$pathConfig = rtrim($pathConfig) . "\n" . $blobsRoot . "\nA> blobs";
}
$pathHelper = new Path($pathConfig);
$pathHelper = $this->createPathHelperWithBlobs($blobsRoot);
// Use addTrailingSlash=false since this is a file path, not a directory
$pathInfo = $pathHelper->getPathInfo($data['path'], false);
} catch (\Exception $e) {
@@ -226,96 +222,6 @@ class syntax_plugin_luxtools_image extends SyntaxPlugin
return DOKU_BASE . 'lib/plugins/luxtools/file.php?' . http_build_query($params, '', '&');
}
/**
* Check if the given path uses the blobs alias.
*/
protected function isBlobsPath(string $path): bool
{
$trimmed = ltrim($path, '/');
return preg_match('/^blobs(\/|$)/', $trimmed) === 1;
}
/**
* Render the "Page not linked" message with copy ID affordance.
*/
protected function renderPageNotLinked(\Doku_Renderer $renderer): void
{
$uuid = $this->getPageUuidSafe();
$text = (string)$this->getLang('pagelink_unlinked');
if ($renderer instanceof \Doku_Renderer_xhtml) {
$renderer->doc .= '<a href="#" class="luxtools-pagelink-copy" data-luxtools-pagelink-copy="1"'
. ' data-uuid="' . hsc($uuid) . '"'
. '>' . hsc($text) . '</a>';
return;
}
$renderer->cdata('[n/a: ' . $text . ']');
}
/**
* Read the current page UUID (if any).
*/
protected function getPageUuidSafe(): string
{
global $ID;
$pageId = is_string($ID) ? $ID : '';
if ($pageId === '') return '';
if (function_exists('cleanID')) {
$pageId = (string)cleanID($pageId);
}
if ($pageId === '') return '';
$depth = (int)$this->getConf('pagelink_search_depth');
if ($depth < 0) $depth = 0;
$pageLink = new PageLink((string)$this->getConf('paths'), $depth);
$uuid = $pageLink->getPageUuid($pageId);
return $uuid ?? '';
}
/**
* Resolve the current page's pagelink folder for the blobs alias.
*/
protected function resolveBlobsRoot(): string
{
static $cached = [];
global $ID;
$pageId = is_string($ID) ? $ID : '';
if ($pageId === '') return '';
if (function_exists('cleanID')) {
$pageId = (string)cleanID($pageId);
}
if ($pageId === '') return '';
if (isset($cached[$pageId])) {
return (string)$cached[$pageId];
}
$depth = (int)$this->getConf('pagelink_search_depth');
if ($depth < 0) $depth = 0;
$pageLink = new PageLink((string)$this->getConf('paths'), $depth);
$uuid = $pageLink->getPageUuid($pageId);
if ($uuid === null) {
$cached[$pageId] = '';
return '';
}
$linkInfo = $pageLink->resolveUuid($uuid);
$folder = $linkInfo['folder'] ?? '';
if (!is_string($folder) || $folder === '') {
$cached[$pageId] = '';
return '';
}
$cached[$pageId] = $folder;
return $folder;
}
/**
* Render the imagebox HTML.
*