www: plugins: update the pagetitle plugin to newer version

This is the version we used when testign the new eo doc system.
This commit is contained in:
Stefan Schmidt 2016-11-29 11:54:26 +01:00
parent 943289fa2e
commit 52b2fdce2d
11 changed files with 559 additions and 48 deletions

View File

@ -0,0 +1,28 @@
<?php
/**
* DokuWiki Plugin PageTitle; Action component
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Satoshi Sahara <sahara.satoshi@gmail.com>
*/
if(!defined('DOKU_INC')) die();
class action_plugin_pagetitle extends DokuWiki_Action_Plugin {
/**
* register the event handlers
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'deleteObsoletedSingleClass');
}
/**
* Delete syntax.php which is obsoleted since multi-components syntax structure
*/
public function deleteObsoletedSingleClass(Doku_Event $event) {
$legacyFile = dirname(__FILE__).'/syntax.php';
if (file_exists($legacyFile)) { unlink($legacyFile); }
}
}

View File

@ -0,0 +1,14 @@
/*
* DokuWiki plugin PageTitle
*/
/* Hierarchical breadcrumbs in pages */
#dokuwiki__content div.youarehere:empty {
display: none;
}
#dokuwiki__content .youarehere {
font-size: 85%;
}
#dokuwiki__content .youarehere:before {
content:"⌇";
}

View File

@ -0,0 +1,9 @@
# deleted.files : Page Title plugin for DokuWiki
#
# This file contains a list of files that were present in previous
# plugin releases but were removed later.
# An up-to-date plugin should not have any of the files installed.
# Since 2015-09-17
syntax.php

View File

@ -0,0 +1,219 @@
<?php
/**
* DokuWiki plugin PageTitle; Helper component
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Satoshi Sahara <sahara.satoshi@gmail.com>
*/
if (!defined('DOKU_INC')) die();
class helper_plugin_pagetitle extends DokuWiki_Plugin {
/**
* Hierarchical breadcrumbs for PageTitle plugin
*
* @param int $start_depth of hierarchical breadcrumbs
* @param bool $print if false return content
* @return bool|string html, or false if no data, true if printed
*/
function tpl_youarehere($start_depth = 0, $print = true) {
global $lang;
$out = '<span class="bchead">'.$lang['youarehere'].'</span>';
$out.= $this->html_youarehere($start_depth);
if ($print) {
echo $out; return (bool) $out;
}
return $out;
}
function html_youarehere($start_depth = 0) {
global $conf, $ID;
if ($ID == $conf['start']) {
$page = '';
} elseif (noNS($ID) == $conf['start']) {
$page = ':'.getNS($ID); // drop tailing start
} else {
$page = ':'.$ID;
}
$parts = explode(':', $page);
$depth = count($parts) -1;
$out = '';
$ns = '';
for ($i = $start_depth; $i < count($parts); $i++) {
$ns.= $parts[$i];
$id = $ns ?: $conf['start'];
resolve_pageid('', $id, $exists);
if (!$exists) {
$id = $ns.':';
resolve_pageid('', $id, $exists);
}
$name = p_get_metadata($id, 'shorttitle') ?: $parts[$i];
$out.= '<bdi>'.$this->html_pagelink($id, $name, $exists).'</bdi>';
if ($i < $depth) $out.= ' &#x00A0;'; // separator
$ns.= ':';
}
return $out;
}
/**
* Prints a link to a WikiPage
* a customised function based on
* tpl_pagelink() defined in inc/template.php,
* html_wikilink() defined in inc/html.php,
* internallink() defined in inc/parser/xhtml.php
*
* @param string $id page id
* @param string $name the name of the link
* @param bool $exists
* @param bool $print if false return content
* @return bool|string html, or false if no data, true if printed
*/
function tpl_pagelink($id = null, $name = null, $exists = null, $print = true) {
global $conf;
$out = $this->html_pagelink($id, $name, $exists);
if ($print) {
echo $out; return (bool) $out;
}
return $out;
}
function html_pagelink($id = null, $name = null, $exists = null) {
global $conf, $ID;
if (is_null($id)) $id = $ID;
$title = p_get_metadata($id, 'title');
if (empty($title)) $title = $id;
if (is_null($exists)) {
$class = (page_exists($id)) ? 'wikilink1' : 'wikilink2';
} else {
$class = ($exists) ? 'wikilink1' : 'wikilink2';
}
$short_title = $name;
if (empty($name)) {
$short_title = p_get_metadata($id, 'shorttitle') ?: noNS($id);
}
$out = '<a href="'.$this->wl($id).'" class="'.$class.'" title="'.hsc($title).'">';
$out.= hsc($short_title).'</a>';
return $out;
}
/**
* builds url of a wikipage
* a simplified function of DokuWiki wl() defined inc/common.php
*
* @param string $id page id
* @return string
*/
function wl($id = null) {
global $conf;
if (noNS($id) == $conf['start']) $id = ltrim(getNS($id).':', ':');
idfilter($id);
$xlink = DOKU_BASE;
switch ($conf['userewrite']) {
case 2: // eg. DOKU_BASE/doku.php/wiki:syntax
$xlink .= DOKU_SCRIPT.'/'.$id;
case 1: // eg. DOKU_BASE/wiki:syntax
$xlink .= $id;
$xlink = ($xlink == '/') ? '/' : rtrim($xlink,'/');
break;
default:
$xlink .= DOKU_SCRIPT;
$xlink .= ($id) ? '?id='.$id : '';
}
return $xlink;
}
/**
* Prints or returns the title of the given page (current one if none given)
* modified from DokuWiki original function tpl_pagetitle()
* defined in inc/template.php
* This variant function returns title from metadata, ignoring $conf['useheading']
*
* @param string $id page id
* @param bool $print if false return content
* @return bool|string html, or false if no data, true if printed
*/
function tpl_pagetitle($id = null, $print = true) {
$out = $this->pagetitle($id);
if ($print) {
echo $out; return (bool) $out;
}
return $out;
}
function pagetitle($id = null) {
global $ACT, $ID, $conf, $lang;
if (is_null($id)) {
$title = (p_get_metadata($ID, 'title')) ?: $ID;
} else {
$title = (p_get_metadata($id, 'title')) ?: $id;
}
// default page title is the page name, modify with the current action
switch ($ACT) {
// admin functions
case 'adminhomepage' :
case 'admin' :
$page_title = $lang['btn_admin'];
// try to get the plugin name
/** @var $plugin DokuWiki_Admin_Plugin */
if (function_exists('plugin_getRequestAdminPlugin') &&
($plugin = plugin_getRequestAdminPlugin()) ) {
$plugin_title = $plugin->getMenuText($conf['lang']);
$page_title = $plugin_title ? $plugin_title : $plugin->getPluginName();
}
break;
// user functions
case 'login' :
case 'profile' :
case 'register' :
case 'resendpwd' :
$page_title = $lang['btn_'.$ACT];
break;
// wiki functions
case 'search' :
case 'index' :
$page_title = $lang['btn_'.$ACT];
break;
// page functions
case 'edit' :
$page_title = "".$title;
break;
case 'revisions' :
$page_title = $title . ' - ' . $lang['btn_revs'];
break;
case 'backlink' :
case 'recent' :
case 'subscribe' :
$page_title = $title . ' - ' . $lang['btn_'.$ACT];
break;
default : // SHOW and anything else not included
$page_title = $title;
}
return hsc($page_title);
}
}

View File

@ -0,0 +1,2 @@
downloadurl=https://github.com/ssahara/dw-plugin-pagetitle/zipball/master
installed=Mon, 05 Sep 2016 13:14:32 +0000

View File

@ -1,7 +1,7 @@
base pagetitle
name Page title plugin
name Page Title plugin
author Satoshi Sahara
email sahara.satoshi@gmail.com
date 2014-08-10
desc Macro to set the title of the page in metadata.
date 2016-09-02
desc Define a title of the wiki page by <title> tag. This plugin allows to write decorative title on the page with setting plain title text in metadata storage.
url https://www.dokuwiki.org/plugin:pagetitle

View File

@ -1,45 +0,0 @@
<?php
/**
* DokuWiki plugin Pagetitle; Syntax component
* Macro to set the title of the page in metadata
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Satoshi Sahara <sahara.satoshi@gmail.com>
*/
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
class syntax_plugin_pagetitle extends DokuWiki_Syntax_Plugin {
protected $special_pattern = '~~(?:Title|ShortTitle):.*?~~';
public function getType() { return 'substition'; }
public function getPType(){ return 'block'; }
public function getSort() { return 990; }
public function connectTo($mode) {
$this->Lexer->addSpecialPattern($this->special_pattern, $mode,
implode('_', array('plugin',$this->getPluginName(),))
);
}
public function handle($match, $state, $pos, Doku_Handler $handler) {
return array($state, $match);
}
public function render($format, Doku_Renderer $renderer, $data) {
list($state, $match) = $data;
list($key, $value) = explode(':', substr($match, 2, -2), 2);
$key = strtolower($key);
if ($format == 'metadata') {
$renderer->meta[$key] = trim($value);
}
return true;
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* DokuWiki plugin PageTitle Breadcrums; Syntax component
* Macro to set the short title of the page in metadata
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Satoshi Sahara <sahara.satoshi@gmail.com>
*/
if (!defined('DOKU_INC')) die();
class syntax_plugin_pagetitle_breadcrumb extends DokuWiki_Syntax_Plugin {
protected $special_pattern = '~~ShortTitle:.*?~~';
protected $check = array(); // ensure first matched pattern only effective
protected $mode;
function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_' from class name
}
public function getType() { return 'substition'; }
public function getPType(){ return 'normal'; }
public function getSort() { return 990; }
public function connectTo($mode) {
$this->Lexer->addSpecialPattern($this->special_pattern, $mode, $this->mode);
}
public function handle($match, $state, $pos, Doku_Handler $handler) {
global $ID;
if ($this->check[$ID]++) {
return false; // ignore match after once handled
}
list($key, $value) = explode(':', substr($match, 2, -2), 2);
$short_title = trim($value);
return array($state, $short_title, $ID);
}
public function render($format, Doku_Renderer $renderer, $data) {
global $ID;
list($state, $short_title, $id) = $data;
if (strcmp($id, $ID) !== 0) return false;
switch ($format) {
case 'metadata':
$renderer->meta['shorttitle'] = $short_title;
return true;
default:
return false;
}
}
}

View File

@ -0,0 +1,144 @@
<?php
/**
* DokuWiki plugin PageTitle Decorative; Syntax component
* Show decorative title on the page, with setting plain title in metadata
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Sahara Satoshi <sahara.satoshi@gmail.com>
*
* The title text can contain wiki formatting markups such as bold,
* itlic, subscript and superscript, but title metadata remains simple
* plain text without any markup.
* example
* wiki source: <title> H<sub>s</sub>O </title>
* page (html): <h1 class="pagetitle">H<sub>2</sub>O</h1>
* title metadata: H2O
*/
if (!defined('DOKU_INC')) die();
class syntax_plugin_pagetitle_decorative extends DokuWiki_Syntax_Plugin {
protected $entry_pattern = '<title\b[^>\r\n]*?>(?=.*?</title>)';
protected $exit_pattern = '</title>';
protected $mode, $name;
protected $store, $capture;
protected $params; // store title tag parameters
protected $check = array(); // ensure first title only effective, used in render()
function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_' from class name
$this->name = substr(get_class($this), 14);
}
function getType() { return 'baseonly';}
function getPType() { return 'block';}
function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
function getSort() { return 49; }
// Connect pattern to lexer
function connectTo($mode) {
$this->Lexer->addEntryPattern($this->entry_pattern, $mode, $this->mode);
}
function postConnect() {
$this->Lexer->addExitPattern($this->exit_pattern, $this->mode);
}
/*
* Handle the match
*/
function handle($match, $state, $pos, Doku_Handler $handler) {
global $ID;
if ($this->check[$ID] > 0) {
return false; // ignore match after once handled
}
switch ($state) {
case DOKU_LEXER_ENTER :
$params = strtolower(trim(substr($match, strpos($match,' '), -1)));
$data = array($state, $ID, $params);
$handler->addPluginCall($this->name, $data, $state,$pos,$match);
return false;
case DOKU_LEXER_UNMATCHED :
$handler->_addCall('cdata', array($match), $pos);
return false;
case DOKU_LEXER_EXIT :
$data = array($state, $ID, '');
$handler->addPluginCall($this->name, $data, $state,$pos,$match);
$this->check[$ID]++;
return false;
}
return false;
}
/**
* Create output
*/
function render($format, Doku_Renderer $renderer, $data) {
global $ID;
list($state, $id, $params) = $data;
switch ($state) {
case DOKU_LEXER_ENTER :
// store title tag parameters
$this->params = $params;
// preserve variables
$this->store = $renderer->doc;
$this->capture = $renderer->capture;
// set doc blank to store parsed "UNMATHCED" content
$renderer->doc = '';
// metadata renderer should always parse "UNMATCHED" content
if ($format == 'metadata') $renderer->capture = true;
return true;
break;
case DOKU_LEXER_EXIT :
// retrieve parsed "UNMATCHED" content
$decorative_title = trim($renderer->doc);
// restore variable
$renderer->doc = $this->store;
if ($format == 'metadata') $renderer->capture = $this->capture;
break; // do not return here
default:
return false; // this should never happen
}
if (strcmp($id, $ID) !== 0) return false;
// get plain title
$title = htmlspecialchars_decode(strip_tags($decorative_title), ENT_QUOTES);
if (empty($title)) return false;
// output title
$method = '_' . $format . '_render';
if (method_exists($this, $method)) {
return $this->$method($decorative_title, $title, $renderer);
}
else return false;
}
/**
* Revised procedures for renderers
*/
protected function _xhtml_render($decorative_title, $title, $renderer) {
if (($wrap = $this->loadHelper('wrap')) != NULL) {
$attr = $wrap->buildAttributes($this->params, 'pagetitle');
} else $attr = ' class="pagetitle"';
// even title in <h1>, it never shown up in the table of contents (TOC)
$renderer->doc .= '<h1'.$attr.'>';
$renderer->doc .= $decorative_title;
$renderer->doc .= '</h1>'.DOKU_LF;
return true;
}
protected function _metadata_render($decorative_title, $title, $renderer) {
$renderer->meta['title'] = $title;
return true;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* DokuWiki plugin PageTitle metaonly; Syntax component
* Macro to set the itle of the page in metadata
* deteriorated decorative syntax component
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Sahara Satoshi <sahara.satoshi@gmail.com>
*
*/
require_once(dirname(__FILE__).'/decorative.php');
class syntax_plugin_pagetitle_metaonly extends syntax_plugin_pagetitle_decorative {
protected $entry_pattern = '~~Title:(?=.*?~~)';
protected $exit_pattern = '~~';
function getType() { return 'baseonly';}
function getPType() { return 'normal';}
function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
function getSort() { return 49; }
/**
* Revised procedures for renderers
*/
protected function _xhtml_render($decorative_title, $title, $renderer) {
return true;
}
protected function _metadata_render($decorative_title, $title, $renderer) {
$renderer->meta['title'] = $title;
return true;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* DokuWiki plugin PageTitle YouAreHere; Syntax component
* Hierarchical breadcrumbs
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Satoshi Sahara <sahara.satoshi@gmail.com>
*/
if (!defined('DOKU_INC')) die();
class syntax_plugin_pagetitle_youarehere extends DokuWiki_Syntax_Plugin {
protected $special_pattern = '<!-- ?YOU_ARE_HERE ?-->';
protected $mode;
function __construct() {
$this->mode = substr(get_class($this), 7); // drop 'syntax_' from class name
}
public function getType() { return 'substition'; }
public function getPType(){ return 'block'; }
public function getSort() { return 990; }
public function connectTo($mode) {
$this->Lexer->addSpecialPattern($this->special_pattern, $mode, $this->mode);
}
public function handle($match, $state, $pos, Doku_Handler $handler) {
return array($state, $match);
}
public function render($format, Doku_Renderer $renderer, $data) {
list($state, $match) = $data;
$template = plugin_load('helper','pagetitle');
$renderer->doc .= DOKU_LF.$match.DOKU_LF; // html comment
$renderer->doc .= '<div class="youarehere">';
$renderer->doc .= $template->html_youarehere(1); // start_depth = 1
$renderer->doc .= '</div>'.DOKU_LF;
return true;
}
}