deprecated trigger_event() in favor of a static method on Event

This commit is contained in:
Andreas Gohr 2018-06-15 17:35:53 +02:00
parent e1d9dcc8b4
commit cbb44eabe0
39 changed files with 136 additions and 85 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler; use dokuwiki\Extension\EventHandler;
if(!class_exists('PHPUnit_Framework_TestCase')) { if(!class_exists('PHPUnit_Framework_TestCase')) {
@ -140,7 +141,7 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase {
// reload language // reload language
$local = $conf['lang']; $local = $conf['lang'];
trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); Event::createAndTrigger('INIT_LANG_LOAD', $local, 'init_lang', true);
global $INPUT; global $INPUT;
$INPUT = new \dokuwiki\Input\Input(); $INPUT = new \dokuwiki\Input\Input();

View File

@ -1,5 +1,7 @@
<?php <?php
use dokuwiki\Extension\Event;
/** /**
* This tests if event handlers can trigger the same event again. * This tests if event handlers can trigger the same event again.
* This is used by plugins that modify cache handling and use metadata * This is used by plugins that modify cache handling and use metadata
@ -16,7 +18,7 @@ class events_nested_test extends DokuWikiTest {
$firstcount++; $firstcount++;
if ($firstcount == 1) { if ($firstcount == 1) {
$param = array(); $param = array();
trigger_event('NESTED_EVENT', $param); Event::createAndTrigger('NESTED_EVENT', $param);
} }
} }
); );
@ -28,7 +30,7 @@ class events_nested_test extends DokuWikiTest {
); );
$param = array(); $param = array();
trigger_event('NESTED_EVENT', $param); Event::createAndTrigger('NESTED_EVENT', $param);
$this->assertEquals(2, $firstcount); $this->assertEquals(2, $firstcount);
$this->assertEquals(2, $secondcount); $this->assertEquals(2, $secondcount);

View File

@ -9,6 +9,8 @@
*/ */
// update message version - always use a string to avoid localized floats! // update message version - always use a string to avoid localized floats!
use dokuwiki\Extension\Event;
$updateVersion = "51"; $updateVersion = "51";
// xdebug_start_profiling(); // xdebug_start_profiling();
@ -111,7 +113,7 @@ if($conf['breadcrumbs']) breadcrumbs();
checkUpdateMessages(); checkUpdateMessages();
$tmp = array(); // No event data $tmp = array(); // No event data
trigger_event('DOKUWIKI_STARTED', $tmp); Event::createAndTrigger('DOKUWIKI_STARTED', $tmp);
//close session //close session
session_write_close(); session_write_close();
@ -120,6 +122,6 @@ session_write_close();
act_dispatch(); act_dispatch();
$tmp = array(); // No event data $tmp = array(); // No event data
trigger_event('DOKUWIKI_DONE', $tmp); Event::createAndTrigger('DOKUWIKI_DONE', $tmp);
// xdebug_dump_function_profile(1); // xdebug_dump_function_profile(1);

View File

@ -180,7 +180,7 @@ function rss_parseOptions() {
$eventData = array( $eventData = array(
'opt' => &$opt, 'opt' => &$opt,
); );
trigger_event('FEED_OPTS_POSTPROCESS', $eventData); Event::createAndTrigger('FEED_OPTS_POSTPROCESS', $eventData);
return $opt; return $opt;
} }

View File

@ -3,6 +3,7 @@
namespace dokuwiki\Action; namespace dokuwiki\Action;
use dokuwiki\Action\Exception\ActionAbort; use dokuwiki\Action\Exception\ActionAbort;
use dokuwiki\Extension\Event;
/** /**
* Class Export * Class Export
@ -96,7 +97,7 @@ class Export extends AbstractAction {
$data['headers'] = $headers; $data['headers'] = $headers;
$data['output'] =& $output; $data['output'] =& $output;
trigger_event('ACTION_EXPORT_POSTPROCESS', $data); Event::createAndTrigger('ACTION_EXPORT_POSTPROCESS', $data);
if(!empty($data['output'])) { if(!empty($data['output'])) {
if(is_array($data['headers'])) foreach($data['headers'] as $key => $val) { if(is_array($data['headers'])) foreach($data['headers'] as $key => $val) {

View File

@ -3,6 +3,7 @@
namespace dokuwiki\Action; namespace dokuwiki\Action;
use dokuwiki\Action\Exception\ActionAbort; use dokuwiki\Action\Exception\ActionAbort;
use dokuwiki\Extension\Event;
/** /**
* Class Redirect * Class Redirect
@ -41,7 +42,7 @@ class Redirect extends AbstractAliasAction {
} }
// execute the redirect // execute the redirect
trigger_event('ACTION_SHOW_REDIRECT', $opts, array($this, 'redirect')); Event::createAndTrigger('ACTION_SHOW_REDIRECT', $opts, array($this, 'redirect'));
// should never be reached // should never be reached
throw new ActionAbort('show'); throw new ActionAbort('show');

View File

@ -4,6 +4,7 @@ namespace dokuwiki\Action;
use dokuwiki\Action\Exception\ActionAbort; use dokuwiki\Action\Exception\ActionAbort;
use dokuwiki\Action\Exception\ActionDisabledException; use dokuwiki\Action\Exception\ActionDisabledException;
use dokuwiki\Extension\Event;
/** /**
* Class Subscribe * Class Subscribe
@ -67,7 +68,7 @@ class Subscribe extends AbstractUserAction {
if(empty($params['action']) || !checkSecurityToken()) return; if(empty($params['action']) || !checkSecurityToken()) return;
// Handle POST data, may throw exception. // Handle POST data, may throw exception.
trigger_event('ACTION_HANDLE_SUBSCRIBE', $params, array($this, 'handlePostData')); Event::createAndTrigger('ACTION_HANDLE_SUBSCRIBE', $params, array($this, 'handlePostData'));
$target = $params['target']; $target = $params['target'];
$style = $params['style']; $style = $params['style'];

View File

@ -3,6 +3,7 @@
namespace dokuwiki\Cache; namespace dokuwiki\Cache;
use \dokuwiki\Debug\PropertyDeprecationHelper; use \dokuwiki\Debug\PropertyDeprecationHelper;
use dokuwiki\Extension\Event;
/** /**
* Generic handling of caching * Generic handling of caching
@ -54,9 +55,9 @@ class Cache
return $this->_event; return $this->_event;
} }
public function setEvent($_event) public function setEvent($event)
{ {
$this->_event = $_event; $this->_event = $event;
} }
/** /**
@ -78,7 +79,7 @@ class Cache
$this->addDependencies(); $this->addDependencies();
if ($this->_event) { if ($this->_event) {
return $this->stats(trigger_event($this->_event, $this, array($this, 'makeDefaultCacheDecision'))); return $this->stats(Event::createAndTrigger($this->_event, $this, array($this, 'makeDefaultCacheDecision')));
} else { } else {
return $this->stats($this->makeDefaultCacheDecision()); return $this->stats($this->makeDefaultCacheDecision());
} }

View File

@ -161,4 +161,23 @@ class Event
{ {
return $this->_default; return $this->_default;
} }
/**
* Convenience method to trigger an event
*
* Creates, triggers and destroys an event in one go
*
* @param string $name name for the event
* @param mixed $data event data
* @param callable $action (optional, default=NULL) default action, a php callback function
* @param bool $canPreventDefault (optional, default=true) can hooks prevent the default action
*
* @return mixed the event results value after all event processing is complete
* by default this is the return value of the default action however
* it can be set or modified by event handler hooks
*/
static public function createAndTrigger($name, &$data, $action=null, $canPreventDefault=true) {
$evt = new Event($name, $data);
return $evt->trigger($action, $canPreventDefault);
}
} }

View File

@ -2,6 +2,8 @@
namespace dokuwiki; namespace dokuwiki;
use dokuwiki\Extension\Event;
class Manifest class Manifest
{ {
public function sendManifest() public function sendManifest()
@ -74,7 +76,7 @@ class Manifest
} }
} }
trigger_event('MANIFEST_SEND', $manifest); Event::createAndTrigger('MANIFEST_SEND', $manifest);
header('Content-Type: application/manifest+json'); header('Content-Type: application/manifest+json');
echo json_encode($manifest); echo json_encode($manifest);

View File

@ -2,6 +2,7 @@
namespace dokuwiki\Menu; namespace dokuwiki\Menu;
use dokuwiki\Extension\Event;
use dokuwiki\Menu\Item\AbstractItem; use dokuwiki\Menu\Item\AbstractItem;
/** /**
@ -42,7 +43,7 @@ abstract class AbstractMenu implements MenuInterface {
'view' => $this->view, 'view' => $this->view,
'items' => array(), 'items' => array(),
); );
trigger_event('MENU_ITEMS_ASSEMBLY', $data, array($this, 'loadItems')); Event::createAndTrigger('MENU_ITEMS_ASSEMBLY', $data, array($this, 'loadItems'));
return $data['items']; return $data['items'];
} }

View File

@ -2,6 +2,7 @@
namespace dokuwiki\Remote; namespace dokuwiki\Remote;
use dokuwiki\Extension\Event;
use dokuwiki\Extension\RemotePlugin; use dokuwiki\Extension\RemotePlugin;
/** /**
@ -141,7 +142,7 @@ class Api
{ {
if ($this->pluginCustomCalls === null) { if ($this->pluginCustomCalls === null) {
$data = array(); $data = array();
trigger_event('RPC_CALL_ADD', $data); Event::createAndTrigger('RPC_CALL_ADD', $data);
$this->pluginCustomCalls = $data; $this->pluginCustomCalls = $data;
} }
return $this->pluginCustomCalls; return $this->pluginCustomCalls;

View File

@ -6,6 +6,7 @@ use Doku_Renderer_xhtml;
use dokuwiki\ChangeLog\MediaChangeLog; use dokuwiki\ChangeLog\MediaChangeLog;
use dokuwiki\ChangeLog\PageChangeLog; use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Extension\AuthPlugin; use dokuwiki\Extension\AuthPlugin;
use dokuwiki\Extension\Event;
define('DOKU_API_VERSION', 10); define('DOKU_API_VERSION', 10);
@ -981,7 +982,7 @@ class ApiCore
'sticky' => false, 'sticky' => false,
'silent' => true, 'silent' => true,
); );
$ok = trigger_event('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper'); $ok = Event::createAndTrigger('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper');
} }
session_write_close(); // we're done with the session session_write_close(); // we're done with the session

View File

@ -156,7 +156,7 @@ class TaskRunner
'trimmedChangelogLines' => $out_lines, 'trimmedChangelogLines' => $out_lines,
'removedChangelogLines' => $extra > 0 ? array_slice($old_lines, 0, -$extra) : $old_lines, 'removedChangelogLines' => $extra > 0 ? array_slice($old_lines, 0, -$extra) : $old_lines,
]; ];
trigger_event('TASK_RECENTCHANGES_TRIM', $eventData); Event::createAndTrigger('TASK_RECENTCHANGES_TRIM', $eventData);
$out_lines = $eventData['trimmedChangelogLines']; $out_lines = $eventData['trimmedChangelogLines'];
// save trimmed changelog // save trimmed changelog

View File

@ -2,6 +2,7 @@
namespace dokuwiki\Ui; namespace dokuwiki\Ui;
use dokuwiki\Extension\Event;
use dokuwiki\Form\Form; use dokuwiki\Form\Form;
class Search extends Ui class Search extends Ui
@ -86,7 +87,7 @@ class Search extends Ui
$searchForm->addFieldsetClose(); $searchForm->addFieldsetClose();
trigger_event('FORM_SEARCH_OUTPUT', $searchForm); Event::createAndTrigger('FORM_SEARCH_OUTPUT', $searchForm);
return $searchForm->toHTML(); return $searchForm->toHTML();
} }
@ -538,7 +539,7 @@ class Search extends Ui
'listItemContent' => [$link], 'listItemContent' => [$link],
'page' => $id, 'page' => $id,
]; ];
trigger_event('SEARCH_RESULT_PAGELOOKUP', $eventData); Event::createAndTrigger('SEARCH_RESULT_PAGELOOKUP', $eventData);
$html .= '<li>' . implode('', $eventData['listItemContent']) . '</li>'; $html .= '<li>' . implode('', $eventData['listItemContent']) . '</li>';
} }
$html .= '</ul> '; $html .= '</ul> ';
@ -606,7 +607,7 @@ class Search extends Ui
'page' => $id, 'page' => $id,
'position' => $position, 'position' => $position,
]; ];
trigger_event('SEARCH_RESULT_FULLPAGE', $eventData); Event::createAndTrigger('SEARCH_RESULT_FULLPAGE', $eventData);
$html .= '<div class="search_fullpage_result">'; $html .= '<div class="search_fullpage_result">';
$html .= '<dt>' . implode(' ', $eventData['resultHeader']) . '</dt>'; $html .= '<dt>' . implode(' ', $eventData['resultHeader']) . '</dt>';
foreach ($eventData['resultBody'] as $class => $htmlContent) { foreach ($eventData['resultBody'] as $class => $htmlContent) {

View File

@ -6,6 +6,8 @@
* @author Andreas Gohr <andi@splitbrain.org> * @author Andreas Gohr <andi@splitbrain.org>
*/ */
use dokuwiki\Extension\Event;
/** /**
* All action processing starts here * All action processing starts here
*/ */
@ -14,7 +16,7 @@ function act_dispatch(){
$router = \dokuwiki\ActionRouter::getInstance(true); $router = \dokuwiki\ActionRouter::getInstance(true);
$headers = array('Content-Type: text/html; charset=utf-8'); $headers = array('Content-Type: text/html; charset=utf-8');
trigger_event('ACTION_HEADERS_SEND',$headers,'act_sendheaders'); Event::createAndTrigger('ACTION_HEADERS_SEND',$headers,'act_sendheaders');
// clear internal variables // clear internal variables
unset($router); unset($router);

View File

@ -108,7 +108,7 @@ function auth_setup() {
'sticky' => $INPUT->bool('r'), 'sticky' => $INPUT->bool('r'),
'silent' => $INPUT->bool('http_credentials') 'silent' => $INPUT->bool('http_credentials')
); );
trigger_event('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper'); Event::createAndTrigger('AUTH_LOGIN_CHECK', $evdata, 'auth_login_wrapper');
} }
//load ACL into a global array XXX //load ACL into a global array XXX
@ -583,7 +583,7 @@ function auth_aclcheck($id, $user, $groups) {
'groups' => $groups 'groups' => $groups
); );
return trigger_event('AUTH_ACL_CHECK', $data, 'auth_aclcheck_cb'); return Event::createAndTrigger('AUTH_ACL_CHECK', $data, 'auth_aclcheck_cb');
} }
/** /**

View File

@ -10,13 +10,11 @@ use dokuwiki\Debug\DebugHelper;
*/ */
class cache extends \dokuwiki\Cache\Cache class cache extends \dokuwiki\Cache\Cache
{ {
public function __construct($key, $ext) public function __construct($key, $ext)
{ {
DebugHelper::dbgDeprecatedFunction(dokuwiki\Cache\Cache::class); DebugHelper::dbgDeprecatedFunction(dokuwiki\Cache\Cache::class);
parent::__construct($key, $ext); parent::__construct($key, $ext);
} }
} }
/** /**

View File

@ -757,7 +757,7 @@ function checkwordblock($text = '') {
$callback = function () { $callback = function () {
return true; return true;
}; };
return trigger_event('COMMON_WORDBLOCK_BLOCKED', $data, $callback, true); return Event::createAndTrigger('COMMON_WORDBLOCK_BLOCKED', $data, $callback, true);
} }
} }
return false; return false;
@ -1380,7 +1380,7 @@ function saveWikiText($id, $text, $summary, $minor = false) {
if($svdta['changeType'] == DOKU_CHANGE_TYPE_DELETE) { if($svdta['changeType'] == DOKU_CHANGE_TYPE_DELETE) {
// Send "update" event with empty data, so plugins can react to page deletion // Send "update" event with empty data, so plugins can react to page deletion
$data = array(array($svdta['file'], '', false), getNS($id), noNS($id), false); $data = array(array($svdta['file'], '', false), getNS($id), noNS($id), false);
trigger_event('IO_WIKIPAGE_WRITE', $data); Event::createAndTrigger('IO_WIKIPAGE_WRITE', $data);
// pre-save deleted revision // pre-save deleted revision
@touch($svdta['file']); @touch($svdta['file']);
clearstatcache(); clearstatcache();
@ -1478,7 +1478,7 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace =
if(!actionOK('subscribe')) return false; //subscribers enabled? if(!actionOK('subscribe')) return false; //subscribers enabled?
if($conf['useacl'] && $INPUT->server->str('REMOTE_USER') && $minor) return false; //skip minors if($conf['useacl'] && $INPUT->server->str('REMOTE_USER') && $minor) return false; //skip minors
$data = array('id' => $id, 'addresslist' => '', 'self' => false, 'replacements' => $replace); $data = array('id' => $id, 'addresslist' => '', 'self' => false, 'replacements' => $replace);
trigger_event( Event::createAndTrigger(
'COMMON_NOTIFY_ADDRESSLIST', $data, 'COMMON_NOTIFY_ADDRESSLIST', $data,
array(new Subscription(), 'notifyaddresses') array(new Subscription(), 'notifyaddresses')
); );

View File

@ -4,6 +4,8 @@
* These classes and functions are deprecated and will be removed in future releases * These classes and functions are deprecated and will be removed in future releases
*/ */
use dokuwiki\Debug\DebugHelper;
/** /**
* @inheritdoc * @inheritdoc
* @deprecated 2018-05-07 * @deprecated 2018-05-07
@ -302,7 +304,8 @@ class HTTPClient extends \dokuwiki\HTTP\HTTPClient {
/** /**
* @deprecated since 2019-03-17 use \dokuwiki\HTTP\DokuHTTPClient instead! * @deprecated since 2019-03-17 use \dokuwiki\HTTP\DokuHTTPClient instead!
*/ */
class DokuHTTPClient extends \dokuwiki\HTTP\DokuHTTPClient { class DokuHTTPClient extends \dokuwiki\HTTP\DokuHTTPClient
{
/** /**
* @inheritdoc * @inheritdoc
@ -313,5 +316,22 @@ class DokuHTTPClient extends \dokuwiki\HTTP\DokuHTTPClient {
DebugHelper::dbgDeprecatedFunction(dokuwiki\HTTP\DokuHTTPClient::class); DebugHelper::dbgDeprecatedFunction(dokuwiki\HTTP\DokuHTTPClient::class);
parent::__construct(); parent::__construct();
} }
}
/**
* function wrapper to process (create, trigger and destroy) an event
*
* @param string $name name for the event
* @param mixed $data event data
* @param callback $action (optional, default=NULL) default action, a php callback function
* @param bool $canPreventDefault (optional, default=true) can hooks prevent the default action
*
* @return mixed the event results value after all event processing is complete
* by default this is the return value of the default action however
* it can be set or modified by event handler hooks
* @deprecated 2018-06-15
*/
function trigger_event($name, &$data, $action=null, $canPreventDefault=true) {
dbg_deprecated('\dokuwiki\Extension\Event::createAndTrigger');
return \dokuwiki\Extension\Event::createAndTrigger($name, $data, $action, $canPreventDefault);
} }

View File

@ -1,21 +0,0 @@
<?php
/**
* trigger_event
*
* function wrapper to process (create, trigger and destroy) an event
*
* @param string $name name for the event
* @param mixed $data event data
* @param callback $action (optional, default=NULL) default action, a php callback function
* @param bool $canPreventDefault (optional, default=true) can hooks prevent the default action
*
* @return mixed the event results value after all event processing is complete
* by default this is the return value of the default action however
* it can be set or modified by event handler hooks
*/
function trigger_event($name, &$data, $action=null, $canPreventDefault=true) {
$evt = new \dokuwiki\Extension\Event($name, $data);
return $evt->trigger($action, $canPreventDefault);
}

View File

@ -39,7 +39,7 @@ function ft_pageSearch($query,&$highlight, $sort = null, $after = null, $before
]; ];
$data['highlight'] =& $highlight; $data['highlight'] =& $highlight;
return trigger_event('SEARCH_QUERY_FULLPAGE', $data, '_ft_pageSearch'); return Event::createAndTrigger('SEARCH_QUERY_FULLPAGE', $data, '_ft_pageSearch');
} }
/** /**
@ -244,7 +244,7 @@ function ft_pageLookup($id, $in_ns=false, $in_title=false, $after = null, $befor
'before' => $before 'before' => $before
]; ];
$data['has_titles'] = true; // for plugin backward compatibility check $data['has_titles'] = true; // for plugin backward compatibility check
return trigger_event('SEARCH_QUERY_PAGELOOKUP', $data, '_ft_pageLookup'); return Event::createAndTrigger('SEARCH_QUERY_PAGELOOKUP', $data, '_ft_pageLookup');
} }
/** /**

View File

@ -9,6 +9,7 @@
use dokuwiki\ChangeLog\MediaChangeLog; use dokuwiki\ChangeLog\MediaChangeLog;
use dokuwiki\ChangeLog\PageChangeLog; use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\Extension\AuthPlugin; use dokuwiki\Extension\AuthPlugin;
use dokuwiki\Extension\Event;
if (!defined('SEC_EDIT_PATTERN')) { if (!defined('SEC_EDIT_PATTERN')) {
define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#'); define('SEC_EDIT_PATTERN', '#<!-- EDIT({.*?}) -->#');
@ -134,7 +135,7 @@ function html_secedit_button($matches){
$data ['target'] = strtolower($data['target']); $data ['target'] = strtolower($data['target']);
$data ['hid'] = strtolower($data['hid']); $data ['hid'] = strtolower($data['hid']);
return trigger_event('HTML_SECEDIT_BUTTON', $data, return Event::createAndTrigger('HTML_SECEDIT_BUTTON', $data,
'html_secedit_get_button'); 'html_secedit_get_button');
} }
@ -299,7 +300,7 @@ function html_show($txt=null){
}else{ }else{
if ($REV||$DATE_AT){ if ($REV||$DATE_AT){
$data = array('rev' => &$REV, 'date_at' => &$DATE_AT); $data = array('rev' => &$REV, 'date_at' => &$DATE_AT);
trigger_event('HTML_SHOWREV_OUTPUT', $data, 'html_showrev'); Event::createAndTrigger('HTML_SHOWREV_OUTPUT', $data, 'html_showrev');
} }
$html = p_wiki_xhtml($ID,$REV,true,$DATE_AT); $html = p_wiki_xhtml($ID,$REV,true,$DATE_AT);
$html = html_secedit($html,$secedit); $html = html_secedit($html,$secedit);
@ -1873,7 +1874,7 @@ function html_edit(){
if ($data['target'] !== 'section') { if ($data['target'] !== 'section') {
// Only emit event if page is writable, section edit data is valid and // Only emit event if page is writable, section edit data is valid and
// edit target is not section. // edit target is not section.
trigger_event('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true); Event::createAndTrigger('HTML_EDIT_FORMSELECTION', $data, 'html_edit_form', true);
} else { } else {
html_edit_form($data); html_edit_form($data);
} }
@ -2222,7 +2223,7 @@ function html_mktocitem($link, $text, $level, $hash='#'){
function html_form($name, &$form) { function html_form($name, &$form) {
// Safety check in case the caller forgets. // Safety check in case the caller forgets.
$form->endFieldset(); $form->endFieldset();
trigger_event('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false); Event::createAndTrigger('HTML_'.strtoupper($name).'FORM_OUTPUT', $form, 'html_form_output', false);
} }
/** /**

View File

@ -69,7 +69,7 @@ function idx_get_version(){
// DokuWiki version is included for the convenience of plugins // DokuWiki version is included for the convenience of plugins
$data = array('dokuwiki'=>$version); $data = array('dokuwiki'=>$version);
trigger_event('INDEXER_VERSION_GET', $data, null, false); Event::createAndTrigger('INDEXER_VERSION_GET', $data, null, false);
unset($data['dokuwiki']); // this needs to be first unset($data['dokuwiki']); // this needs to be first
ksort($data); ksort($data);
foreach ($data as $plugin=>$vers) foreach ($data as $plugin=>$vers)

View File

@ -3,6 +3,7 @@
* Initialize some defaults needed for DokuWiki * Initialize some defaults needed for DokuWiki
*/ */
use dokuwiki\Extension\Event;
use dokuwiki\Extension\EventHandler; use dokuwiki\Extension\EventHandler;
/** /**
@ -221,7 +222,7 @@ global $EVENT_HANDLER;
$EVENT_HANDLER = new EventHandler(); $EVENT_HANDLER = new EventHandler();
$local = $conf['lang']; $local = $conf['lang'];
trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); Event::createAndTrigger('INIT_LANG_LOAD', $local, 'init_lang', true);
// setup authentication system // setup authentication system

View File

@ -7,6 +7,7 @@
*/ */
use dokuwiki\HTTP\DokuHTTPClient; use dokuwiki\HTTP\DokuHTTPClient;
use dokuwiki\Extension\Event;
/** /**
* Removes empty directories * Removes empty directories
@ -39,7 +40,7 @@ function io_sweepNS($id,$basedir='datadir'){
if ($ns_type!==false) { if ($ns_type!==false) {
$data = array($id, $ns_type); $data = array($id, $ns_type);
$delone = true; // we deleted at least one dir $delone = true; // we deleted at least one dir
trigger_event('IO_NAMESPACE_DELETED', $data); Event::createAndTrigger('IO_NAMESPACE_DELETED', $data);
} }
} else { return $delone; } } else { return $delone; }
} }
@ -69,7 +70,7 @@ function io_sweepNS($id,$basedir='datadir'){
function io_readWikiPage($file, $id, $rev=false) { function io_readWikiPage($file, $id, $rev=false) {
if (empty($rev)) { $rev = false; } if (empty($rev)) { $rev = false; }
$data = array(array($file, true), getNS($id), noNS($id), $rev); $data = array(array($file, true), getNS($id), noNS($id), $rev);
return trigger_event('IO_WIKIPAGE_READ', $data, '_io_readWikiPage_action', false); return Event::createAndTrigger('IO_WIKIPAGE_READ', $data, '_io_readWikiPage_action', false);
} }
/** /**
@ -189,7 +190,7 @@ function io_writeWikiPage($file, $content, $id, $rev=false) {
if (empty($rev)) { $rev = false; } if (empty($rev)) { $rev = false; }
if ($rev===false) { io_createNamespace($id); } // create namespaces as needed if ($rev===false) { io_createNamespace($id); } // create namespaces as needed
$data = array(array($file, $content, false), getNS($id), noNS($id), $rev); $data = array(array($file, $content, false), getNS($id), noNS($id), $rev);
return trigger_event('IO_WIKIPAGE_WRITE', $data, '_io_writeWikiPage_action', false); return Event::createAndTrigger('IO_WIKIPAGE_WRITE', $data, '_io_writeWikiPage_action', false);
} }
/** /**
@ -469,7 +470,7 @@ function io_createNamespace($id, $ns_type='pages') {
$missing = array_reverse($missing); // inside out $missing = array_reverse($missing); // inside out
foreach ($missing as $ns) { foreach ($missing as $ns) {
$data = array($ns, $ns_type); $data = array($ns, $ns_type);
trigger_event('IO_NAMESPACE_CREATED', $data); Event::createAndTrigger('IO_NAMESPACE_CREATED', $data);
} }
} }

View File

@ -8,6 +8,8 @@
// end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?) // end of line for mail lines - RFC822 says CRLF but postfix (and other MTAs?)
// think different // think different
use dokuwiki\Extension\Event;
if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n"); if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n");
#define('MAILHEADER_ASCIIONLY',1); #define('MAILHEADER_ASCIIONLY',1);
@ -103,7 +105,7 @@ function mail_setup(){
function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){ function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){
dbg_deprecated('class Mailer::'); dbg_deprecated('class Mailer::');
$message = compact('to','subject','body','from','cc','bcc','headers','params'); $message = compact('to','subject','body','from','cc','bcc','headers','params');
return trigger_event('MAIL_MESSAGE_SEND',$message,'_mail_send_action'); return Event::createAndTrigger('MAIL_MESSAGE_SEND',$message,'_mail_send_action');
} }
/** /**

View File

@ -484,7 +484,7 @@ function media_save($file, $id, $ow, $auth, $move) {
$data[5] = $move; $data[5] = $move;
// trigger event // trigger event
return trigger_event('MEDIA_UPLOAD_FINISH', $data, '_media_upload_action', true); return Event::createAndTrigger('MEDIA_UPLOAD_FINISH', $data, '_media_upload_action', true);
} }
/** /**
@ -1275,7 +1275,7 @@ function media_diff($image, $ns, $auth, $fromajax = false) {
$data[5] = $fromajax; $data[5] = $fromajax;
// trigger event // trigger event
return trigger_event('MEDIA_DIFF', $data, '_media_file_diff', true); return Event::createAndTrigger('MEDIA_DIFF', $data, '_media_file_diff', true);
} }
/** /**

View File

@ -636,7 +636,7 @@ function isHiddenPage($id){
'id' => $id, 'id' => $id,
'hidden' => false 'hidden' => false
); );
trigger_event('PAGEUTILS_ID_HIDEPAGE', $data, '_isHiddenPage'); \dokuwiki\Extension\Event::createAndTrigger('PAGEUTILS_ID_HIDEPAGE', $data, '_isHiddenPage');
return $data['hidden']; return $data['hidden'];
} }

View File

@ -1,5 +1,6 @@
<?php <?php
use dokuwiki\Extension\Event;
use dokuwiki\Extension\SyntaxPlugin; use dokuwiki\Extension\SyntaxPlugin;
use dokuwiki\Parsing\Handler\Block; use dokuwiki\Parsing\Handler\Block;
use dokuwiki\Parsing\Handler\CallWriter; use dokuwiki\Parsing\Handler\CallWriter;
@ -83,7 +84,7 @@ class Doku_Handler {
$this->calls = $B->process($this->calls); $this->calls = $B->process($this->calls);
} }
trigger_event('PARSER_HANDLER_DONE',$this); Event::createAndTrigger('PARSER_HANDLER_DONE',$this);
array_unshift($this->calls,array('document_start',array(),0)); array_unshift($this->calls,array('document_start',array(),0));
$last_call = end($this->calls); $last_call = end($this->calls);

View File

@ -211,7 +211,7 @@ function p_get_instructions($text){
} }
// Do the parsing // Do the parsing
trigger_event('PARSER_WIKITEXT_PREPROCESS', $text); Event::createAndTrigger('PARSER_WIKITEXT_PREPROCESS', $text);
$p = $Parser->parse($text); $p = $Parser->parse($text);
// dbg($p); // dbg($p);
return $p; return $p;
@ -678,7 +678,7 @@ function p_render($mode,$instructions,&$info,$date_at=''){
// Post process and return the output // Post process and return the output
$data = array($mode,& $Renderer->doc); $data = array($mode,& $Renderer->doc);
trigger_event('RENDERER_CONTENT_POSTPROCESS',$data); Event::createAndTrigger('RENDERER_CONTENT_POSTPROCESS',$data);
return $Renderer->doc; return $Renderer->doc;
} }

View File

@ -81,9 +81,9 @@ function tpl_content($prependTOC = true) {
$INFO['prependTOC'] = $prependTOC; $INFO['prependTOC'] = $prependTOC;
ob_start(); ob_start();
trigger_event('TPL_ACT_RENDER', $ACT, 'tpl_content_core'); Event::createAndTrigger('TPL_ACT_RENDER', $ACT, 'tpl_content_core');
$html_output = ob_get_clean(); $html_output = ob_get_clean();
trigger_event('TPL_CONTENT_DISPLAY', $html_output, 'ptln'); Event::createAndTrigger('TPL_CONTENT_DISPLAY', $html_output, 'ptln');
return !empty($html_output); return !empty($html_output);
} }
@ -150,7 +150,7 @@ function tpl_toc($return = false) {
} }
} }
trigger_event('TPL_TOC_RENDER', $toc, null, false); Event::createAndTrigger('TPL_TOC_RENDER', $toc, null, false);
$html = html_TOC($toc); $html = html_TOC($toc);
if($return) return $html; if($return) return $html;
echo $html; echo $html;
@ -359,7 +359,7 @@ function tpl_metaheaders($alt = true) {
); );
// trigger event here // trigger event here
trigger_event('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true); Event::createAndTrigger('TPL_METAHEADER_OUTPUT', $head, '_tpl_metaheaders_action', true);
return true; return true;
} }
@ -703,7 +703,7 @@ function tpl_searchform($ajax = true, $autocomplete = true) {
$searchForm->addTagClose('div'); $searchForm->addTagClose('div');
} }
$searchForm->addTagClose('div'); $searchForm->addTagClose('div');
trigger_event('FORM_QUICKSEARCH_OUTPUT', $searchForm); Event::createAndTrigger('FORM_QUICKSEARCH_OUTPUT', $searchForm);
echo $searchForm->toHTML(); echo $searchForm->toHTML();
@ -1139,7 +1139,7 @@ function tpl_img($maxwidth = 0, $maxheight = 0, $link = true, $params = null) {
$p['src'] = $src; $p['src'] = $src;
$data = array('url'=> ($link ? $url : null), 'params'=> $p); $data = array('url'=> ($link ? $url : null), 'params'=> $p);
return trigger_event('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true); return Event::createAndTrigger('TPL_IMG_DISPLAY', $data, '_tpl_img_action', true);
} }
/** /**

View File

@ -127,7 +127,7 @@ function css_out(){
// plugins decide whether to include the DW default styles. // plugins decide whether to include the DW default styles.
// This can be done by preventing the Default. // This can be done by preventing the Default.
$media_files['DW_DEFAULT'] = css_filewrapper('DW_DEFAULT'); $media_files['DW_DEFAULT'] = css_filewrapper('DW_DEFAULT');
trigger_event('CSS_STYLES_INCLUDED', $media_files['DW_DEFAULT'], 'css_defaultstyles'); Event::createAndTrigger('CSS_STYLES_INCLUDED', $media_files['DW_DEFAULT'], 'css_defaultstyles');
// build the stylesheet // build the stylesheet
foreach ($mediatypes as $mediatype) { foreach ($mediatypes as $mediatype) {

View File

@ -1,4 +1,7 @@
<?php <?php
use dokuwiki\Extension\Event;
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
define('DOKU_MEDIADETAIL',1); define('DOKU_MEDIADETAIL',1);
require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/init.php');
@ -12,7 +15,7 @@ $REV = $INPUT->int('rev');
$INFO = array_merge(pageinfo(),mediainfo()); $INFO = array_merge(pageinfo(),mediainfo());
$tmp = array(); $tmp = array();
trigger_event('DETAIL_STARTED', $tmp); Event::createAndTrigger('DETAIL_STARTED', $tmp);
//close session //close session
session_write_close(); session_write_close();

View File

@ -7,8 +7,9 @@
*/ */
use dokuwiki\Cache\Cache; use dokuwiki\Cache\Cache;
use dokuwiki\Extension\Event;
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ .'/../../');
if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching) if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session or authentication here (better caching)
if(!defined('NL')) define('NL',"\n"); if(!defined('NL')) define('NL',"\n");
if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here
@ -75,7 +76,7 @@ function js_out(){
} }
// Let plugins decide to either put more scripts here or to remove some // Let plugins decide to either put more scripts here or to remove some
trigger_event('JS_SCRIPT_LIST', $files); Event::createAndTrigger('JS_SCRIPT_LIST', $files);
// The generated script depends on some dynamic options // The generated script depends on some dynamic options
$cache = new Cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].md5(serialize($files)),'.js'); $cache = new Cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].md5(serialize($files)),'.js');

View File

@ -1,4 +1,7 @@
<?php <?php
use dokuwiki\Extension\Event;
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../');
define('DOKU_MEDIAMANAGER',1); define('DOKU_MEDIAMANAGER',1);
@ -38,7 +41,7 @@
$AUTH = $INFO['perm']; // shortcut for historical reasons $AUTH = $INFO['perm']; // shortcut for historical reasons
$tmp = array(); $tmp = array();
trigger_event('MEDIAMANAGER_STARTED', $tmp); Event::createAndTrigger('MEDIAMANAGER_STARTED', $tmp);
session_write_close(); //close session session_write_close(); //close session
// do not display the manager if user does not have read access // do not display the manager if user does not have read access

View File

@ -2,6 +2,8 @@
namespace dokuwiki\plugin\config\core; namespace dokuwiki\plugin\config\core;
use dokuwiki\Extension\Event;
/** /**
* Configuration loader * Configuration loader
* *
@ -28,7 +30,7 @@ class Loader {
$this->plugins = plugin_list(); $this->plugins = plugin_list();
$this->template = $conf['template']; $this->template = $conf['template'];
// allow plugins to remove configurable plugins // allow plugins to remove configurable plugins
trigger_event('PLUGIN_CONFIG_PLUGINLIST', $this->plugins); Event::createAndTrigger('PLUGIN_CONFIG_PLUGINLIST', $this->plugins);
} }
/** /**

View File

@ -1,13 +1,13 @@
<?php <?php
use dokuwiki\HTTP\DokuHTTPClient; use dokuwiki\HTTP\DokuHTTPClient;
use dokuwiki\Extension\Event;
/** /**
* Popularity Feedback Plugin * Popularity Feedback Plugin
* *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*/ */
class helper_plugin_popularity extends Dokuwiki_Plugin class helper_plugin_popularity extends Dokuwiki_Plugin
{ {
/** /**
@ -244,7 +244,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin
protected function addPluginUsageData(&$data) protected function addPluginUsageData(&$data)
{ {
$pluginsData = array(); $pluginsData = array();
trigger_event('PLUGIN_POPULARITY_DATA_SETUP', $pluginsData); Event::createAndTrigger('PLUGIN_POPULARITY_DATA_SETUP', $pluginsData);
foreach ($pluginsData as $plugin => $d) { foreach ($pluginsData as $plugin => $d) {
if (is_array($d)) { if (is_array($d)) {
foreach ($d as $key => $value) { foreach ($d as $key => $value) {

View File

@ -1,4 +1,7 @@
<?php <?php
use dokuwiki\Extension\Event;
/** /**
* Plugin for testing the test system * Plugin for testing the test system
* *
@ -15,7 +18,7 @@ class action_plugin_testing extends DokuWiki_Action_Plugin {
public function dokuwikiStarted() { public function dokuwikiStarted() {
$param = array(); $param = array();
trigger_event('TESTING_PLUGIN_INSTALLED', $param); Event::createAndTrigger('TESTING_PLUGIN_INSTALLED', $param);
msg('The testing plugin is enabled and should be disabled.',-1); msg('The testing plugin is enabled and should be disabled.',-1);
} }
} }