From 8f7e02ac11941eccdced4e6401738dc931608bfd Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 19 Aug 2023 15:22:31 +0200 Subject: [PATCH 1/8] replace sort by the sort in pagelist --- syntax/topic.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/syntax/topic.php b/syntax/topic.php index 031fef8..b229275 100644 --- a/syntax/topic.php +++ b/syntax/topic.php @@ -113,32 +113,19 @@ function render($format, Doku_Renderer $renderer, $data) { if (!$pagelist = $this->loadHelper('pagelist')) { return false; } - $pagelist->sort = false; - $pagelist->rsort = false; $configflags = explode(',', str_replace(" ", "", $this->getConf('pagelist_flags'))); - $flags = array_merge($configflags, $flags); - foreach($flags as $key => $flag) { - if($flag == "") { + $flags[] = 'defaultsortby=pagename'; //default sortby if a sort requested + $flags = array_merge($configflags, $flags); + foreach ($flags as $key => $flag) { + if ($flag == "") { unset($flags[$key]); } - } + } $pagelist->setFlags($flags); $pagelist->startList(); - // Sort pages by pagename if required by flags - if($pagelist->sort || $pagelist->rsort) { - $fnc = function($a, $b) { - return strcmp(noNS($a["id"]), noNS($b["id"])); - }; - usort($pages, $fnc); - // rsort is true - revserse sort the pages - if($pagelist->rsort) { - krsort($pages); - } - } - foreach ($pages as $page) { $pagelist->addPage($page); } From b504f6d6cd1cd65c1a906b76a2928d587414c38c Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 19 Aug 2023 17:43:50 +0200 Subject: [PATCH 2/8] Make title of tagpage translatable Improves #246 --- action.php | 2 +- lang/en/lang.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/action.php b/action.php index bcf908e..2d3f7cd 100644 --- a/action.php +++ b/action.php @@ -98,8 +98,8 @@ public function performTagAction(Doku_Event $event, $param) { $pagelist->addPage($page); } - print '

TAG: ' . hsc(str_replace('_', ' ', $INPUT->str('tag'))) . '

' . DOKU_LF; print '
' . DOKU_LF; + print '

'. sprintf($this->getLang('tagpageheading'), hsc(str_replace('_', ' ', $INPUT->str('tag')))) . '

'; print $pagelist->finishList(); print '
' . DOKU_LF; diff --git a/lang/en/lang.php b/lang/en/lang.php index 1764d5b..ee3617e 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -9,6 +9,7 @@ */ // custom language strings for the plugin +$lang['tagpageheading'] = 'TAG: %s'; $lang['tag'] = 'Tag'; $lang['tags'] = 'Tags'; $lang['topic'] = 'Topic'; From 192775ee4fad3dc4a17fabeb7edaef9e8531449c Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 19 Aug 2023 17:53:19 +0200 Subject: [PATCH 3/8] code reformatting --- action.php | 29 ++--- helper.php | 291 +++++++++++++++++++++++------------------- syntax/count.php | 71 +++++++---- syntax/searchtags.php | 78 ++++++----- syntax/tag.php | 53 +++++--- syntax/tagpage.php | 43 ++++--- syntax/topic.php | 53 +++++--- 7 files changed, 356 insertions(+), 262 deletions(-) diff --git a/action.php b/action.php index 2d3f7cd..df34b40 100644 --- a/action.php +++ b/action.php @@ -15,21 +15,21 @@ class action_plugin_tag extends DokuWiki_Action_Plugin { * @param Doku_Event_Handler $controller */ public function register(Doku_Event_Handler $controller) { - $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'catchTagAction', array()); - $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'performTagAction', array()); - $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'beautifyKeywordsInMetaHeader', array()); + $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'catchTagAction'); + $controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'performTagAction'); + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'beautifyKeywordsInMetaHeader'); if($this->getConf('toolbar_icon')) { - $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertToolbarButton', array ()); + $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertToolbarButton'); } - $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'setTagIndexversion', array()); - $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'addTagsToIndex', array()); + $controller->register_hook('INDEXER_VERSION_GET', 'BEFORE', $this, 'setTagIndexversion'); + $controller->register_hook('INDEXER_PAGE_ADD', 'BEFORE', $this, 'addTagsToIndex'); } /** * Add a version string to the index so it is rebuilt * whenever the stored data format changes. */ - public function setTagIndexversion(Doku_Event $event, $param) { + public function setTagIndexversion(Doku_Event $event) { global $conf; $event->data['plugin_tag'] = '0.2.deaccent='.$conf['deaccent']; } @@ -37,13 +37,13 @@ public function setTagIndexversion(Doku_Event $event, $param) { /** * Add all data of the subject metadata to the metadata index. */ - public function addTagsToIndex(Doku_Event $event, $param) { + public function addTagsToIndex(Doku_Event $event) { /* @var helper_plugin_tag $helper */ if ($helper = $this->loadHelper('tag')) { // make sure the tags are cleaned and no duplicate tags are added to the index $tags = p_get_metadata($event->data['page'], 'subject'); if (!is_array($tags)) { - $event->data['metadata']['subject'] = array(); + $event->data['metadata']['subject'] = []; } else { $event->data['metadata']['subject'] = $helper->cleanTagList($tags); } @@ -55,7 +55,7 @@ public function addTagsToIndex(Doku_Event $event, $param) { * * @author Michael Klier */ - public function catchTagAction(Doku_Event $event, $param) { + public function catchTagAction(Doku_Event $event) { if($event->data != 'showtag') return; $event->preventDefault(); } @@ -64,10 +64,9 @@ public function catchTagAction(Doku_Event $event, $param) { * Display the tag page * * @param Doku_Event $event The TPL_ACT_UNKNOWN event - * @param array $param optional parameters (unused) * @return void */ - public function performTagAction(Doku_Event $event, $param) { + public function performTagAction(Doku_Event $event) { global $lang, $INPUT; if($event->data != 'showtag') return; @@ -98,10 +97,10 @@ public function performTagAction(Doku_Event $event, $param) { $pagelist->addPage($page); } - print '
' . DOKU_LF; print '

'. sprintf($this->getLang('tagpageheading'), hsc(str_replace('_', ' ', $INPUT->str('tag')))) . '

'; + print '
'; print $pagelist->finishList(); - print '
' . DOKU_LF; + print '
'; } else { print '

' . $lang['nothingfound'] . '

'; @@ -111,7 +110,7 @@ public function performTagAction(Doku_Event $event, $param) { /** * Inserts the tag toolbar button */ - public function insertToolbarButton(Doku_Event $event, $param) { + public function insertToolbarButton(Doku_Event $event) { $event->data[] = array( 'type' => 'format', 'title' => $this->getLang('toolbar_icon'), diff --git a/helper.php b/helper.php index 1f67fbb..6412a60 100644 --- a/helper.php +++ b/helper.php @@ -10,7 +10,8 @@ /** * Helper part of the tag plugin, allows to query and print tags */ -class helper_plugin_tag extends DokuWiki_Plugin { +class helper_plugin_tag extends DokuWiki_Plugin +{ /** * @deprecated 2022-10-02 Use the helper_plugin_tag::getNamespace() function instead! @@ -29,12 +30,13 @@ class helper_plugin_tag extends DokuWiki_Plugin { * @var array * @deprecated 2022-08-31 Not used/filled any more by tag plugin */ - var $topic_idx = []; + var $topic_idx = []; /** * Constructor gets default preferences and language strings */ - public function __construct() { + public function __construct() + { global $ID; $this->namespace = $this->getConf('namespace'); @@ -50,62 +52,63 @@ public function __construct() { * * @return array Method description */ - public function getMethods() { + public function getMethods() + { $result = []; $result[] = [ - 'name' => 'overrideSortFlags', - 'desc' => 'takes an array of sortflags and overrides predefined value', + 'name' => 'overrideSortFlags', + 'desc' => 'takes an array of sortflags and overrides predefined value', 'params' => [ 'name' => 'string' ] ]; $result[] = [ - 'name' => 'th', - 'desc' => 'returns the header for the tags column for pagelist', - 'return' => ['header' => 'string'], + 'name' => 'th', + 'desc' => 'returns the header for the tags column for pagelist', + 'return' => ['header' => 'string'], ]; $result[] = [ - 'name' => 'td', - 'desc' => 'returns the tag links of a given page', - 'params' => ['id' => 'string'], - 'return' => ['links' => 'string'], + 'name' => 'td', + 'desc' => 'returns the tag links of a given page', + 'params' => ['id' => 'string'], + 'return' => ['links' => 'string'], ]; $result[] = [ - 'name' => 'tagLinks', - 'desc' => 'generates tag links for given words', - 'params' => ['tags' => 'array'], - 'return' => ['links' => 'string'], + 'name' => 'tagLinks', + 'desc' => 'generates tag links for given words', + 'params' => ['tags' => 'array'], + 'return' => ['links' => 'string'], ]; $result[] = [ - 'name' => 'getTopic', - 'desc' => 'returns a list of pages tagged with the given keyword', - 'params' => [ - 'namespace (optional)' => 'string', - 'number (not used)' => 'integer', - 'tag (required)' => 'string' - ], - 'return' => ['pages' => 'array'], + 'name' => 'getTopic', + 'desc' => 'returns a list of pages tagged with the given keyword', + 'params' => [ + 'namespace (optional)' => 'string', + 'number (not used)' => 'integer', + 'tag (required)' => 'string' + ], + 'return' => ['pages' => 'array'], ]; $result[] = [ - 'name' => 'tagRefine', - 'desc' => 'refines an array of pages with tags', - 'params' => [ - 'pages to refine' => 'array', - 'refinement tags' => 'string' - ], - 'return' => ['pages' => 'array'], + 'name' => 'tagRefine', + 'desc' => 'refines an array of pages with tags', + 'params' => [ + 'pages to refine' => 'array', + 'refinement tags' => 'string' + ], + 'return' => ['pages' => 'array'], ]; $result[] = [ - 'name' => 'tagOccurrences', - 'desc' => 'returns a list of tags with their number of occurrences', - 'params' => [ - 'list of tags to get the occurrences for' => 'array', - 'namespaces to which the search shall be restricted' => 'array', - 'if all tags shall be returned (then the first parameter is ignored)' => 'boolean', - 'if the namespaces shall be searched recursively' => 'boolean' - ], - 'return' => ['tags' => 'array'], + 'name' => 'tagOccurrences', + 'desc' => 'returns a list of tags with their number of occurrences', + 'params' => [ + 'list of tags to get the occurrences for' => 'array', + 'namespaces to which the search shall be restricted' => 'array', + 'if all tags shall be returned (then the first parameter is ignored)' => 'boolean', + 'if the namespaces shall be searched recursively' => 'boolean' + ], + 'return' => ['tags' => 'array'], ]; return $result; } @@ -118,11 +121,12 @@ public function getMethods() { * 'sortorder' => string * @return void */ - public function overrideSortFlags($newflags = []) { - if(isset($newflags['sortkey'])) { + public function overrideSortFlags($newflags = []) + { + if (isset($newflags['sortkey'])) { $this->sort = trim($newflags['sortkey']); } - if(isset($newflags['sortorder'])) { + if (isset($newflags['sortorder'])) { $this->sortorder = trim($newflags['sortorder']); } } @@ -130,7 +134,8 @@ public function overrideSortFlags($newflags = []) { /** * Returns the column header for the Pagelist Plugin */ - public function th() { + public function th() + { return $this->getLang('tags'); } @@ -140,7 +145,8 @@ public function th() { * @param string $id page id * @return string html content for cell of table */ - public function td($id) { + public function td($id) + { $subject = $this->getTagsFromPageMetadata($id); return $this->tagLinks($subject); } @@ -149,7 +155,8 @@ public function td($id) { * * @return string|false */ - public function getNamespace() { + public function getNamespace() + { return $this->namespace; } @@ -159,7 +166,8 @@ public function getNamespace() { * @param array $tags an array of tags * @return string HTML link tags */ - public function tagLinks($tags) { + public function tagLinks($tags) + { if (empty($tags) || ($tags[0] == '')) { return ''; } @@ -168,7 +176,7 @@ public function tagLinks($tags) { foreach ($tags as $tag) { $links[] = $this->tagLink($tag); } - return implode(','.DOKU_LF.DOKU_TAB, $links); + return implode(',' . DOKU_LF . DOKU_TAB, $links); } /** @@ -176,10 +184,11 @@ public function tagLinks($tags) { * * @param string $tag the tag the link shall point to * @param string $title the title of the link (optional) - * @param bool $dynamic if the link class shall be changed if no pages with the specified tag exist + * @param bool $dynamic if the link class shall be changed if no pages with the specified tag exist * @return string The HTML code of the link */ - public function tagLink($tag, $title = '', $dynamic = false) { + public function tagLink($tag, $title = '', $dynamic = false) + { global $conf; $svtag = $tag; $tagTitle = str_replace('_', ' ', noNS($tag)); @@ -194,7 +203,7 @@ public function tagLink($tag, $title = '', $dynamic = false) { } if ($exists) { $class = 'wikilink1'; - $url = wl($tag); + $url = wl($tag); if ($conf['useheading']) { // important: set render param to false to prevent recursion! $heading = p_get_first_heading($tag, false); @@ -213,7 +222,7 @@ public function tagLink($tag, $title = '', $dynamic = false) { } else { $class = 'wikilink1'; } - $url = wl($tag, ['do'=>'showtag', 'tag'=>$svtag]); + $url = wl($tag, ['do' => 'showtag', 'tag' => $svtag]); } if (!$title) { $title = $tagTitle; @@ -225,22 +234,23 @@ public function tagLink($tag, $title = '', $dynamic = false) { 'title' => hsc($title) ]; Event::createAndTrigger('PLUGIN_TAG_LINK', $link); - return ''; + return ''; } /** * Returns a list of pages with a certain tag; very similar to ft_backlinks() * * @param string $ns A namespace to which all pages need to belong, "." for only the root namespace - * @param int $num The maximum number of pages that shall be returned + * @param int $num The maximum number of pages that shall be returned * @param string $tagquery The tag string that shall be searched e.g. 'tag +tag -tag' * @return array The list of pages * * @author Esther Brunner */ - public function getTopic($ns = '', $num = null, $tagquery = '') { + public function getTopic($ns = '', $num = null, $tagquery = '') + { global $INPUT; if (!$tagquery) { $tagquery = $INPUT->str('tag'); @@ -256,9 +266,9 @@ public function getTopic($ns = '', $num = null, $tagquery = '') { foreach ($pages as $page) { // exclude pages depending on ACL and namespace - if($this->isNotVisible($page, $ns)) continue; + if ($this->isNotVisible($page, $ns)) continue; - $pageTags = $this->getTagsFromPageMetadata($page); + $pageTags = $this->getTagsFromPageMetadata($page); // don't trust index if (!$this->matchWithPageTags($pageTags, $queryTags)) continue; @@ -272,18 +282,18 @@ public function getTopic($ns = '', $num = null, $tagquery = '') { if ($isDraft && $perm < AUTH_CREATE) continue; $title = $meta['title'] ?? ''; - $date = ($this->sort == 'mdate' ? $meta['date']['modified'] : $meta['date']['created'] ); + $date = ($this->sort == 'mdate' ? $meta['date']['modified'] : $meta['date']['created']); $taglinks = $this->tagLinks($pageTags); // determine the sort key - switch($this->sort) { + switch ($this->sort) { case 'id': $sortkey = $page; break; case 'ns': $pos = strrpos($page, ':'); if ($pos === false) { - $sortkey = "\0".$page; + $sortkey = "\0" . $page; } else { $sortkey = substr_replace($page, "\0\0", $pos, 1); } @@ -305,16 +315,16 @@ public function getTopic($ns = '', $num = null, $tagquery = '') { $sortkey = $this->uniqueKey($sortkey, $result); $result[$sortkey] = [ - 'id' => $page, - 'title' => $title, - 'date' => $date, - 'user' => $meta['creator'], - 'desc' => $meta['description']['abstract'], - 'cat' => $pageTags[0], - 'tags' => $taglinks, - 'perm' => $perm, - 'exists' => true, - 'draft' => $isDraft + 'id' => $page, + 'title' => $title, + 'date' => $date, + 'user' => $meta['creator'], + 'desc' => $meta['description']['abstract'], + 'cat' => $pageTags[0], + 'tags' => $taglinks, + 'perm' => $perm, + 'exists' => true, + 'draft' => $isDraft ]; if ($num && count($result) >= $num) { @@ -339,7 +349,8 @@ public function getTopic($ns = '', $num = null, $tagquery = '') { * @param string $tagquery The list of tags in the form "tag +tag2 -tag3". The tags will be cleaned. * @return array The filtered list of pages */ - public function tagRefine($pages, $tagquery) { + public function tagRefine($pages, $tagquery) + { if (!is_array($pages)) { // wrong data type return $pages; @@ -354,27 +365,28 @@ public function tagRefine($pages, $tagquery) { } return $pages; - } - - /** - * Get count of occurrences for a list of tags - * - * @param array $tags array of tags - * @param array $namespaces array of namespaces where to count the tags - * @param boolean $allTags boolean if all available tags should be counted - * @param boolean $isRecursive boolean if counting of pages in subnamespaces is allowed - * @return array with: - * $tag => int count - */ - public function tagOccurrences($tags, $namespaces = null, $allTags = false, $isRecursive = null) { + } + + /** + * Get count of occurrences for a list of tags + * + * @param array $tags array of tags + * @param array $namespaces array of namespaces where to count the tags + * @param boolean $allTags boolean if all available tags should be counted + * @param boolean $isRecursive boolean if counting of pages in subnamespaces is allowed + * @return array with: + * $tag => int count + */ + public function tagOccurrences($tags, $namespaces = null, $allTags = false, $isRecursive = null) + { // map with trim here in order to remove newlines from tags - if($allTags) { + if ($allTags) { $tags = array_map('trim', idx_getIndex('subject', '_w')); } $tags = $this->cleanTagList($tags); $tagOccurrences = []; //occurrences // $namespaces not specified - if(!$namespaces || $namespaces[0] == '' || !is_array($namespaces)) { + if (!$namespaces || $namespaces[0] == '' || !is_array($namespaces)) { $namespaces = null; } @@ -414,8 +426,8 @@ public function tagOccurrences($tags, $namespaces = null, $allTags = false, $isR $tagOccurrences[$tag] = 0; foreach ($pages as $page) { foreach ($namespaces as $ns) { - if(strpos($page, $ns.':') === 0 ) { - $tagOccurrences[$tag]++ ; + if (strpos($page, $ns . ':') === 0) { + $tagOccurrences[$tag]++; break; } } @@ -435,7 +447,8 @@ public function tagOccurrences($tags, $namespaces = null, $allTags = false, $isR * @param string $id the page id * @return array */ - protected function getTagsFromPageMetadata($id){ + protected function getTagsFromPageMetadata($id) + { $tags = p_get_metadata($id, 'subject'); if (!is_array($tags)) { $tags = explode(' ', $tags); @@ -449,7 +462,8 @@ protected function getTagsFromPageMetadata($id){ * @param array $queryTags the tags to filter e.g. ['tag'(OR), '+tag'(AND), '-tag'(NOT)] * @return array the matching page ids */ - public function getIndexedPagesMatchingTagQuery($queryTags) { + public function getIndexedPagesMatchingTagQuery($queryTags) + { $result = []; // array of page ids $cleanTags = []; @@ -487,7 +501,6 @@ public function getIndexedPagesMatchingTagQuery($queryTags) { } - /** * Splits a string into an array of tags * @@ -495,7 +508,8 @@ public function getIndexedPagesMatchingTagQuery($queryTags) { * @param bool $clean replace placeholders and clean id * @return string[] */ - public function parseTagList($tags, $clean = false) { + public function parseTagList($tags, $clean = false) + { // support for "quoted phrase tags", replaces spaces by underscores if (preg_match_all('#".*?"#', $tags, $matches)) { @@ -520,7 +534,8 @@ public function parseTagList($tags, $clean = false) { * @param string[] $tags * @return string[] */ - public function cleanTagList($tags) { + public function cleanTagList($tags) + { return array_unique(array_map([$this, 'cleanTag'], $tags)); } @@ -530,11 +545,12 @@ public function cleanTagList($tags) { * @param string $tag * @return string */ - protected function cleanTag($tag) { + protected function cleanTag($tag) + { $prefix = substr($tag, 0, 1); $tag = $this->replacePlaceholders($tag); if ($prefix === '-' || $prefix === '+') { - return $prefix.cleanID($tag); + return $prefix . cleanID($tag); } else { return cleanID($tag); } @@ -546,28 +562,29 @@ protected function cleanTag($tag) { * @param string $tag * @return string */ - protected function replacePlaceholders($tag) { + protected function replacePlaceholders($tag) + { global $USERINFO, $INPUT; $user = $INPUT->server->str('REMOTE_USER'); //only available for logged-in users - if($USERINFO) { - $name = cleanID($USERINFO['name']); + if ($USERINFO) { + $name = cleanID($USERINFO['name']); // FIXME or delete, is unreliable because just first entry of group array is used, regardless the order of groups.. $group = cleanID($USERINFO['grps'][0]); } else { - $name = ''; + $name = ''; $group = ''; } $replace = [ - '@USER@' => cleanID($user), - '@NAME@' => $name, - '@GROUP@' => $group, - '@YEAR@' => date('Y'), - '@MONTH@' => date('m'), - '@DAY@' => date('d'), + '@USER@' => cleanID($user), + '@NAME@' => $name, + '@GROUP@' => $group, + '@YEAR@' => date('Y'), + '@MONTH@' => date('m'), + '@DAY@' => date('d'), ]; return str_replace(array_keys($replace), array_values($replace), $tag); } @@ -582,7 +599,8 @@ protected function replacePlaceholders($tag) { * @author Ilya S. Lebedev * @author Esther Brunner */ - protected function uniqueKey($key, $result) { + protected function uniqueKey($key, $result) + { // increase numeric keys by one if (is_numeric($key)) { @@ -593,10 +611,10 @@ protected function uniqueKey($key, $result) { // append a number to literal keys } else { - $num = 0; + $num = 0; $testkey = $key; while (array_key_exists($testkey, $result)) { - $testkey = $key.$num; + $testkey = $key . $num; $num++; } return $testkey; @@ -610,7 +628,8 @@ protected function uniqueKey($key, $result) { * @param string $ns * @return bool if the page is shown */ - public function isVisible($id, $ns='') { + public function isVisible($id, $ns = '') + { return !$this->isNotVisible($id, $ns); } @@ -621,7 +640,8 @@ public function isVisible($id, $ns='') { * @param string $ns the namespace authorized * @return bool if the page is hidden */ - public function isNotVisible($id, $ns="") { + public function isNotVisible($id, $ns = "") + { // discard hidden pages if (isHiddenPage($id)) { return true; @@ -632,14 +652,14 @@ public function isNotVisible($id, $ns="") { } // filter by namespace, root namespace is identified with a dot - if($ns == '.') { + if ($ns == '.') { // root namespace is specified, discard all pages who lay outside the root namespace - if(getNS($id) !== false) { + if (getNS($id) !== false) { return true; } } else { // hide if ns is not matching the page id (match gives strpos===0) - if ($ns && strpos(':'.getNS($id).':', ':'.$ns.':') !== 0) { + if ($ns && strpos(':' . getNS($id) . ':', ':' . $ns . ':') !== 0) { return true; } } @@ -653,7 +673,8 @@ public function isNotVisible($id, $ns="") { * @param string $tag2 tag from index * @return bool is equal? */ - public function tagCompare($tag1, $tag2) { + public function tagCompare($tag1, $tag2) + { return $tag1 === $tag2; } @@ -664,9 +685,10 @@ public function tagCompare($tag1, $tag2) { * @param string[] $queryTags tags we are looking ['tag', '+tag', '-tag'] * @return bool */ - protected function matchWithPageTags($pageTags, $queryTags) { + protected function matchWithPageTags($pageTags, $queryTags) + { $result = false; - foreach($queryTags as $tag) { + foreach ($queryTags as $tag) { if ($tag[0] == "+" and !in_array(substr($tag, 1), $pageTags)) { $result = false; } @@ -682,38 +704,41 @@ protected function matchWithPageTags($pageTags, $queryTags) { /** - * @deprecated 2022-08-31 use parseTagList() instead ! - * * @param string $tags * @param bool $clean * @return string[] + * @deprecated 2022-08-31 use parseTagList() instead ! + * */ - public function _parseTagList($tags, $clean = false) { + public function _parseTagList($tags, $clean = false) + { return $this->parseTagList($tags, $clean); } /** * Opposite of isNotVisible() * - * @deprecated 2022-08-31 use isVisible() instead ! - * * @param string $id * @param string $ns * @return bool + * @deprecated 2022-08-31 use isVisible() instead ! + * */ - public function _isVisible($id, $ns='') { + public function _isVisible($id, $ns = '') + { return $this->isVisible($id, $ns); } /** * Clean a list (array) of tags using _cleanTag * - * @deprecated 2022-08-31 use cleanTagList() instead ! - * * @param string[] $tags * @return string[] + * @deprecated 2022-08-31 use cleanTagList() instead ! + * */ - public function _cleanTagList($tags) { + public function _cleanTagList($tags) + { return $this->cleanTagList($tags); } @@ -725,19 +750,21 @@ public function _cleanTagList($tags) { * * @deprecated 2022-08-31 use getIndexedPagesMatchingTagQuery() instead ! */ - function _tagIndexLookup($queryTags) { + function _tagIndexLookup($queryTags) + { return $this->getIndexedPagesMatchingTagQuery($queryTags); } /** * Get the subject metadata cleaning the result * - * @deprecated 2022-08-31 use getTagsFromPageMetadata() instead ! - * * @param string $id the page id * @return array + * @deprecated 2022-08-31 use getTagsFromPageMetadata() instead ! + * */ - public function _getSubjectMetadata($id){ + public function _getSubjectMetadata($id) + { return $this->getTagsFromPageMetadata($id); } } diff --git a/syntax/count.php b/syntax/count.php index dffd4ce..b0f3399 100644 --- a/syntax/count.php +++ b/syntax/count.php @@ -11,25 +11,38 @@ */ /** Count syntax, allows to list tag counts */ -class syntax_plugin_tag_count extends DokuWiki_Syntax_Plugin { +class syntax_plugin_tag_count extends DokuWiki_Syntax_Plugin +{ /** * @return string Syntax type */ - function getType() { return 'substition'; } + function getType() + { + return 'substition'; + } + /** * @return int Sort order */ - function getSort() { return 305; } + function getSort() + { + return 305; + } + /** * @return string Paragraph type */ - function getPType() { return 'block';} + function getPType() + { + return 'block'; + } /** * @param string $mode Parser mode */ - function connectTo($mode) { + function connectTo($mode) + { $this->Lexer->addSpecialPattern('\{\{count>.*?\}\}', $mode, 'plugin_tag_count'); } @@ -37,18 +50,19 @@ function connectTo($mode) { * Handle matches of the count syntax * * @param string $match The match of the syntax - * @param int $state The state of the handler - * @param int $pos The position in the document - * @param Doku_Handler $handler The handler + * @param int $state The state of the handler + * @param int $pos The position in the document + * @param Doku_Handler $handler The handler * @return array|false Data for the renderer */ - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { $match = trim(substr($match, 8, -2)); // get given tags - [$tags, $nsstring] = array_pad(explode('&', $match,2),2,''); // split to tags and allowed namespaces + [$tags, $nsstring] = array_pad(explode('&', $match, 2), 2, ''); // split to tags and allowed namespaces $allowedNamespaces = explode(' ', $nsstring); // split given namespaces into an array - if($allowedNamespaces && $allowedNamespaces[0] == '') { + if ($allowedNamespaces && $allowedNamespaces[0] == '') { unset($allowedNamespaces[0]); // When exists, remove leading space after the delimiter $allowedNamespaces = array_values($allowedNamespaces); } @@ -62,7 +76,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { } /** @var helper_plugin_tag $helper */ - if(!($helper = $this->loadHelper('tag'))) { + if (!($helper = $this->loadHelper('tag'))) { return false; } @@ -75,12 +89,13 @@ function handle($match, $state, $pos, Doku_Handler $handler) { /** * Render xhtml output or metadata * - * @param string $format Renderer mode (supported modes: xhtml and metadata) - * @param Doku_Renderer $renderer The renderer - * @param array $data The data from the handler function + * @param string $format Renderer mode (supported modes: xhtml and metadata) + * @param Doku_Renderer $renderer The renderer + * @param array $data The data from the handler function * @return bool If rendering was successful. */ - function render($format, Doku_Renderer $renderer, $data) { + function render($format, Doku_Renderer $renderer, $data) + { if ($data === false) return false; list($tags, $allowedNamespaces) = $data; @@ -89,12 +104,12 @@ function render($format, Doku_Renderer $renderer, $data) { // implemented for the count syntax $renderer->nocache(); - if($format == "xhtml") { + if ($format == "xhtml") { /** @var helper_plugin_tag $helper */ - if(!($helper = $this->loadHelper('tag'))) return false; + if (!($helper = $this->loadHelper('tag'))) return false; // get tags and their occurrences - if($tags[0] == '+') { + if ($tags[0] == '+') { // no tags given, list all tags for allowed namespaces $occurrences = $helper->tagOccurrences($tags, $allowedNamespaces, true); } else { @@ -104,24 +119,24 @@ function render($format, Doku_Renderer $renderer, $data) { $class = "inline"; // valid: inline, ul, pagelist $col = "page"; - $renderer->doc .= ''; + $renderer->doc .= '
'; $renderer->doc .= ''; - $renderer->doc .= ''; - $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; $renderer->doc .= ''; - if(empty($occurrences)) { + if (empty($occurrences)) { // Skip output $renderer->doc .= ''; - $renderer->doc .= ''; + $renderer->doc .= ''; $renderer->doc .= ''; } else { - foreach($occurrences as $tagname => $count) { - if($count <= 0) continue; // don't display tags with zero occurrences + foreach ($occurrences as $tagname => $count) { + if ($count <= 0) continue; // don't display tags with zero occurrences $renderer->doc .= ''; - $renderer->doc .= ''; - $renderer->doc .= ''; + $renderer->doc .= ''; + $renderer->doc .= ''; $renderer->doc .= ''; } } diff --git a/syntax/searchtags.php b/syntax/searchtags.php index a75dda1..f7cb7e6 100644 --- a/syntax/searchtags.php +++ b/syntax/searchtags.php @@ -10,41 +10,53 @@ /** * Tagsearch syntax, displays a tag search form with results similar to the topic syntax */ -class syntax_plugin_tag_searchtags extends DokuWiki_Syntax_Plugin { +class syntax_plugin_tag_searchtags extends DokuWiki_Syntax_Plugin +{ /** * @return string Syntax type */ - function getType() { return 'substition'; } + function getType() + { + return 'substition'; + } /** * @return string Paragraph type */ - function getPType() { return 'block'; } + function getPType() + { + return 'block'; + } /** * @return int Sort order */ - function getSort() { return 295; } + function getSort() + { + return 295; + } /** * @param string $mode Parser mode */ - function connectTo($mode) { - $this->Lexer->addSpecialPattern('\{\{searchtags}}', $mode,'plugin_tag_searchtags'); + function connectTo($mode) + { + $this->Lexer->addSpecialPattern('\{\{searchtags}}', $mode, 'plugin_tag_searchtags'); // make sure that flags really start with & and media files starting with "searchtags" still work - $this->Lexer->addSpecialPattern('\{\{searchtags&.*?\}\}',$mode,'plugin_tag_searchtags'); + $this->Lexer->addSpecialPattern('\{\{searchtags&.*?\}\}', $mode, 'plugin_tag_searchtags'); } /** * Handle matches of the searchtags syntax * * @param string $match The match of the syntax - * @param int $state The state of the handler - * @param int $pos The position in the document - * @param Doku_Handler $handler The handler + * @param int $state The state of the handler + * @param int $pos The position in the document + * @param Doku_Handler $handler The handler * @return array Data for the renderer */ - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { $flags = substr($match, 12, -2); // strip {{searchtags from start and }} from end // remove empty flags by using array_filter (removes elements == false) return array_filter(explode('&', $flags)); @@ -53,12 +65,13 @@ function handle($match, $state, $pos, Doku_Handler $handler) { /** * Render xhtml output or metadata * - * @param string $format Renderer mode (supported modes: xhtml and metadata) - * @param Doku_Renderer $renderer The renderer - * @param array $data The data from the handler function + * @param string $format Renderer mode (supported modes: xhtml and metadata) + * @param Doku_Renderer $renderer The renderer + * @param array $data The data from the handler function * @return bool If rendering was successful. */ - function render($format, Doku_Renderer $renderer, $data) { + function render($format, Doku_Renderer $renderer, $data) + { global $lang; $flags = $data; @@ -77,8 +90,8 @@ function render($format, Doku_Renderer $renderer, $data) { // Prepare the flags for the pagelist plugin $configflags = explode(',', str_replace(" ", "", $this->getConf('pagelist_flags'))); $flags = array_merge($configflags, $flags); - foreach($flags as $key => $flag) { - if($flag == "") { + foreach ($flags as $key => $flag) { + if ($flag == "") { unset($flags[$key]); } } @@ -123,13 +136,14 @@ function render($format, Doku_Renderer $renderer, $data) { * * @return string the HTML code of the search form */ - private function getForm($nonsform=false) { + private function getForm($nonsform = false) + { global $conf, $lang; if (!$nonsform) { // Get the list of all namespaces for the dropdown $namespaces = []; - search($namespaces,$conf['datadir'],'search_namespaces', []); + search($namespaces, $conf['datadir'], 'search_namespaces', []); // build the list in the form value => label from the namespace search result $ns_select = ['' => '']; @@ -200,13 +214,13 @@ private function getForm($nonsform=false) { $form->addElement(form_makeCloseTag('td')); $form->addElement(form_makeOpenTag('td')); $attr = array(); - if ($this->isSelected('-'.$tag)) { + if ($this->isSelected('-' . $tag)) { $attr['checked'] = 'checked'; } - $form->addElement(form_makeCheckboxField('plugin__tag_search_tags[]', '-'.$tag, '-', '', 'minus', $attr)); + $form->addElement(form_makeCheckboxField('plugin__tag_search_tags[]', '-' . $tag, '-', '', 'minus', $attr)); $form->addElement(form_makeCloseTag('td')); $form->addElement(form_makeOpenTag('td')); - $form->addElement(hsc($tag).' ['.$count.']'); + $form->addElement(hsc($tag) . ' [' . $count . ']'); $form->addElement(form_makeCloseTag('td')); $form->addElement(form_makeCloseTag('tr')); } @@ -228,7 +242,8 @@ private function getForm($nonsform=false) { * Returns the currently selected namespace * @return string the cleaned namespace id */ - private function getNS() { + private function getNS() + { global $INPUT; if ($INPUT->post->has('plugin__tag_search_namespace')) { return cleanID($INPUT->post->str('plugin__tag_search_namespace')); @@ -241,7 +256,8 @@ private function getNS() { * Returns the tag search string from the selected tags * @return string|null the tag search or null when no tags were selected */ - private function getTagSearchString() { + private function getTagSearchString() + { global $INPUT; if ($INPUT->post->has('plugin__tag_search_tags') && is_array($INPUT->post->param('plugin__tag_search_tags'))) { $tags = $INPUT->post->arr('plugin__tag_search_tags'); @@ -252,16 +268,16 @@ private function getTagSearchString() { foreach ($tags as $tag) { $tag = (string)$tag; if ($tag[0] == '-') { - $negative_tags .= $tag.' '; + $negative_tags .= $tag . ' '; } else { if ($positive_tags === '') { - $positive_tags = $tag.' '; + $positive_tags = $tag . ' '; } else { - $positive_tags .= $plus.$tag.' '; + $positive_tags .= $plus . $tag . ' '; } } } - return $positive_tags.$negative_tags; + return $positive_tags . $negative_tags; } else { return null; // return NULL when no tags were selected so no results will be displayed } @@ -273,7 +289,8 @@ private function getTagSearchString() { * @param string $tag The tag to check * @return bool if the tag was checked */ - private function isSelected($tag) { + private function isSelected($tag) + { global $INPUT; if ($INPUT->post->has('plugin__tag_search_tags')) { return in_array($tag, $INPUT->post->arr('plugin__tag_search_tags'), true); @@ -287,7 +304,8 @@ private function isSelected($tag) { * * @return bool if the query should use AND */ - private function useAnd() { + private function useAnd() + { global $INPUT; return $INPUT->post->has('plugin__tag_search_and'); } diff --git a/syntax/tag.php b/syntax/tag.php index 4d454ae..c9af244 100644 --- a/syntax/tag.php +++ b/syntax/tag.php @@ -13,25 +13,38 @@ /** * Tag syntax plugin, allows to specify tags in a page */ -class syntax_plugin_tag_tag extends DokuWiki_Syntax_Plugin { +class syntax_plugin_tag_tag extends DokuWiki_Syntax_Plugin +{ /** * @return string Syntax type */ - function getType() { return 'substition'; } + function getType() + { + return 'substition'; + } + /** * @return int Sort order */ - function getSort() { return 305; } + function getSort() + { + return 305; + } + /** * @return string Paragraph type */ - function getPType() { return 'block';} + function getPType() + { + return 'block'; + } /** * @param string $mode Parser mode */ - function connectTo($mode) { + function connectTo($mode) + { $this->Lexer->addSpecialPattern('\{\{tag>.*?\}\}', $mode, 'plugin_tag_tag'); } @@ -39,12 +52,13 @@ function connectTo($mode) { * Handle matches of the tag syntax * * @param string $match The match of the syntax - * @param int $state The state of the handler - * @param int $pos The position in the document - * @param Doku_Handler $handler The handler + * @param int $state The state of the handler + * @param int $pos The position in the document + * @param Doku_Handler $handler The handler * @return array|false Data for the renderer */ - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { $tags = trim(substr($match, 6, -2)); // strip markup & whitespace $tags = trim($tags, "\xe2\x80\x8b"); // strip word/wordpad breaklines $tags = preg_replace(['/[[:blank:]]+/', '/\s+/'], " ", $tags); // replace linebreaks and multiple spaces with one space character @@ -65,12 +79,13 @@ function handle($match, $state, $pos, Doku_Handler $handler) { /** * Render xhtml output or metadata * - * @param string $format Renderer mode (supported modes: xhtml and metadata) - * @param Doku_Renderer $renderer The renderer - * @param array $data The data from the handler function + * @param string $format Renderer mode (supported modes: xhtml and metadata) + * @param Doku_Renderer $renderer The renderer + * @param array $data The data from the handler function * @return bool If rendering was successful. */ - function render($format, Doku_Renderer $renderer, $data) { + function render($format, Doku_Renderer $renderer, $data) + { if ($data === false) return false; /** @var helper_plugin_tag $helper */ if (!$helper = $this->loadHelper('tag')) return false; @@ -81,14 +96,14 @@ function render($format, Doku_Renderer $renderer, $data) { if (!$tags) { return true; } - $renderer->doc .= '
' - . ''.DOKU_LF - . DOKU_TAB.$tags.DOKU_LF + $renderer->doc .= '
' + . '' . DOKU_LF + . DOKU_TAB . $tags . DOKU_LF . '' - . '
'.DOKU_LF; + . '
' . DOKU_LF; return true; - // for metadata renderer + // for metadata renderer } elseif ($format == 'metadata') { /** @var Doku_Renderer_metadata $renderer */ // erase tags on persistent metadata no more used @@ -107,7 +122,7 @@ function render($format, Doku_Renderer $renderer, $data) { $renderer->meta['subject'] = array_unique(array_merge($renderer->meta['subject'], $data)); if ($renderer->capture) { - $renderer->doc .= DOKU_LF.implode(' ', $data).DOKU_LF; + $renderer->doc .= DOKU_LF . implode(' ', $data) . DOKU_LF; } // add references if tag page exists diff --git a/syntax/tagpage.php b/syntax/tagpage.php index 6f3a8e8..71d9a4b 100644 --- a/syntax/tagpage.php +++ b/syntax/tagpage.php @@ -9,46 +9,52 @@ */ /** Tagpage syntax, allows to link to a given tag */ -class syntax_plugin_tag_tagpage extends DokuWiki_Syntax_Plugin { +class syntax_plugin_tag_tagpage extends DokuWiki_Syntax_Plugin +{ /** * @return string Syntax type */ - function getType() { + function getType() + { return 'substition'; } /** * @return int Sort order */ - function getSort() { + function getSort() + { return 305; } /** * @return string Paragraph type */ - function getPType() { + function getPType() + { return 'normal'; } /** * @param string $mode Parser mode */ - function connectTo($mode) { + function connectTo($mode) + { $this->Lexer->addSpecialPattern('\{\{tagpage>.*?\}\}', $mode, 'plugin_tag_tagpage'); } /** * Handle matches of the count syntax * - * @param string $match The match of the syntax - * @param int $state The state of the handler - * @param int $pos The position in the document - * @param Doku_Handler $handler The handler + * @param string $match The match of the syntax + * @param int $state The state of the handler + * @param int $pos The position in the document + * @param Doku_Handler $handler The handler * @return array Data for the renderer */ - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { $params = []; $match = trim(substr($match, 10, -2)); // get given tag $match = array_pad(explode('|', $match, 2), 2, ''); // split to tags, link name and options @@ -63,23 +69,24 @@ function handle($match, $state, $pos, Doku_Handler $handler) { /** * Render xhtml output * - * @param string $format Renderer mode (supported modes: xhtml) - * @param Doku_Renderer $renderer The renderer - * @param array $data The data from the handler function + * @param string $format Renderer mode (supported modes: xhtml) + * @param Doku_Renderer $renderer The renderer + * @param array $data The data from the handler function * @return bool If rendering was successful. */ - function render($format, Doku_Renderer $renderer, $data) { - if($data['tag'] === '') return false; + function render($format, Doku_Renderer $renderer, $data) + { + if ($data['tag'] === '') return false; - if($format == "xhtml") { - if($data['dynamic']) { + if ($format == "xhtml") { + if ($data['dynamic']) { // deactivate (renderer) cache as long as there is no proper cache handling // implemented for the count syntax $renderer->nocache(); } /** @var helper_plugin_tag $helper */ - if(!$helper = $this->loadHelper('tag')) { + if (!$helper = $this->loadHelper('tag')) { return false; } diff --git a/syntax/topic.php b/syntax/topic.php index b229275..b0d760e 100644 --- a/syntax/topic.php +++ b/syntax/topic.php @@ -9,42 +9,54 @@ /** * Topic syntax, displays links to all wiki pages with a certain tag */ -class syntax_plugin_tag_topic extends DokuWiki_Syntax_Plugin { +class syntax_plugin_tag_topic extends DokuWiki_Syntax_Plugin +{ /** * @return string Syntax type */ - function getType() { return 'substition'; } + function getType() + { + return 'substition'; + } /** * @return string Paragraph type */ - function getPType() { return 'block'; } + function getPType() + { + return 'block'; + } /** * @return int Sort order */ - function getSort() { return 295; } + function getSort() + { + return 295; + } /** * @param string $mode Parser mode */ - function connectTo($mode) { + function connectTo($mode) + { //syntax without options catches wrong used syntax too - $this->Lexer->addSpecialPattern('\{\{topic>}\}',$mode,'plugin_tag_topic'); - $this->Lexer->addSpecialPattern('\{\{topic>.+?\}\}',$mode,'plugin_tag_topic'); + $this->Lexer->addSpecialPattern('\{\{topic>}\}', $mode, 'plugin_tag_topic'); + $this->Lexer->addSpecialPattern('\{\{topic>.+?\}\}', $mode, 'plugin_tag_topic'); } /** * Handle matches of the topic syntax * * @param string $match The match of the syntax - * @param int $state The state of the handler - * @param int $pos The position in the document - * @param Doku_Handler $handler The handler + * @param int $state The state of the handler + * @param int $pos The position in the document + * @param Doku_Handler $handler The handler * @return array Data for the renderer */ - function handle($match, $state, $pos, Doku_Handler $handler) { + function handle($match, $state, $pos, Doku_Handler $handler) + { global $ID; $match = substr($match, 8, -2); // strip {{topic> from start and }} from end list($match, $flags) = array_pad(explode('&', $match, 2), 2, ''); @@ -53,7 +65,7 @@ function handle($match, $state, $pos, Doku_Handler $handler) { if (!$tag) { $tag = $ns; - $ns = ''; + $ns = ''; } if ($ns == '*' || $ns == ':') { @@ -70,26 +82,27 @@ function handle($match, $state, $pos, Doku_Handler $handler) { /** * Render xhtml output or metadata * - * @param string $format Renderer mode (supported modes: xhtml and metadata) - * @param Doku_Renderer $renderer The renderer - * @param array $data The data from the handler function + * @param string $format Renderer mode (supported modes: xhtml and metadata) + * @param Doku_Renderer $renderer The renderer + * @param array $data The data from the handler function * @return bool If rendering was successful. */ - function render($format, Doku_Renderer $renderer, $data) { + function render($format, Doku_Renderer $renderer, $data) + { list($ns, $tag, $flags) = $data; /* extract sort flags into array */ $sortflags = []; - foreach($flags as $flag) { + foreach ($flags as $flag) { $separator_pos = strpos($flag, '='); if ($separator_pos === false) { continue; // no "=" found, skip to next flag } - $conf_name = trim(strtolower(substr($flag, 0 , $separator_pos))); - $conf_val = trim(strtolower(substr($flag, $separator_pos+1))); + $conf_name = trim(strtolower(substr($flag, 0, $separator_pos))); + $conf_val = trim(strtolower(substr($flag, $separator_pos + 1))); - if(in_array($conf_name, ['sortkey', 'sortorder'])) { + if (in_array($conf_name, ['sortkey', 'sortorder'])) { $sortflags[$conf_name] = $conf_val; } } From bf27ea7af0212382156a81a235d2102a35411658 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 19 Aug 2023 18:03:45 +0200 Subject: [PATCH 4/8] Fixes rtl issues Fixes #246 --- helper.php | 2 +- style.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helper.php b/helper.php index 6412a60..7558dfe 100644 --- a/helper.php +++ b/helper.php @@ -176,7 +176,7 @@ public function tagLinks($tags) foreach ($tags as $tag) { $links[] = $this->tagLink($tag); } - return implode(',' . DOKU_LF . DOKU_TAB, $links); + return implode(',' . DOKU_LF, $links); } /** diff --git a/style.css b/style.css index 39b7f1a..aefd296 100644 --- a/style.css +++ b/style.css @@ -1,7 +1,7 @@ div.dokuwiki div.tags, div.dokuwiki div.tagstop { font-size: 95%; - text-align: right; + text-align: end; } div.dokuwiki div.tags { From ef93eb29c8caaa38aae2cfb27ab643bce98e97ac Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sat, 19 Aug 2023 20:58:50 +0200 Subject: [PATCH 5/8] sort tag cloud by tag name Fixes #195 and #189 --- helper.php | 2 ++ syntax/searchtags.php | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/helper.php b/helper.php index 7558dfe..076aa12 100644 --- a/helper.php +++ b/helper.php @@ -6,6 +6,7 @@ use dokuwiki\Extension\Event; use dokuwiki\Utf8\PhpString; +use dokuwiki\Utf8\Sort; /** * Helper part of the tag plugin, allows to query and print tags @@ -438,6 +439,7 @@ public function tagOccurrences($tags, $namespaces = null, $allTags = false, $isR unset($tagOccurrences[$tag]); } } + Sort::ksort($tagOccurrences); return $tagOccurrences; } diff --git a/syntax/searchtags.php b/syntax/searchtags.php index f7cb7e6..7ab2fcc 100644 --- a/syntax/searchtags.php +++ b/syntax/searchtags.php @@ -177,8 +177,6 @@ private function getForm($nonsform = false) if ($my = $this->loadHelper('tag')) { $tags = $my->tagOccurrences(array(), NULL, true); } - // sort tags by name ($tags is in the form $tag => $count) - ksort($tags); // display error message when no tags were found if (!isset($tags) || $tags == NULL) { From 5871336d5a4a0d866e205c68a910bc2ee37273bb Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Fri, 25 Aug 2023 23:19:55 +0200 Subject: [PATCH 6/8] replace trim() by str_replace for cleaning U+200b (zero width space) Fixes #250 --- syntax/tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/tag.php b/syntax/tag.php index c9af244..384e00c 100644 --- a/syntax/tag.php +++ b/syntax/tag.php @@ -60,7 +60,7 @@ function connectTo($mode) function handle($match, $state, $pos, Doku_Handler $handler) { $tags = trim(substr($match, 6, -2)); // strip markup & whitespace - $tags = trim($tags, "\xe2\x80\x8b"); // strip word/wordpad breaklines + $tags = str_replace("\xe2\x80\x8b", '', $tags); // strip word/wordpad breaklines(U+200b) $tags = preg_replace(['/[[:blank:]]+/', '/\s+/'], " ", $tags); // replace linebreaks and multiple spaces with one space character $tags = preg_replace('/[\x00-\x1F\x7F]/u', '', $tags); // strip unprintable ascii code out of utf-8 coded string From 406c3998d4e775d94ed59787e5086f37f40db269 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 28 Aug 2023 21:15:35 +0200 Subject: [PATCH 7/8] add class `tag_count_table` to the count table Fixes #123 --- syntax/count.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/count.php b/syntax/count.php index b0f3399..575f94d 100644 --- a/syntax/count.php +++ b/syntax/count.php @@ -116,7 +116,7 @@ function render($format, Doku_Renderer $renderer, $data) $occurrences = $helper->tagOccurrences($tags, $allowedNamespaces); } - $class = "inline"; // valid: inline, ul, pagelist + $class = "tag_count_table inline"; // valid: inline, ul, pagelist $col = "page"; $renderer->doc .= '
'.$this->getLang('tag').''.$this->getLang('count').'' . $this->getLang('tag') . '' . $this->getLang('count') . '
'.$this->getLang('empty_output').'' . $this->getLang('empty_output') . '
'.$helper->tagLink($tagname).''.$count.'' . $helper->tagLink($tagname) . '' . $count . '
'; From d62d79114a548b69495b91136b6cc55e9eea48a7 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Mon, 28 Aug 2023 23:11:16 +0200 Subject: [PATCH 8/8] only on table, not rows --- syntax/count.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/count.php b/syntax/count.php index 575f94d..5f882f8 100644 --- a/syntax/count.php +++ b/syntax/count.php @@ -116,10 +116,10 @@ function render($format, Doku_Renderer $renderer, $data) $occurrences = $helper->tagOccurrences($tags, $allowedNamespaces); } - $class = "tag_count_table inline"; // valid: inline, ul, pagelist + $class = "inline"; // valid: inline, ul, pagelist $col = "page"; - $renderer->doc .= '
'; + $renderer->doc .= '
'; $renderer->doc .= ''; $renderer->doc .= ''; $renderer->doc .= '';
' . $this->getLang('tag') . '' . $this->getLang('count') . '