Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions MenuItem.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<?php

namespace dokuwiki\plugin\move;

use dokuwiki\Menu\Item\AbstractItem;

/**
* Class MenuItem
*
* Implements the Rename button for DokuWiki's menu system
*
* @package dokuwiki\plugin\move
*/
class MenuItem extends AbstractItem {

class MenuItem extends AbstractItem
{
/** @var string icon file */
protected $svg = __DIR__ . '/images/rename.svg';

protected $type = "plugin_move";

public function getLinkAttributes($classprefix = 'menuitem ') {
public function getLinkAttributes($classprefix = 'menuitem ')
{
$attr = parent::getLinkAttributes($classprefix);
if (empty($attr['class'])) {
$attr['class'] = '';
Expand All @@ -28,7 +32,8 @@ public function getLinkAttributes($classprefix = 'menuitem ') {
*
* @return string
*/
public function getLabel() {
public function getLabel()
{
$hlp = plugin_load('action', 'move_rename');
return $hlp->getLang('renamepage');
}
Expand Down
3 changes: 2 additions & 1 deletion MoveResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
/**
* We need the "pure" resolver without any special handling for startpages or autoplurals
*/
class MoveResolver extends Resolver {
class MoveResolver extends Resolver
{
}
36 changes: 20 additions & 16 deletions action/progress.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,66 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;

/**
* Move Plugin AJAX handler to step through a move plan
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <[email protected]>
*/

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if (!defined('DOKU_INC')) die();

/**
* Class action_plugin_move_progress
*/
class action_plugin_move_progress extends DokuWiki_Action_Plugin {

class action_plugin_move_progress extends ActionPlugin
{
/**
* Register event handlers.
*
* @param Doku_Event_Handler $controller The plugin controller
* @param EventHandler $controller The plugin controller
*/
public function register(Doku_Event_Handler $controller) {
public function register(EventHandler $controller)
{
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
}

/**
* Step up
*
* @param Doku_Event $event
* @param Event $event
*/
public function handle_ajax(Doku_Event $event) {
if($event->data != 'plugin_move_progress') return;
public function handle_ajax(Event $event)
{
if ($event->data != 'plugin_move_progress') return;
$event->preventDefault();
$event->stopPropagation();

global $INPUT;
global $USERINFO;

if(!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
if (!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
http_status(403);
exit;
}

$return = array(
'error' => '',
'complete' => false,
'progress' => 0
);
$return = ['error' => '', 'complete' => false, 'progress' => 0];

/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');

if(!$plan->isCommited()) {
if (!$plan->isCommited()) {
// There is no plan. Something went wrong
$return['complete'] = true;
} else {
$todo = $plan->nextStep($INPUT->bool('skip'));
$return['progress'] = $plan->getProgress();
$return['error'] = $plan->getLastError();
if($todo === 0) $return['complete'] = true;
if ($todo === 0) $return['complete'] = true;
}

header('Content-Type: application/json');
Expand Down
81 changes: 47 additions & 34 deletions action/rename.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\plugin\move\MenuItem;

/**
* Move Plugin Page Rename Functionality
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Andreas Gohr <[email protected]>
*/

// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
if (!defined('DOKU_INC')) die();

/**
* Class action_plugin_move_rename
*/
class action_plugin_move_rename extends DokuWiki_Action_Plugin {

class action_plugin_move_rename extends ActionPlugin
{
/**
* Register event handlers.
*
* @param Doku_Event_Handler $controller The plugin controller
* @param EventHandler $controller The plugin controller
*/
public function register(Doku_Event_Handler $controller) {
public function register(EventHandler $controller)
{
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_init');

// TODO: DEPRECATED JAN 2018
$controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'handle_pagetools');

$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', array());
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', []);
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handleAjaxMediaManager');
}

/**
* set JavaScript info if renaming of current page is possible
*/
public function handle_init() {
public function handle_init()
{
global $JSINFO;
global $INFO;
global $INPUT;
Expand All @@ -56,10 +65,11 @@ public function handle_init() {
*
* TODO: DEPRECATED JAN 2018
*
* @param Doku_Event $event
* @param Event $event
*/
public function handle_pagetools(Doku_Event $event) {
if($event->data['view'] != 'main') return;
public function handle_pagetools(Event $event)
{
if ($event->data['view'] != 'main') return;
if (!$this->getConf('pagetools_integration')) {
return;
}
Expand All @@ -68,35 +78,37 @@ public function handle_pagetools(Doku_Event $event) {
$offset = count($event->data['items']) - 1;
$event->data['items'] =
array_slice($event->data['items'], 0, $offset, true) +
array('plugin_move' => $newitem) +
['plugin_move' => $newitem] +
array_slice($event->data['items'], $offset, null, true);
}

/**
* Add 'rename' button to page tools, new SVG based mechanism
*
* @param Doku_Event $event
* @param Event $event
*/
public function addsvgbutton(Doku_Event $event) {
public function addsvgbutton(Event $event)
{
global $INFO, $JSINFO;
if(
if (
$event->data['view'] !== 'page' ||
!$this->getConf('pagetools_integration') ||
empty($JSINFO['move_renameokay'])
) {
return;
}
if(!$INFO['exists']) {
if (!$INFO['exists']) {
return;
}
array_splice($event->data['items'], -1, 0, array(new \dokuwiki\plugin\move\MenuItem()));
array_splice($event->data['items'], -1, 0, [new MenuItem()]);
}

/**
* Rename a single page
*/
public function handle_ajax(Doku_Event $event) {
if($event->data != 'plugin_move_rename') return;
public function handle_ajax(Event $event)
{
if ($event->data != 'plugin_move_rename') return;
$event->preventDefault();
$event->stopPropagation();

Expand All @@ -111,26 +123,26 @@ public function handle_ajax(Doku_Event $event) {

header('Content-Type: application/json');

if($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) {
if ($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) {
// all went well, redirect
echo json_encode(array('redirect_url' => wl($dst, '', true, '&')));
echo json_encode(['redirect_url' => wl($dst, '', true, '&')]);
} else {
if(isset($MSG[0])) {
if (isset($MSG[0])) {
$error = $MSG[0]; // first error
} else {
$error = $this->getLang('cantrename');
}
echo json_encode(array('error' => $error));
echo json_encode(['error' => $error]);
}
}

/**
* Handle media renames in media manager
*
* @param Doku_Event $event
* @param Event $event
* @return void
*/
public function handleAjaxMediaManager(Doku_Event $event)
public function handleAjaxMediaManager(Event $event)
{
if ($event->data !== 'plugin_move_rename_mediamanager') return;

Expand Down Expand Up @@ -189,17 +201,18 @@ public function handleAjaxMediaManager(Doku_Event $event)
* @param $id
* @return bool
*/
public function renameOkay($id) {
public function renameOkay($id)
{
global $conf;
global $ACT;
global $USERINFO;
if(!($ACT == 'show' || empty($ACT))) return false;
if(!page_exists($id)) return false;
if(auth_quickaclcheck($id) < AUTH_EDIT) return false;
if(checklock($id) !== false || @file_exists(wikiLockFN($id))) return false;
if(!$conf['useacl']) return true;
if(!isset($_SERVER['REMOTE_USER'])) return false;
if(!auth_isMember($this->getConf('allowrename'), $_SERVER['REMOTE_USER'], (array) $USERINFO['grps'])) return false;
if ($ACT != 'show' && !empty($ACT)) return false;
if (!page_exists($id)) return false;
if (auth_quickaclcheck($id) < AUTH_EDIT) return false;
if (checklock($id) !== false || @file_exists(wikiLockFN($id))) return false;
if (!$conf['useacl']) return true;
if (!isset($_SERVER['REMOTE_USER'])) return false;
if (!auth_isMember($this->getConf('allowrename'), $_SERVER['REMOTE_USER'], (array) $USERINFO['grps'])) return false;

return true;
}
Expand All @@ -210,10 +223,10 @@ public function renameOkay($id) {
* Alternatively give anything the class "plugin_move_page" - it will automatically be hidden and shown and
* trigger the page move dialog.
*/
public function tpl() {
public function tpl()
{
echo '<a href="" class="plugin_move_page">';
echo $this->getLang('renamepage');
echo '</a>';
}

}
Loading