aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/inc/Menu
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2023-09-02 14:42:51 +0200
committerGitHub <noreply@github.com>2023-09-02 14:42:51 +0200
commit5ff5424d8c81c7123d8656a787af2ff85b3dec21 (patch)
tree322929ee01d892bb3c927e7fe1238369c647f820 /inc/Menu
parent0613df3287b82a98b1e97cf86ed9d4c8fbd16f1c (diff)
parent91560755291852b8302767d454183a7662666f7e (diff)
downloaddokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.tar.gz
dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.zip
Merge pull request #4045 from dokuwiki/autofix
Use Rector to autofix code smell
Diffstat (limited to 'inc/Menu')
-rw-r--r--inc/Menu/AbstractMenu.php38
-rw-r--r--inc/Menu/DetailMenu.php11
-rw-r--r--inc/Menu/Item/AbstractItem.php91
-rw-r--r--inc/Menu/Item/Admin.php10
-rw-r--r--inc/Menu/Item/Back.php12
-rw-r--r--inc/Menu/Item/Backlink.php8
-rw-r--r--inc/Menu/Item/Edit.php31
-rw-r--r--inc/Menu/Item/ImgBackto.php10
-rw-r--r--inc/Menu/Item/Index.php10
-rw-r--r--inc/Menu/Item/Login.php12
-rw-r--r--inc/Menu/Item/Media.php8
-rw-r--r--inc/Menu/Item/MediaManager.php16
-rw-r--r--inc/Menu/Item/Profile.php10
-rw-r--r--inc/Menu/Item/Recent.php8
-rw-r--r--inc/Menu/Item/Register.php10
-rw-r--r--inc/Menu/Item/Resendpwd.php10
-rw-r--r--inc/Menu/Item/Revert.php2
-rw-r--r--inc/Menu/Item/Revisions.php8
-rw-r--r--inc/Menu/Item/Subscribe.php10
-rw-r--r--inc/Menu/Item/Top.php15
-rw-r--r--inc/Menu/MenuInterface.php4
-rw-r--r--inc/Menu/MobileMenu.php30
-rw-r--r--inc/Menu/PageMenu.php14
-rw-r--r--inc/Menu/SiteMenu.php11
-rw-r--r--inc/Menu/UserMenu.php12
25 files changed, 193 insertions, 208 deletions
diff --git a/inc/Menu/AbstractMenu.php b/inc/Menu/AbstractMenu.php
index 37e5d2cc3..499500696 100644
--- a/inc/Menu/AbstractMenu.php
+++ b/inc/Menu/AbstractMenu.php
@@ -12,10 +12,10 @@ use dokuwiki\Menu\Item\AbstractItem;
* It contains convenience functions to display the menu in HTML, but template authors can also
* just accesst the items via getItems() and create the HTML as however they see fit.
*/
-abstract class AbstractMenu implements MenuInterface {
-
+abstract class AbstractMenu implements MenuInterface
+{
/** @var string[] list of Item classes to load */
- protected $types = array();
+ protected $types = [];
/** @var int the context this menu is used in */
protected $context = AbstractItem::CTX_DESKTOP;
@@ -28,7 +28,8 @@ abstract class AbstractMenu implements MenuInterface {
*
* @param int $context the context this menu is used in
*/
- public function __construct($context = AbstractItem::CTX_DESKTOP) {
+ public function __construct($context = AbstractItem::CTX_DESKTOP)
+ {
$this->context = $context;
}
@@ -38,30 +39,29 @@ abstract class AbstractMenu implements MenuInterface {
* @return AbstractItem[]
* @triggers MENU_ITEMS_ASSEMBLY
*/
- public function getItems() {
- $data = array(
- 'view' => $this->view,
- 'items' => array(),
- );
- Event::createAndTrigger('MENU_ITEMS_ASSEMBLY', $data, array($this, 'loadItems'));
+ public function getItems()
+ {
+ $data = ['view' => $this->view, 'items' => []];
+ Event::createAndTrigger('MENU_ITEMS_ASSEMBLY', $data, [$this, 'loadItems']);
return $data['items'];
}
/**
* Default action for the MENU_ITEMS_ASSEMBLY event
*
- * @see getItems()
* @param array $data The plugin data
+ * @see getItems()
*/
- public function loadItems(&$data) {
- foreach($this->types as $class) {
+ public function loadItems(&$data)
+ {
+ foreach ($this->types as $class) {
try {
$class = "\\dokuwiki\\Menu\\Item\\$class";
/** @var AbstractItem $item */
$item = new $class();
- if(!$item->visibleInContext($this->context)) continue;
+ if (!$item->visibleInContext($this->context)) continue;
$data['items'][] = $item;
- } catch(\RuntimeException $ignored) {
+ } catch (\RuntimeException $ignored) {
// item not available
}
}
@@ -77,10 +77,11 @@ abstract class AbstractMenu implements MenuInterface {
* @param bool $svg add the SVG link
* @return string
*/
- public function getListItems($classprefix = '', $svg = true) {
+ public function getListItems($classprefix = '', $svg = true)
+ {
$html = '';
- foreach($this->getItems() as $item) {
- if($classprefix !== false) {
+ foreach ($this->getItems() as $item) {
+ if ($classprefix !== false) {
$class = ' class="' . $classprefix . $item->getType() . '"';
} else {
$class = '';
@@ -92,5 +93,4 @@ abstract class AbstractMenu implements MenuInterface {
}
return $html;
}
-
}
diff --git a/inc/Menu/DetailMenu.php b/inc/Menu/DetailMenu.php
index 27c0c6fce..2eb5c089e 100644
--- a/inc/Menu/DetailMenu.php
+++ b/inc/Menu/DetailMenu.php
@@ -8,14 +8,9 @@ namespace dokuwiki\Menu;
* This menu offers options on an image detail view. It usually displayed similar to
* the PageMenu.
*/
-class DetailMenu extends AbstractMenu {
-
+class DetailMenu extends AbstractMenu
+{
protected $view = 'detail';
- protected $types = array(
- 'MediaManager',
- 'ImgBackto',
- 'Top',
- );
-
+ protected $types = ['MediaManager', 'ImgBackto', 'Top'];
}
diff --git a/inc/Menu/Item/AbstractItem.php b/inc/Menu/Item/AbstractItem.php
index c6b04bfd3..509ce9747 100644
--- a/inc/Menu/Item/AbstractItem.php
+++ b/inc/Menu/Item/AbstractItem.php
@@ -17,14 +17,14 @@ namespace dokuwiki\Menu\Item;
* Children usually just need to overwrite the different properties, but for complex things
* the accessors may be overwritten instead.
*/
-abstract class AbstractItem {
-
+abstract class AbstractItem
+{
/** menu item is to be shown on desktop screens only */
- const CTX_DESKTOP = 1;
+ public const CTX_DESKTOP = 1;
/** menu item is to be shown on mobile screens only */
- const CTX_MOBILE = 2;
+ public const CTX_MOBILE = 2;
/** menu item is to be shown in all contexts */
- const CTX_ALL = 3;
+ public const CTX_ALL = 3;
/** @var string name of the action, usually the lowercase class name */
protected $type = '';
@@ -35,7 +35,7 @@ abstract class AbstractItem {
/** @var string the method to be used when this action is used in a form */
protected $method = 'get';
/** @var array parameters for the action (should contain the do parameter) */
- protected $params = array();
+ protected $params = [];
/** @var bool when true, a rel=nofollow should be used */
protected $nofollow = true;
/** @var string this item's label may contain a placeholder, which is replaced with this */
@@ -58,13 +58,14 @@ abstract class AbstractItem {
*
* @throws \RuntimeException when the action is disabled
*/
- public function __construct() {
+ public function __construct()
+ {
global $ID;
$this->id = $ID;
$this->type = $this->getType();
$this->params['do'] = $this->type;
- if(!actionOK($this->type)) throw new \RuntimeException("action disabled: {$this->type}");
+ if (!actionOK($this->type)) throw new \RuntimeException("action disabled: {$this->type}");
}
/**
@@ -76,16 +77,17 @@ abstract class AbstractItem {
*
* @return string
*/
- public function getLabel() {
- if($this->label !== '') return $this->label;
+ public function getLabel()
+ {
+ if ($this->label !== '') return $this->label;
/** @var array $lang */
global $lang;
$label = $lang['btn_' . $this->type];
- if(strpos($label, '%s')) {
+ if (strpos($label, '%s')) {
$label = sprintf($label, $this->replacement);
}
- if($label === '') $label = '[' . $this->type . ']';
+ if ($label === '') $label = '[' . $this->type . ']';
return $label;
}
@@ -97,8 +99,9 @@ abstract class AbstractItem {
*
* @return string
*/
- public function getTitle() {
- if($this->title === '') return $this->getLabel();
+ public function getTitle()
+ {
+ if ($this->title === '') return $this->getLabel();
return $this->title;
}
@@ -110,11 +113,12 @@ abstract class AbstractItem {
*
* Please note that the generated URL is *not* XML escaped.
*
- * @see wl()
* @return string
+ * @see wl()
*/
- public function getLink() {
- if($this->id && $this->id[0] == '#') {
+ public function getLink()
+ {
+ if ($this->id && $this->id[0] == '#') {
return $this->id;
} else {
return wl($this->id, $this->params, false, '&');
@@ -124,21 +128,19 @@ abstract class AbstractItem {
/**
* Convenience method to get the attributes for constructing an <a> element
*
- * @see buildAttributes()
* @param string|false $classprefix create a class from type with this prefix, false for no class
* @return array
+ * @see buildAttributes()
*/
- public function getLinkAttributes($classprefix = 'menuitem ') {
- $attr = array(
- 'href' => $this->getLink(),
- 'title' => $this->getTitle(),
- );
- if($this->isNofollow()) $attr['rel'] = 'nofollow';
- if($this->getAccesskey()) {
+ public function getLinkAttributes($classprefix = 'menuitem ')
+ {
+ $attr = ['href' => $this->getLink(), 'title' => $this->getTitle()];
+ if ($this->isNofollow()) $attr['rel'] = 'nofollow';
+ if ($this->getAccesskey()) {
$attr['accesskey'] = $this->getAccesskey();
$attr['title'] .= ' [' . $this->getAccesskey() . ']';
}
- if($classprefix !== false) $attr['class'] = $classprefix . $this->getType();
+ if ($classprefix !== false) $attr['class'] = $classprefix . $this->getType();
return $attr;
}
@@ -152,10 +154,11 @@ abstract class AbstractItem {
* @param bool $svg add SVG icon to the link
* @return string
*/
- public function asHtmlLink($classprefix = 'menuitem ', $svg = true) {
+ public function asHtmlLink($classprefix = 'menuitem ', $svg = true)
+ {
$attr = buildAttributes($this->getLinkAttributes($classprefix));
$html = "<a $attr>";
- if($svg) {
+ if ($svg) {
$html .= '<span>' . hsc($this->getLabel()) . '</span>';
$html .= inlineSVG($this->getSvg());
} else {
@@ -173,7 +176,8 @@ abstract class AbstractItem {
*
* @return string
*/
- public function asHtmlButton() {
+ public function asHtmlButton()
+ {
return html_btn(
$this->getType(),
$this->id,
@@ -192,15 +196,17 @@ abstract class AbstractItem {
* @param int $ctx the current context
* @return bool
*/
- public function visibleInContext($ctx) {
- return (bool) ($ctx & $this->context);
+ public function visibleInContext($ctx)
+ {
+ return (bool)($ctx & $this->context);
}
/**
* @return string the name of this item
*/
- public function getType() {
- if($this->type === '') {
+ public function getType()
+ {
+ if ($this->type === '') {
$this->type = strtolower(substr(strrchr(get_class($this), '\\'), 1));
}
return $this->type;
@@ -209,28 +215,32 @@ abstract class AbstractItem {
/**
* @return string
*/
- public function getAccesskey() {
+ public function getAccesskey()
+ {
return $this->accesskey;
}
/**
* @return array
*/
- public function getParams() {
+ public function getParams()
+ {
return $this->params;
}
/**
* @return bool
*/
- public function isNofollow() {
+ public function isNofollow()
+ {
return $this->nofollow;
}
/**
* @return string
*/
- public function getSvg() {
+ public function getSvg()
+ {
return $this->svg;
}
@@ -239,8 +249,9 @@ abstract class AbstractItem {
*
* @return array
*/
- public function getLegacyData() {
- return array(
+ public function getLegacyData()
+ {
+ return [
'accesskey' => $this->accesskey ?: null,
'type' => $this->type,
'id' => $this->id,
@@ -248,6 +259,6 @@ abstract class AbstractItem {
'params' => $this->params,
'nofollow' => $this->nofollow,
'replacement' => $this->replacement
- );
+ ];
}
}
diff --git a/inc/Menu/Item/Admin.php b/inc/Menu/Item/Admin.php
index e5506c220..d75b8ad6f 100644
--- a/inc/Menu/Item/Admin.php
+++ b/inc/Menu/Item/Admin.php
@@ -7,10 +7,11 @@ namespace dokuwiki\Menu\Item;
*
* Opens the Admin screen. Only shown to managers or above
*/
-class Admin extends AbstractItem {
-
+class Admin extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
parent::__construct();
$this->svg = DOKU_INC . 'lib/images/menu/settings.svg';
@@ -20,9 +21,8 @@ class Admin extends AbstractItem {
public function visibleInContext($ctx)
{
global $INFO;
- if(!$INFO['ismanager']) return false;
+ if (!$INFO['ismanager']) return false;
return parent::visibleInContext($ctx);
}
-
}
diff --git a/inc/Menu/Item/Back.php b/inc/Menu/Item/Back.php
index a7cc1d976..6c67492c4 100644
--- a/inc/Menu/Item/Back.php
+++ b/inc/Menu/Item/Back.php
@@ -8,22 +8,22 @@ namespace dokuwiki\Menu\Item;
* Navigates back up one namepspace. This is currently not used in any menu. Templates
* would need to add this item manually.
*/
-class Back extends AbstractItem {
-
+class Back extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $ID;
parent::__construct();
$parent = tpl_getparent($ID);
- if(!$parent) {
+ if (!$parent) {
throw new \RuntimeException("No parent for back action");
}
$this->id = $parent;
- $this->params = array('do' => '');
+ $this->params = ['do' => ''];
$this->accesskey = 'b';
$this->svg = DOKU_INC . 'lib/images/menu/12-back_arrow-left.svg';
}
-
}
diff --git a/inc/Menu/Item/Backlink.php b/inc/Menu/Item/Backlink.php
index 6dc242bdd..906d6004a 100644
--- a/inc/Menu/Item/Backlink.php
+++ b/inc/Menu/Item/Backlink.php
@@ -7,12 +7,12 @@ namespace dokuwiki\Menu\Item;
*
* Shows the backlinks for the current page
*/
-class Backlink extends AbstractItem {
-
+class Backlink extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
parent::__construct();
$this->svg = DOKU_INC . 'lib/images/menu/08-backlink_link-variant.svg';
}
-
}
diff --git a/inc/Menu/Item/Edit.php b/inc/Menu/Item/Edit.php
index 579b6885d..c063ca28a 100644
--- a/inc/Menu/Item/Edit.php
+++ b/inc/Menu/Item/Edit.php
@@ -8,38 +8,39 @@ namespace dokuwiki\Menu\Item;
* Most complex item. Shows the edit button but mutates to show, draft and create based on
* current state.
*/
-class Edit extends AbstractItem {
-
+class Edit extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $ACT;
global $INFO;
global $REV;
parent::__construct();
- if($ACT === 'show') {
+ if ($ACT === 'show') {
$this->method = 'post';
- if($INFO['writable']) {
+ if ($INFO['writable']) {
$this->accesskey = 'e';
- if(!empty($INFO['draft'])) {
+ if (!empty($INFO['draft'])) {
$this->type = 'draft';
$this->params['do'] = 'draft';
} else {
$this->params['rev'] = $REV;
- if(!$INFO['exists']) {
+ if (!$INFO['exists']) {
$this->type = 'create';
}
}
} else {
- if(!actionOK("source")) throw new \RuntimeException("action disabled: source");
+ if (!actionOK("source")) throw new \RuntimeException("action disabled: source");
$params['rev'] = $REV;
$this->type = 'source';
$this->accesskey = 'v';
}
} else {
if (auth_quickaclcheck($INFO['id']) < AUTH_READ) throw new \RuntimeException("no permission to read");
- $this->params = array('do' => '');
+ $this->params = ['do' => ''];
$this->type = 'show';
$this->accesskey = 'v';
}
@@ -50,17 +51,17 @@ class Edit extends AbstractItem {
/**
* change the icon according to what type the edit button has
*/
- protected function setIcon() {
- $icons = array(
+ protected function setIcon()
+ {
+ $icons = [
'edit' => '01-edit_pencil.svg',
'create' => '02-create_pencil.svg',
'draft' => '03-draft_android-studio.svg',
'show' => '04-show_file-document.svg',
- 'source' => '05-source_file-xml.svg',
- );
- if(isset($icons[$this->type])) {
+ 'source' => '05-source_file-xml.svg'
+ ];
+ if (isset($icons[$this->type])) {
$this->svg = DOKU_INC . 'lib/images/menu/' . $icons[$this->type];
}
}
-
}
diff --git a/inc/Menu/Item/ImgBackto.php b/inc/Menu/Item/ImgBackto.php
index 72820a53a..2d8a2c9b3 100644
--- a/inc/Menu/Item/ImgBackto.php
+++ b/inc/Menu/Item/ImgBackto.php
@@ -7,18 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Links back to the originating page from a detail image view
*/
-class ImgBackto extends AbstractItem {
-
+class ImgBackto extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $ID;
parent::__construct();
$this->svg = DOKU_INC . 'lib/images/menu/12-back_arrow-left.svg';
$this->type = 'img_backto';
- $this->params = array();
+ $this->params = [];
$this->accesskey = 'b';
$this->replacement = $ID;
}
-
}
diff --git a/inc/Menu/Item/Index.php b/inc/Menu/Item/Index.php
index 41326738b..a7459546e 100644
--- a/inc/Menu/Item/Index.php
+++ b/inc/Menu/Item/Index.php
@@ -7,10 +7,11 @@ namespace dokuwiki\Menu\Item;
*
* Shows the sitemap
*/
-class Index extends AbstractItem {
-
+class Index extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $conf;
global $ID;
parent::__construct();
@@ -19,9 +20,8 @@ class Index extends AbstractItem {
$this->svg = DOKU_INC . 'lib/images/menu/file-tree.svg';
// allow searchbots to get to the sitemap from the homepage (when dokuwiki isn't providing a sitemap.xml)
- if($conf['start'] == $ID && !$conf['sitemap']) {
+ if ($conf['start'] == $ID && !$conf['sitemap']) {
$this->nofollow = false;
}
}
-
}
diff --git a/inc/Menu/Item/Login.php b/inc/Menu/Item/Login.php
index 671f6a78a..ca2542b02 100644
--- a/inc/Menu/Item/Login.php
+++ b/inc/Menu/Item/Login.php
@@ -7,17 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Show a login or logout item, based on the current state
*/
-class Login extends AbstractItem {
-
+class Login extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $INPUT;
parent::__construct();
$this->svg = DOKU_INC . 'lib/images/menu/login.svg';
$this->params['sectok'] = getSecurityToken();
- if($INPUT->server->has('REMOTE_USER')) {
- if(!actionOK('logout')) {
+ if ($INPUT->server->has('REMOTE_USER')) {
+ if (!actionOK('logout')) {
throw new \RuntimeException("logout disabled");
}
$this->params['do'] = 'logout';
@@ -25,5 +26,4 @@ class Login extends AbstractItem {
$this->svg = DOKU_INC . 'lib/images/menu/logout.svg';
}
}
-
}
diff --git a/inc/Menu/Item/Media.php b/inc/Menu/Item/Media.php
index 0e5f47bae..3f0cc481e 100644
--- a/inc/Menu/Item/Media.php
+++ b/inc/Menu/Item/Media.php
@@ -7,15 +7,15 @@ namespace dokuwiki\Menu\Item;
*
* Opens the media manager
*/
-class Media extends AbstractItem {
-
+class Media extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $ID;
parent::__construct();
$this->svg = DOKU_INC . 'lib/images/menu/folder-multiple-image.svg';
$this->params['ns'] = getNS($ID);
}
-
}
diff --git a/inc/Menu/Item/MediaManager.php b/inc/Menu/Item/MediaManager.php
index 8549d2005..2bd5c1a85 100644
--- a/inc/Menu/Item/MediaManager.php
+++ b/inc/Menu/Item/MediaManager.php
@@ -7,26 +7,22 @@ namespace dokuwiki\Menu\Item;
*
* Opens the current image in the media manager. Used on image detail view.
*/
-class MediaManager extends AbstractItem {
-
+class MediaManager extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $IMG;
parent::__construct();
$imgNS = getNS($IMG);
$authNS = auth_quickaclcheck("$imgNS:*");
- if($authNS < AUTH_UPLOAD) {
+ if ($authNS < AUTH_UPLOAD) {
throw new \RuntimeException("media manager link only with upload permissions");
}
$this->svg = DOKU_INC . 'lib/images/menu/11-mediamanager_folder-image.svg';
$this->type = 'mediaManager';
- $this->params = array(
- 'ns' => $imgNS,
- 'image' => $IMG,
- 'do' => 'media'
- );
+ $this->params = ['ns' => $imgNS, 'image' => $IMG, 'do' => 'media'];
}
-
}
diff --git a/inc/Menu/Item/Profile.php b/inc/Menu/Item/Profile.php
index 2b4ceeb77..2e24c2803 100644
--- a/inc/Menu/Item/Profile.php
+++ b/inc/Menu/Item/Profile.php
@@ -7,18 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Open the user's profile
*/
-class Profile extends AbstractItem {
-
+class Profile extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $INPUT;
parent::__construct();
- if(!$INPUT->server->str('REMOTE_USER')) {
+ if (!$INPUT->server->str('REMOTE_USER')) {
throw new \RuntimeException("profile is only for logged in users");
}
$this->svg = DOKU_INC . 'lib/images/menu/account-card-details.svg';
}
-
}
diff --git a/inc/Menu/Item/Recent.php b/inc/Menu/Item/Recent.php
index ff90ce605..dabfef123 100644
--- a/inc/Menu/Item/Recent.php
+++ b/inc/Menu/Item/Recent.php
@@ -7,14 +7,14 @@ namespace dokuwiki\Menu\Item;
*
* Show the site wide recent changes
*/
-class Recent extends AbstractItem {
-
+class Recent extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
parent::__construct();
$this->accesskey = 'r';
$this->svg = DOKU_INC . 'lib/images/menu/calendar-clock.svg';
}
-
}
diff --git a/inc/Menu/Item/Register.php b/inc/Menu/Item/Register.php
index 615146ea6..dd2c806cb 100644
--- a/inc/Menu/Item/Register.php
+++ b/inc/Menu/Item/Register.php
@@ -7,18 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Open the view to register a new account
*/
-class Register extends AbstractItem {
-
+class Register extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $INPUT;
parent::__construct();
- if($INPUT->server->str('REMOTE_USER')) {
+ if ($INPUT->server->str('REMOTE_USER')) {
throw new \RuntimeException("no register when already logged in");
}
$this->svg = DOKU_INC . 'lib/images/menu/account-plus.svg';
}
-
}
diff --git a/inc/Menu/Item/Resendpwd.php b/inc/Menu/Item/Resendpwd.php
index 7ddc6b02f..6903d0b07 100644
--- a/inc/Menu/Item/Resendpwd.php
+++ b/inc/Menu/Item/Resendpwd.php
@@ -7,18 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Access the "forgot password" dialog
*/
-class Resendpwd extends AbstractItem {
-
+class Resendpwd extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $INPUT;
parent::__construct();
- if($INPUT->server->str('REMOTE_USER')) {
+ if ($INPUT->server->str('REMOTE_USER')) {
throw new \RuntimeException("no resendpwd when already logged in");
}
$this->svg = DOKU_INC . 'lib/images/menu/lock-reset.svg';
}
-
}
diff --git a/inc/Menu/Item/Revert.php b/inc/Menu/Item/Revert.php
index f4ae1b36d..c7a3d9fdb 100644
--- a/inc/Menu/Item/Revert.php
+++ b/inc/Menu/Item/Revert.php
@@ -9,7 +9,6 @@ namespace dokuwiki\Menu\Item;
*/
class Revert extends AbstractItem
{
-
/** @inheritdoc */
public function __construct()
{
@@ -25,5 +24,4 @@ class Revert extends AbstractItem
$this->params['sectok'] = getSecurityToken();
$this->svg = DOKU_INC . 'lib/images/menu/06-revert_replay.svg';
}
-
}
diff --git a/inc/Menu/Item/Revisions.php b/inc/Menu/Item/Revisions.php
index 3009a7924..4b220b801 100644
--- a/inc/Menu/Item/Revisions.php
+++ b/inc/Menu/Item/Revisions.php
@@ -7,15 +7,15 @@ namespace dokuwiki\Menu\Item;
*
* Access the old revisions of the current page
*/
-class Revisions extends AbstractItem {
-
+class Revisions extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
parent::__construct();
$this->accesskey = 'o';
$this->type = 'revs';
$this->svg = DOKU_INC . 'lib/images/menu/07-revisions_history.svg';
}
-
}
diff --git a/inc/Menu/Item/Subscribe.php b/inc/Menu/Item/Subscribe.php
index 1c9d335f8..0545e79eb 100644
--- a/inc/Menu/Item/Subscribe.php
+++ b/inc/Menu/Item/Subscribe.php
@@ -7,18 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Access the subscription management view
*/
-class Subscribe extends AbstractItem {
-
+class Subscribe extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
global $INPUT;
parent::__construct();
- if(!$INPUT->server->str('REMOTE_USER')) {
+ if (!$INPUT->server->str('REMOTE_USER')) {
throw new \RuntimeException("subscribe is only for logged in users");
}
$this->svg = DOKU_INC . 'lib/images/menu/09-subscribe_email-outline.svg';
}
-
}
diff --git a/inc/Menu/Item/Top.php b/inc/Menu/Item/Top.php
index a05c4f119..685dcbd17 100644
--- a/inc/Menu/Item/Top.php
+++ b/inc/Menu/Item/Top.php
@@ -8,15 +8,16 @@ namespace dokuwiki\Menu\Item;
* Scroll back to the top. Uses a hash as $id which is handled special in getLink().
* Not shown in mobile context
*/
-class Top extends AbstractItem {
-
+class Top extends AbstractItem
+{
/** @inheritdoc */
- public function __construct() {
+ public function __construct()
+ {
parent::__construct();
$this->svg = DOKU_INC . 'lib/images/menu/10-top_arrow-up.svg';
$this->accesskey = 't';
- $this->params = array('do' => '');
+ $this->params = ['do' => ''];
$this->id = '#dokuwiki__top';
$this->context = self::CTX_DESKTOP;
}
@@ -26,11 +27,11 @@ class Top extends AbstractItem {
*
* Uses html_topbtn()
*
- * @todo this does currently not support the SVG icon
* @return string
+ * @todo this does currently not support the SVG icon
*/
- public function asHtmlButton() {
+ public function asHtmlButton()
+ {
return html_topbtn();
}
-
}
diff --git a/inc/Menu/MenuInterface.php b/inc/Menu/MenuInterface.php
index 91dde9db6..52e06a256 100644
--- a/inc/Menu/MenuInterface.php
+++ b/inc/Menu/MenuInterface.php
@@ -9,8 +9,8 @@ use dokuwiki\Menu\Item\AbstractItem;
*
* Defines what a Menu provides
*/
-Interface MenuInterface {
-
+interface MenuInterface
+{
/**
* Get the list of action items in this menu
*
diff --git a/inc/Menu/MobileMenu.php b/inc/Menu/MobileMenu.php
index 209805646..c9d13932f 100644
--- a/inc/Menu/MobileMenu.php
+++ b/inc/Menu/MobileMenu.php
@@ -11,23 +11,24 @@ use dokuwiki\Menu\Item\AbstractItem;
* menus. This is a meta menu, aggregating the items from the other menus and offering a combined
* view. The idea is to use this on mobile devices, thus the context is fixed to CTX_MOBILE
*/
-class MobileMenu implements MenuInterface {
-
+class MobileMenu implements MenuInterface
+{
/**
* Returns all items grouped by view
*
* @return AbstractItem[][]
*/
- public function getGroupedItems() {
+ public function getGroupedItems()
+ {
$pagemenu = new PageMenu(AbstractItem::CTX_MOBILE);
$sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE);
$usermenu = new UserMenu(AbstractItem::CTX_MOBILE);
- return array(
+ return [
'page' => $pagemenu->getItems(),
'site' => $sitemenu->getItems(),
'user' => $usermenu->getItems()
- );
+ ];
}
/**
@@ -37,9 +38,10 @@ class MobileMenu implements MenuInterface {
*
* @return AbstractItem[]
*/
- public function getItems() {
+ public function getItems()
+ {
$menu = $this->getGroupedItems();
- return call_user_func_array('array_merge', array_values($menu));
+ return array_merge(...array_values($menu));
}
/**
@@ -51,7 +53,8 @@ class MobileMenu implements MenuInterface {
* @param string $button submit button label
* @return string
*/
- public function getDropdown($empty = '', $button = '&gt;') {
+ public function getDropdown($empty = '', $button = '&gt;')
+ {
global $ID;
global $REV;
/** @var string[] $lang */
@@ -61,18 +64,18 @@ class MobileMenu implements MenuInterface {
$html = '<form action="' . script() . '" method="get" accept-charset="utf-8">';
$html .= '<div class="no">';
$html .= '<input type="hidden" name="id" value="' . $ID . '" />';
- if($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
- if($INPUT->server->str('REMOTE_USER')) {
+ if ($REV) $html .= '<input type="hidden" name="rev" value="' . $REV . '" />';
+ if ($INPUT->server->str('REMOTE_USER')) {
$html .= '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
}
$html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">';
$html .= '<option value="">' . $empty . '</option>';
- foreach($this->getGroupedItems() as $tools => $items) {
- if (count($items)) {
+ foreach ($this->getGroupedItems() as $tools => $items) {
+ if ($items !== []) {
$html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">';
- foreach($items as $item) {
+ foreach ($items as $item) {
$params = $item->getParams();
$html .= '<option value="' . $params['do'] . '">';
$html .= hsc($item->getLabel());
@@ -89,5 +92,4 @@ class MobileMenu implements MenuInterface {
return $html;
}
-
}
diff --git a/inc/Menu/PageMenu.php b/inc/Menu/PageMenu.php
index 9c0a55e2d..2ad219614 100644
--- a/inc/Menu/PageMenu.php
+++ b/inc/Menu/PageMenu.php
@@ -7,17 +7,9 @@ namespace dokuwiki\Menu;
*
* Actions manipulating the current page. Shown as a floating menu in the dokuwiki template
*/
-class PageMenu extends AbstractMenu {
-
+class PageMenu extends AbstractMenu
+{
protected $view = 'page';
- protected $types = array(
- 'Edit',
- 'Revert',
- 'Revisions',
- 'Backlink',
- 'Subscribe',
- 'Top',
- );
-
+ protected $types = ['Edit', 'Revert', 'Revisions', 'Backlink', 'Subscribe', 'Top'];
}
diff --git a/inc/Menu/SiteMenu.php b/inc/Menu/SiteMenu.php
index dba6888c7..4edef6c50 100644
--- a/inc/Menu/SiteMenu.php
+++ b/inc/Menu/SiteMenu.php
@@ -7,14 +7,9 @@ namespace dokuwiki\Menu;
*
* Actions that are not bound to an individual page but provide toolsfor the whole wiki.
*/
-class SiteMenu extends AbstractMenu {
-
+class SiteMenu extends AbstractMenu
+{
protected $view = 'site';
- protected $types = array(
- 'Recent',
- 'Media',
- 'Index'
- );
-
+ protected $types = ['Recent', 'Media', 'Index'];
}
diff --git a/inc/Menu/UserMenu.php b/inc/Menu/UserMenu.php
index 01028d3cc..b094b1937 100644
--- a/inc/Menu/UserMenu.php
+++ b/inc/Menu/UserMenu.php
@@ -7,15 +7,9 @@ namespace dokuwiki\Menu;
*
* Actions related to the current user
*/
-class UserMenu extends AbstractMenu {
-
+class UserMenu extends AbstractMenu
+{
protected $view = 'user';
- protected $types = array(
- 'Profile',
- 'Admin',
- 'Register',
- 'Login',
- );
-
+ protected $types = ['Profile', 'Admin', 'Register', 'Login'];
}