DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:headerfooter

HeaderFooter Plugin

Compatible with DokuWiki

Weatherwax, Binky, Ponder Stibbons, Hrun

plugin Add header or footer text to pages only when they are displayed

Last updated on
2014-09-20
Provides
Action
Conflicts with
data

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to footer

Tagged with annotations, embed, footer, header, include, template


:!: If you only need the footer functionality look at the new footer plugin.


This plugin can help adding additional text to every page(on top or bottom) in a namespace, while you don't have to require those pages' author to change them. That's to say, the specified pages will show additional context only when displayed. All pages created or not created in this namespace will be influenced. It's a really useful funcion for all! It has invaluable potential and see MAGIC USE.

Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Examples/Usage

To add header or footer text to pages in a namespace, you need to create a file named _header.txt or _footer.txt in the namespace directory (root namespace is under data/pages), which contains all you need to add. Then, put the file in a namespace. It's all! Easy enough? Yes, just like what the page template does!

Some tips

  • Remember: the _header.txt and _footer.txt support the same markup syntax as you use in any common wiki page.
  • Be careful for using head line, because we don't want to see any “EDIT” button in the suplus text.
  • Currently in a namespace, only the same level pages are influenced by _header.txt or _footer.txt, subdirectories are not influenced. (If needed, just put the same _header.txt/_footer.txt in subdirectories)
  • For some non-English languages, think of the files' encoding. UTF-8 is preferable.

Why don't my pages react with this plugin?

  • The most common reason is that due to the page cache, your page will delay to correctly display the newest version. A convenient way is that closing the plugin in plugin management and reopen it again. It'll refresh the cache. Another way to refresh a page is to add the parameter purge to the URL. Example:
    http://www.example.com/namespace/page?purge=true
  • Be sure that your pages and _header.txt/_footer.txt are in the same level directory.

MAGIC USE

I used to look for this function for long, but cannot find a likely one. In fact, this is the core function in some famous wiki such as pmwiki. This function is important and you can use it to fulfill some VERY USEFUL goals just like the following:

  • Force to add an index in every page when displayed.1)
  • Force to add some description on top of the contents of a page.
  • Force to add a tag as footer text in every page. 2)
  • Add Pagenav plugin on the bottom of every page.
  • Add an additional text only when printing a page (e.g. a hint for restricted reliability of the wiki content)

If you have some creative use of this plugin, just add it here.

Configuration and Settings

The default behaviour is managed by the wiki admin through the Configuration Settings.

Name Value Description
separation paragraph (default) using a blank line as a split between the origin text and header/footer text.(it means new paragraph).
nothing using nothing as split, which means you have to deal with the border between the origin text and header/footer text.

Change Log

  • 2014-09-20
    • Initial release

Rewrite and feature enhancement

:!: These changes are mailed to given email address of author, however, I didn't get an answer yet.

Following is a rewrite of action.php (in detail, a rewrite of handle_parser_wikitext_preprocess). Enhancements are:

  1. Support for non default storage path for data, especially for farms. Uses Dokuwiki functions instead of custom written
  2. Support for inheritage, using __header.txt and __footer.txt (two underscores). Mechanism is same and the implementation is based on code for namespace_templates
  3. Support for replacement patterns as shown here. Same as
action.php
<?php
/**
 * DokuWiki Plugin headerfooter (Action Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Li Zheng <lzpublic@qq.com>
 */
 
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
 
class action_plugin_headerfooter extends DokuWiki_Action_Plugin {
    public function register(Doku_Event_Handler $controller) {
 
       $controller->register_hook('PARSER_WIKITEXT_PREPROCESS', 'AFTER', $this, 'handle_parser_wikitext_preprocess');
 
    }
    public function handle_parser_wikitext_preprocess(Doku_Event &$event, $param) {
        global $INFO;
        global $ID;
        global $conf;
 
        //what does this mean???
        if ($INFO['id'] != '') return; // 发现每页会执行两次,当id为空时是真正的文本,否则是菜单。
 
        //helper array needed for parsePageTemplate
        //so that replacement like shown here is possible: https://www.dokuwiki.org/namespace_templates#replacement_patterns
        $data = array(
            'id'        => $ID, // the id of the page to be created
            'tpl'       => '', // the text used as template
        );
 
        $headerpath = '';
        $path = dirname(wikiFN($ID));
        if (@file_exists($path.'/_header.txt')) {
            $headerpath = $path.'/_header.txt';
        } else {
            // search upper namespaces for templates
            $len = strlen(rtrim($conf['datadir'], '/'));
            while (strlen($path) >= $len) {
                if (@file_exists($path.'/__header.txt')) {
                    $headerpath = $path.'/__header.txt';
                    break;
                }
                $path = substr($path, 0, strrpos($path, '/'));
            }
        }
 
        if (!empty($headerpath)) {
            $header = file_get_contents($headerpath);
            if ($header !== false) {
                $data['tpl'] = cleanText($header);
                $header = parsePageTemplate($data);
 
                if ($this->getConf('separation') == 'paragraph') { // 如果使用段落来分割
                    $header = rtrim($header, " \r\n\\") . "\n\n";
                }
                $event->data = $header . $event->data;
            }
        }
 
 
        $footerpath = '';
        $path = dirname(wikiFN($ID));
        if (@file_exists($path.'/_footer.txt')) {
            $footerpath = $path.'/_footer.txt';
        } else {
            // search upper namespaces for templates
            $len = strlen(rtrim($conf['datadir'], '/'));
            while (strlen($path) >= $len) {
                if (@file_exists($path.'/__footer.txt')) {
                    $footerpath = $path.'/__footer.txt';
                    break;
                }
                $path = substr($path, 0, strrpos($path, '/'));
            }
        }
 
        if (!empty($footerpath)) {
            $footer = file_get_contents($footerpath);
            if ($footer !== false) {
                $data['tpl'] = cleanText($footer);
                $footer = parsePageTemplate($data);
 
                if ($this->getConf('separation') == 'paragraph') { // 如果使用段落来分割
                    $footer = rtrim($footer, " \r\n\\") . "\n\n";
                }
                $event->data .= $footer;
            }
        }
    }
}

Bugs

If you find any bug, please mail me at lzpublic [at] qq [dot] com.

Bugs and Discussion

Use this Discussion page, please.

Forks

1)
need other index plugins
2)
need the tag plugin.
plugin/headerfooter.txt · Last modified: 2023-12-16 18:55 by Aleksandr

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki