Compare commits
10 commits
c24b382c3b
...
b91a53b1a2
Author | SHA1 | Date | |
---|---|---|---|
b91a53b1a2 | |||
047a5be134 | |||
77a903816c | |||
3243439d75 | |||
035c6ab484 | |||
02692388ca | |||
c10599048e | |||
3e901fd66e | |||
04af95e6f3 | |||
9e5c7a32e3 |
10 changed files with 44 additions and 53 deletions
16
MenuItem.php
16
MenuItem.php
|
@ -5,6 +5,11 @@ namespace dokuwiki\plugin\childrenpages;
|
||||||
use dokuwiki\Menu\Item\AbstractItem;
|
use dokuwiki\Menu\Item\AbstractItem;
|
||||||
|
|
||||||
class MenuItem extends AbstractItem {
|
class MenuItem extends AbstractItem {
|
||||||
|
/**
|
||||||
|
* @var bool $is_active True if it is a link to the current page
|
||||||
|
*/
|
||||||
|
public $is_active;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a menu item from a passed string
|
* Generate a menu item from a passed string
|
||||||
*
|
*
|
||||||
|
@ -24,6 +29,7 @@ class MenuItem extends AbstractItem {
|
||||||
$this->label = $label;
|
$this->label = $label;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->setTargetFromType($type, $strip_namespace);
|
$this->setTargetFromType($type, $strip_namespace);
|
||||||
|
$this->setIsActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,6 +75,16 @@ class MenuItem extends AbstractItem {
|
||||||
$this->params = [];
|
$this->params = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the active status of the link
|
||||||
|
*/
|
||||||
|
protected function setIsActive() : void {
|
||||||
|
global $INFO;
|
||||||
|
$current_page_id = $INFO['id'];
|
||||||
|
$target_page_id = $this->id;
|
||||||
|
$this->is_active = ( $target_page_id === $current_page_id );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to get the attributes for constructing an <a> element
|
* Convenience method to get the attributes for constructing an <a> element
|
||||||
* Parent method is declared in dokuwiki\Menu\Item\AbstractItem
|
* Parent method is declared in dokuwiki\Menu\Item\AbstractItem
|
||||||
|
|
50
README.md
50
README.md
|
@ -5,64 +5,30 @@ through links in the page menu.
|
||||||
|
|
||||||
[![thumbnail]][screenshot]
|
[![thumbnail]][screenshot]
|
||||||
|
|
||||||
[thumbnail]: img/thumbnail.png
|
[thumbnail]: https://git.vv221.fr/dokuwiki-childrenpages/plain/img/thumbnail.png
|
||||||
[screenshot]: img/screenshot.png
|
[screenshot]: https://git.vv221.fr/dokuwiki-childrenpages/plain/img/screenshot.png
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Installation using archives
|
### Requirements
|
||||||
|
|
||||||
#### Requirements
|
|
||||||
|
|
||||||
* `curl`
|
|
||||||
* `tar`
|
|
||||||
* `gzip`
|
|
||||||
|
|
||||||
#### Current stable version (1.1.0)
|
|
||||||
|
|
||||||
Assuming the root directory of your DokuWiki installation is `/srv/dokuwiki`:
|
|
||||||
```
|
|
||||||
DOKUWIKI_PATH=/srv/dokuwiki
|
|
||||||
TARBALL_URL=https://forge.dotslashplay.it/vv221/dokuwiki-childrenpages/-/archive/1.0.0/dokuwiki-childrenpages-1.1.0.tar.gz
|
|
||||||
curl "$TARBALL_URL" > dokuwiki-childrenpages-1.1.0.tar.gz
|
|
||||||
mkdir --parents "$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
|
||||||
gzip --stdout --decompress dokuwiki-childrenpages-1.1.0.tar.gz | tar xf - --strip-components=1 --directory="$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
|
||||||
rm dokuwiki-childrenpages-1.1.0.tar.gz
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Latest development version
|
|
||||||
|
|
||||||
Assuming the root directory of your DokuWiki installation is `/srv/dokuwiki`:
|
|
||||||
```
|
|
||||||
DOKUWIKI_PATH=/srv/dokuwiki
|
|
||||||
TARBALL_URL=https://forge.dotslashplay.it/vv221/dokuwiki-childrenpages/-/archive/master/dokuwiki-childrenpages-master.tar.gz
|
|
||||||
curl "$TARBALL_URL" > dokuwiki-childrenpages-master.tar.gz
|
|
||||||
mkdir --parents "$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
|
||||||
gzip --stdout --decompress dokuwiki-childrenpages-master.tar.gz | tar xf - --strip-components=1 --directory="$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
|
||||||
rm dokuwiki-childrenpages-master.tar.gz
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation using git
|
|
||||||
|
|
||||||
#### Requirements
|
|
||||||
|
|
||||||
* `git`
|
* `git`
|
||||||
|
|
||||||
#### Current stable version (1.1.0)
|
### Current stable version (1.2.1)
|
||||||
|
|
||||||
Assuming the root directory of your DokuWiki installation is `/srv/dokuwiki`:
|
Assuming the root directory of your DokuWiki installation is `/srv/dokuwiki`:
|
||||||
```
|
```
|
||||||
DOKUWIKI_PATH=/srv/dokuwiki
|
DOKUWIKI_PATH=/srv/dokuwiki
|
||||||
REPO_URL=https://forge.dotslashplay.it/vv221/dokuwiki-childrenpages.git
|
REPO_URL=https://git.vv221.fr/dokuwiki-childrenpages
|
||||||
git clone --branch 1.1.0 --depth 1 "$REPO_URL" "$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
git clone --branch 1.2.1 --depth 1 "$REPO_URL" "$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Latest development version
|
### Latest development version
|
||||||
|
|
||||||
Assuming the root directory of your DokuWiki installation is `/srv/dokuwiki`:
|
Assuming the root directory of your DokuWiki installation is `/srv/dokuwiki`:
|
||||||
```
|
```
|
||||||
DOKUWIKI_PATH=/srv/dokuwiki
|
DOKUWIKI_PATH=/srv/dokuwiki
|
||||||
REPO_URL=https://forge.dotslashplay.it/vv221/dokuwiki-childrenpages.git
|
REPO_URL=https://git.vv221.fr/dokuwiki-childrenpages
|
||||||
git clone --branch master --depth 1 "$REPO_URL" "$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
git clone --branch master --depth 1 "$REPO_URL" "$DOKUWIKI_PATH/lib/plugins/childrenpages"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
17
action.php
17
action.php
|
@ -3,7 +3,7 @@
|
||||||
* Children pages plugin: Shows links to children pages in the page menu
|
* Children pages plugin: Shows links to children pages in the page menu
|
||||||
*
|
*
|
||||||
* @license BSD 2-Clause
|
* @license BSD 2-Clause
|
||||||
* @author Antoine Le Gonidec <vv221.dokuwiki@dotslashplay.it>
|
* @author Antoine Le Gonidec <vv221.dokuwiki@vv221.fr>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// must be run within Dokuwiki
|
// must be run within Dokuwiki
|
||||||
|
@ -40,17 +40,19 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
||||||
if ( $event->data['view'] !== 'page' ) {
|
if ( $event->data['view'] !== 'page' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Check if all links should be shown, or if the one to the current page shoud be excluded
|
||||||
|
$show_all_links = (bool) $this->getConf('show_link_to_current_page');
|
||||||
// If the current page is included in a reserved namespace, add a link back to main page
|
// If the current page is included in a reserved namespace, add a link back to main page
|
||||||
$children_types = $this->getConf('children_list');
|
$children_types = $this->getConf('children_list');
|
||||||
$top_namespace = $this->getTopLevelNamespace();
|
$top_namespace = $this->getTopLevelNamespace();
|
||||||
$is_child_page = in_array($top_namespace, $children_types);
|
$is_child_page = in_array($top_namespace, $children_types);
|
||||||
if ( $is_child_page ) {
|
if ( $show_all_links || $is_child_page ) {
|
||||||
$main_label = $this->getLang('btn_main');
|
$main_label = $this->getLang('btn_main');
|
||||||
$this->addMenuItem($event, '_main', $main_label, $top_namespace);
|
$this->addMenuItem($event, '_main', $main_label, $is_child_page);
|
||||||
}
|
}
|
||||||
// Add menu items for each child page
|
// Add menu items for each child page
|
||||||
foreach ( $children_types as $child_type ) {
|
foreach ( $children_types as $child_type ) {
|
||||||
if ( $child_type !== $top_namespace ) {
|
if ( $show_all_links || $child_type !== $top_namespace ) {
|
||||||
$child_label = $this->getLang("btn_$child_type");
|
$child_label = $this->getLang("btn_$child_type");
|
||||||
$this->addMenuItem($event, $child_type, $child_label, $is_child_page);
|
$this->addMenuItem($event, $child_type, $child_label, $is_child_page);
|
||||||
}
|
}
|
||||||
|
@ -91,10 +93,13 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
||||||
$language = $translation_plugin->getLangPart($INFO['id']);
|
$language = $translation_plugin->getLangPart($INFO['id']);
|
||||||
}
|
}
|
||||||
// Skip top-level language namespace if one is in use
|
// Skip top-level language namespace if one is in use
|
||||||
|
$namespace = explode(':', $INFO['namespace']);
|
||||||
if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) {
|
if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) {
|
||||||
return explode(':', $INFO['namespace'])[1];
|
// FIXME: $namespace is sometimes shorter than expected,
|
||||||
|
// this might be the symptom of some bug.
|
||||||
|
return ( count($namespace) > 1 ) ? $namespace[1] : null;
|
||||||
} else {
|
} else {
|
||||||
return explode(':', $INFO['namespace'])[0];
|
return $namespace[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$conf['children_list'] = array('animation', 'gameplay', 'dev', 'talk');
|
$conf['children_list'] = array('animation', 'gameplay', 'dev', 'talk');
|
||||||
|
$conf['show_link_to_current_page'] = 0;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$meta['children_list'] = [ 'array' ];
|
$meta['children_list'] = [ 'array' ];
|
||||||
|
$meta['show_link_to_current_page'] = [ 'onoff' ];
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$lang['btn_main'] = 'Back to main page';
|
$lang['btn_main'] = 'Main article';
|
||||||
|
|
||||||
$lang['btn_animation'] = 'Animation';
|
$lang['btn_animation'] = 'Animation';
|
||||||
$lang['btn_dev'] = 'Dev';
|
$lang['btn_dev'] = 'Dev';
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$lang['children_list'] = 'List of namespaces reserved for children pages';
|
$lang['children_list'] = 'List of namespaces reserved for children pages';
|
||||||
|
$lang['show_link_to_current_page'] = 'Include a link to the page currently shown';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$lang['btn_main'] = 'Retour à la page principale';
|
$lang['btn_main'] = 'Article principal';
|
||||||
|
|
||||||
$lang['btn_animation'] = 'Animation';
|
$lang['btn_animation'] = 'Animation';
|
||||||
$lang['btn_dev'] = 'Dev';
|
$lang['btn_dev'] = 'Dev';
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$lang['children_list'] = 'Liste des espaces de nom réservés aux pages enfants';
|
$lang['children_list'] = 'Liste des espaces de nom réservés aux pages enfants';
|
||||||
|
$lang['show_link_to_current_page'] = 'Inclure un lien vers la page actuellement affichée';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
base childrenpages
|
base childrenpages
|
||||||
author Antoine Le Gonidec
|
author Antoine Le Gonidec
|
||||||
email vv221.dokuwiki@dotslashplay.it
|
email numenaute@vv221.fr
|
||||||
date 2020-04-03
|
date 2024-10-04
|
||||||
name Children pages
|
name Children pages
|
||||||
desc For each page, this plugin adds children pages in pre-set namespaces, reachable through links in the page menu
|
desc For each page, this plugin adds children pages in pre-set namespaces, reachable through links in the page menu
|
||||||
url https://forge.dotslashplay.it/vv221/dokuwiki-childrenpages
|
url https://port.numenaute.org/dokuwiki/dokuwiki-plugin-childrenpages
|
||||||
|
|
Loading…
Reference in a new issue