From e5981fe6c06601de559485d1037eb67ac9bdcd4a Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Fri, 22 Sep 2023 23:16:18 +0200 Subject: [PATCH] Fix #292 #297 deprecated id resolving functions * Add a new gerneric resolver to resolve ids without cleaning * Replace deprecated calls * Remove some unused variables --- GenericResolver.php | 11 +++++++++++ helper.php | 18 +++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 GenericResolver.php diff --git a/GenericResolver.php b/GenericResolver.php new file mode 100644 index 0000000..d02d69c --- /dev/null +++ b/GenericResolver.php @@ -0,0 +1,11 @@ + * @author Michael Hamann */ +use dokuwiki\plugin\include\GenericResolver; +use dokuwiki\File\PageResolver; /** * Helper functions for the include plugin and other plugins that want to include pages. @@ -302,7 +304,6 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $this->_get_firstsec($ins, $page, $flags); // only first section } - $ns = getNS($page); $num = count($ins); $conv_idx = array(); // conversion index @@ -544,13 +545,12 @@ function _permalink(&$ins, $page, $sect, $flags) { */ private function adapt_links(&$ins, $page, $included_pages = null) { $num = count($ins); - $ns = getNS($page); for($i=0; $i<$num; $i++) { // adjust links with image titles if (strpos($ins[$i][0], 'link') !== false && isset($ins[$i][1][1]) && is_array($ins[$i][1][1]) && $ins[$i][1][1]['type'] == 'internalmedia') { // resolve relative ids, but without cleaning in order to preserve the name - $media_id = resolve_id($ns, $ins[$i][1][1]['src']); + $media_id = (new GenericResolver($page))->resolveId($ins[$i][1][1]['src']); // make sure that after resolving the link again it will be the same link if ($media_id[0] != ':') $media_id = ':'.$media_id; $ins[$i][1][1]['src'] = $media_id; @@ -567,7 +567,7 @@ private function adapt_links(&$ins, $page, $included_pages = null) { $link_params = $link_parts[1]; } // resolve the id without cleaning it - $link_id = resolve_id($ns, $link_id, false); + $link_id = (new GenericResolver($page))->resolveId($link_id); // this id is internal (i.e. absolute) now, add ':' to make resolve_id work again if ($link_id[0] != ':') $link_id = ':'.$link_id; // restore parameters @@ -579,8 +579,7 @@ private function adapt_links(&$ins, $page, $included_pages = null) { $link_id = $ins[$i][1][0]; $link_parts = explode('?', $link_id, 2); if (count($link_parts) === 1) { - $exists = false; - resolve_pageid($ns, $link_id, $exists); + $link_id = (new PageResolver($page))->resolveId($link_id); $link_parts = explode('#', $link_id, 2); $hash = ''; @@ -725,7 +724,8 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { break; default: $page = $this->_apply_macro($page, $parent_id); - resolve_pageid(getNS($parent_id), $page, $exists); // resolve shortcuts and clean ID + // resolve shortcuts and clean ID + $page = (new PageResolver($parent_id))->resolveId($page); if (auth_quickaclcheck($page) >= AUTH_READ) $pages[] = $page; } @@ -843,8 +843,8 @@ function _get_language_of_wiki($id, $parent_id) { arsort($langs); foreach($langs as $lang => $langq){ $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id); - resolve_pageid(getNS($parent_id), $testpage, $exists); - if($exists){ + $testpage = (new PageResolver($parent_id))->resolveId($testpage); + if (page_exists($testpage)) { $result = $lang; break; }