Skip to content
Snippets Groups Projects
Commit 6e197037 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Merge pull request #139 from dom-mel/hidden_event

Added PAGEUTILS_ID_HIDEPAGE Event
parents 11531294 fb55b51e
No related branches found
No related tags found
No related merge requests found
<?php
class PageUtilsIsHiddenPageTest extends DokuWikiTest {
function prepare($hidePages = '^:test$', $act = 'show') {
global $conf;
global $ACT;
$conf['hidepages'] = $hidePages;
$ACT = $act;
}
function testHiddenOff(){
$this->prepare('');
$this->assertFalse(isHiddenPage('test'));
}
function testHiddenOffAdmin(){
$this->prepare('^:test$', 'admin');
$this->assertFalse(isHiddenPage('test'));
}
function testHiddenOnMatch(){
$this->prepare();
$this->assertTrue(isHiddenPage('test'));
}
function testHiddenOnNoMatch(){
$this->prepare();
$this->assertFalse(isHiddenPage('another'));
}
function testEventHandlerBefore() {
global $EVENT_HANDLER;
$this->prepare();
$EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'alwaysHide');
$this->assertTrue(isHiddenPage('another'));
}
function alwaysHide(Doku_Event &$event, $params) {
$event->data['hidden'] = true;
}
function testEventHandlerBeforeAndPrevent() {
global $EVENT_HANDLER;
$this->prepare();
$EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'showBefore');
$this->assertFalse(isHiddenPage('test'));
}
function showBefore(Doku_Event &$event, $params) {
$event->data['hidden'] = false;
$event->preventDefault();
$event->stopPropagation();
}
function testEventHandlerAfter() {
global $EVENT_HANDLER;
$this->prepare();
$EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'alwaysHide');
$this->assertTrue(isHiddenPage('another'));
}
function testEventHandlerAfterHide() {
global $EVENT_HANDLER;
$this->prepare();
$EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'hideBeforeWithoutPrevent');
$this->assertTrue(isHiddenPage('another'));
}
function hideBeforeWithoutPrevent(Doku_Event &$event, $params) {
$event->data['hidden'] = true;
}
function testEventHandlerAfterShow() {
global $EVENT_HANDLER;
$this->prepare();
$EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'showAfter');
$this->assertFalse(isHiddenPage('test'));
}
function showAfter(Doku_Event &$event, $params) {
$event->data['hidden'] = false;
}
}
//Setup VIM: ex: et ts=4 :
...@@ -536,15 +536,25 @@ function getCacheName($data,$ext=''){ ...@@ -536,15 +536,25 @@ function getCacheName($data,$ext=''){
* @author Andreas Gohr <gohr@cosmocode.de> * @author Andreas Gohr <gohr@cosmocode.de>
*/ */
function isHiddenPage($id){ function isHiddenPage($id){
$data = array(
'id' => $id,
'hidden' => false
);
trigger_event('PAGEUTILS_ID_HIDEPAGE', $data, '_isHiddenPage');
return $data['hidden'];
}
function _isHiddenPage(&$data) {
global $conf; global $conf;
global $ACT; global $ACT;
if(empty($conf['hidepages'])) return false;
if($ACT == 'admin') return false;
if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){ if ($data['hidden']) return;
return true; if(empty($conf['hidepages'])) return;
if($ACT == 'admin') return;
if(preg_match('/'.$conf['hidepages'].'/ui',':'.$data['id'])){
$data['hidden'] = true;
} }
return false;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment