Internal Links using PageID

Hi Admin,


Sometimes, I reorganized wiki pages (moving to another sub-page, rename wiki) and it will break the links from another pages.


Can we use wiki PageId to create links because PageId never be changed.


Thanks and Regards,

Show Files (1 file)

Comments

  1. Re: Internal Links using PageID

    I created this simple action code

    <?php
    
    
    // {{link pageid=}}
    
    if (!defined('IN_WACKO'))
    {
        exit;
    }
    
    if (!isset($pageid))		$pageid	= '';
    if (!isset($inline))		$inline	= '0';
    
    $pages = $this->db->load_all(
    		"SELECT tag, title " .
    		"FROM " . $this->db->table_prefix . "page " .
    		"WHERE page_id IN ( " . $pageid . ")" .
    		"ORDER BY title");
    
    if ($inline == '0') {
        echo '<style type="text/css" scoped>ul + br {display: none;} ul,ol {margin-top: 10px;margin-bottom: 10px;}</style>';
    	echo '<ul>';
    	foreach ($pages as $_page)
    	{
    		echo  '<li>' . $this->link('/' . $_page['tag'], '', $_page['title']) . '</li>';
    	}
    	echo '</ul>';
    } else {
    	echo $this->link('/' . $pages[0]['tag'], '', $pages[0]['title']);
    }	


    and then call it in wikipage

    {{link pageid=313}}	
  2. Re: Internal Links using PageID

    Improved action with template:

    action/plink.php
    
    <?php

    if (!defined('IN_WACKO'))
    {
        exit;
    }

    // TODO:
    //        (internal) link: title, tag
    //        (external) hashid: page link, version link

    // {{plink page_ids="1,2,3"}}

    if (!isset($page_ids))    return;
    if (!isset(
    $inline))    $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 _ =
    		[ ' // move to CSS file and asign class ' ]
    		<style scoped>
    			ul + br	{display: none;}
    			ul, ol	{margin-top: 10px; margin-bottom: 10px;}
    		</style>
    		<ul>
    			[= l _ =
    				<li>[ ' link ' ]</li>
    			=]
    		</ul>
    	=]
    	[= i _ =
    		[= l _ =
    			[ ' delim ' ][ ' link ' ]
    		=]
    	=]	


    To the topic itself more later, I just improved your action. I renamed the action to plink to distinguage it from similar actions/functions.
    • WikiAdmin
    • 20.10.2022 08:19 edited
  3. Re: Internal Links using PageID

    Please check for a copy or file naming error.

    I tested it on my local XAMPP, and copied it. Main is declared, you may compare it with a similar template - right now I can't spot an error.
    • WikiAdmin
    • 21.10.2022 13:04 edited
  4. Re: Internal Links using PageID

    There is no difference between the versions regarding the template engine. Looks like a typo or copy error to me. I can provide a zip file tomorrow.

    file:plink_action.zip

    Please try the sample files in the zip file. The problem with copy code around is, that the template requirers the correct line feed to work.
    • WikiAdmin
    • 21.10.2022 12:49 edited
  5. Re: Internal Links using PageID

    Please check the SQL query log, it should show you the error. Whith true the query gets cached. I have a 6.0 testing instance, but didn't used it - what could go wrong.

    An empty result indicates, that it throw the return, so it has no results. You can add there also a message.
    • WikiAdmin
    • 21.10.2022 12:52 edited
  6. Re: Internal Links using PageID

    Got it,

    I changed this line
    if ($pages = $this->db->load_all(
        "SELECT tag, title " .
        // "FROM " . $this->prefix . "page " .  // <<-------change this line
        "WHERE page_id IN (" . $this->ids_string($_page_ids) . ") " .
        "ORDER BY title", true)
    )	


    to

    "FROM " . $this->db->table_prefix . "page " .	


    Thanks WikiAdmin..
    • coffe1nk
    • 21.10.2022 16:18 edited
  7. Re: Internal Links using PageID

    Good to know that it works, the table prefix is already available in the 6.0 repo head, but I did not check against the 6.0.32 tag. The non-working template was probably caused by a non-complient line feed. I forgot to mention that LF line ending is mandatory.

    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
Log in or create an account to post a comment.