From 15bd568bc5bbdc48e06bb37289b379db96b53411 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 17:53:47 +0200 Subject: [PATCH 01/18] automatic code style fixes --- GenericResolver.php | 5 +- action.php | 141 ++++++++------- conf/default.php | 2 + conf/metadata.php | 2 + helper.php | 342 +++++++++++++++++++----------------- syntax/closelastsecedit.php | 17 +- syntax/editbtn.php | 19 +- syntax/footer.php | 30 ++-- syntax/header.php | 38 ++-- syntax/include.php | 35 ++-- syntax/locallink.php | 21 ++- syntax/readmore.php | 21 ++- syntax/sorttag.php | 26 +-- syntax/wrap.php | 29 +-- 14 files changed, 417 insertions(+), 311 deletions(-) diff --git a/GenericResolver.php b/GenericResolver.php index d02d69c..edbfae3 100644 --- a/GenericResolver.php +++ b/GenericResolver.php @@ -1,5 +1,7 @@ helper = plugin_load('helper', 'include'); } /** * plugin should use this method to register its handlers with the dokuwiki's event controller */ - function register(Doku_Event_Handler $controller) { + function register(Doku_Event_Handler $controller) + { /* @var Doku_event_handler $controller */ $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexer'); $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'handle_indexer_version'); - $controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare'); + $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, '_cache_prepare'); $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove $controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_form'); $controller->register_hook('HTML_CONFLICTFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove @@ -47,8 +50,9 @@ function register(Doku_Event_Handler $controller) { * Add a version string to the index so it is rebuilt * whenever the handler is updated or the safeindex setting is changed */ - public function handle_indexer_version($event, $param) { - $event->data['plugin_include'] = '0.1.safeindex='.$this->getConf('safeindex'); + public function handle_indexer_version($event, $param) + { + $event->data['plugin_include'] = '0.1.safeindex=' . $this->getConf('safeindex'); } /** @@ -57,7 +61,8 @@ public function handle_indexer_version($event, $param) { * @param Doku_Event $event the event object * @param array $params optional parameters (unused) */ - public function handle_indexer(Doku_Event $event, $params) { + public function handle_indexer(Doku_Event $event, $params) + { global $USERINFO; // check if the feature is enabled at all @@ -111,7 +116,7 @@ public function handle_indexer(Doku_Event $event, $params) { if ($tag_called) { $tag_helper = $this->loadHelper('tag', false); if ($tag_helper) { - if (isset($meta['subject'])) { + if (isset($meta['subject'])) { $event->data['metadata']['subject'] = $tag_helper->_cleanTagList($meta['subject']); } else { $event->data['metadata']['subject'] = array(); @@ -128,9 +133,10 @@ public function handle_indexer(Doku_Event $event, $params) { /** * Used for debugging purposes only */ - function handle_metadata(&$event, $param) { + function handle_metadata(&$event, $param) + { global $conf; - if($conf['allowdebug'] && $this->getConf('debugoutput')) { + if ($conf['allowdebug'] && $this->getConf('debugoutput')) { dbglog('---- PLUGIN INCLUDE META DATA START ----'); dbglog($event->data); dbglog('---- PLUGIN INCLUDE META DATA END ----'); @@ -143,31 +149,32 @@ function handle_metadata(&$event, $param) { * @author Michael Klier * @author Michael Hamann */ - function handle_parser(Doku_Event $event, $param) { + function handle_parser(Doku_Event $event, $param) + { global $ID; $level = 0; $ins =& $event->data->calls; $num = count($ins); - for($i=0; $i<$num; $i++) { - switch($ins[$i][0]) { - case 'plugin': - switch($ins[$i][1][0]) { - case 'include_include': - $ins[$i][1][1][4] = $level; - break; + for ($i = 0; $i < $num; $i++) { + switch ($ins[$i][0]) { + case 'plugin': + switch ($ins[$i][1][0]) { + case 'include_include': + $ins[$i][1][1][4] = $level; + break; /* FIXME: this doesn't work anymore that way with the new structure // some plugins already close open sections // so we need to make sure we don't close them twice - case 'box': + case 'box': $this->helper->sec_close = false; break; */ - } - break; - case 'section_open': - $level = $ins[$i][1][0]; - break; + } + break; + case 'section_open': + $level = $ins[$i][1][0]; + break; } } } @@ -179,7 +186,7 @@ function handle_form(Doku_Event $event, $param) { if (!array_key_exists('redirect_id', $_REQUEST)) return; - if(is_a($event->data, \dokuwiki\Form\Form::class)) { + if (is_a($event->data, \dokuwiki\Form\Form::class)) { $event->data->setHiddenField('redirect_id', cleanID($_REQUEST['redirect_id'])); } else { // todo remove when old FORM events are no longer supported @@ -190,35 +197,37 @@ function handle_form(Doku_Event $event, $param) /** * Modify the data for the redirect when there is a redirect_id set */ - function handle_redirect(Doku_Event &$event, $param) { - if (array_key_exists('redirect_id', $_REQUEST)) { - // Render metadata when this is an older DokuWiki version where - // metadata is not automatically re-rendered as the page has probably - // been changed but is not directly displayed - $versionData = getVersionData(); - if ($versionData['date'] < '2010-11-23') { - p_set_metadata($event->data['id'], array(), true); + function handle_redirect(Doku_Event &$event, $param) + { + if (array_key_exists('redirect_id', $_REQUEST)) { + // Render metadata when this is an older DokuWiki version where + // metadata is not automatically re-rendered as the page has probably + // been changed but is not directly displayed + $versionData = getVersionData(); + if ($versionData['date'] < '2010-11-23') { + p_set_metadata($event->data['id'], array(), true); + } + $event->data['id'] = cleanID($_REQUEST['redirect_id']); + $event->data['title'] = ''; } - $event->data['id'] = cleanID($_REQUEST['redirect_id']); - $event->data['title'] = ''; - } } /** * prepare the cache object for default _useCache action */ - function _cache_prepare(Doku_Event &$event, $param) { + function _cache_prepare(Doku_Event &$event, $param) + { global $conf; /* @var cache_renderer $cache */ $cache =& $event->data; - if(!isset($cache->page)) return; - if(!isset($cache->mode) || $cache->mode == 'i') return; + if (!isset($cache->page)) return; + if (!isset($cache->mode) || $cache->mode == 'i') return; $depends = p_get_metadata($cache->page, 'plugin_include'); - if($conf['allowdebug'] && $this->getConf('debugoutput')) { + if ($conf['allowdebug'] && $this->getConf('debugoutput')) { dbglog('---- PLUGIN INCLUDE CACHE DEPENDS START ----'); dbglog($depends); dbglog('---- PLUGIN INCLUDE CACHE DEPENDS END ----'); @@ -226,14 +235,15 @@ function _cache_prepare(Doku_Event &$event, $param) { if (!is_array($depends)) return; // nothing to do for us - if (!is_array($depends['pages']) || + if ( + !is_array($depends['pages']) || !is_array($depends['instructions']) || $depends['pages'] != $this->helper->_get_included_pages_from_meta_instructions($depends['instructions']) || // the include_content url parameter may change the behavior for included pages - $depends['include_content'] != isset($_REQUEST['include_content'])) { - + $depends['include_content'] != isset($_REQUEST['include_content']) + ) { $cache->depends['purge'] = true; // included pages changed or old metadata - request purge. - if($conf['allowdebug'] && $this->getConf('debugoutput')) { + if ($conf['allowdebug'] && $this->getConf('debugoutput')) { dbglog('---- PLUGIN INCLUDE: REQUESTING CACHE PURGE ----'); dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META START ----'); dbglog($depends['pages']); @@ -241,7 +251,6 @@ function _cache_prepare(Doku_Event &$event, $param) { dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS START ----'); dbglog($this->helper->_get_included_pages_from_meta_instructions($depends['instructions'])); dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS END ----'); - } } else { // add plugin.info.txt to depends for nicer upgrades @@ -261,7 +270,8 @@ function _cache_prepare(Doku_Event &$event, $param) { * and replace normal section edit buttons when the current page is different from the * global $ID. */ - function handle_secedit_button(Doku_Event &$event, $params) { + function handle_secedit_button(Doku_Event &$event, $params) + { // stack of included pages in the form ('id' => page, 'rev' => modification time, 'writable' => bool) static $page_stack = array(); @@ -290,14 +300,18 @@ function handle_secedit_button(Doku_Event &$event, $params) { $params['hid'] = $data['hid']; } $event->result = '
' . DOKU_LF . - html_btn('incledit', $page_stack[0]['id'], '', - $params, 'post', + html_btn( + 'incledit', + $page_stack[0]['id'], + '', + $params, + 'post', $data['name'], - $lang['btn_secedit'].' ('.$page_stack[0]['id'].')') . + $lang['btn_secedit'] . ' (' . $page_stack[0]['id'] . ')' + ) . '
' . DOKU_LF; } } elseif (!empty($page_stack)) { - // Special handling for the edittable plugin if ($data['target'] == 'table' && !plugin_isdisabled('edittable')) { /* @var action_plugin_edittable_editor $edittable */ @@ -319,11 +333,16 @@ function handle_secedit_button(Doku_Event &$event, $params) { $event->result = "
" . - html_btn('secedit', $page_stack[0]['id'], '', + html_btn( + 'secedit', + $page_stack[0]['id'], + '', array_merge(array('do' => 'edit', 'rev' => $page_stack[0]['rev'], - 'summary' => '['.$name.'] '), $data), - 'post', $name) . '
'; + 'summary' => '[' . $name . '] '), $data), + 'post', + $name + ) . ''; } else { $event->result = ''; } @@ -335,11 +354,13 @@ function handle_secedit_button(Doku_Event &$event, $params) { $event->stopPropagation(); } - public function handle_move_register(Doku_Event $event, $params) { + public function handle_move_register(Doku_Event $event, $params) + { $event->data['handlers']['include_include'] = array($this, 'rewrite_include'); } - public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_move_handler $handler) { + public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_move_handler $handler) + { $syntax = substr($match, 2, -2); // strip markup $replacers = explode('|', $syntax); $syntax = array_shift($replacers); @@ -358,10 +379,10 @@ public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_mov if ($newpage == $page) { return $match; } else { - $result = '{{'.$mode.'>'.$newpage; - if ($sect) $result .= '#'.$sect; - if ($flags) $result .= '&'.$flags; - if ($replacers) $result .= '|'.$replacers; + $result = '{{' . $mode . '>' . $newpage; + if ($sect) $result .= '#' . $sect; + if ($flags) $result .= '&' . $flags; + if ($replacers) $result .= '|' . $replacers; $result .= '}}'; return $result; } diff --git a/conf/default.php b/conf/default.php index c619005..734ed03 100644 --- a/conf/default.php +++ b/conf/default.php @@ -1,7 +1,9 @@ */ + $meta['noheader'] = array('onoff'); $meta['firstseconly'] = array('onoff'); $meta['showtaglogos'] = array('onoff'); diff --git a/helper.php b/helper.php index 9dca93b..6471bf9 100644 --- a/helper.php +++ b/helper.php @@ -1,4 +1,5 @@ @@ -6,13 +7,16 @@ * @author Gina Häußge, Michael Klier * @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. */ -class helper_plugin_include extends DokuWiki_Plugin { // DokuWiki_Helper_Plugin +class helper_plugin_include extends DokuWiki_Plugin +{ + // DokuWiki_Helper_Plugin var $defaults = array(); var $sec_close = true; @@ -23,7 +27,8 @@ class helper_plugin_include extends DokuWiki_Plugin { // DokuWiki_Helper_Plugin /** * Constructor loads default config settings once */ - function __construct() { + function __construct() + { $this->defaults['noheader'] = $this->getConf('noheader'); $this->defaults['firstsec'] = $this->getConf('firstseconly'); $this->defaults['editbtn'] = $this->getConf('showeditbtn'); @@ -53,7 +58,8 @@ function __construct() { /** * Available methods for other plugins */ - function getMethods() { + function getMethods() + { $result = array(); $result[] = array( 'name' => 'get_flags', @@ -66,7 +72,8 @@ function getMethods() { /** * Overrides standard values for showfooter and firstseconly settings */ - function get_flags($setflags) { + function get_flags($setflags) + { // load defaults $flags = $this->defaults; foreach ($setflags as $flag) { @@ -236,7 +243,8 @@ function get_flags($setflags) { * @author Michael Klier * @author Michael Hamann */ - function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) { + function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) + { $key = ($sect) ? $page . '#' . $sect : $page; $this->includes[$key] = true; // legacy code for keeping compatibility with other plugins @@ -251,16 +259,16 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $ $title = ''; if ($flags['title']) $title = p_get_first_heading($page); - if($flags['parlink']) { + if ($flags['parlink']) { $ins = array( array('p_open', array()), - array('internallink', array(':'.$key, $title)), + array('internallink', array(':' . $key, $title)), array('p_close', array()), ); } else { - $ins = array(array('internallink', array(':'.$key,$title))); + $ins = array(array('internallink', array(':' . $key,$title))); } - }else { + } else { $ins = array(); } } else { @@ -292,15 +300,16 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $ * * @author Michael Klier */ - function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = array()) { + function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = array()) + { global $conf; // filter instructions if needed - if(!empty($sect)) { + if (!empty($sect)) { $this->_get_section($ins, $sect); // section required } - if($flags['firstsec']) { + if ($flags['firstsec']) { $this->_get_firstsec($ins, $page, $flags); // only first section } @@ -315,8 +324,8 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $this->adapt_links($ins, $page, $included_pages); - for($i=0; $i<$num; $i++) { - switch($ins[$i][0]) { + for ($i = 0; $i < $num; $i++) { + switch ($ins[$i][0]) { case 'document_start': case 'document_end': case 'section_edit': @@ -324,27 +333,26 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc break; case 'header': // get section title of first section - if($sect && !$sect_title) { + if ($sect && !$sect_title) { $sect_title = $ins[$i][1][0]; } // check if we need to skip the first header - if((!$no_header) && $flags['noheader']) { + if ((!$no_header) && $flags['noheader']) { $no_header = true; } $conv_idx[] = $i; // get index of first header - if($first_header == -1) $first_header = $i; + if ($first_header == -1) $first_header = $i; // get max level of this instructions set - if(!$lvl_max || ($ins[$i][1][1] < $lvl_max)) { + if (!$lvl_max || ($ins[$i][1][1] < $lvl_max)) { $lvl_max = $ins[$i][1][1]; } break; case 'section_open': if ($flags['inline']) unset($ins[$i]); - else - $conv_idx[] = $i; + else $conv_idx[] = $i; break; case 'section_close': if ($flags['inline']) @@ -355,7 +363,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc break; case 'plugin': // FIXME skip other plugins? - switch($ins[$i][1][0]) { + switch ($ins[$i][1][0]) { case 'tag_tag': // skip tags case 'discussion_comments': // skip comments case 'linkback': // skip linkbacks @@ -399,37 +407,37 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc $footer_lvl = false; $contains_secedit = false; $section_close_at = false; - foreach($conv_idx as $idx) { - if($ins[$idx][0] == 'header') { - if ($section_close_at === false && isset($ins[$idx+1]) && $ins[$idx+1][0] == 'section_open') { + foreach ($conv_idx as $idx) { + if ($ins[$idx][0] == 'header') { + if ($section_close_at === false && isset($ins[$idx + 1]) && $ins[$idx + 1][0] == 'section_open') { // store the index of the first heading that is followed by a new section // the wrap plugin creates sections without section_open so the section shouldn't be closed before them $section_close_at = $idx; } - if($no_header && !$hdr_deleted) { - unset ($ins[$idx]); + if ($no_header && !$hdr_deleted) { + unset($ins[$idx]); $hdr_deleted = true; continue; } - if($flags['indent']) { + if ($flags['indent']) { $lvl_new = (($ins[$idx][1][1] + $diff) > 5) ? 5 : ($ins[$idx][1][1] + $diff); $ins[$idx][1][1] = $lvl_new; } - if($ins[$idx][1][1] <= $conf['maxseclevel']) + if ($ins[$idx][1][1] <= $conf['maxseclevel']) $contains_secedit = true; // set permalink - if($flags['link'] && !$has_permalink && ($idx == $first_header)) { + if ($flags['link'] && !$has_permalink && ($idx == $first_header)) { $this->_permalink($ins[$idx], $page, $sect, $flags); $has_permalink = true; } // set footer level - if(!$footer_lvl && ($idx == $first_header) && !$no_header) { - if($flags['indent'] && isset($lvl_new)) { + if (!$footer_lvl && ($idx == $first_header) && !$no_header) { + if ($flags['indent'] && isset($lvl_new)) { $footer_lvl = $lvl_new; } else { $footer_lvl = $lvl_max; @@ -437,14 +445,14 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc } } else { // it's a section - if($flags['indent']) { + if ($flags['indent']) { $lvl_new = (($ins[$idx][1][0] + $diff) > 5) ? 5 : ($ins[$idx][1][0] + $diff); $ins[$idx][1][0] = $lvl_new; } // check if noheader is used and set the footer level to the first section - if($no_header && !$footer_lvl) { - if($flags['indent'] && isset($lvl_new)) { + if ($no_header && !$footer_lvl) { + if ($flags['indent'] && isset($lvl_new)) { $footer_lvl = $lvl_new; } else { $footer_lvl = $lvl_max; @@ -458,15 +466,15 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc array_push($ins, array('plugin', array('include_closelastsecedit', array($endpos)))); } - $include_secid = (isset($flags['include_secid']) ? $flags['include_secid'] : NULL); + $include_secid = (isset($flags['include_secid']) ? $flags['include_secid'] : null); // add edit button - if($flags['editbtn']) { + if ($flags['editbtn']) { $this->_editbtn($ins, $page, $sect, $sect_title, ($flags['redirect'] ? $root_id : false), $include_secid); } // add footer - if($flags['footer']) { + if ($flags['footer']) { $ins[] = $this->_footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id); } @@ -495,7 +503,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc array_push($ins, array('entity', array($flags['aftereach']))); // close previous section if any and re-open after inclusion - if($lvl != 0 && $this->sec_close && !$flags['inline']) { + if ($lvl != 0 && $this->sec_close && !$flags['inline']) { array_unshift($ins, array('section_close', array())); $ins[] = array('section_open', array($lvl)); } @@ -506,7 +514,8 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc * * @author Michael Klier */ - function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) { + function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) + { $footer = array(); $footer[0] = 'plugin'; $footer[1] = array('include_footer', array($page, $sect, $sect_title, $flags, $root_id, $footer_lvl)); @@ -518,7 +527,8 @@ function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) { * * @author Michael Klier */ - function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '') { + function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '') + { $title = ($sect) ? $sect_title : $page; $editbtn = array(); $editbtn[0] = 'plugin'; @@ -531,7 +541,8 @@ function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '') { * * @author Michael Klier */ - function _permalink(&$ins, $page, $sect, $flags) { + function _permalink(&$ins, $page, $sect, $flags) + { $ins[0] = 'plugin'; $ins[1] = array('include_header', array($ins[1][0], $ins[1][1], $ins[1][2], $page, $sect, $flags)); } @@ -543,19 +554,20 @@ function _permalink(&$ins, $page, $sect, $flags) { * @param string $page The included page * @param array $included_pages The array of pages that are included */ - private function adapt_links(&$ins, $page, $included_pages = null) { + private function adapt_links(&$ins, $page, $included_pages = null) + { $num = count($ins); - for($i=0; $i<$num; $i++) { + 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 = (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; + if ($media_id[0] != ':') $media_id = ':' . $media_id; $ins[$i][1][1]['src'] = $media_id; } - switch($ins[$i][0]) { + switch ($ins[$i][0]) { case 'internallink': case 'internalmedia': // make sure parameters aren't touched @@ -569,9 +581,9 @@ private function adapt_links(&$ins, $page, $included_pages = null) { // resolve the id without cleaning it $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; + if ($link_id[0] != ':') $link_id = ':' . $link_id; // restore parameters - $ins[$i][1][0] = ($link_params != '') ? $link_id.'?'.$link_params : $link_id; + $ins[$i][1][0] = ($link_params != '') ? $link_id . '?' . $link_params : $link_id; if ($ins[$i][0] == 'internallink' && !empty($included_pages)) { // change links to included pages into local links @@ -605,7 +617,7 @@ private function adapt_links(&$ins, $page, $included_pages = null) { /* Convert local links to internal links if the page hasn't been fully included */ if ($included_pages == null || !array_key_exists($page, $included_pages)) { $ins[$i][0] = 'internallink'; - $ins[$i][1][0] = ':'.$page.'#'.$ins[$i][1][0]; + $ins[$i][1][0] = ':' . $page . '#' . $ins[$i][1][0]; } break; } @@ -617,7 +629,8 @@ private function adapt_links(&$ins, $page, $included_pages = null) { * * @author Michael Klier */ - function _get_section(&$ins, $sect) { + function _get_section(&$ins, $sect) + { $num = count($ins); $offset = false; $lvl = false; @@ -626,9 +639,8 @@ function _get_section(&$ins, $sect) { $check = array(); // used for sectionID() in order to get the same ids as the xhtml renderer - for($i=0; $i<$num; $i++) { + for ($i = 0; $i < $num; $i++) { if ($ins[$i][0] == 'header') { - // found the right header if (sectionID($ins[$i][1][0], $check) == $sect) { $offset = $i; @@ -642,7 +654,7 @@ function _get_section(&$ins, $sect) { } $offset = $offset ? $offset : 0; $end = $end ? $end : ($num - 1); - if(is_array($ins)) { + if (is_array($ins)) { $ins = array_slice($ins, $offset, $end); // store the end position in the include_closelastsecedit instruction so it can generate a matching button $ins[] = array('plugin', array('include_closelastsecedit', array($endpos))); @@ -654,12 +666,13 @@ function _get_section(&$ins, $sect) { * * @author Michael Klier */ - function _get_firstsec(&$ins, $page, $flags) { + function _get_firstsec(&$ins, $page, $flags) + { $num = count($ins); $first_sect = false; $endpos = null; // end position in the input text - for($i=0; $i<$num; $i++) { - if($ins[$i][0] == 'section_close') { + for ($i = 0; $i < $num; $i++) { + if ($ins[$i][0] == 'section_close') { $first_sect = $i; } if ($ins[$i][0] == 'header') { @@ -673,7 +686,7 @@ function _get_firstsec(&$ins, $page, $flags) { } // only truncate the content and add the read more link when there is really // more than that first section - if(($first_sect) && ($ins[$i][0] == 'section_open')) { + if (($first_sect) && ($ins[$i][0] == 'section_open')) { $ins = array_slice($ins, 0, $first_sect); if ($flags['readmore']) { $ins[] = array('plugin', array('include_readmore', array($page))); @@ -691,50 +704,51 @@ function _get_firstsec(&$ins, $page, $flags) { * * @author Michael Hamann */ - function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { + function _get_included_pages($mode, $page, $sect, $parent_id, $flags) + { global $conf; $pages = array(); - switch($mode) { - case 'namespace': - $page = cleanID($page); - $ns = utf8_encodeFN(str_replace(':', '/', $page)); - // depth is absolute depth, not relative depth, but 0 has a special meaning. - $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0; - search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth, 'skipacl' => false), $ns); - if (is_array($pagearrays)) { - foreach ($pagearrays as $pagearray) { - if (!isHiddenPage($pagearray['id'])) // skip hidden pages + switch ($mode) { + case 'namespace': + $page = cleanID($page); + $ns = utf8_encodeFN(str_replace(':', '/', $page)); + // depth is absolute depth, not relative depth, but 0 has a special meaning. + $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0; + search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth, 'skipacl' => false), $ns); + if (is_array($pagearrays)) { + foreach ($pagearrays as $pagearray) { + if (!isHiddenPage($pagearray['id'])) // skip hidden pages $pages[] = $pagearray['id']; + } } - } - break; - case 'tagtopic': - if (!$this->taghelper) + break; + case 'tagtopic': + if (!$this->taghelper) $this->taghelper = plugin_load('helper', 'tag'); - if(!$this->taghelper) { - msg('You have to install the tag plugin to use this functionality!', -1); - return array(); - } - $tag = $page; - $sect = ''; - $pagearrays = $this->taghelper->getTopic('', null, $tag); - foreach ($pagearrays as $pagearray) { - $pages[] = $pagearray['id']; - } - break; - default: - $page = $this->_apply_macro($page, $parent_id); - // resolve shortcuts and clean ID - $page = (new PageResolver($parent_id))->resolveId($page); - if (auth_quickaclcheck($page) >= AUTH_READ) + if (!$this->taghelper) { + msg('You have to install the tag plugin to use this functionality!', -1); + return array(); + } + $tag = $page; + $sect = ''; + $pagearrays = $this->taghelper->getTopic('', null, $tag); + foreach ($pagearrays as $pagearray) { + $pages[] = $pagearray['id']; + } + break; + default: + $page = $this->_apply_macro($page, $parent_id); + // resolve shortcuts and clean ID + $page = (new PageResolver($parent_id))->resolveId($page); + if (auth_quickaclcheck($page) >= AUTH_READ) $pages[] = $page; } if (isset($flags['exclude'])) $pages = array_filter($pages, function ($page) use ($flags) { if (@preg_match($flags['exclude'], $page)) - return FALSE; - return TRUE; + return false; + return true; }); if (count($pages) > 1) { @@ -769,7 +783,7 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { $key = ''; break; } - $key .= '_'.$page; + $key .= '_' . $page; $ordered_pages[$key] = $page; } if ($flags['rsort']) { @@ -800,7 +814,8 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) { * 0 if str1 is lesser than * str2, and 0 if they are equal. */ - function _r_strnatcasecmp($a, $b) { + function _r_strnatcasecmp($a, $b) + { return strnatcasecmp($b, $a); } @@ -808,7 +823,8 @@ function _r_strnatcasecmp($a, $b) { * This function generates the list of all included pages from a list of metadata * instructions. */ - function _get_included_pages_from_meta_instructions($instructions) { + function _get_included_pages_from_meta_instructions($instructions) + { $pages = array(); foreach ($instructions as $instruction) { $mode = $instruction['mode']; @@ -825,39 +841,45 @@ function _get_included_pages_from_meta_instructions($instructions) { * Get wiki language from "HTTP_ACCEPT_LANGUAGE" * We allow the pattern e.g. "ja,en-US;q=0.7,en;q=0.3" */ - function _get_language_of_wiki($id, $parent_id) { - global $conf; - $result = $conf['lang']; - if(strpos($id, '@BROWSER_LANG@') !== false){ - $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\*)(;q=(0(.[0-9]{0,3})?|1(.0{0,3})?))?/"; - if(preg_match_all( - $brlangp, $_SERVER["HTTP_ACCEPT_LANGUAGE"], - $matches, PREG_SET_ORDER - )){ - $langs = array(); - foreach($matches as $match){ - $langname = $match[1] == '*' ? $conf['lang'] : $match[1]; - $qvalue = $match[4] == '' ? 1.0 : $match[4]; - $langs[$langname] = $qvalue; - } - arsort($langs); - foreach($langs as $lang => $langq){ - $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id); - $testpage = (new PageResolver($parent_id))->resolveId($testpage); - if (page_exists($testpage)) { - $result = $lang; - break; - } - } - } - } - return cleanID($result); + function _get_language_of_wiki($id, $parent_id) + { + global $conf; + $result = $conf['lang']; + if (strpos($id, '@BROWSER_LANG@') !== false) { + $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\*)(;q=(0(.[0-9]{0,3})?|1(.0{0,3})?))?/"; + if ( + preg_match_all( + $brlangp, + $_SERVER["HTTP_ACCEPT_LANGUAGE"], + $matches, + PREG_SET_ORDER + ) + ) { + $langs = array(); + foreach ($matches as $match) { + $langname = $match[1] == '*' ? $conf['lang'] : $match[1]; + $qvalue = $match[4] == '' ? 1.0 : $match[4]; + $langs[$langname] = $qvalue; + } + arsort($langs); + foreach ($langs as $lang => $langq) { + $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id); + $testpage = (new PageResolver($parent_id))->resolveId($testpage); + if (page_exists($testpage)) { + $result = $lang; + break; + } + } + } + } + return cleanID($result); } /** * Makes user or date dependent includes possible */ - function _apply_macro($id, $parent_id) { + function _apply_macro($id, $parent_id) + { global $USERINFO; /* @var Input $INPUT */ global $INPUT; @@ -865,7 +887,7 @@ function _apply_macro($id, $parent_id) { // The following is basicaly copied from basicinfo() because // this function can be called from within pageinfo() in // p_get_metadata and thus we cannot rely on $INFO being set - if($INPUT->server->has('REMOTE_USER')) { + if ($INPUT->server->has('REMOTE_USER')) { $user = $INPUT->server->str('REMOTE_USER'); } else { // no registered user - use IP @@ -887,34 +909,34 @@ function _apply_macro($id, $parent_id) { } $time_stamp = time(); - if(preg_match('/@DATE(\w+)@/',$id,$matches)) { - switch($matches[1]) { - case 'PMONTH': - $time_stamp = strtotime("-1 month"); - break; - case 'NMONTH': - $time_stamp = strtotime("+1 month"); - break; - case 'NWEEK': - $time_stamp = strtotime("+1 week"); - break; - case 'PWEEK': - $time_stamp = strtotime("-1 week"); - break; - case 'TOMORROW': - $time_stamp = strtotime("+1 day"); - break; - case 'YESTERDAY': - $time_stamp = strtotime("-1 day"); - break; - case 'NYEAR': - $time_stamp = strtotime("+1 year"); - break; - case 'PYEAR': - $time_stamp = strtotime("-1 year"); - break; + if (preg_match('/@DATE(\w+)@/', $id, $matches)) { + switch ($matches[1]) { + case 'PMONTH': + $time_stamp = strtotime("-1 month"); + break; + case 'NMONTH': + $time_stamp = strtotime("+1 month"); + break; + case 'NWEEK': + $time_stamp = strtotime("+1 week"); + break; + case 'PWEEK': + $time_stamp = strtotime("-1 week"); + break; + case 'TOMORROW': + $time_stamp = strtotime("+1 day"); + break; + case 'YESTERDAY': + $time_stamp = strtotime("-1 day"); + break; + case 'NYEAR': + $time_stamp = strtotime("+1 year"); + break; + case 'PYEAR': + $time_stamp = strtotime("-1 year"); + break; } - $id = preg_replace('/@DATE(\w+)@/','', $id); + $id = preg_replace('/@DATE(\w+)@/', '', $id); } $replace = array( @@ -922,18 +944,18 @@ function _apply_macro($id, $parent_id) { '@NAME@' => cleanID($name), '@GROUP@' => cleanID($group), '@BROWSER_LANG@' => $this->_get_language_of_wiki($id, $parent_id), - '@YEAR@' => date('Y',$time_stamp), - '@MONTH@' => date('m',$time_stamp), - '@WEEK@' => date('W',$time_stamp), - '@DAY@' => date('d',$time_stamp), - '@YEARPMONTH@' => date('Ym',strtotime("-1 month")), - '@PMONTH@' => date('m',strtotime("-1 month")), - '@NMONTH@' => date('m',strtotime("+1 month")), - '@YEARNMONTH@' => date('Ym',strtotime("+1 month")), - '@YEARPWEEK@' => date('YW',strtotime("-1 week")), - '@PWEEK@' => date('W',strtotime("-1 week")), - '@NWEEK@' => date('W',strtotime("+1 week")), - '@YEARNWEEK@' => date('YW',strtotime("+1 week")), + '@YEAR@' => date('Y', $time_stamp), + '@MONTH@' => date('m', $time_stamp), + '@WEEK@' => date('W', $time_stamp), + '@DAY@' => date('d', $time_stamp), + '@YEARPMONTH@' => date('Ym', strtotime("-1 month")), + '@PMONTH@' => date('m', strtotime("-1 month")), + '@NMONTH@' => date('m', strtotime("+1 month")), + '@YEARNMONTH@' => date('Ym', strtotime("+1 month")), + '@YEARPWEEK@' => date('YW', strtotime("-1 week")), + '@PWEEK@' => date('W', strtotime("-1 week")), + '@NWEEK@' => date('W', strtotime("+1 week")), + '@YEARNWEEK@' => date('YW', strtotime("+1 week")), ); return str_replace(array_keys($replace), array_values($replace), $id); } diff --git a/syntax/closelastsecedit.php b/syntax/closelastsecedit.php index a5741c8..9064559 100644 --- a/syntax/closelastsecedit.php +++ b/syntax/closelastsecedit.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_closelastsecedit extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_closelastsecedit extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - function getSort() { + function getSort() + { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } /** * Finishes the last open section edit */ - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { if ($mode == 'xhtml') { /** @var Doku_Renderer_xhtml $renderer */ list($endpos) = $data; diff --git a/syntax/editbtn.php b/syntax/editbtn.php index 4d9367f..1c38e59 100644 --- a/syntax/editbtn.php +++ b/syntax/editbtn.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_editbtn extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_editbtn extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - - function getSort() { + + function getSort() + { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -25,7 +29,8 @@ function handle($match, $state, $pos, Doku_Handler $handler) { * * @author Michael Klier */ - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { list($title, $hid) = $data; if ($mode == 'xhtml') { if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions diff --git a/syntax/footer.php b/syntax/footer.php index 523d005..7664432 100644 --- a/syntax/footer.php +++ b/syntax/footer.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - function getSort() { + function getSort() + { return 300; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -26,13 +30,14 @@ function handle($match, $state, $pos, Doku_Handler $handler) { * Code heavily copied from the header renderer from inc/parser/xhtml.php, just * added an href parameter to the anchor tag linking to the wikilink. */ - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data; if ($mode == 'xhtml') { $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer); - return true; + return true; } return false; } @@ -42,10 +47,11 @@ function render($mode, Doku_Renderer $renderer, $data) { * @param $renderer Doku_Renderer_xhtml The (xhtml) renderer * @return string The HTML code of the footer */ - function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) { + function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) + { global $conf, $ID; - if(!$flags['footer']) return ''; + if (!$flags['footer']) return ''; $meta = p_get_metadata($page); $exists = page_exists($page); @@ -72,7 +78,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) if ($flags['date'] && $exists) { $date = $meta['date']['created']; if ($date) { - $xhtml[] = '' + $xhtml[] = '' . dformat($date) . ''; } @@ -82,7 +88,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) if ($flags['mdate'] && $exists) { $mdate = $meta['date']['modified']; if ($mdate) { - $xhtml[] = '' + $xhtml[] = '' . dformat($mdate) . ''; } @@ -117,7 +123,7 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) // tags - let Tag Plugin do the work for us if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag = plugin_load('helper', 'tag'))) { $tags = $tag->td($page); - if($tags) { + if ($tags) { $xhtml .= '
' . DOKU_LF . DOKU_TAB . $tags . DOKU_LF . DOKU_TAB . '
' . DOKU_LF; diff --git a/syntax/header.php b/syntax/header.php index 3f14dcb..fd81571 100644 --- a/syntax/header.php +++ b/syntax/header.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_header extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_header extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - - function getSort() { + + function getSort() + { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } /** * Renders a permalink header. - * + * * Code heavily copied from the header renderer from inc/parser/xhtml.php, just * added an href parameter to the anchor tag linking to the wikilink. */ - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { global $conf; list($headline, $lvl, $pos, $page, $sect, $flags) = $data; @@ -39,11 +44,11 @@ function render($mode, Doku_Renderer $renderer, $data) { $hid = $renderer->_headerToLink($headline, true); $renderer->toc_additem($hid, $headline, $lvl); $url = ($sect) ? wl($page) . '#' . $sect : wl($page); - $renderer->doc .= DOKU_LF.'doc .= DOKU_LF . '_get_firsttag($page); - if($tag) { + if ($tag) { $classes[] = 'include_firsttag__' . $tag; } } @@ -57,10 +62,10 @@ function render($mode, Doku_Renderer $renderer, $data) { } } if ($classes) { - $renderer->doc .= ' class="'. implode(' ', $classes) . '"'; + $renderer->doc .= ' class="' . implode(' ', $classes) . '"'; } $headline = $renderer->_xmlEntities($headline); - $renderer->doc .= ' id="'.$hid.'">'; + $renderer->doc .= ' id="' . $hid . '">'; $renderer->doc .= $headline; $renderer->doc .= '' . DOKU_LF; return true; @@ -75,8 +80,9 @@ function render($mode, Doku_Renderer $renderer, $data) { * * @author Michael Klier */ - function _get_firsttag($page) { - if(plugin_isdisabled('tag') || (!plugin_load('helper', 'tag'))) { + function _get_firsttag($page) + { + if (plugin_isdisabled('tag') || (!plugin_load('helper', 'tag'))) { return false; } $subject = p_get_metadata($page, 'subject'); @@ -85,7 +91,7 @@ function _get_firsttag($page) { } else { list($tag, $rest) = explode(' ', $subject, 2); } - if($tag) { + if ($tag) { return $tag; } else { return false; diff --git a/syntax/include.php b/syntax/include.php index 44b803a..cd97d46 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -1,4 +1,5 @@ Lexer->addSpecialPattern("{{page>.+?}}", $mode, 'plugin_include_include'); $this->Lexer->addSpecialPattern("{{section>.+?}}", $mode, 'plugin_include_include'); $this->Lexer->addSpecialPattern("{{namespace>.+?}}", $mode, 'plugin_include_include'); @@ -65,7 +76,8 @@ function connectTo($mode) { * @param Doku_Handler $handler The hanlder object * @return array The instructions of the plugin */ - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { $match = substr($match, 2, -2); // strip markup list($match, $flags) = array_pad(explode('&', $match, 2), 2, ''); @@ -74,7 +86,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { list($mode, $page, $sect) = array_pad(preg_split('/>|#/u', $match, 3), 3, null); $check = false; if (isset($sect)) $sect = sectionID($sect, $check); - $level = NULL; + $level = null; return array($mode, $page, $sect, explode('&', $flags), $level, $pos); } @@ -83,7 +95,8 @@ function handle($match, $state, $pos, Doku_Handler $handler) { * * @author Michael Hamann */ - function render($format, Doku_Renderer $renderer, $data) { + function render($format, Doku_Renderer $renderer, $data) + { global $ID; // static stack that records all ancestors of the child pages @@ -92,7 +105,7 @@ function render($format, Doku_Renderer $renderer, $data) { // when there is no id just assume the global $ID is the current id if (empty($page_stack)) $page_stack[] = $ID; - $parent_id = $page_stack[count($page_stack)-1]; + $parent_id = $page_stack[count($page_stack) - 1]; $root_id = $page_stack[0]; list($mode, $page, $sect, $flags, $level, $pos) = $data; @@ -137,7 +150,7 @@ function render($format, Doku_Renderer $renderer, $data) { $renderer->meta['relation']['references'][$id] = $exists; $renderer->meta['relation']['haspart'][$id] = $exists; if (!$sect && !$flags['firstsec'] && !$flags['linkonly'] && !isset($renderer->meta['plugin_include']['secids'][$id])) { - $renderer->meta['plugin_include']['secids'][$id] = array('hid' => 'plugin_include__'.str_replace(':', '__', $id), 'pos' => $pos); + $renderer->meta['plugin_include']['secids'][$id] = array('hid' => 'plugin_include__' . str_replace(':', '__', $id), 'pos' => $pos); } } diff --git a/syntax/locallink.php b/syntax/locallink.php index 2a6a612..1c55476 100644 --- a/syntax/locallink.php +++ b/syntax/locallink.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_locallink extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_locallink extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - function getSort() { + function getSort() + { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -25,7 +29,8 @@ function handle($match, $state, $pos, Doku_Handler $handler) { * * @author Michael Hamann */ - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { global $ID; if ($mode == 'xhtml') { /** @var Doku_Renderer_xhtml $renderer */ @@ -33,8 +38,8 @@ function render($mode, Doku_Renderer $renderer, $data) { // construct title in the same way it would be done for internal links $default = $renderer->_simpleTitle($id); $name = $renderer->_getLinkTitle($name, $default, $isImage, $id); - $title = $ID.' ↵'; - $renderer->doc .= ''; + $title = $ID . ' ↵'; + $renderer->doc .= ''; $renderer->doc .= $name; $renderer->doc .= ''; return true; diff --git a/syntax/readmore.php b/syntax/readmore.php index 689e11d..049ce8f 100644 --- a/syntax/readmore.php +++ b/syntax/readmore.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_readmore extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_readmore extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - function getSort() { + function getSort() + { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { list($page) = $data; if ($mode == 'xhtml') { - $renderer->doc .= DOKU_LF.'

'.DOKU_LF; + $renderer->doc .= DOKU_LF . '

' . DOKU_LF; } else { $renderer->p_open(); } @@ -32,7 +37,7 @@ function render($mode, Doku_Renderer $renderer, $data) { $renderer->internallink($page, $this->getLang('readmore')); if ($mode == 'xhtml') { - $renderer->doc .= DOKU_LF.'

'.DOKU_LF; + $renderer->doc .= DOKU_LF . '

' . DOKU_LF; } else { $renderer->p_close(); } diff --git a/syntax/sorttag.php b/syntax/sorttag.php index c7704ba..ca1cae6 100644 --- a/syntax/sorttag.php +++ b/syntax/sorttag.php @@ -8,12 +8,13 @@ * @author Michael Hamann * */ -class syntax_plugin_include_sorttag extends DokuWiki_Syntax_Plugin { - +class syntax_plugin_include_sorttag extends DokuWiki_Syntax_Plugin +{ /** * What kind of syntax are we? */ - public function getType(){ + public function getType() + { return 'substition'; } @@ -22,36 +23,41 @@ public function getType(){ * * @return string The paragraph type */ - public function getPType() { + public function getPType() + { return 'block'; } /** * Where to sort in? */ - public function getSort(){ + public function getSort() + { return 139; } /** * Connect pattern to lexer */ - public function connectTo($mode) { - $this->Lexer->addSpecialPattern('{{include_n>.+?}}',$mode,'plugin_include_sorttag'); + public function connectTo($mode) + { + $this->Lexer->addSpecialPattern('{{include_n>.+?}}', $mode, 'plugin_include_sorttag'); } /** * Handle the match */ - public function handle($match, $state, $pos, Doku_Handler $handler){ - $match = substr($match,12,-2); + public function handle($match, $state, $pos, Doku_Handler $handler) + { + $match = substr($match, 12, -2); return array($match); } /** * Render output */ - public function render($mode, Doku_Renderer $renderer, $data) { + public function render($mode, Doku_Renderer $renderer, $data) + { if ($mode === 'metadata') { /** @var Doku_Renderer_metadata $renderer */ $renderer->meta['include_n'] = $data[0]; diff --git a/syntax/wrap.php b/syntax/wrap.php index 1cb630c..a960e38 100644 --- a/syntax/wrap.php +++ b/syntax/wrap.php @@ -1,4 +1,5 @@ */ -class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin { - - function getType() { +class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin +{ + function getType() + { return 'formatting'; } - function getSort() { + function getSort() + { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -28,10 +32,11 @@ function handle($match, $state, $pos, Doku_Handler $handler) { * @author Michael Klier * @author Michael Hamann */ - function render($mode, Doku_Renderer $renderer, $data) { + function render($mode, Doku_Renderer $renderer, $data) + { if ($mode == 'xhtml') { $state = array_shift($data); - switch($state) { + switch ($state) { case 'open': list($page, $redirect, $secid) = $data; if ($redirect) { @@ -55,14 +60,14 @@ function render($mode, Doku_Renderer $renderer, $data) { } else { $renderer->startSectionEdit(0, 'plugin_include_end', $page); } - if ($secid === NULL) { + if ($secid === null) { $id = ''; } else { - $id = ' id="'.$secid.'"'; + $id = ' id="' . $secid . '"'; } - $renderer->doc .= '
' . DOKU_LF; - if (is_a($renderer,'renderer_plugin_dw2pdf')) { - $renderer->doc .= ''; + $renderer->doc .= '
' . DOKU_LF; + if (is_a($renderer, 'renderer_plugin_dw2pdf')) { + $renderer->doc .= ''; } break; case 'close': From 26ba47fc72793a13ea5db25080d211f510e2b9ee Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:05:59 +0200 Subject: [PATCH 02/18] cleanup for wrap syntax removed old compatibility checks (auto) reformatted the code used guardian pattern to reduce complexity removed unneeded line feeds --- syntax/wrap.php | 100 +++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/syntax/wrap.php b/syntax/wrap.php index a960e38..a9249e6 100644 --- a/syntax/wrap.php +++ b/syntax/wrap.php @@ -1,5 +1,7 @@ * @author Michael Hamann */ - -class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_wrap extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -29,55 +33,47 @@ function handle($match, $state, $pos, Doku_Handler $handler) * Wraps the included page in a div and writes section edits for the action component * so it can detect where an included page starts/ends. * - * @author Michael Klier - * @author Michael Hamann + * @inheritdoc */ - function render($mode, Doku_Renderer $renderer, $data) + public function render($mode, Doku_Renderer $renderer, $data) { - if ($mode == 'xhtml') { - $state = array_shift($data); - switch ($state) { - case 'open': - list($page, $redirect, $secid) = $data; - if ($redirect) { - if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions - $renderer->startSectionEdit(0, array('target' => 'plugin_include_start', 'name' => $page, 'hid' => '')); - } else { - $renderer->startSectionEdit(0, 'plugin_include_start', $page); - } - } else { - if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions - $renderer->startSectionEdit(0, array('target' => 'plugin_include_start_noredirect', 'name' => $page, 'hid' => '')); - } else { - $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $page); - } - } - $renderer->finishSectionEdit(); - // Start a new section with type != section so headers in the included page - // won't print section edit buttons of the parent page - if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions - $renderer->startSectionEdit(0, array('target' => 'plugin_include_end', 'name' => $page, 'hid' => '')); - } else { - $renderer->startSectionEdit(0, 'plugin_include_end', $page); - } - if ($secid === null) { - $id = ''; - } else { - $id = ' id="' . $secid . '"'; - } - $renderer->doc .= '' . DOKU_LF; - break; - } - return true; + if ($mode !== 'xhtml') return false; + + $state = array_shift($data); + switch ($state) { + case 'open': + [$page, $redirect, $secid] = $data; + if ($redirect) { + $renderer->startSectionEdit( + 0, + ['target' => 'plugin_include_start', 'name' => $page, 'hid' => ''] + ); + } else { + $renderer->startSectionEdit( + 0, + ['target' => 'plugin_include_start_noredirect', 'name' => $page, 'hid' => ''] + ); + } + $renderer->finishSectionEdit(); + // Start a new section with type != section so headers in the included page + // won't print section edit buttons of the parent page + $renderer->startSectionEdit(0, ['target' => 'plugin_include_end', 'name' => $page, 'hid' => '']); + if ($secid === null) { + $id = ''; + } else { + $id = ' id="' . $secid . '"'; + } + $renderer->doc .= ''; + break; } - return false; + + return true; } } -// vim:ts=4:sw=4:et: From 5cfa41d4dac77d1484ea01836fec151baa3145d8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:08:58 +0200 Subject: [PATCH 03/18] cleaned readmore syntax (auto) reformatted removed unneeded line feeds --- syntax/readmore.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/syntax/readmore.php b/syntax/readmore.php index 049ce8f..93c8514 100644 --- a/syntax/readmore.php +++ b/syntax/readmore.php @@ -1,35 +1,44 @@ */ - -class syntax_plugin_include_readmore extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_readmore extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } - function render($mode, Doku_Renderer $renderer, $data) + /** + * Renders the readmore link for the included page. + * + * @inheritdoc + */ + public function render($mode, Doku_Renderer $renderer, $data) { - list($page) = $data; + [$page] = $data; if ($mode == 'xhtml') { - $renderer->doc .= DOKU_LF . '

' . DOKU_LF; + $renderer->doc .= '

'; } else { $renderer->p_open(); } @@ -37,7 +46,7 @@ function render($mode, Doku_Renderer $renderer, $data) $renderer->internallink($page, $this->getLang('readmore')); if ($mode == 'xhtml') { - $renderer->doc .= DOKU_LF . '

' . DOKU_LF; + $renderer->doc .= '

'; } else { $renderer->p_close(); } @@ -45,4 +54,3 @@ function render($mode, Doku_Renderer $renderer, $data) return true; } } -// vim:ts=4:sw=4:et: From 901dd1a657cef56e979ded3b98ce311f405f26b9 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:12:18 +0200 Subject: [PATCH 04/18] cleaned up locallink syntax (auto) reformatted guardian pattern --- syntax/locallink.php | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/syntax/locallink.php b/syntax/locallink.php index 1c55476..507422d 100644 --- a/syntax/locallink.php +++ b/syntax/locallink.php @@ -1,25 +1,29 @@ */ - -class syntax_plugin_include_locallink extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_locallink extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -27,24 +31,22 @@ function handle($match, $state, $pos, Doku_Handler $handler) /** * Displays a local link to an included page * - * @author Michael Hamann + * @inheritdoc */ - function render($mode, Doku_Renderer $renderer, $data) + public function render($mode, Doku_Renderer $renderer, $data) { global $ID; - if ($mode == 'xhtml') { - /** @var Doku_Renderer_xhtml $renderer */ - list($hash, $name, $id) = $data; - // construct title in the same way it would be done for internal links - $default = $renderer->_simpleTitle($id); - $name = $renderer->_getLinkTitle($name, $default, $isImage, $id); - $title = $ID . ' ↵'; - $renderer->doc .= '
'; - $renderer->doc .= $name; - $renderer->doc .= ''; - return true; - } - return false; + if ($mode != 'xhtml') return false; + + /** @var Doku_Renderer_xhtml $renderer */ + [$hash, $name, $id] = $data; + // construct title in the same way it would be done for internal links + $default = $renderer->_simpleTitle($id); + $name = $renderer->_getLinkTitle($name, $default, $isImage, $id); + $title = $ID . ' ↵'; + $renderer->doc .= ''; + $renderer->doc .= $name; + $renderer->doc .= ''; + return true; } } -// vim:ts=4:sw=4:et: From 86eb5c069627aa42d3ce8c35038f7fceca0ae666 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:16:59 +0200 Subject: [PATCH 05/18] cleaned header syntax removed old compatibility checks (auto) reformatted droped line feeds --- syntax/header.php | 85 ++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/syntax/header.php b/syntax/header.php index fd81571..89fc4d0 100644 --- a/syntax/header.php +++ b/syntax/header.php @@ -1,5 +1,7 @@ * @author Michael Klier */ - -class syntax_plugin_include_header extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_header extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -32,47 +36,45 @@ function handle($match, $state, $pos, Doku_Handler $handler) * * Code heavily copied from the header renderer from inc/parser/xhtml.php, just * added an href parameter to the anchor tag linking to the wikilink. + * @inheritdoc */ - function render($mode, Doku_Renderer $renderer, $data) + public function render($mode, Doku_Renderer $renderer, $data) { global $conf; - list($headline, $lvl, $pos, $page, $sect, $flags) = $data; + [$headline, $lvl, $pos, $page, $sect, $flags] = $data; - if ($mode == 'xhtml') { - /** @var Doku_Renderer_xhtml $renderer */ - $hid = $renderer->_headerToLink($headline, true); - $renderer->toc_additem($hid, $headline, $lvl); - $url = ($sect) ? wl($page) . '#' . $sect : wl($page); - $renderer->doc .= DOKU_LF . '_get_firsttag($page); - if ($tag) { - $classes[] = 'include_firsttag__' . $tag; - } - } - // the include header instruction is always at the beginning of the first section edit inside the include - // wrap so there is no need to close a previous section edit. - if ($lvl <= $conf['maxseclevel']) { - if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions - $classes[] = $renderer->startSectionEdit($pos, array('target' => 'section', 'name' => $headline, 'hid' => $hid)); - } else { - $classes[] = $renderer->startSectionEdit($pos, 'section', $headline); - } - } - if ($classes) { - $renderer->doc .= ' class="' . implode(' ', $classes) . '"'; - } - $headline = $renderer->_xmlEntities($headline); - $renderer->doc .= ' id="' . $hid . '">'; - $renderer->doc .= $headline; - $renderer->doc .= '' . DOKU_LF; - return true; - } else { + if ($mode != 'xhtml') { + // just output a standard header for all non-xhtml modes $renderer->header($headline, $lvl, $pos); + return true; + } + + /** @var Doku_Renderer_xhtml $renderer */ + $hid = $renderer->_headerToLink($headline, true); + $renderer->toc_additem($hid, $headline, $lvl); + $url = ($sect) ? wl($page) . '#' . $sect : wl($page); + $renderer->doc .= 'getFirsttag($page); + if ($tag) { + $classes[] = 'include_firsttag__' . $tag; + } + } + // the include header instruction is always at the beginning of the first section edit inside the include + // wrap so there is no need to close a previous section edit. + if ($lvl <= $conf['maxseclevel']) { + $classes[] = $renderer->startSectionEdit($pos, ['target' => 'section', 'name' => $headline, 'hid' => $hid]); + } + if ($classes) { + $renderer->doc .= ' class="' . implode(' ', $classes) . '"'; } - return false; + $headline = $renderer->_xmlEntities($headline); + $renderer->doc .= ' id="' . $hid . '">'; + $renderer->doc .= $headline; + $renderer->doc .= ''; + return true; } /** @@ -80,7 +82,7 @@ function render($mode, Doku_Renderer $renderer, $data) * * @author Michael Klier */ - function _get_firsttag($page) + protected function getFirsttag($page) { if (plugin_isdisabled('tag') || (!plugin_load('helper', 'tag'))) { return false; @@ -89,7 +91,7 @@ function _get_firsttag($page) if (is_array($subject)) { $tag = $subject[0]; } else { - list($tag, $rest) = explode(' ', $subject, 2); + [$tag, $rest] = explode(' ', $subject, 2); } if ($tag) { return $tag; @@ -98,4 +100,3 @@ function _get_firsttag($page) } } } -// vim:ts=4:sw=4:et: From 2503385c81d6d8580b4ad3480dcbd0b2fc2f9346 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:19:43 +0200 Subject: [PATCH 06/18] cleaned edit button syntax guardian pattern dropped old compatibility (auto) reformatted --- syntax/editbtn.php | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/syntax/editbtn.php b/syntax/editbtn.php index 1c38e59..b441796 100644 --- a/syntax/editbtn.php +++ b/syntax/editbtn.php @@ -1,25 +1,29 @@ */ - -class syntax_plugin_include_editbtn extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_editbtn extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -27,22 +31,15 @@ function handle($match, $state, $pos, Doku_Handler $handler) /** * Renders an include edit button * - * @author Michael Klier + * @inheritdoc */ - function render($mode, Doku_Renderer $renderer, $data) + public function render($mode, Doku_Renderer $renderer, $data) { - list($title, $hid) = $data; - if ($mode == 'xhtml') { - if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions - $renderer->startSectionEdit(0, array('target' => 'plugin_include_editbtn', 'name' => $title, 'hid' => $hid)); - } else { - $renderer->startSectionEdit(0, 'plugin_include_editbtn', $title); - } + [$title, $hid] = $data; + if ($mode != 'xhtml') return false; - $renderer->finishSectionEdit(); - return true; - } - return false; + $renderer->startSectionEdit(0, ['target' => 'plugin_include_editbtn', 'name' => $title, 'hid' => $hid]); + $renderer->finishSectionEdit(); + return true; } } -// vim:ts=4:sw=4:et: From 1e26a1eed59bd668a7fd309e8cec88265d9b3d70 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:22:10 +0200 Subject: [PATCH 07/18] cleaned last section edit finish syntax (auto) reformatted guardian pattern --- syntax/closelastsecedit.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/syntax/closelastsecedit.php b/syntax/closelastsecedit.php index 9064559..c3fede4 100644 --- a/syntax/closelastsecedit.php +++ b/syntax/closelastsecedit.php @@ -1,41 +1,45 @@ */ - -class syntax_plugin_include_closelastsecedit extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_closelastsecedit extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 50; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } /** * Finishes the last open section edit + * + * @inheritdoc */ - function render($mode, Doku_Renderer $renderer, $data) + public function render($mode, Doku_Renderer $renderer, $data) { - if ($mode == 'xhtml') { - /** @var Doku_Renderer_xhtml $renderer */ - list($endpos) = $data; - $renderer->finishSectionEdit($endpos); - return true; - } - return false; + if ($mode != 'xhtml') return false; + + /** @var Doku_Renderer_xhtml $renderer */ + [$endpos] = $data; + $renderer->finishSectionEdit($endpos); + return true; } } -// vim:ts=4:sw=4:et: From 8eb341991cc618d2b675d5d546419927c9796dbc Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:28:35 +0200 Subject: [PATCH 08/18] cleaned up footer syntax removed old compability (auto) reformatting guardian --- syntax/footer.php | 100 +++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 42 deletions(-) diff --git a/syntax/footer.php b/syntax/footer.php index 7664432..d910400 100644 --- a/syntax/footer.php +++ b/syntax/footer.php @@ -1,25 +1,29 @@ */ - -class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_footer extends SyntaxPlugin { - function getType() + /** @inheritdoc */ + public function getType() { return 'formatting'; } - function getSort() + /** @inheritdoc */ + public function getSort() { return 300; } - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser } @@ -29,17 +33,18 @@ function handle($match, $state, $pos, Doku_Handler $handler) * * Code heavily copied from the header renderer from inc/parser/xhtml.php, just * added an href parameter to the anchor tag linking to the wikilink. + * + * @inheritdoc */ - function render($mode, Doku_Renderer $renderer, $data) + public function render($mode, Doku_Renderer $renderer, $data) { + if ($mode != 'xhtml') return false; + /** @var Doku_Renderer_xhtml $renderer */ - list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data; + [$page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl] = $data; - if ($mode == 'xhtml') { - $renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer); - return true; - } - return false; + $renderer->doc .= $this->htmlFooter($page, $sect, $sect_title, $flags, $footer_lvl, $renderer); + return true; } /** @@ -47,30 +52,31 @@ function render($mode, Doku_Renderer $renderer, $data) * @param $renderer Doku_Renderer_xhtml The (xhtml) renderer * @return string The HTML code of the footer */ - function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) + protected function htmlFooter($page, $sect, $sect_title, $flags, $footer_lvl, $renderer) { - global $conf, $ID; + global $conf; if (!$flags['footer']) return ''; - $meta = p_get_metadata($page); + $meta = p_get_metadata($page); $exists = page_exists($page); - $xhtml = array(); + $xhtml = []; + // permalink if ($flags['permalink']) { $class = ($exists ? 'wikilink1' : 'wikilink2'); - $url = ($sect) ? wl($page) . '#' . $sect : wl($page); - $name = ($sect) ? $sect_title : $page; + $url = ($sect) ? wl($page) . '#' . $sect : wl($page); + $name = ($sect) ? $sect_title : $page; $title = ($sect) ? $page . '#' . $sect : $page; if (!$title) $title = str_replace('_', ' ', noNS($page)); - $link = array( - 'url' => $url, - 'title' => $title, - 'name' => $name, - 'target' => $conf['target']['wiki'], - 'class' => $class . ' permalink', - 'more' => 'rel="bookmark"', - ); + $link = [ + 'url' => $url, + 'title' => $title, + 'name' => $name, + 'target' => $conf['target']['wiki'], + 'class' => $class . ' permalink', + 'more' => 'rel="bookmark"' + ]; $xhtml[] = $renderer->_formatLink($link); } @@ -79,8 +85,8 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) $date = $meta['date']['created']; if ($date) { $xhtml[] = '' - . dformat($date) - . ''; + . dformat($date) + . ''; } } @@ -89,31 +95,37 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) $mdate = $meta['date']['modified']; if ($mdate) { $xhtml[] = '' - . dformat($mdate) - . ''; + . dformat($mdate) + . ''; } } // author if ($flags['user'] && $exists) { - $author = $meta['user']; + $author = $meta['user']; if ($author) { - if (function_exists('userlink')) { - $xhtml[] = '' . userlink($author) . ''; - } else { // DokuWiki versions < 2014-05-05 doesn't have userlink support, fall back to not providing a link - $xhtml[] = '' . editorinfo($author) . ''; - } + $xhtml[] = '' . userlink($author) . ''; } } // comments - let Discussion Plugin do the work for us - if (empty($sect) && $flags['comments'] && (!plugin_isdisabled('discussion')) && ($discussion = plugin_load('helper', 'discussion'))) { + if ( + empty($sect) && + $flags['comments'] && + (!plugin_isdisabled('discussion')) && + ($discussion = plugin_load('helper', 'discussion')) + ) { $disc = $discussion->td($page); if ($disc) $xhtml[] = '' . $disc . ''; } // linkbacks - let Linkback Plugin do the work for us - if (empty($sect) && $flags['linkbacks'] && (!plugin_isdisabled('linkback')) && ($linkback = plugin_load('helper', 'linkback'))) { + if ( + empty($sect) && + $flags['linkbacks'] && + (!plugin_isdisabled('linkback')) && + ($linkback = plugin_load('helper', 'linkback')) + ) { $link = $linkback->td($page); if ($link) $xhtml[] = '' . $link . ''; } @@ -121,12 +133,17 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) $xhtml = implode(DOKU_LF . DOKU_TAB . '· ', $xhtml); // tags - let Tag Plugin do the work for us - if (empty($sect) && $flags['tags'] && (!plugin_isdisabled('tag')) && ($tag = plugin_load('helper', 'tag'))) { + if ( + empty($sect) && + $flags['tags'] && + (!plugin_isdisabled('tag')) && + ($tag = plugin_load('helper', 'tag')) + ) { $tags = $tag->td($page); if ($tags) { $xhtml .= '
' . DOKU_LF - . DOKU_TAB . $tags . DOKU_LF - . DOKU_TAB . '
' . DOKU_LF; + . DOKU_TAB . $tags . DOKU_LF + . DOKU_TAB . '
' . DOKU_LF; } } @@ -136,4 +153,3 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer) return '
' . DOKU_LF . DOKU_TAB . $xhtml . DOKU_LF . '
' . DOKU_LF; } } -// vim:ts=4:sw=4:et: From 3fbe59d4895f6929604402020924681aacd8b1f1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:34:19 +0200 Subject: [PATCH 09/18] cleaned up include syntax mostly (auto) reformatting The render method is quite long and complex and proabably should be split up later --- syntax/include.php | 125 ++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 65 deletions(-) diff --git a/syntax/include.php b/syntax/include.php index cd97d46..3810bb8 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -1,5 +1,7 @@ * @author Gina Häußge, Michael Klier */ - -/** - * All DokuWiki plugins to extend the parser/rendering mechanism - * need to inherit from this class - */ -class syntax_plugin_include_include extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_include extends SyntaxPlugin { /** @var $helper helper_plugin_include */ - var $helper = null; - - /** - * Get syntax plugin type. - * - * @return string The plugin type. - */ - function getType() + public $helper; + + /** @inheritdoc */ + public function getType() { return 'substition'; } - /** - * Get sort order of syntax plugin. - * - * @return int The sort order. - */ - function getSort() + /** @inheritdoc */ + public function getSort() { return 303; } - /** - * Get paragraph type. - * - * @return string The paragraph type. - */ - function getPType() + /** @inheritdoc */ + public function getPType() { return 'block'; } - /** - * Connect patterns/modes - * - * @param $mode mixed The current mode - */ - function connectTo($mode) + /** @inheritdoc */ + public function connectTo($mode) { $this->Lexer->addSpecialPattern("{{page>.+?}}", $mode, 'plugin_include_include'); $this->Lexer->addSpecialPattern("{{section>.+?}}", $mode, 'plugin_include_include'); @@ -67,40 +48,28 @@ function connectTo($mode) $this->Lexer->addSpecialPattern("{{tagtopic>.+?}}", $mode, 'plugin_include_include'); } - /** - * Handle syntax matches - * - * @param string $match The current match - * @param int $state The match state - * @param int $pos The position of the match - * @param Doku_Handler $handler The hanlder object - * @return array The instructions of the plugin - */ - function handle($match, $state, $pos, Doku_Handler $handler) + /** @inheritdoc */ + public function handle($match, $state, $pos, Doku_Handler $handler) { $match = substr($match, 2, -2); // strip markup - list($match, $flags) = array_pad(explode('&', $match, 2), 2, ''); + [$match, $flags] = array_pad(explode('&', $match, 2), 2, ''); // break the pattern up into its parts - list($mode, $page, $sect) = array_pad(preg_split('/>|#/u', $match, 3), 3, null); + [$mode, $page, $sect] = array_pad(preg_split('/>|#/u', $match, 3), 3, null); $check = false; if (isset($sect)) $sect = sectionID($sect, $check); $level = null; - return array($mode, $page, $sect, explode('&', $flags), $level, $pos); + return [$mode, $page, $sect, explode('&', $flags), $level, $pos]; } - /** - * Renders the included page(s) - * - * @author Michael Hamann - */ - function render($format, Doku_Renderer $renderer, $data) + /** @inheritdoc */ + public function render($format, Doku_Renderer $renderer, $data) { global $ID; // static stack that records all ancestors of the child pages - static $page_stack = array(); + static $page_stack = []; // when there is no id just assume the global $ID is the current id if (empty($page_stack)) $page_stack[] = $ID; @@ -108,10 +77,11 @@ function render($format, Doku_Renderer $renderer, $data) $parent_id = $page_stack[count($page_stack) - 1]; $root_id = $page_stack[0]; - list($mode, $page, $sect, $flags, $level, $pos) = $data; + [$mode, $page, $sect, $flags, $level, $pos] = $data; - if (!$this->helper) + if (!$this->helper) { $this->helper = plugin_load('helper', 'include'); + } $flags = $this->helper->get_flags($flags); $pages = $this->helper->_get_included_pages($mode, $page, $sect, $parent_id, $flags); @@ -125,14 +95,24 @@ function render($format, Doku_Renderer $renderer, $data) unset($renderer->meta['plugin_include']); } - $renderer->meta['plugin_include']['instructions'][] = compact('mode', 'page', 'sect', 'parent_id', 'flags'); - if (!isset($renderer->meta['plugin_include']['pages'])) - $renderer->meta['plugin_include']['pages'] = array(); // add an array for array_merge - $renderer->meta['plugin_include']['pages'] = array_merge($renderer->meta['plugin_include']['pages'], $pages); + $renderer->meta['plugin_include']['instructions'][] = [ + 'mode' => $mode, + 'page' => $page, + 'sect' => $sect, + 'parent_id' => $parent_id, + 'flags' => $flags + ]; + if (!isset($renderer->meta['plugin_include']['pages'])) { + $renderer->meta['plugin_include']['pages'] = []; // add an array for array_merge + } + $renderer->meta['plugin_include']['pages'] = array_merge( + $renderer->meta['plugin_include']['pages'], + $pages + ); $renderer->meta['plugin_include']['include_content'] = isset($_REQUEST['include_content']); } - $secids = array(); + $secids = []; if ($format == 'xhtml' || $format == 'odt') { $secids = p_get_metadata($ID, 'plugin_include secids'); } @@ -143,14 +123,22 @@ function render($format, Doku_Renderer $renderer, $data) $exists = $page['exists']; if (in_array($id, $page_stack)) continue; - array_push($page_stack, $id); + $page_stack[] = $id; // add references for backlink if ($format == 'metadata') { $renderer->meta['relation']['references'][$id] = $exists; - $renderer->meta['relation']['haspart'][$id] = $exists; - if (!$sect && !$flags['firstsec'] && !$flags['linkonly'] && !isset($renderer->meta['plugin_include']['secids'][$id])) { - $renderer->meta['plugin_include']['secids'][$id] = array('hid' => 'plugin_include__' . str_replace(':', '__', $id), 'pos' => $pos); + $renderer->meta['relation']['haspart'][$id] = $exists; + if ( + !$sect && + !$flags['firstsec'] && + !$flags['linkonly'] && + !isset($renderer->meta['plugin_include']['secids'][$id]) + ) { + $renderer->meta['plugin_include']['secids'][$id] = [ + 'hid' => 'plugin_include__' . str_replace(':', '__', $id), + 'pos' => $pos + ]; } } @@ -160,7 +148,15 @@ function render($format, Doku_Renderer $renderer, $data) unset($flags['include_secid']); } - $instructions = $this->helper->_get_instructions($id, $sect, $mode, $level, $flags, $root_id, $secids); + $instructions = $this->helper->_get_instructions( + $id, + $sect, + $mode, + $level, + $flags, + $root_id, + $secids + ); if (!$flags['editbtn']) { global $conf; @@ -183,4 +179,3 @@ function render($format, Doku_Renderer $renderer, $data) return true; } } -// vim:ts=4:sw=4:et: From 1739944dbcf0b33a10de4d0748ead6c132636ee2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 18:36:47 +0200 Subject: [PATCH 10/18] clened up sorttag syntax --- syntax/sorttag.php | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/syntax/sorttag.php b/syntax/sorttag.php index ca1cae6..44034fd 100644 --- a/syntax/sorttag.php +++ b/syntax/sorttag.php @@ -1,61 +1,48 @@ * @author Michael Hamann - * */ -class syntax_plugin_include_sorttag extends DokuWiki_Syntax_Plugin +class syntax_plugin_include_sorttag extends SyntaxPlugin { - /** - * What kind of syntax are we? - */ + /** @inheritdoc */ public function getType() { return 'substition'; } - /** - * The paragraph type - block, we don't need paragraph tags - * - * @return string The paragraph type - */ + /** @inheritdoc */ public function getPType() { return 'block'; } - /** - * Where to sort in? - */ + /** @inheritdoc */ public function getSort() { return 139; } - /** - * Connect pattern to lexer - */ + /** @inheritdoc */ public function connectTo($mode) { $this->Lexer->addSpecialPattern('{{include_n>.+?}}', $mode, 'plugin_include_sorttag'); } - /** - * Handle the match - */ + /** @inheritdoc */ public function handle($match, $state, $pos, Doku_Handler $handler) { $match = substr($match, 12, -2); - return array($match); + return [$match]; } - /** - * Render output - */ + /** @inheritdoc */ public function render($mode, Doku_Renderer $renderer, $data) { if ($mode === 'metadata') { From 5b20ec9e03fd98e8b583a62f2c419718fa4f899f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 19:21:17 +0200 Subject: [PATCH 11/18] clean up helper (auto) reformatting PSR-2 renaming I started on cleaning up the instruction handling methods, but left most of them as is. This needs a more detail oriented refactoring. The passing of an instruction array that is modified by reference is not ideal. Methods still need type hints and parameter doc blocks. --- helper.php | 409 +++++++++++++++++++++++++++++------------------------ 1 file changed, 228 insertions(+), 181 deletions(-) diff --git a/helper.php b/helper.php index 6471bf9..f7e512e 100644 --- a/helper.php +++ b/helper.php @@ -8,78 +8,92 @@ * @author Michael Hamann */ +use dokuwiki\Extension\Plugin; use dokuwiki\plugin\include\GenericResolver; use dokuwiki\File\PageResolver; /** * Helper functions for the include plugin and other plugins that want to include pages. */ -class helper_plugin_include extends DokuWiki_Plugin +class helper_plugin_include extends Plugin { - // DokuWiki_Helper_Plugin + // DokuWiki_Helper_Plugin - var $defaults = array(); - var $sec_close = true; + public $defaults = []; + public $sec_close = true; /** @var helper_plugin_tag $taghelper */ - var $taghelper = null; - var $includes = array(); // deprecated - compatibility code for the blog plugin + public $taghelper; + public $includes = []; // deprecated - compatibility code for the blog plugin /** * Constructor loads default config settings once */ - function __construct() + public function __construct() { - $this->defaults['noheader'] = $this->getConf('noheader'); - $this->defaults['firstsec'] = $this->getConf('firstseconly'); - $this->defaults['editbtn'] = $this->getConf('showeditbtn'); - $this->defaults['taglogos'] = $this->getConf('showtaglogos'); - $this->defaults['footer'] = $this->getConf('showfooter'); - $this->defaults['redirect'] = $this->getConf('doredirect'); - $this->defaults['date'] = $this->getConf('showdate'); - $this->defaults['mdate'] = $this->getConf('showmdate'); - $this->defaults['user'] = $this->getConf('showuser'); - $this->defaults['comments'] = $this->getConf('showcomments'); + $this->defaults['noheader'] = $this->getConf('noheader'); + $this->defaults['firstsec'] = $this->getConf('firstseconly'); + $this->defaults['editbtn'] = $this->getConf('showeditbtn'); + $this->defaults['taglogos'] = $this->getConf('showtaglogos'); + $this->defaults['footer'] = $this->getConf('showfooter'); + $this->defaults['redirect'] = $this->getConf('doredirect'); + $this->defaults['date'] = $this->getConf('showdate'); + $this->defaults['mdate'] = $this->getConf('showmdate'); + $this->defaults['user'] = $this->getConf('showuser'); + $this->defaults['comments'] = $this->getConf('showcomments'); $this->defaults['linkbacks'] = $this->getConf('showlinkbacks'); - $this->defaults['tags'] = $this->getConf('showtags'); - $this->defaults['link'] = $this->getConf('showlink'); + $this->defaults['tags'] = $this->getConf('showtags'); + $this->defaults['link'] = $this->getConf('showlink'); $this->defaults['permalink'] = $this->getConf('showpermalink'); - $this->defaults['indent'] = $this->getConf('doindent'); - $this->defaults['linkonly'] = $this->getConf('linkonly'); - $this->defaults['title'] = $this->getConf('title'); - $this->defaults['pageexists'] = $this->getConf('pageexists'); - $this->defaults['parlink'] = $this->getConf('parlink'); - $this->defaults['inline'] = false; - $this->defaults['order'] = $this->getConf('order'); - $this->defaults['rsort'] = $this->getConf('rsort'); - $this->defaults['depth'] = $this->getConf('depth'); - $this->defaults['readmore'] = $this->getConf('readmore'); + $this->defaults['indent'] = $this->getConf('doindent'); + $this->defaults['linkonly'] = $this->getConf('linkonly'); + $this->defaults['title'] = $this->getConf('title'); + $this->defaults['pageexists'] = $this->getConf('pageexists'); + $this->defaults['parlink'] = $this->getConf('parlink'); + $this->defaults['inline'] = false; + $this->defaults['order'] = $this->getConf('order'); + $this->defaults['rsort'] = $this->getConf('rsort'); + $this->defaults['depth'] = $this->getConf('depth'); + $this->defaults['readmore'] = $this->getConf('readmore'); } /** * Available methods for other plugins */ - function getMethods() + public function getMethods() { - $result = array(); - $result[] = array( - 'name' => 'get_flags', - 'desc' => 'overrides standard values for showfooter and firstseconly settings', - 'params' => array('flags' => 'array'), - ); - return $result; + return [ + [ + 'name' => 'getFlags', + 'desc' => 'overrides standard values for showfooter and firstseconly settings', + 'params' => ['flags' => 'array'] + ] + ]; + } + + /** + * This is not a PSR-2 compliant method name + * @deprecated 2025-07-04 + * + */ + public function get_flags($setflags) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps + { + dbg_deprecated('getFlags()'); + return $this->getFlags($setflags); } /** * Overrides standard values for showfooter and firstseconly settings */ - function get_flags($setflags) + public function getFlags($setflags) { + global $INPUT; + // load defaults $flags = $this->defaults; foreach ($setflags as $flag) { $value = ''; if (strpos($flag, '=') !== false) { - list($flag, $value) = explode('=', $flag, 2); + [$flag, $value] = explode('=', $flag, 2); } switch ($flag) { case 'footer': @@ -232,18 +246,16 @@ function get_flags($setflags) } } // the include_content URL parameter overrides flags - if (isset($_REQUEST['include_content'])) + if ($INPUT->has('include_content')) { $flags['linkonly'] = 0; + } return $flags; } /** * Returns the converted instructions of a give page/section - * - * @author Michael Klier - * @author Michael Hamann */ - function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) + protected function getInstructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = []) { $key = ($sect) ? $page . '#' . $sect : $page; $this->includes[$key] = true; // legacy code for keeping compatibility with other plugins @@ -255,34 +267,31 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $ } if ($flags['linkonly']) { - if (page_exists($page) || $flags['pageexists'] == 0) { + if (page_exists($page) || $flags['pageexists'] == 0) { $title = ''; if ($flags['title']) $title = p_get_first_heading($page); if ($flags['parlink']) { - $ins = array( - array('p_open', array()), - array('internallink', array(':' . $key, $title)), - array('p_close', array()), - ); + $ins = [['p_open', []], ['internallink', [':' . $key, $title]], ['p_close', []]]; } else { - $ins = array(array('internallink', array(':' . $key,$title))); + $ins = [['internallink', [':' . $key, $title]]]; } } else { - $ins = array(); + $ins = []; } } else { if (page_exists($page)) { global $ID; + // Change the global $ID as otherwise plugins like the discussion plugin will save data for wrong page $backupID = $ID; - $ID = $page; // Change the global $ID as otherwise plugins like the discussion plugin will save data for the wrong page + $ID = $page; $ins = p_cached_instructions(wikiFN($page), false, $page); $ID = $backupID; } else { - $ins = array(); + $ins = []; } - $this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages); + $this->convertInstructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages); } return $ins; } @@ -290,39 +299,39 @@ function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $ /** * Converts instructions of the included page * - * The funcion iterates over the given list of instructions and generates + * The function iterates over the given list of instructions and generates * an index of header and section indicies. It also removes document * start/end instructions, converts links, and removes unwanted * instructions like tags, comments, linkbacks. * - * Later all header/section levels are convertet to match the current + * Later all header/section levels are converted to match the current * inclusion level. * * @author Michael Klier */ - function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = array()) + protected function convertInstructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $included_pages = []) { global $conf; // filter instructions if needed if (!empty($sect)) { - $this->_get_section($ins, $sect); // section required + $this->getSection($ins, $sect); // section required } if ($flags['firstsec']) { - $this->_get_firstsec($ins, $page, $flags); // only first section + $this->getFirstSection($ins, $page, $flags); // only first section } $num = count($ins); - $conv_idx = array(); // conversion index - $lvl_max = false; // max level + $conv_idx = []; // conversion index + $lvl_max = false; // max level $first_header = -1; - $no_header = false; + $no_header = false; $sect_title = false; - $endpos = null; // end position of the raw wiki text + $endpos = null; // end position of the raw wiki text - $this->adapt_links($ins, $page, $included_pages); + $this->adaptLinks($ins, $page, $included_pages); for ($i = 0; $i < $num; $i++) { switch ($ins[$i][0]) { @@ -359,7 +368,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc unset($ins[$i]); break; case 'nest': - $this->adapt_links($ins[$i][1][0], $page, $included_pages); + $this->adaptLinks($ins[$i][1][0], $page, $included_pages); break; case 'plugin': // FIXME skip other plugins? @@ -402,16 +411,17 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc if ($no_header) $diff -= 1; // push up one level if "noheader" // convert headers and set footer/permalink - $hdr_deleted = false; - $has_permalink = false; - $footer_lvl = false; + $hdr_deleted = false; + $has_permalink = false; + $footer_lvl = false; $contains_secedit = false; $section_close_at = false; foreach ($conv_idx as $idx) { if ($ins[$idx][0] == 'header') { if ($section_close_at === false && isset($ins[$idx + 1]) && $ins[$idx + 1][0] == 'section_open') { // store the index of the first heading that is followed by a new section - // the wrap plugin creates sections without section_open so the section shouldn't be closed before them + // the wrap plugin creates sections without section_open so the section + // shouldn't be closed before them $section_close_at = $idx; } @@ -431,7 +441,7 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc // set permalink if ($flags['link'] && !$has_permalink && ($idx == $first_header)) { - $this->_permalink($ins[$idx], $page, $sect, $flags); + $ins[$idx] = $this->permalinkHeaderInstruction($ins[$idx], $page, $sect, $flags); $has_permalink = true; } @@ -463,110 +473,142 @@ function _convert_instructions(&$ins, $lvl, $page, $sect, $flags, $root_id, $inc // close last open section of the included page if there is any if ($contains_secedit) { - array_push($ins, array('plugin', array('include_closelastsecedit', array($endpos)))); + $ins[] = ['plugin', ['include_closelastsecedit', [$endpos]]]; } - $include_secid = (isset($flags['include_secid']) ? $flags['include_secid'] : null); + $include_secid = ($flags['include_secid'] ?? null); // add edit button if ($flags['editbtn']) { - $this->_editbtn($ins, $page, $sect, $sect_title, ($flags['redirect'] ? $root_id : false), $include_secid); + $ins[] = $this->editButtonInstruction( + $page, + $sect, + $sect_title, + ($flags['redirect'] ? $root_id : false), + $include_secid + ); } // add footer if ($flags['footer']) { - $ins[] = $this->_footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id); + $ins[] = $this->footerInstruction($page, $sect, $sect_title, $flags, $footer_lvl, $root_id); } // wrap content at the beginning of the include that is not in a section in a section if ($lvl > 0 && $section_close_at !== 0 && $flags['indent'] && !$flags['inline']) { if ($section_close_at === false) { - $ins[] = array('section_close', array()); - array_unshift($ins, array('section_open', array($lvl))); + $ins[] = ['section_close', []]; + array_unshift($ins, ['section_open', [$lvl]]); } else { $section_close_idx = array_search($section_close_at, array_keys($ins)); if ($section_close_idx > 0) { $before_ins = array_slice($ins, 0, $section_close_idx); $after_ins = array_slice($ins, $section_close_idx); - $ins = array_merge($before_ins, array(array('section_close', array())), $after_ins); - array_unshift($ins, array('section_open', array($lvl))); + $ins = array_merge($before_ins, [['section_close', []]], $after_ins); + array_unshift($ins, ['section_open', [$lvl]]); } } } // add instructions entry wrapper - array_unshift($ins, array('plugin', array('include_wrap', array('open', $page, $flags['redirect'], $include_secid)))); + array_unshift($ins, ['plugin', ['include_wrap', ['open', $page, $flags['redirect'], $include_secid]]]); if (isset($flags['beforeeach'])) - array_unshift($ins, array('entity', array($flags['beforeeach']))); - array_push($ins, array('plugin', array('include_wrap', array('close')))); + array_unshift($ins, ['entity', [$flags['beforeeach']]]); + $ins[] = ['plugin', ['include_wrap', ['close']]]; if (isset($flags['aftereach'])) - array_push($ins, array('entity', array($flags['aftereach']))); + $ins[] = ['entity', [$flags['aftereach']]]; // close previous section if any and re-open after inclusion if ($lvl != 0 && $this->sec_close && !$flags['inline']) { - array_unshift($ins, array('section_close', array())); - $ins[] = array('section_open', array($lvl)); + array_unshift($ins, ['section_close', []]); + $ins[] = ['section_open', [$lvl]]; } } /** - * Appends instruction item for the include plugin footer - * - * @author Michael Klier + * Returns instruction item for the include plugin footer */ - function _footer($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) + protected function footerInstruction($page, $sect, $sect_title, $flags, $footer_lvl, $root_id) { - $footer = array(); - $footer[0] = 'plugin'; - $footer[1] = array('include_footer', array($page, $sect, $sect_title, $flags, $root_id, $footer_lvl)); - return $footer; + return [ + 0 => 'plugin', + 1 => [ + 'include_footer', + [ + $page, + $sect, + $sect_title, + $flags, + $root_id, + $footer_lvl + ] + ] + ]; } /** - * Appends instruction item for an edit button + * Returns instruction item for an edit button * * @author Michael Klier */ - function _editbtn(&$ins, $page, $sect, $sect_title, $root_id, $hid = '') + public function editButtonInstruction($page, $sect, $sect_title, $root_id, $hid = '') { $title = ($sect) ? $sect_title : $page; - $editbtn = array(); + $editbtn = []; $editbtn[0] = 'plugin'; - $editbtn[1] = array('include_editbtn', array($title, $hid)); - $ins[] = $editbtn; + $editbtn[1] = ['include_editbtn', [$title, $hid]]; + return $editbtn; } /** - * Convert instruction item for a permalink header + * Convert the given header into instruction item for a permalink header * * @author Michael Klier */ - function _permalink(&$ins, $page, $sect, $flags) + public function permalinkHeaderInstruction($originalHeader, $page, $sect, $flags) { - $ins[0] = 'plugin'; - $ins[1] = array('include_header', array($ins[1][0], $ins[1][1], $ins[1][2], $page, $sect, $flags)); + return [ + 0 => 'plugin', + 1 => [ + 'include_permalink', + [ + $originalHeader[1][0], + $originalHeader[1][1], + $originalHeader[1][2], + $page, + $sect, + $flags + ] + ] + ]; } /** * Convert internal and local links depending on the included pages * - * @param array $ins The instructions that shall be adapted - * @param string $page The included page - * @param array $included_pages The array of pages that are included + * @param array $ins The instructions that shall be adapted + * @param string $page The included page + * @param array $included_pages The array of pages that are included */ - private function adapt_links(&$ins, $page, $included_pages = null) + private function adaptLinks(&$ins, $page, $included_pages = null) { $num = count($ins); 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') { + 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 = (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; } + switch ($ins[$i][0]) { case 'internallink': case 'internalmedia': @@ -596,18 +638,27 @@ private function adapt_links(&$ins, $page, $included_pages = null) $link_parts = explode('#', $link_id, 2); $hash = ''; if (count($link_parts) === 2) { - list($link_id, $hash) = $link_parts; + [$link_id, $hash] = $link_parts; } if (array_key_exists($link_id, $included_pages)) { if ($hash) { - // hopefully the hash is also unique in the including page (otherwise this might be the wrong link target) + // hopefully the hash is also unique in the including page + // (otherwise this might be the wrong link target) $ins[$i][0] = 'locallink'; $ins[$i][1][0] = $hash; } else { - // the include section ids are different from normal section ids (so they won't conflict) but this + // the include section ids are different from normal section ids + // (so they won't conflict) but this // also means that the normal locallink function can't be used $ins[$i][0] = 'plugin'; - $ins[$i][1] = array('include_locallink', array($included_pages[$link_id]['hid'], $ins[$i][1][1], $ins[$i][1][0])); + $ins[$i][1] = [ + 'include_locallink', + [ + $included_pages[$link_id]['hid'], + $ins[$i][1][1], + $ins[$i][1][0] + ] + ]; } } } @@ -626,38 +677,37 @@ private function adapt_links(&$ins, $page, $included_pages = null) /** * Get a section including its subsections - * - * @author Michael Klier */ - function _get_section(&$ins, $sect) + protected function getSection(&$ins, $sect) { $num = count($ins); $offset = false; - $lvl = false; - $end = false; + $lvl = false; + $end = false; $endpos = null; // end position in the input text, needed for section edit buttons - $check = array(); // used for sectionID() in order to get the same ids as the xhtml renderer + $check = []; // used for sectionID() in order to get the same ids as the xhtml renderer for ($i = 0; $i < $num; $i++) { if ($ins[$i][0] == 'header') { // found the right header if (sectionID($ins[$i][1][0], $check) == $sect) { $offset = $i; - $lvl = $ins[$i][1][1]; + $lvl = $ins[$i][1][1]; } elseif ($offset && $lvl && ($ins[$i][1][1] <= $lvl)) { $end = $i - $offset; - $endpos = $ins[$i][1][2]; // the position directly after the found section, needed for the section edit button + // the position directly after the found section, needed for the section edit button: + $endpos = $ins[$i][1][2]; break; } } } - $offset = $offset ? $offset : 0; - $end = $end ? $end : ($num - 1); + $offset = $offset ?: 0; + $end = $end ?: $num - 1; if (is_array($ins)) { $ins = array_slice($ins, $offset, $end); // store the end position in the include_closelastsecedit instruction so it can generate a matching button - $ins[] = array('plugin', array('include_closelastsecedit', array($endpos))); + $ins[] = ['plugin', ['include_closelastsecedit', [$endpos]]]; } } @@ -666,7 +716,7 @@ function _get_section(&$ins, $sect) * * @author Michael Klier */ - function _get_firstsec(&$ins, $page, $flags) + protected function getFirstSection(&$ins, $page, $flags) { $num = count($ins); $first_sect = false; @@ -689,11 +739,11 @@ function _get_firstsec(&$ins, $page, $flags) if (($first_sect) && ($ins[$i][0] == 'section_open')) { $ins = array_slice($ins, 0, $first_sect); if ($flags['readmore']) { - $ins[] = array('plugin', array('include_readmore', array($page))); + $ins[] = ['plugin', ['include_readmore', [$page]]]; } - $ins[] = array('section_close', array()); - // store the end position in the include_closelastsecedit instruction so it can generate a matching button - $ins[] = array('plugin', array('include_closelastsecedit', array($endpos))); + $ins[] = ['section_close', []]; + // store end position in the include_closelastsecedit instruction so it can generate a matching button + $ins[] = ['plugin', ['include_closelastsecedit', [$endpos]]]; return; } } @@ -701,47 +751,45 @@ function _get_firstsec(&$ins, $page, $flags) /** * Gives a list of pages for a given include statement - * - * @author Michael Hamann */ - function _get_included_pages($mode, $page, $sect, $parent_id, $flags) + public function getIncludedPages($mode, $page, $sect, $parent_id, $flags) { global $conf; - $pages = array(); + $pages = []; switch ($mode) { case 'namespace': - $page = cleanID($page); - $ns = utf8_encodeFN(str_replace(':', '/', $page)); + $page = cleanID($page); + $ns = utf8_encodeFN(str_replace(':', '/', $page)); // depth is absolute depth, not relative depth, but 0 has a special meaning. $depth = $flags['depth'] ? $flags['depth'] + substr_count($page, ':') + ($page ? 1 : 0) : 0; - search($pagearrays, $conf['datadir'], 'search_allpages', array('depth' => $depth, 'skipacl' => false), $ns); + search($pagearrays, $conf['datadir'], 'search_allpages', ['depth' => $depth, 'skipacl' => false], $ns); if (is_array($pagearrays)) { foreach ($pagearrays as $pagearray) { if (!isHiddenPage($pagearray['id'])) // skip hidden pages - $pages[] = $pagearray['id']; + $pages[] = $pagearray['id']; } } break; case 'tagtopic': if (!$this->taghelper) - $this->taghelper = plugin_load('helper', 'tag'); + $this->taghelper = plugin_load('helper', 'tag'); if (!$this->taghelper) { msg('You have to install the tag plugin to use this functionality!', -1); - return array(); + return []; } - $tag = $page; - $sect = ''; + $tag = $page; + $sect = ''; $pagearrays = $this->taghelper->getTopic('', null, $tag); foreach ($pagearrays as $pagearray) { $pages[] = $pagearray['id']; } break; default: - $page = $this->_apply_macro($page, $parent_id); + $page = $this->applyMacro($page, $parent_id); // resolve shortcuts and clean ID $page = (new PageResolver($parent_id))->resolveId($page); if (auth_quickaclcheck($page) >= AUTH_READ) - $pages[] = $page; + $pages[] = $page; } if (isset($flags['exclude'])) @@ -754,12 +802,12 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) if (count($pages) > 1) { if ($flags['order'] === 'id') { if ($flags['rsort']) { - usort($pages, array($this, '_r_strnatcasecmp')); + usort($pages, [$this, 'reverseStrnatcasecmp']); } else { natcasesort($pages); } } else { - $ordered_pages = array(); + $ordered_pages = []; foreach ($pages as $page) { $key = ''; switch ($flags['order']) { @@ -787,7 +835,7 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) $ordered_pages[$key] = $page; } if ($flags['rsort']) { - uksort($ordered_pages, array($this, '_r_strnatcasecmp')); + uksort($ordered_pages, [$this, 'reverseStrnatcasecmp']); } else { uksort($ordered_pages, 'strnatcasecmp'); } @@ -795,10 +843,10 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) } } - $result = array(); + $result = []; foreach ($pages as $page) { $exists = page_exists($page); - $result[] = array('id' => $page, 'exists' => $exists, 'parent_id' => $parent_id); + $result[] = ['id' => $page, 'exists' => $exists, 'parent_id' => $parent_id]; } return $result; } @@ -814,7 +862,7 @@ function _get_included_pages($mode, $page, $sect, $parent_id, $flags) * 0 if str1 is lesser than * str2, and 0 if they are equal. */ - function _r_strnatcasecmp($a, $b) + public function reverseStrnatcasecmp($a, $b) { return strnatcasecmp($b, $a); } @@ -823,16 +871,16 @@ function _r_strnatcasecmp($a, $b) * This function generates the list of all included pages from a list of metadata * instructions. */ - function _get_included_pages_from_meta_instructions($instructions) + protected function getIncludedPagesFromMetaInstructions($instructions) { - $pages = array(); + $pages = []; foreach ($instructions as $instruction) { - $mode = $instruction['mode']; - $page = $instruction['page']; - $sect = $instruction['sect']; + $mode = $instruction['mode']; + $page = $instruction['page']; + $sect = $instruction['sect']; $parent_id = $instruction['parent_id']; - $flags = $instruction['flags']; - $pages = array_merge($pages, $this->_get_included_pages($mode, $page, $sect, $parent_id, $flags)); + $flags = $instruction['flags']; + $pages = array_merge($pages, $this->getIncludedPages($mode, $page, $sect, $parent_id, $flags)); } return $pages; } @@ -841,12 +889,12 @@ function _get_included_pages_from_meta_instructions($instructions) * Get wiki language from "HTTP_ACCEPT_LANGUAGE" * We allow the pattern e.g. "ja,en-US;q=0.7,en;q=0.3" */ - function _get_language_of_wiki($id, $parent_id) + protected function getLanguageOfWiki($id, $parent_id) { global $conf; $result = $conf['lang']; if (strpos($id, '@BROWSER_LANG@') !== false) { - $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\*)(;q=(0(.[0-9]{0,3})?|1(.0{0,3})?))?/"; + $brlangp = "/([a-zA-Z]{1,8}(-[a-zA-Z]{1,8})*|\\*)(;q=(0(.\\d{0,3})?|1(.0{0,3})?))?/"; if ( preg_match_all( $brlangp, @@ -855,15 +903,15 @@ function _get_language_of_wiki($id, $parent_id) PREG_SET_ORDER ) ) { - $langs = array(); + $langs = []; foreach ($matches as $match) { $langname = $match[1] == '*' ? $conf['lang'] : $match[1]; $qvalue = $match[4] == '' ? 1.0 : $match[4]; $langs[$langname] = $qvalue; } arsort($langs); - foreach ($langs as $lang => $langq) { - $testpage = $this->_apply_macro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id); + foreach (array_keys($langs) as $lang) { + $testpage = $this->applyMacro(str_replace('@BROWSER_LANG@', $lang, $id), $parent_id); $testpage = (new PageResolver($parent_id))->resolveId($testpage); if (page_exists($testpage)) { $result = $lang; @@ -878,7 +926,7 @@ function _get_language_of_wiki($id, $parent_id) /** * Makes user or date dependent includes possible */ - function _apply_macro($id, $parent_id) + protected function applyMacro($id, $parent_id) { global $USERINFO; /* @var Input $INPUT */ @@ -888,7 +936,7 @@ function _apply_macro($id, $parent_id) // this function can be called from within pageinfo() in // p_get_metadata and thus we cannot rely on $INFO being set if ($INPUT->server->has('REMOTE_USER')) { - $user = $INPUT->server->str('REMOTE_USER'); + $user = $INPUT->server->str('REMOTE_USER'); } else { // no registered user - use IP $user = clientIP(true); @@ -896,7 +944,7 @@ function _apply_macro($id, $parent_id) // Take user's name if possible, login name otherwise if (!empty($USERINFO['name'])) { - $name = $USERINFO['name']; + $name = $USERINFO['name']; } else { $name = $user; } @@ -939,25 +987,24 @@ function _apply_macro($id, $parent_id) $id = preg_replace('/@DATE(\w+)@/', '', $id); } - $replace = array( - '@USER@' => cleanID($user), - '@NAME@' => cleanID($name), - '@GROUP@' => cleanID($group), - '@BROWSER_LANG@' => $this->_get_language_of_wiki($id, $parent_id), - '@YEAR@' => date('Y', $time_stamp), - '@MONTH@' => date('m', $time_stamp), - '@WEEK@' => date('W', $time_stamp), - '@DAY@' => date('d', $time_stamp), - '@YEARPMONTH@' => date('Ym', strtotime("-1 month")), - '@PMONTH@' => date('m', strtotime("-1 month")), - '@NMONTH@' => date('m', strtotime("+1 month")), - '@YEARNMONTH@' => date('Ym', strtotime("+1 month")), - '@YEARPWEEK@' => date('YW', strtotime("-1 week")), - '@PWEEK@' => date('W', strtotime("-1 week")), - '@NWEEK@' => date('W', strtotime("+1 week")), - '@YEARNWEEK@' => date('YW', strtotime("+1 week")), - ); + $replace = [ + '@USER@' => cleanID($user), + '@NAME@' => cleanID($name), + '@GROUP@' => cleanID($group), + '@BROWSER_LANG@' => $this->getLanguageOfWiki($id, $parent_id), + '@YEAR@' => date('Y', $time_stamp), + '@MONTH@' => date('m', $time_stamp), + '@WEEK@' => date('W', $time_stamp), + '@DAY@' => date('d', $time_stamp), + '@YEARPMONTH@' => date('Ym', strtotime("-1 month")), + '@PMONTH@' => date('m', strtotime("-1 month")), + '@NMONTH@' => date('m', strtotime("+1 month")), + '@YEARNMONTH@' => date('Ym', strtotime("+1 month")), + '@YEARPWEEK@' => date('YW', strtotime("-1 week")), + '@PWEEK@' => date('W', strtotime("-1 week")), + '@NWEEK@' => date('W', strtotime("+1 week")), + '@YEARNWEEK@' => date('YW', strtotime("+1 week")) + ]; return str_replace(array_keys($replace), array_values($replace), $id); } } -// vim:ts=4:sw=4:et: From 8d623175903456d86607b21900290032b3970f60 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 19:41:37 +0200 Subject: [PATCH 12/18] cleanup action (auto) reformatting PSR-2 name changes --- action.php | 166 ++++++++++++++++++++++++++--------------------------- helper.php | 4 +- 2 files changed, 82 insertions(+), 88 deletions(-) diff --git a/action.php b/action.php index db0525f..495a865 100644 --- a/action.php +++ b/action.php @@ -1,5 +1,10 @@ * @author Michael Klier */ - -/** - * All DokuWiki plugins to extend the parser/rendering mechanism - * need to inherit from this class - */ -class action_plugin_include extends DokuWiki_Action_Plugin +class action_plugin_include extends ActionPlugin { /* @var helper_plugin_include $helper */ - var $helper = null; + public $helper; - function __construct() + /** + * Constructor + * + * Initializes the helper + */ + public function __construct() { $this->helper = plugin_load('helper', 'include'); } - /** - * plugin should use this method to register its handlers with the dokuwiki's event controller - */ - function register(Doku_Event_Handler $controller) + /** @inheritdoc */ + public function register(EventHandler $controller) { /* @var Doku_event_handler $controller */ - $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handle_indexer'); - $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'handle_indexer_version'); - $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, '_cache_prepare'); - $controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove - $controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handle_form'); - $controller->register_hook('HTML_CONFLICTFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove - $controller->register_hook('FORM_CONFLICT_OUTPUT', 'BEFORE', $this, 'handle_form'); - $controller->register_hook('HTML_DRAFTFORM_OUTPUT', 'BEFORE', $this, 'handle_form'); // todo remove - $controller->register_hook('FORM_DRAFT_OUTPUT', 'BEFORE', $this, 'handle_form'); - $controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'handle_redirect'); - $controller->register_hook('PARSER_HANDLER_DONE', 'BEFORE', $this, 'handle_parser'); - $controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handle_metadata'); - $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'handle_secedit_button'); - $controller->register_hook('PLUGIN_MOVE_HANDLERS_REGISTER', 'BEFORE', $this, 'handle_move_register'); + $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'handleIndexer'); + $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'handleIndexerVersion'); + $controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handleCachePrepare'); + $controller->register_hook('FORM_EDIT_OUTPUT', 'BEFORE', $this, 'handleForm'); + $controller->register_hook('FORM_CONFLICT_OUTPUT', 'BEFORE', $this, 'handleForm'); + $controller->register_hook('FORM_DRAFT_OUTPUT', 'BEFORE', $this, 'handleForm'); + $controller->register_hook('ACTION_SHOW_REDIRECT', 'BEFORE', $this, 'handleRedirect'); + $controller->register_hook('PARSER_HANDLER_DONE', 'BEFORE', $this, 'handleParser'); + $controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handleMetadata'); + $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'handleSeceditButton'); + $controller->register_hook('PLUGIN_MOVE_HANDLERS_REGISTER', 'BEFORE', $this, 'handleMoveRegister'); } /** * Add a version string to the index so it is rebuilt * whenever the handler is updated or the safeindex setting is changed */ - public function handle_indexer_version($event, $param) + public function handleIndexerVersion($event, $param) { $event->data['plugin_include'] = '0.1.safeindex=' . $this->getConf('safeindex'); } /** - * Handles the INDEXER_PAGE_ADD event, prevents indexing of metadata from included pages that aren't public if enabled + * Handles the INDEXER_PAGE_ADD event + * + * prevents indexing of metadata from included pages that aren't public if enabled * - * @param Doku_Event $event the event object - * @param array $params optional parameters (unused) + * @param Event $event the event object + * @param array $params optional parameters (unused) */ - public function handle_indexer(Doku_Event $event, $params) + public function handleIndexer(Event $event, $params) { global $USERINFO; @@ -77,7 +79,7 @@ public function handle_indexer(Doku_Event $event, $params) // check if the current metadata indicates that non-public pages were included if ($inclmeta !== null && isset($inclmeta['pages'])) { foreach ($inclmeta['pages'] as $page) { - if (auth_aclcheck($page['id'], '', array()) < AUTH_READ) { // is $page public? + if (auth_aclcheck($page['id'], '', []) < AUTH_READ) { // is $page public? $all_public = false; break; } @@ -95,21 +97,22 @@ public function handle_indexer(Doku_Event $event, $params) // metadata is only rendered once for a page in one request - thus we need to render manually. $meta = p_read_metadata($event->data['page']); // load the original metdata $meta = p_render_metadata($event->data['page'], $meta); // render the metadata - p_save_metadata($event->data['page'], $meta); // save the metadata so other event handlers get the public metadata, too + p_save_metadata($event->data['page'], $meta); // save the metadata so other event handlers get it, too $meta = $meta['current']; // we are only interested in current metadata. // check if the tag plugin handler has already been called before the include plugin $tag_called = isset($event->data['metadata']['subject']); - // Reset the metadata in the renderer. This removes data from all other event handlers, but we need to be on the safe side here. - $event->data['metadata'] = array('title' => $meta['title']); + // Reset the metadata in the renderer. + // This removes data from all other event handlers, but we need to be on the safe side here. + $event->data['metadata'] = ['title' => $meta['title']]; // restore the relation references metadata if (isset($meta['relation']['references'])) { $event->data['metadata']['relation_references'] = array_keys($meta['relation']['references']); } else { - $event->data['metadata']['relation_references'] = array(); + $event->data['metadata']['relation_references'] = []; } // restore the tag metadata if the tag plugin handler has been called before the include plugin handler. @@ -119,7 +122,7 @@ public function handle_indexer(Doku_Event $event, $params) if (isset($meta['subject'])) { $event->data['metadata']['subject'] = $tag_helper->_cleanTagList($meta['subject']); } else { - $event->data['metadata']['subject'] = array(); + $event->data['metadata']['subject'] = []; } } } @@ -133,7 +136,7 @@ public function handle_indexer(Doku_Event $event, $params) /** * Used for debugging purposes only */ - function handle_metadata(&$event, $param) + public function handleMetadata(&$event, $param) { global $conf; if ($conf['allowdebug'] && $this->getConf('debugoutput')) { @@ -149,7 +152,7 @@ function handle_metadata(&$event, $param) * @author Michael Klier * @author Michael Hamann */ - function handle_parser(Doku_Event $event, $param) + public function handleParser(Event $event, $param) { global $ID; @@ -159,17 +162,8 @@ function handle_parser(Doku_Event $event, $param) for ($i = 0; $i < $num; $i++) { switch ($ins[$i][0]) { case 'plugin': - switch ($ins[$i][1][0]) { - case 'include_include': - $ins[$i][1][1][4] = $level; - break; - /* FIXME: this doesn't work anymore that way with the new structure - // some plugins already close open sections - // so we need to make sure we don't close them twice - case 'box': - $this->helper->sec_close = false; - break; - */ + if ($ins[$i][1][0] === 'include_include') { + $ins[$i][1][1][4] = $level; } break; case 'section_open': @@ -182,11 +176,11 @@ function handle_parser(Doku_Event $event, $param) /** * Add a hidden input to the form to preserve the redirect_id */ - function handle_form(Doku_Event $event, $param) + public function handleForm(Event $event, $param) { if (!array_key_exists('redirect_id', $_REQUEST)) return; - if (is_a($event->data, \dokuwiki\Form\Form::class)) { + if (is_a($event->data, Form::class)) { $event->data->setHiddenField('redirect_id', cleanID($_REQUEST['redirect_id'])); } else { // todo remove when old FORM events are no longer supported @@ -197,15 +191,15 @@ function handle_form(Doku_Event $event, $param) /** * Modify the data for the redirect when there is a redirect_id set */ - function handle_redirect(Doku_Event &$event, $param) + public function handleRedirect(Event &$event, $param) { if (array_key_exists('redirect_id', $_REQUEST)) { - // Render metadata when this is an older DokuWiki version where - // metadata is not automatically re-rendered as the page has probably - // been changed but is not directly displayed + // Render metadata when this is an older DokuWiki version where + // metadata is not automatically re-rendered as the page has probably + // been changed but is not directly displayed $versionData = getVersionData(); if ($versionData['date'] < '2010-11-23') { - p_set_metadata($event->data['id'], array(), true); + p_set_metadata($event->data['id'], [], true); } $event->data['id'] = cleanID($_REQUEST['redirect_id']); $event->data['title'] = ''; @@ -215,7 +209,7 @@ function handle_redirect(Doku_Event &$event, $param) /** * prepare the cache object for default _useCache action */ - function _cache_prepare(Doku_Event &$event, $param) + public function handleCachePrepare(Event &$event, $param) { global $conf; @@ -238,7 +232,7 @@ function _cache_prepare(Doku_Event &$event, $param) if ( !is_array($depends['pages']) || !is_array($depends['instructions']) || - $depends['pages'] != $this->helper->_get_included_pages_from_meta_instructions($depends['instructions']) || + $depends['pages'] != $this->helper->getIncludedPagesFromMetaInstructions($depends['instructions']) || // the include_content url parameter may change the behavior for included pages $depends['include_content'] != isset($_REQUEST['include_content']) ) { @@ -249,12 +243,12 @@ function _cache_prepare(Doku_Event &$event, $param) dbglog($depends['pages']); dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META END ----'); dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS START ----'); - dbglog($this->helper->_get_included_pages_from_meta_instructions($depends['instructions'])); + dbglog($this->helper->getIncludedPagesFromMetaInstructions($depends['instructions'])); dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS END ----'); } } else { // add plugin.info.txt to depends for nicer upgrades - $cache->depends['files'][] = dirname(__FILE__) . '/plugin.info.txt'; + $cache->depends['files'][] = __DIR__ . '/plugin.info.txt'; foreach ($depends['pages'] as $page) { if (!$page['exists']) continue; $file = wikiFN($page['id']); @@ -270,10 +264,10 @@ function _cache_prepare(Doku_Event &$event, $param) * and replace normal section edit buttons when the current page is different from the * global $ID. */ - function handle_secedit_button(Doku_Event &$event, $params) + public function handleSeceditButton(Event &$event, $params) { // stack of included pages in the form ('id' => page, 'rev' => modification time, 'writable' => bool) - static $page_stack = array(); + static $page_stack = []; global $ID, $lang; @@ -283,18 +277,22 @@ function handle_secedit_button(Doku_Event &$event, $params) // handle the "section edits" added by the include plugin $fn = wikiFN($data['name']); $perm = auth_quickaclcheck($data['name']); - array_unshift($page_stack, array( - 'id' => $data['name'], - 'rev' => @filemtime($fn), - 'writable' => (page_exists($data['name']) ? (is_writable($fn) && $perm >= AUTH_EDIT) : $perm >= AUTH_CREATE), - 'redirect' => ($data['target'] == 'plugin_include_start'), - )); + array_unshift( + $page_stack, + [ + 'id' => $data['name'], + 'rev' => @filemtime($fn), + 'writable' => + (page_exists($data['name']) + ? (is_writable($fn) && $perm >= AUTH_EDIT) + : $perm >= AUTH_CREATE), + 'redirect' => ($data['target'] == 'plugin_include_start')] + ); } elseif ($data['target'] == 'plugin_include_end') { array_shift($page_stack); } elseif ($data['target'] == 'plugin_include_editbtn') { if ($page_stack[0]['writable']) { - $params = array('do' => 'edit', - 'id' => $page_stack[0]['id']); + $params = ['do' => 'edit', 'id' => $page_stack[0]['id']]; if ($page_stack[0]['redirect']) { $params['redirect_id'] = $ID; $params['hid'] = $data['hid']; @@ -337,9 +335,10 @@ function handle_secedit_button(Doku_Event &$event, $params) 'secedit', $page_stack[0]['id'], '', - array_merge(array('do' => 'edit', - 'rev' => $page_stack[0]['rev'], - 'summary' => '[' . $name . '] '), $data), + array_merge( + ['do' => 'edit', 'rev' => $page_stack[0]['rev'], 'summary' => '[' . $name . '] '], + $data + ), 'post', $name ) . '
'; @@ -354,27 +353,23 @@ function handle_secedit_button(Doku_Event &$event, $params) $event->stopPropagation(); } - public function handle_move_register(Doku_Event $event, $params) + public function handleMoveRegister(Event $event, $params) { - $event->data['handlers']['include_include'] = array($this, 'rewrite_include'); + $event->data['handlers']['include_include'] = [$this, 'rewriteInclude']; } - public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_move_handler $handler) + public function rewriteInclude($match, $pos, $state, $plugin, helper_plugin_move_handler $handler) { $syntax = substr($match, 2, -2); // strip markup $replacers = explode('|', $syntax); $syntax = array_shift($replacers); - list($syntax, $flags) = array_pad(explode('&', $syntax, 2), 2, ""); + [$syntax, $flags] = array_pad(explode('&', $syntax, 2), 2, ""); // break the pattern up into its parts - list($mode, $page, $sect) = array_pad(preg_split('/>|#/u', $syntax, 3), 3, ""); + [$mode, $page, $sect] = array_pad(preg_split('/>|#/u', $syntax, 3), 3, ""); - if (method_exists($handler, 'adaptRelativeId')) { // move plugin before version 2015-05-16 - $newpage = $handler->adaptRelativeId($page); - } else { - $newpage = $handler->resolveMoves($page, 'page'); - $newpage = $handler->relativeLink($page, $newpage, 'page'); - } + $newpage = $handler->resolveMoves($page, 'page'); + $newpage = $handler->relativeLink($page, $newpage, 'page'); if ($newpage == $page) { return $match; @@ -388,4 +383,3 @@ public function rewrite_include($match, $pos, $state, $plugin, helper_plugin_mov } } } -// vim:ts=4:sw=4:et: diff --git a/helper.php b/helper.php index f7e512e..9832f28 100644 --- a/helper.php +++ b/helper.php @@ -255,7 +255,7 @@ public function getFlags($setflags) /** * Returns the converted instructions of a give page/section */ - protected function getInstructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = []) + public function getInstructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = []) { $key = ($sect) ? $page . '#' . $sect : $page; $this->includes[$key] = true; // legacy code for keeping compatibility with other plugins @@ -871,7 +871,7 @@ public function reverseStrnatcasecmp($a, $b) * This function generates the list of all included pages from a list of metadata * instructions. */ - protected function getIncludedPagesFromMetaInstructions($instructions) + public function getIncludedPagesFromMetaInstructions($instructions) { $pages = []; foreach ($instructions as $instruction) { From 2cfc6e2c1e7e5581ed7d94248cde09d0ca246c76 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 19:43:20 +0200 Subject: [PATCH 13/18] adjusted files for renamed methods --- _test/namespace_includes.test.php | 22 +++++++++++----------- syntax/include.php | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/_test/namespace_includes.test.php b/_test/namespace_includes.test.php index 1da3234..6f9d254 100644 --- a/_test/namespace_includes.test.php +++ b/_test/namespace_includes.test.php @@ -66,7 +66,7 @@ protected function getDirContent ($dir) { */ public function test_hidden() { $flags = $this->helper->get_flags(array()); - $pages = $this->helper->_get_included_pages('namespace', 'inclhidden:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'inclhidden:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclhidden:visible', 'exists' => true, 'parent_id' => ''), ), $pages); @@ -77,24 +77,24 @@ public function test_hidden() { */ public function test_depth() { $flags = $this->helper->get_flags(array()); - $pages = $this->helper->_get_included_pages('namespace', 'incltest:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'incltest:', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:level1', 'exists' => true, 'parent_id' => ''), ), $pages); $flags = $this->helper->get_flags(array('depth=2')); - $pages = $this->helper->_get_included_pages('namespace', 'incltest:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'incltest:', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:level1', 'exists' => true, 'parent_id' => ''), array('id' => 'incltest:ns:level2', 'exists' => true, 'parent_id' => ''), ), $pages); $flags = $this->helper->get_flags(array('depth=2')); - $pages = $this->helper->_get_included_pages('namespace', 'incltest:ns', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'incltest:ns', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:ns:level2', 'exists' => true, 'parent_id' => ''), array('id' => 'incltest:ns:ns:level3', 'exists' => true, 'parent_id' => ''), ), $pages); $flags = $this->helper->get_flags(array('depth=0')); - $pages = $this->helper->_get_included_pages('namespace', 'incltest:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'incltest:', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:level1', 'exists' => true, 'parent_id' => ''), array('id' => 'incltest:ns:level2', 'exists' => true, 'parent_id' => ''), @@ -103,10 +103,10 @@ public function test_depth() { // test include of the root namespace $flags = $this->helper->get_flags(array()); - $pages = $this->helper->_get_included_pages('namespace', ':', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', ':', '', '', $flags); $this->assertEquals(array(array('id' => 'mailinglist', 'exists' => true, 'parent_id' => '')), $pages); $flags = $this->helper->get_flags(array('depth=2')); - $pages = $this->helper->_get_included_pages('namespace', ':', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', ':', '', '', $flags); $expected = array( array('id' => 'inclhidden:visible', 'exists' => true, 'parent_id' => ''), array('id' => 'inclorder:page1', 'exists' => true, 'parent_id' => ''), @@ -144,7 +144,7 @@ public function test_depth() { public function test_order() { $flags = $this->helper->get_flags(array()); - $pages = $this->helper->_get_included_pages('namespace', 'inclorder:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page1', 'exists' => true, 'parent_id' => ''), @@ -154,7 +154,7 @@ public function test_order() { ), $pages); $flags = $this->helper->get_flags(array('rsort')); - $pages = $this->helper->_get_included_pages('namespace', 'inclorder:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page4', 'exists' => true, 'parent_id' => ''), array('id' => 'inclorder:page3', 'exists' => true, 'parent_id' => ''), @@ -162,7 +162,7 @@ public function test_order() { array('id' => 'inclorder:page1', 'exists' => true, 'parent_id' => ''), ), $pages); $flags = $this->helper->get_flags(array('order=custom')); - $pages = $this->helper->_get_included_pages('namespace', 'inclorder:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page4', 'exists' => true, 'parent_id' => ''), array('id' => 'inclorder:page3', 'exists' => true, 'parent_id' => ''), @@ -171,7 +171,7 @@ public function test_order() { ), $pages); $flags = $this->helper->get_flags(array('order=custom', 'rsort')); - $pages = $this->helper->_get_included_pages('namespace', 'inclorder:', '', '', $flags); + $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page2', 'exists' => true, 'parent_id' => ''), array('id' => 'inclorder:page1', 'exists' => true, 'parent_id' => ''), diff --git a/syntax/include.php b/syntax/include.php index 3810bb8..c337524 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -84,7 +84,7 @@ public function render($format, Doku_Renderer $renderer, $data) } $flags = $this->helper->get_flags($flags); - $pages = $this->helper->_get_included_pages($mode, $page, $sect, $parent_id, $flags); + $pages = $this->helper->getIncludedPages($mode, $page, $sect, $parent_id, $flags); if ($format == 'metadata') { /** @var Doku_Renderer_metadata $renderer */ @@ -148,7 +148,7 @@ public function render($format, Doku_Renderer $renderer, $data) unset($flags['include_secid']); } - $instructions = $this->helper->_get_instructions( + $instructions = $this->helper->getInstructions( $id, $sect, $mode, From c69a46a1c765f9c0494da2a1d15337041044fa2e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 19:48:40 +0200 Subject: [PATCH 14/18] fix use of get_flags() --- _test/namespace_includes.test.php | 22 +++++++++++----------- syntax/include.php | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/_test/namespace_includes.test.php b/_test/namespace_includes.test.php index 6f9d254..ccdd273 100644 --- a/_test/namespace_includes.test.php +++ b/_test/namespace_includes.test.php @@ -65,7 +65,7 @@ protected function getDirContent ($dir) { * Test hiding of hidden pages in namespace includes */ public function test_hidden() { - $flags = $this->helper->get_flags(array()); + $flags = $this->helper->getFlags(array()); $pages = $this->helper->getIncludedPages('namespace', 'inclhidden:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclhidden:visible', 'exists' => true, 'parent_id' => ''), @@ -76,24 +76,24 @@ public function test_hidden() { * Test include depth limit */ public function test_depth() { - $flags = $this->helper->get_flags(array()); + $flags = $this->helper->getFlags(array()); $pages = $this->helper->getIncludedPages('namespace', 'incltest:', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:level1', 'exists' => true, 'parent_id' => ''), ), $pages); - $flags = $this->helper->get_flags(array('depth=2')); + $flags = $this->helper->getFlags(array('depth=2')); $pages = $this->helper->getIncludedPages('namespace', 'incltest:', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:level1', 'exists' => true, 'parent_id' => ''), array('id' => 'incltest:ns:level2', 'exists' => true, 'parent_id' => ''), ), $pages); - $flags = $this->helper->get_flags(array('depth=2')); + $flags = $this->helper->getFlags(array('depth=2')); $pages = $this->helper->getIncludedPages('namespace', 'incltest:ns', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:ns:level2', 'exists' => true, 'parent_id' => ''), array('id' => 'incltest:ns:ns:level3', 'exists' => true, 'parent_id' => ''), ), $pages); - $flags = $this->helper->get_flags(array('depth=0')); + $flags = $this->helper->getFlags(array('depth=0')); $pages = $this->helper->getIncludedPages('namespace', 'incltest:', '', '', $flags); $this->assertEquals(array( array('id' => 'incltest:level1', 'exists' => true, 'parent_id' => ''), @@ -102,10 +102,10 @@ public function test_depth() { ), $pages); // test include of the root namespace - $flags = $this->helper->get_flags(array()); + $flags = $this->helper->getFlags(array()); $pages = $this->helper->getIncludedPages('namespace', ':', '', '', $flags); $this->assertEquals(array(array('id' => 'mailinglist', 'exists' => true, 'parent_id' => '')), $pages); - $flags = $this->helper->get_flags(array('depth=2')); + $flags = $this->helper->getFlags(array('depth=2')); $pages = $this->helper->getIncludedPages('namespace', ':', '', '', $flags); $expected = array( array('id' => 'inclhidden:visible', 'exists' => true, 'parent_id' => ''), @@ -143,7 +143,7 @@ public function test_depth() { */ public function test_order() { - $flags = $this->helper->get_flags(array()); + $flags = $this->helper->getFlags(array()); $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( @@ -153,7 +153,7 @@ public function test_order() { array('id' => 'inclorder:page4', 'exists' => true, 'parent_id' => ''), ), $pages); - $flags = $this->helper->get_flags(array('rsort')); + $flags = $this->helper->getFlags(array('rsort')); $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page4', 'exists' => true, 'parent_id' => ''), @@ -161,7 +161,7 @@ public function test_order() { array('id' => 'inclorder:page2', 'exists' => true, 'parent_id' => ''), array('id' => 'inclorder:page1', 'exists' => true, 'parent_id' => ''), ), $pages); - $flags = $this->helper->get_flags(array('order=custom')); + $flags = $this->helper->getFlags(array('order=custom')); $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page4', 'exists' => true, 'parent_id' => ''), @@ -170,7 +170,7 @@ public function test_order() { array('id' => 'inclorder:page2', 'exists' => true, 'parent_id' => ''), ), $pages); - $flags = $this->helper->get_flags(array('order=custom', 'rsort')); + $flags = $this->helper->getFlags(array('order=custom', 'rsort')); $pages = $this->helper->getIncludedPages('namespace', 'inclorder:', '', '', $flags); $this->assertEquals(array( array('id' => 'inclorder:page2', 'exists' => true, 'parent_id' => ''), diff --git a/syntax/include.php b/syntax/include.php index c337524..e279c47 100644 --- a/syntax/include.php +++ b/syntax/include.php @@ -82,7 +82,7 @@ public function render($format, Doku_Renderer $renderer, $data) if (!$this->helper) { $this->helper = plugin_load('helper', 'include'); } - $flags = $this->helper->get_flags($flags); + $flags = $this->helper->getFlags($flags); $pages = $this->helper->getIncludedPages($mode, $page, $sect, $parent_id, $flags); From f9b92abf4d7307a4ea93eb5b1df1bcc0dc44d5eb Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2025 19:55:40 +0200 Subject: [PATCH 15/18] fix overlong line in config metadata --- conf/metadata.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conf/metadata.php b/conf/metadata.php index 8202795..4492007 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -27,7 +27,10 @@ $meta['pageexists'] = array('onoff'); $meta['parlink'] = array('onoff'); $meta['safeindex'] = array('onoff'); -$meta['order'] = array('multichoice', '_choices' => array('id', 'title', 'created', 'modified', 'indexmenu', 'custom')); +$meta['order'] = array( + 'multichoice', + '_choices' => array('id', 'title', 'created', 'modified', 'indexmenu', 'custom') +); $meta['rsort'] = array('onoff'); $meta['depth'] = array('numeric', '_min' => 0); $meta['readmore'] = array('onoff'); From 15b2a7c1889370231bb9d737bbb2d1451b306a75 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 5 Jul 2025 20:29:00 +0200 Subject: [PATCH 16/18] fix type hints and pass by reference for event handlers --- action.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/action.php b/action.php index 495a865..c05f66d 100644 --- a/action.php +++ b/action.php @@ -50,7 +50,7 @@ public function register(EventHandler $controller) * Add a version string to the index so it is rebuilt * whenever the handler is updated or the safeindex setting is changed */ - public function handleIndexerVersion($event, $param) + public function handleIndexerVersion(Event $event, $param) { $event->data['plugin_include'] = '0.1.safeindex=' . $this->getConf('safeindex'); } @@ -136,7 +136,7 @@ public function handleIndexer(Event $event, $params) /** * Used for debugging purposes only */ - public function handleMetadata(&$event, $param) + public function handleMetadata(Event $event, $param) { global $conf; if ($conf['allowdebug'] && $this->getConf('debugoutput')) { @@ -191,7 +191,7 @@ public function handleForm(Event $event, $param) /** * Modify the data for the redirect when there is a redirect_id set */ - public function handleRedirect(Event &$event, $param) + public function handleRedirect(Event $event, $param) { if (array_key_exists('redirect_id', $_REQUEST)) { // Render metadata when this is an older DokuWiki version where @@ -209,7 +209,7 @@ public function handleRedirect(Event &$event, $param) /** * prepare the cache object for default _useCache action */ - public function handleCachePrepare(Event &$event, $param) + public function handleCachePrepare(Event $event, $param) { global $conf; @@ -264,7 +264,7 @@ public function handleCachePrepare(Event &$event, $param) * and replace normal section edit buttons when the current page is different from the * global $ID. */ - public function handleSeceditButton(Event &$event, $params) + public function handleSeceditButton(Event $event, $params) { // stack of included pages in the form ('id' => page, 'rev' => modification time, 'writable' => bool) static $page_stack = []; From 431a77ae13eeee563083d6f41773eb8ce2a2d632 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 5 Jul 2025 20:37:56 +0200 Subject: [PATCH 17/18] replace deprecated dbg_log calls Instead the debug logger is used. --- action.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/action.php b/action.php index c05f66d..2db5690 100644 --- a/action.php +++ b/action.php @@ -4,6 +4,7 @@ use dokuwiki\Extension\EventHandler; use dokuwiki\Extension\Event; use dokuwiki\Form\Form; +use dokuwiki\Logger; /** * Include Plugin: Display a wiki page within another wiki page @@ -211,8 +212,6 @@ public function handleRedirect(Event $event, $param) */ public function handleCachePrepare(Event $event, $param) { - global $conf; - /* @var cache_renderer $cache */ $cache =& $event->data; @@ -221,10 +220,8 @@ public function handleCachePrepare(Event $event, $param) $depends = p_get_metadata($cache->page, 'plugin_include'); - if ($conf['allowdebug'] && $this->getConf('debugoutput')) { - dbglog('---- PLUGIN INCLUDE CACHE DEPENDS START ----'); - dbglog($depends); - dbglog('---- PLUGIN INCLUDE CACHE DEPENDS END ----'); + if ($this->getConf('debugoutput')) { + Logger::debug('include plugin: cache depends for ' . $cache->page, $depends); } if (!is_array($depends)) return; // nothing to do for us @@ -237,14 +234,11 @@ public function handleCachePrepare(Event $event, $param) $depends['include_content'] != isset($_REQUEST['include_content']) ) { $cache->depends['purge'] = true; // included pages changed or old metadata - request purge. - if ($conf['allowdebug'] && $this->getConf('debugoutput')) { - dbglog('---- PLUGIN INCLUDE: REQUESTING CACHE PURGE ----'); - dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META START ----'); - dbglog($depends['pages']); - dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META END ----'); - dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS START ----'); - dbglog($this->helper->getIncludedPagesFromMetaInstructions($depends['instructions'])); - dbglog('---- PLUGIN INCLUDE CACHE PAGES FROM META_INSTRUCTIONS END ----'); + if ($this->getConf('debugoutput')) { + Logger::debug('include plugin: cache purge for ' . $cache->page, [ + 'meta-pages' => $depends['pages'], + 'inst-pages' => $this->helper->getIncludedPagesFromMetaInstructions($depends['instructions']), + ]); } } else { // add plugin.info.txt to depends for nicer upgrades @@ -286,7 +280,7 @@ public function handleSeceditButton(Event $event, $params) (page_exists($data['name']) ? (is_writable($fn) && $perm >= AUTH_EDIT) : $perm >= AUTH_CREATE), - 'redirect' => ($data['target'] == 'plugin_include_start')] + 'redirect' => ($data['target'] == 'plugin_include_start')] ); } elseif ($data['target'] == 'plugin_include_end') { array_shift($page_stack); From 3ea2da345a88a49e22645dcd73e29b69f1314ddd Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 7 Jul 2025 21:07:49 +0200 Subject: [PATCH 18/18] add backwards compatibility to helper --- helper.php | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/helper.php b/helper.php index 9832f28..d0b027b 100644 --- a/helper.php +++ b/helper.php @@ -71,14 +71,41 @@ public function getMethods() } /** - * This is not a PSR-2 compliant method name - * @deprecated 2025-07-04 + * Magic method to handle deprecated method calls * + * @param string $func The name of the method being called + * @param array $args The arguments passed to the method + * @return mixed */ - public function get_flags($setflags) // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps + public function __call($func, $args) { - dbg_deprecated('getFlags()'); - return $this->getFlags($setflags); + switch ($func) { + case 'get_flags': + dbg_deprecated('getFlags()'); + return $this->getFlags($args[0]); + case '_get_instructions': + dbg_deprecated('getInstructions()'); + return $this->getInstructions( + $args[0], // page + $args[1], // sect + $args[2], // mode + $args[3], // lvl + $args[4], // flags + $args[5] ?? null, // root_id + $args[6] ?? [] // included_pages + ); + case '_get_included_pages': + dbg_deprecated('getIncludedPages()'); + return $this->getIncludedPages( + $args[0], // mode + $args[1], // page + $args[2], // sect + $args[3], // parent_id + $args[4] // flags + ); + default: + throw new \BadMethodCallException("Method $func does not exist in " . __CLASS__); + } } /**