Skip to content

Commit

Permalink
Add new page button, new folder button
Browse files Browse the repository at this point in the history
  • Loading branch information
SoarinFerret committed May 29, 2020
1 parent af0870a commit 589a603
Show file tree
Hide file tree
Showing 12 changed files with 650 additions and 69 deletions.
18 changes: 13 additions & 5 deletions DeletePageButton.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
<?php
/**
* Delete Page Button plugin
* Delete Button plugin
*
* @copyright (c) 2020 Cody Ernesti
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Cody Ernesti
*
* Modified from: https://github.com/dregad/dokuwiki-plugin-deletepagebutton
*
* Original license info:
*
* @copyright (c) 2020 Damien Regad
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Damien Regad
*/

namespace dokuwiki\plugin\deletepagebutton;
namespace dokuwiki\plugin\pagebuttons;
use dokuwiki\Menu\Item\AbstractItem;

/**
* Class DeletePageButton
*
* Implements the plugin's Delete button for DokuWiki's menu system
*
* @package dokuwiki\plugin\deletepagebutton
* @package dokuwiki\plugin\pagebuttons
*/
class DeletePageButton extends AbstractItem {

Expand All @@ -35,7 +42,8 @@ public function __construct() {
*/
public function getLabel() {
$plugin = plugin_load('action', $this->type);
return $plugin->getLang('menu_item');
return "Delete Page";
//return $plugin->getLang('delete_menu_item');
}

}
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions NewFolderButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* New Folder Button plugin
*
* @copyright (c) 2020 Cody Ernesti
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Cody Ernesti
*/

namespace dokuwiki\plugin\pagebuttons;
use dokuwiki\Menu\Item\AbstractItem;

/**
* Class NewFolderButton
*
* Implements the plugin's NewFolder button for DokuWiki's menu system
*
* @package dokuwiki\plugin\pagebuttons
*/
class NewFolderButton extends AbstractItem {

/** @var string icon file */
protected $svg = __DIR__ . '/images/folder-plus-outline.svg';

/** @inheritdoc */
public function __construct() {
parent::__construct();
$this->params['sectok'] = getSecurityToken();
}

/**
* Get label from plugin language file
*
* @return string
*/
public function getLabel() {
$plugin = plugin_load('action', $this->type);
return "New Folder";
//return $plugin->getLang('newfolder_menu_item');
}

}
42 changes: 42 additions & 0 deletions NewPageButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Page Buttons plugin
*
* @copyright (c) 2020 Cody Ernesti
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Cody Ernesti
*/

namespace dokuwiki\plugin\pagebuttons;
use dokuwiki\Menu\Item\AbstractItem;

/**
* Class NewPageButton
*
* Implements the plugin's new button for DokuWiki's menu system
*
* @package dokuwiki\plugin\pagebuttons
*/
class NewPageButton extends AbstractItem {

/** @var string icon file */
protected $svg = __DIR__ . '/images/file-plus-outline.svg';

/** @inheritdoc */
public function __construct() {
parent::__construct();
$this->params['sectok'] = getSecurityToken();
}

/**
* Get label from plugin language file
*
* @return string
*/
public function getLabel() {
$plugin = plugin_load('action', $this->type);
return "New Page";
//return $plugin->getLang('newpage_menu_item');
}

}
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Delete Page Button Plugin for DokuWiki
# Page Buttons Plugin for DokuWiki

The plugin adds a _Delete page_ button to DokuWiki's
[PageMenu](https://www.dokuwiki.org/devel:menus).
The plugin adds a few Page Menu buttons to perform useful actions:

This provides a simpler, quicker and more intuitive way for users to
delete wiki pages, compared to the
[documented page deletion method](https://www.dokuwiki.org/page#delete_a_page).
* _Delete Page_ - Deletes the current page
* _New Page_ - Creates a 'subpage' under the current namespace
* _New Folder_ - Creates a 'subfolder' under the current namespace

![Screenshot](images/screenshot.png)

Copyright (c) 2020 Damien Regad <[email protected]>


## License

This program is free software; you can redistribute it and/or modify
Expand All @@ -24,17 +20,12 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.


## Installation and Configuration

Please refer to https://www.dokuwiki.org/plugin:deletepagebutton for information
on how to install and configure this plugin in DokuWiki.

If you install this plugin manually, make sure it is installed in
`lib/plugins/deletepagebutton/` - if the folder is called differently,
`lib/plugins/pagebuttons/` - if the folder is called differently,
it will not work!


## Compatibility

This plugin has been developped and tested with DokuWiki release
Expand All @@ -45,12 +36,14 @@ Earlier releases are not supported.
## Support

Source code and support for this plugin can be found at
https://github.com/dregad/dokuwiki-plugin-deletepagebutton
https://github.com/SoarinFerret/dokuwiki-plugin-pagebuttons

## Credits

Icon: https://materialdesignicons.com/icon/trash-can-outline
Icons:
* https://materialdesignicons.com/icon/trash-can-outline
* https://materialdesignicons.com/icon/folder-plus-outline
* https://materialdesignicons.com/icon/file-plus-outline


I first thought I could adapt
[this old plugin](https://github.com/caillou/dokuwiki-plugin-delete)
but I ended up restarting from scratch.
Built off the work provided here: https://github.com/dregad/dokuwiki-plugin-deletepagebutton
82 changes: 68 additions & 14 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?php
/**
* Delete Page Button plugin
* Page Buttons plugin
*
* @copyright (c) 2020 Cody Ernesti
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Cody Ernesti
*
* Modified from: https://github.com/dregad/dokuwiki-plugin-deletepagebutton
*
* Original license info:
*
* @copyright (c) 2020 Damien Regad
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
Expand All @@ -10,23 +18,27 @@
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

use dokuwiki\plugin\deletepagebutton\DeletePageButton;
use dokuwiki\plugin\pagebuttons\DeletePageButton;
use dokuwiki\plugin\pagebuttons\NewPageButton;
use dokuwiki\plugin\pagebuttons\NewFolderButton;

/**
* Class action_plugin_deletepagebutton
* Class action_plugin_pagebuttons
*
* @package dokuwiki\plugin\deletepagebutton
* @package dokuwiki\plugin\pagebuttons
*/
class action_plugin_deletepagebutton extends DokuWiki_Action_Plugin {
class action_plugin_pagebuttons extends DokuWiki_Action_Plugin {

/**
* Register event handlers.
*
* @param Doku_Event_Handler $controller The plugin controller
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addButton' );
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'deletePage' );
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addNewPageButton' );
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addNewFolderButton' );
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addDeleteButton' );
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'actionPage' );
}

/**
Expand All @@ -36,7 +48,7 @@ public function register(Doku_Event_Handler $controller) {
*
* @param Doku_Event $event
*/
public function addButton(Doku_Event $event) {
public function addDeleteButton(Doku_Event $event) {
global $ID;

if (
Expand All @@ -49,6 +61,46 @@ public function addButton(Doku_Event $event) {
array_splice($event->data['items'], -1, 0, array(new DeletePageButton()));
}

/**
* Hook for MENU_ITEMS_ASSEMBLY event.
*
* Adds 'New Page' button to DokuWiki's PageMenu.
*
* @param Doku_Event $event
*/
public function addNewPageButton(Doku_Event $event) {
global $ID;

if (
$event->data['view'] !== 'page'
|| !(substr_compare($ID, ":start", -strlen(":start")) === 0)
) {
return;
}

array_splice($event->data['items'], -1, 0, array(new NewPageButton()));
}

/**
* Hook for MENU_ITEMS_ASSEMBLY event.
*
* Adds 'New Page' button to DokuWiki's PageMenu.
*
* @param Doku_Event $event
*/
public function addNewFolderButton(Doku_Event $event) {
global $ID;

if (
$event->data['view'] !== 'page'
|| !(substr_compare($ID, ":start", -strlen(":start")) === 0)
) {
return;
}

array_splice($event->data['items'], -1, 0, array(new NewFolderButton()));
}

/**
* Determines whether the Delete button should be shown.
*
Expand All @@ -72,20 +124,22 @@ protected function canDelete($id) {
*
* @param Doku_Event $event
*/
public function deletePage(Doku_Event $event) {
public function actionPage(Doku_Event $event) {
global $ID, $INFO, $lang;

// Ignore other actions
if ($event->data != 'deletepagebutton') {
if ($event->data != 'deletepagebutton' && $event->data != 'newfolderbutton' && $event->data != 'newpagebutton') {
return;
};

if(checkSecurityToken() && $INFO['exists']) {
// Save the page with empty contents to delete it
saveWikiText($ID, null, $lang['deleted']);
if($event->data == 'deletepagebutton'){
// Save the page with empty contents to delete it
saveWikiText($ID, null, $lang['deleted']);

// Display confirmation message
msg($this->getLang('deleted_ok'), 1);
// Display confirmation message
msg($this->getLang('deleted_ok'), 1);
}
}

// Redirect to page view
Expand Down
1 change: 1 addition & 0 deletions images/file-plus-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/folder-plus-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 21 additions & 7 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<?php
/**
* Delete Page Button plugin - English language file
* Page Buttons plugin - English language file
*
* @copyright (c) 2020 Cody Ernesti
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Cody Ernesti
*
* Modified from: https://github.com/dregad/dokuwiki-plugin-deletepagebutton
*
* Original license info:
*
* @copyright (c) 2020 Damien Regad
* @license GPLv2 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Damien Regad
*/

$lang['menu_item'] = 'Delete page';
$lang['deleted_ok'] = 'Page deleted successfully';
$lang['newpage_menu_item'] = 'New page';
$lang['delete_menu_item'] = 'Delete page';
$lang['newfolder_menu_item'] = 'New folder';
$lang['deleted_ok'] = 'Page deleted successfully';

$lang['js']['title'] = $lang['menu_item'];
$lang['js']['confirm'] = 'Are you sure you want to delete this page ?';
$lang['js']['btn_ok'] = 'OK';
$lang['js']['btn_cancel'] = 'Cancel';
$lang['js']['delete_title'] = $lang['delete_menu_item'];
$lang['js']['newpage_title'] = $lang['newpage_menu_item'];
$lang['js']['newfolder_title'] = $lang['newfolder_menu_item'];
$lang['js']['delete_confirm'] = 'Are you sure you want to delete this page ?';
$lang['js']['newpage_prompt'] = 'What is the name of the sub-page you would like to create ?';
$lang['js']['newfolder_prompt'] = 'What is the name of sub-folder you would like to create ?';
$lang['js']['btn_ok'] = 'OK';
$lang['js']['btn_cancel'] = 'Cancel';
16 changes: 0 additions & 16 deletions lang/fr/lang.php

This file was deleted.

Loading

0 comments on commit 589a603

Please sign in to comment.