Action: PageID Link
Compatible with: R6.1 Current version: 0.2 Credits: coffe1nk |
Create internal links using the PageID
{{plink page_ids="1,2,3" [inline=0|1]}}
1. Description
The plink action allows you to create internal links using the PageIDs. Because the PageID never changes, it enables you to set links to wiki pages which will be reorganized (moving to another sub-page, get renamed) which will not break.
This is the equivalent to the hashid action, which creates a permalink for the use outside of the wiki.
action/plink.php
<?php
if (!defined('IN_WACKO'))
{
exit;
}
// {{plink page_ids="1,2,3" [inline=0|1]}}
if (!isset($page_ids)) return;
// set defaults
$inline ??= 0;
$_page_ids = explode(',', $page_ids);
if ($pages = $this->db->load_all(
"SELECT tag, title " .
"FROM " . $this->prefix . "page " .
"WHERE page_id IN (" . $this->ids_string($_page_ids) . ") " .
"ORDER BY title", true)
)
{
$tpl->enter($inline ? 'i_' : 'u_');
$i = 0;
foreach ($pages as $_page)
{
$tpl->l_link = $this->link('/' . $_page['tag'], '', $_page['title']);
if ($inline && $i++ > 0)
{
$tpl->l_delim = ', ';
}
}
$tpl->leave(); // u_ / i_
}
action/template/plink.tpl
[ === main === ] [ ' message ' ] [= u _ = <ul> [= l _ = <li>[ ' link ' ]</li> =] </ul> =] [= i _ = [= l _ = [ ' delim ' ][ ' link ' ] =] =]
Use LF not CRLF line endings in WackoWiki templates.
If you don't do this in templates, the templating engine will throw an error:
templatest: no main template found in action_or_handler/template/path.tpl
In version prior to 6.0.32 you must replace the new introduced short table prefix $this->prefix
with $this->db->table_prefix
to make it work.
2. Usage
{{plink page_ids="1, 2, 3" inline=1}}
Shows all links inline. The double quotes are required if you use spaces.
{{plink page_ids=100}}
Shows link as a list.
2.1. local usage of repository
symlink the plink action from community action folder in wacko/action and wacko/action/template folder in repo
ln -s ../../community/action/plink.php plink.php ln -s ../../../community/action/template/plink.tpl plink.tpl
3. Changelog
0.1 Intitial version
0.2 added template
4. ToDo
- Add support hashid and revision_id?
- add link parameter to select between page tag and title
- discuss the concept hashid versus primary keys
- add the action either to the community folder or the core (does it fit conceptually)
5. See also
- Forum: Internal Links Using PageID
- hashid action (permalink)