-
Notifications
You must be signed in to change notification settings - Fork 13
/
action.php
71 lines (62 loc) · 2.24 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Datatemplate plugin.
*
* Action plugin component, for cache validity determination
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Christoph Clausen <[email protected]>
*/
if(!defined('DOKU_INC')) die(); // no Dokuwiki, no go
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class action_plugin_datatemplate extends DokuWiki_Action_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Christoph Clausen',
'email' => '[email protected]',
'date' => '2011-08-27',
'name' => 'Datatemplate Plugin',
'desc' => 'A template extension for the data plugin',
'url' => 'http://www.dokuwiki.org/plugin:datatemplate',
);
}
/**
* plugin should use this method to register its handlers with the dokuwiki's event controller
*/
function register(Doku_Event_Handler $controller) {
$controller->register_hook('PARSER_CACHE_USE','BEFORE', $this, '_cache_prepare');
}
/**
* prepare the cache object for default _useCache action
*/
function _cache_prepare(&$event, $param) {
$cache =& $event->data;
// we're only interested in wiki pages and supported render modes
if (!isset($cache->page)) return;
if (!isset($cache->mode) || $cache->mode != 'metadata') return;
$files = $this->_get_dependencies($cache->page);
$cache->depends['files'] = array_merge($cache->depends['files'], $files);
}
/**
* Get list of files that this page depends on. Usually, this would just be
* a single template file.
*/
function _get_dependencies($id) {
$hasPart = p_get_metadata($id, 'relation haspart');
if(empty($hasPart) || !is_array($hasPart)) return array();
$files = array();
foreach($hasPart as $file => $data) {
if(empty($data['owner']) || $data['owner'] != $this->getPluginName()) continue;
$files[] = $file;
}
return $files;
}
}