summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Eckelmann <eckelmann@cosmocode.de>2012-11-05 10:57:42 +0100
committerDominik Eckelmann <eckelmann@cosmocode.de>2012-11-05 10:57:42 +0100
commitfb55b51ef82bc3066173e7547500d9e79c410e34 (patch)
tree9b0b32a6cb91eb82ce757d53aaa846566b51db4d
parent8449cc9d82848df24eb88a73dd81d7e048933287 (diff)
downloadrpg-fb55b51ef82bc3066173e7547500d9e79c410e34.tar.gz
rpg-fb55b51ef82bc3066173e7547500d9e79c410e34.tar.bz2
changed PAGEUTILS_ID_HIDEPAGE to has BEFORE/AFTER
-rw-r--r--_test/tests/inc/PageUtilsIsHiddenPage.test.php52
-rw-r--r--inc/pageutils.php22
2 files changed, 61 insertions, 13 deletions
diff --git a/_test/tests/inc/PageUtilsIsHiddenPage.test.php b/_test/tests/inc/PageUtilsIsHiddenPage.test.php
index 153d0e8f6..a7077862e 100644
--- a/_test/tests/inc/PageUtilsIsHiddenPage.test.php
+++ b/_test/tests/inc/PageUtilsIsHiddenPage.test.php
@@ -33,16 +33,62 @@ class PageUtilsIsHiddenPageTest extends DokuWikiTest {
$this->assertFalse(isHiddenPage('another'));
}
- function testEventHandler() {
+ function testEventHandlerBefore() {
global $EVENT_HANDLER;
$this->prepare();
$EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'alwaysHide');
- $this->assertFalse(isHiddenPage('test'));
+ $this->assertTrue(isHiddenPage('another'));
}
function alwaysHide(Doku_Event &$event, $params) {
- $event->data['hide'] = true;
+ $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;
}
}
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 853d3fb4d..3bb10883f 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -536,23 +536,25 @@ function getCacheName($data,$ext=''){
* @author Andreas Gohr <gohr@cosmocode.de>
*/
function isHiddenPage($id){
- global $conf;
- global $ACT;
-
$data = array(
'id' => $id,
'hidden' => false
);
- trigger_event('PAGEUTILS_ID_HIDEPAGE', $id);
+ trigger_event('PAGEUTILS_ID_HIDEPAGE', $data, '_isHiddenPage');
+ return $data['hidden'];
+}
- if ($data['hidden']) return true;
- if(empty($conf['hidepages'])) return false;
- if($ACT == 'admin') return false;
+function _isHiddenPage(&$data) {
+ global $conf;
+ global $ACT;
- if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){
- return true;
+ if ($data['hidden']) return;
+ if(empty($conf['hidepages'])) return;
+ if($ACT == 'admin') return;
+
+ if(preg_match('/'.$conf['hidepages'].'/ui',':'.$data['id'])){
+ $data['hidden'] = true;
}
- return false;
}
/**