Skip to content

Commit

Permalink
Fix #292 #297 deprecated id resolving functions
Browse files Browse the repository at this point in the history
* Add a new gerneric resolver to resolve ids without cleaning
* Replace deprecated calls
* Remove some unused variables
  • Loading branch information
michitux committed Sep 22, 2023
1 parent 5126bb8 commit e5981fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions GenericResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace dokuwiki\plugin\include;
use dokuwiki\File\Resolver;

/**
* Resolves ids without cleaning them.
*
* @package dokuwiki\plugin\include
*/
class GenericResolver extends Resolver {
}
18 changes: 9 additions & 9 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* @author Gina Häußge, Michael Klier <[email protected]>
* @author Michael Hamann <[email protected]>
*/
use dokuwiki\plugin\include\GenericResolver;
use dokuwiki\File\PageResolver;

/**
* Helper functions for the include plugin and other plugins that want to include pages.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 = '';
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit e5981fe

Please sign in to comment.