2020-03-30 21:32:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2020-04-02 22:50:50 +00:00
|
|
|
* Tabpage plugin: Shows links to children pages in the page menu
|
2020-03-30 21:32:07 +00:00
|
|
|
*
|
|
|
|
* @license BSD 2-Clause
|
|
|
|
* @author Antoine Le Gonidec <vv221.dokuwiki@dotslashplay.it>
|
|
|
|
*/
|
|
|
|
|
|
|
|
// must be run within Dokuwiki
|
|
|
|
if ( ! defined('DOKU_INC') ) {
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2020-04-02 23:15:41 +00:00
|
|
|
use dokuwiki\plugin\childrenpages\MenuItem;
|
|
|
|
|
2020-04-02 22:50:50 +00:00
|
|
|
class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
2020-03-30 21:32:07 +00:00
|
|
|
/**
|
|
|
|
* Registers a callback function for a given event
|
|
|
|
*
|
|
|
|
* @param Doku_Event_Handler $controller
|
|
|
|
*/
|
2020-04-02 22:04:45 +00:00
|
|
|
public function register(Doku_Event_Handler $controller) : void {
|
2020-04-02 23:15:41 +00:00
|
|
|
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addMenuItems');
|
2020-04-02 21:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add new items to the page menu
|
|
|
|
*
|
|
|
|
* @param Doku_Event $event
|
|
|
|
*/
|
2020-04-02 23:15:41 +00:00
|
|
|
public function addMenuItems(Doku_Event $event) : void {
|
2020-04-02 22:56:58 +00:00
|
|
|
global $INFO;
|
2020-04-02 21:48:40 +00:00
|
|
|
// Check that this method has been called in the expected context
|
|
|
|
if ( $event->name !== 'MENU_ITEMS_ASSEMBLY' ) {
|
|
|
|
$message = "Tabpage plugin error:";
|
|
|
|
$message .= "addMenuItem method should only be called by \"MENU_ITEMS_ASSEMBLY\" event";
|
|
|
|
$message .= ", but it has been called by \"$event->name\".";
|
|
|
|
throw new Exception($message);
|
|
|
|
}
|
2020-04-02 22:04:45 +00:00
|
|
|
// Only add content to the page menu
|
|
|
|
if ( $event->data['view'] !== 'page' ) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-02 22:56:58 +00:00
|
|
|
// Only add links if the current page is not included in a namespace
|
|
|
|
if ( ! empty($INFO['namespace']) ) {
|
|
|
|
return;
|
|
|
|
}
|
2020-04-02 23:15:41 +00:00
|
|
|
// Get the list of children pages
|
2020-04-02 23:44:50 +00:00
|
|
|
$children_types = [ 'animation', 'gameplay', 'dev', 'talk' ];
|
|
|
|
foreach ( $children_types as $child_type ) {
|
|
|
|
$child_label = $this->getLang("btn_$child_type");
|
|
|
|
$this->addMenuItem($event, $child_type, $child_label);
|
2020-04-02 23:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new item to the page menu
|
|
|
|
*
|
|
|
|
* @param Doku_Event $event
|
2020-04-02 23:44:50 +00:00
|
|
|
* @param string $type
|
|
|
|
* @param string $name
|
2020-04-02 23:15:41 +00:00
|
|
|
*/
|
2020-04-02 23:44:50 +00:00
|
|
|
protected function addMenuItem(Doku_Event $event, string $type, string $name) {
|
|
|
|
$item = $this->generateMenuItem($type, $name);
|
2020-04-02 23:15:41 +00:00
|
|
|
$event->data['items'][] = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a new menu item
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
*/
|
2020-04-02 23:44:50 +00:00
|
|
|
protected function generateMenuItem(string $type, string $name) {
|
|
|
|
return new MenuItem($type, $name);
|
2020-03-30 21:32:07 +00:00
|
|
|
}
|
|
|
|
}
|