[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] Plugin consolidation: Deprecate ShowPages & TitleSearch in favor of ListPages

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <696aa6f7a4f83_2c181708987c0@gitlab-sidekiq-low-urgency-cpu-bound-v2-dbc59874-bznzd.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
20deb3f8 by Moïse Nturubika at 2026-01-16T20:52:18+00:00
[ENH] Plugin consolidation: Deprecate ShowPages & TitleSearch in favor of ListPages
---
* [REF] ParserLib: Unify default params logic with WikiPlugin_Helper

* [FIX] PluginTitleSearch: Preserve legacy list view behavior

* [REF] Consolidate ShowPages and TitleSearch into ListPages

* [ENH] Plugin consolidation: Deprecate ShowPages & TitleSearch in favor of ListPages

See merge request tikiwiki/tiki!9267

- - - - -


4 changed files:

- lib/core/WikiPlugin/Helper.php
- lib/parser/parserlib.php
- lib/wiki-plugins/wikiplugin_showpages.php
- lib/wiki-plugins/wikiplugin_titlesearch.php


Changes:

=====================================
lib/core/WikiPlugin/Helper.php
=====================================
@@ -60,4 +60,28 @@ class WikiPlugin_Helper
 
         return $result;
     }
+
+    /**
+     * Apply default parameters from plugin info
+     *
+     * @param array $params Parameter values
+     * @param array $info Plugin info
+     * @return array Updated parameters with defaults
+     */
+    public static function applyParamsDefaults($params, $info)
+    {
+        if (isset($info['params'])) {
+            foreach ($info['params'] as $key => $param) {
+                if (! isset($params[$key])) {
+                    if (isset($param['default'])) {
+                        $params[$key] = $param['default'];
+                    } else {
+                        $params[$key] = null;
+                    }
+                }
+            }
+        }
+
+        return $params;
+    }
 }


=====================================
lib/parser/parserlib.php
=====================================
@@ -142,25 +142,18 @@ class ParserLib extends TikiDb_Bridge
      */
     private function processPluginParams(&$params, $info)
     {
+        // Delegate default application to shared helper (single source of truth)
+        $params = WikiPlugin_Helper::applyParamsDefaults($params, $info);
+
         $missingRequired = [];
         if (isset($info['params'])) {
             foreach ($info['params'] as $key => $param) {
-                // Validate required parameters
                 if (isset($param['required']) && $param['required'] === true) {
                     // Parameter is required and has no default - check if user provided it
-                    if (! isset($param['default']) && ! isset($params[$key])) {
+                    if (! isset($param['default']) && $params[$key] === null) {
                         $missingRequired[] = $key;
                     }
                 }
-
-                // Apply default if parameter not set
-                if (! isset($params[$key])) {
-                    if (isset($param['default'])) {
-                        $params[$key] = $param['default'];
-                    } else {
-                        $params[$key] = null;
-                    }
-                }
             }
         }
 


=====================================
lib/wiki-plugins/wikiplugin_showpages.php
=====================================
@@ -9,7 +9,7 @@ function wikiplugin_showpages_info()
     return [
         'name' => tra('Show Pages'),
         'documentation' => 'PluginShowPages',
-        'description' => tra('Find pages by searching within page names'),
+        'description' => tra('Deprecated: Use PluginListPages instead. Find pages by searching within page names.'),
         'prefs' => [ 'wikiplugin_showpages' ],
         'iconname' => 'search',
         'introduced' => 1,
@@ -47,34 +47,28 @@ function wikiplugin_showpages_info()
 
 function wikiplugin_showpages($data, $params)
 {
-    global $tikilib, $prefs;
+    include_once('lib/wiki-plugins/wikiplugin_listpages.php');
 
-    extract($params, EXTR_SKIP);
+    // Default parameters required by wikiplugin_listpages
+    $listpagesParams = [];
+    $info = wikiplugin_listpages_info();
+    $listpagesParams = WikiPlugin_Helper::applyParamsDefaults($listpagesParams, $info);
 
-    if (is_null($max)) {
-        $max = -1;
+    if (isset($params['find'])) {
+        $listpagesParams['find'] = $params['find'];
     }
 
-    if ((strpos($display, 'name') === false && strpos($display, 'desc') === false)) {
-        $display = 'name|desc';
+    if (isset($params['max'])) {
+        $listpagesParams['max'] = $params['max'];
     }
 
-    $data = $tikilib->list_pages(0, $max, 'pageName_asc', $find, null, false);
-
-    $text = '';
-
-    foreach ($data["data"] as $page) {
-        if (isset($prefs['feature_wiki_description']) && $prefs['feature_wiki_description'] == 'y' && strpos($display, 'desc') !== false) {
-            $desc = $tikilib->page_exists_desc($page["pageName"]);
-        } else {
-            $desc = '';
-        }
-        $text .= "<a href=\"tiki-index.php?page=" . $page["pageName"] . "\" title=\"" . tra("Last modified by") . " " . $page["user"] . "\" class=\"wiki\">";
-        $text .= (strpos($display, 'name') !== false || strlen($desc) == 0 ? $page["pageName"] : $desc);
-        $text .= "</a>";
-        $text .= (strpos($display, 'name') !== false && $desc !== $page["pageName"] && strlen($desc) > 0 ? " - $desc" : "");
-        $text .= "<br />";
+    // Map display parameter to showNameOnly or showNameAndDescriptionOnly
+    $display = $params['display'] ?? 'name|desc';
+    if ($display === 'name') {
+        $listpagesParams['showNameOnly'] = 'y';
+    } else {
+        $listpagesParams['showNameAndDescriptionOnly'] = 'y';
     }
 
-    return $text;
+    return wikiplugin_listpages($data, $listpagesParams);
 }


=====================================
lib/wiki-plugins/wikiplugin_titlesearch.php
=====================================
@@ -5,15 +5,12 @@
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
 
-use Tiki\Lib\Wiki\PluginsLib;
-use Tiki\Lib\Wiki\PluginsLibUtil;
-
 function wikiplugin_titlesearch_info()
 {
     return [
         'name' => tra('Title Search'),
         'documentation' => 'PluginTitleSearch',
-        'description' => tra('Search page titles'),
+        'description' => tra('Deprecated: Use PluginListPages instead. Search page titles.'),
         'prefs' => [ 'feature_wiki', 'wikiplugin_titlesearch' ],
         'iconname' => 'search',
         'introduced' => 1,
@@ -21,7 +18,7 @@ function wikiplugin_titlesearch_info()
             'search' => [
                 'required' => true,
                 'name' => tra('Search Criteria'),
-                'description' => tra('Portion of a page name.'),
+                'description' => tra('Portion of a page name. Maps to the "find" parameter in ListPages.'),
                 'since' => '1',
                 'filter' => 'text',
                 'default' => '',
@@ -29,7 +26,7 @@ function wikiplugin_titlesearch_info()
             'info' => [
                 'required' => false,
                 'name' => tra('Information'),
-                'description' => tra('Also show page hits or user'),
+                'description' => tra('Show page hits or user. Note: This is now controlled by wiki_list_hits and wiki_list_user preferences.'),
                 'since' => '1',
                 'filter' => 'alpha',
                 'separator' => '|',
@@ -44,7 +41,7 @@ function wikiplugin_titlesearch_info()
             'exclude' => [
                 'required' => false,
                 'name' => tra('Exclude'),
-                'description' => tra('Pipe-separated list of page names to exclude from results.'),
+                'description' => tra('Pipe-separated list of page names to exclude from results. Maps to "exclude_pages" in ListPages.'),
                 'since' => '1',
                 'filter' => 'text',
                 'separator' => '|',
@@ -66,105 +63,36 @@ function wikiplugin_titlesearch_info()
         ],
     ];
 }
-class WikiPluginTitleSearch extends PluginsLib
+
+function wikiplugin_titlesearch($data, $params)
 {
-    public $expanded_params = ["exclude", "info"];
-    public function getDescription()
-    {
-        return wikiplugin_titlesearch_help();
-    }
-    public function getDefaultArguments()
-    {
-        return ['exclude' => '',
-            'noheader' => 0,
-            'info' => false,
-            'search' => false,
-                'style' => 'table'
-        ];
-    }
-    public function getName()
-    {
-        return "TitleSearch";
-    }
-    public function getVersion()
-    {
-        return preg_replace("/[Revision: $]/", '', "\$Revision: 1.25 $");
-    }
-    public function run($data, $params)
-    {
-        $tikilib = TikiLib::lib('tiki');
-        $aInfoPreset = array_keys($this->aInfoPresetNames);
-        $exclude = $params['exclude'] ?? '';
-        $params = $this->getParams($params, true);
-        extract($params, EXTR_SKIP);
-        if (! $search) {
-            return $this->error("You have to define a search");
-        }
+    include_once('lib/wiki-plugins/wikiplugin_listpages.php');
 
-        // no additional infos in list output
-        if (isset($style) && $style == 'list') {
-            $info = false;
-        }
+    // Default parameters required by wikiplugin_listpages
+    $listpagesParams = [];
+    $info = wikiplugin_listpages_info();
+    $listpagesParams = WikiPlugin_Helper::applyParamsDefaults($listpagesParams, $info);
 
-        //
-        /////////////////////////////////
-        // Create a valid list for $info
-        /////////////////////////////////
-        //
-        if ($info) {
-            $info_temp = [];
-            foreach ($info as $sInfo) {
-                if (in_array(trim($sInfo), $aInfoPreset)) {
-                    $info_temp[] = trim($sInfo);
-                }
-                $info = $info_temp ? $info_temp :
-                false;
-            }
-        } else {
-            $info = false;
-        }
-        //
-        /////////////////////////////////
-        // Process pages
-        /////////////////////////////////
-        //
-        $sOutput = "";
-        $aPages = $tikilib->list_pages(0, -1, 'pageName_desc', $search, null, false);
-        foreach ($aPages["data"] as $idPage => $aPage) {
-            if (! empty($exclude)) {
-                if (in_array($aPage["pageName"], $exclude)) {
-                    unset($aPages["data"][$idPage]);
-                    $aPages["count"]--;
-                }
-            }
-        }
-        //
-        /////////////////////////////////
-        // Start of Output
-        /////////////////////////////////
-        //
-        if (! $noheader) {
-            // Create header
-            $count = $aPages["count"];
-            if (! $count) {
-                $sOutput  .= tra("No pages found for title search") . " '__" . $search . "__'";
-            } elseif ($count == 1) {
-                $sOutput  .= tra("One page found for title search") . " '__" . $search . "__'";
-            } else {
-                $sOutput = "$count " . tra("pages found for title search") . " '__" . $search . "__'";
-            }
-            $sOutput  .= "\n";
-        }
-        if (isset($style) && $style == 'list') {
-            $sOutput .= PluginsLibUtil::createList($aPages["data"]);
+    // Force list view (TitleSearch legacy behavior)
+    $listpagesParams['showNameOnly'] = 'y';
+
+    // Map parameters: search -> find
+    if (isset($params['search'])) {
+        $listpagesParams['find'] = $params['search'];
+    }
+
+    // Map parameters: exclude -> exclude_pages
+    if (isset($params['exclude'])) {
+        if (is_array($params['exclude'])) {
+            $listpagesParams['exclude_pages'] = implode('|', $params['exclude']);
         } else {
-            $sOutput .= PluginsLibUtil::createTable($aPages["data"], $info);
+            $listpagesParams['exclude_pages'] = $params['exclude'];
         }
-        return $sOutput;
     }
-}
-function wikiplugin_titlesearch($data, $params)
-{
-    $plugin = new WikiPluginTitleSearch();
-    return $plugin->run($data, $params);
+
+    if (isset($params['noheader'])) {
+        $listpagesParams['noheader'] = $params['noheader'];
+    }
+
+    return wikiplugin_listpages($data, $listpagesParams);
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/20deb3f8fb022b998327889632d05a66e57a88c5

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/20deb3f8fb022b998327889632d05a66e57a88c5
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.