はじまりの大地
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Move Plugin AJAX handler to step through a move plan
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
// must be run within Dokuwiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class action_plugin_move_progress
|
||||
*/
|
||||
class action_plugin_move_progress 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('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Step up
|
||||
*
|
||||
* @param Doku_Event $event
|
||||
*/
|
||||
public function handle_ajax(Doku_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'])) {
|
||||
http_status(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
$return = array(
|
||||
'error' => '',
|
||||
'complete' => false,
|
||||
'progress' => 0
|
||||
);
|
||||
|
||||
/** @var helper_plugin_move_plan $plan */
|
||||
$plan = plugin_load('helper', 'move_plan');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$json = new JSON();
|
||||
header('Content-Type: application/json');
|
||||
echo $json->encode($return);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* Move Plugin Page Rename Functionality
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
// must be run within Dokuwiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class action_plugin_move_rename
|
||||
*/
|
||||
class action_plugin_move_rename 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('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('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() {
|
||||
global $JSINFO;
|
||||
global $INFO;
|
||||
global $INPUT;
|
||||
global $USERINFO;
|
||||
|
||||
if (isset($INFO['id'])) {
|
||||
$JSINFO['move_renameokay'] = $this->renameOkay($INFO['id']);
|
||||
} else {
|
||||
$JSINFO['move_renameokay'] = false;
|
||||
}
|
||||
|
||||
$JSINFO['move_allowrename'] = auth_isMember(
|
||||
$this->getConf('allowrename'),
|
||||
$INPUT->server->str('REMOTE_USER'),
|
||||
$USERINFO['grps'] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a button to the default template
|
||||
*
|
||||
* TODO: DEPRECATED JAN 2018
|
||||
*
|
||||
* @param Doku_Event $event
|
||||
*/
|
||||
public function handle_pagetools(Doku_Event $event) {
|
||||
if($event->data['view'] != 'main') return;
|
||||
if (!$this->getConf('pagetools_integration')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$newitem = '<li class="plugin_move_page"><a href=""><span>' . $this->getLang('renamepage') . '</span></a></li>';
|
||||
$offset = count($event->data['items']) - 1;
|
||||
$event->data['items'] =
|
||||
array_slice($event->data['items'], 0, $offset, true) +
|
||||
array('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
|
||||
*/
|
||||
public function addsvgbutton(Doku_Event $event) {
|
||||
global $INFO, $JSINFO;
|
||||
if(
|
||||
$event->data['view'] !== 'page' ||
|
||||
!$this->getConf('pagetools_integration') ||
|
||||
empty($JSINFO['move_renameokay'])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if(!$INFO['exists']) {
|
||||
return;
|
||||
}
|
||||
array_splice($event->data['items'], -1, 0, array(new \dokuwiki\plugin\move\MenuItem()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a single page
|
||||
*/
|
||||
public function handle_ajax(Doku_Event $event) {
|
||||
if($event->data != 'plugin_move_rename') return;
|
||||
$event->preventDefault();
|
||||
$event->stopPropagation();
|
||||
|
||||
global $MSG;
|
||||
global $INPUT;
|
||||
|
||||
$src = cleanID($INPUT->str('id'));
|
||||
$dst = cleanID($INPUT->str('newid'));
|
||||
|
||||
/** @var helper_plugin_move_op $MoveOperator */
|
||||
$MoveOperator = plugin_load('helper', 'move_op');
|
||||
|
||||
$JSON = new JSON();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) {
|
||||
// all went well, redirect
|
||||
echo $JSON->encode(array('redirect_url' => wl($dst, '', true, '&')));
|
||||
} else {
|
||||
if(isset($MSG[0])) {
|
||||
$error = $MSG[0]; // first error
|
||||
} else {
|
||||
$error = $this->getLang('cantrename');
|
||||
}
|
||||
echo $JSON->encode(array('error' => $error));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle media renames in media manager
|
||||
*
|
||||
* @param Doku_Event $event
|
||||
* @return void
|
||||
*/
|
||||
public function handleAjaxMediaManager(Doku_Event $event)
|
||||
{
|
||||
if ($event->data !== 'plugin_move_rename_mediamanager') return;
|
||||
|
||||
if (!checkSecurityToken()) {
|
||||
throw new \Exception('Security token did not match');
|
||||
}
|
||||
|
||||
$event->preventDefault();
|
||||
$event->stopPropagation();
|
||||
|
||||
global $INPUT;
|
||||
global $MSG;
|
||||
global $USERINFO;
|
||||
|
||||
$src = cleanID($INPUT->str('src'));
|
||||
$dst = cleanID($INPUT->str('dst'));
|
||||
|
||||
/** @var helper_plugin_move_op $moveOperator */
|
||||
$moveOperator = plugin_load('helper', 'move_op');
|
||||
|
||||
if ($src && $dst) {
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$response = [];
|
||||
|
||||
// check user/group restrictions
|
||||
if (
|
||||
!auth_isMember($this->getConf('allowrename'), $INPUT->server->str('REMOTE_USER'), (array) $USERINFO['grps'])
|
||||
) {
|
||||
$response['error'] = $this->getLang('notallowed');
|
||||
echo json_encode($response);
|
||||
return;
|
||||
}
|
||||
|
||||
$response['success'] = $moveOperator->moveMedia($src, $dst);
|
||||
|
||||
if ($response['success']) {
|
||||
$ns = getNS($dst);
|
||||
$response['redirect_url'] = wl($dst, ['do' => 'media', 'ns' => $ns], true, '&');
|
||||
} else {
|
||||
$response['error'] = sprintf($this->getLang('mediamoveerror'), $src);
|
||||
if (isset($MSG)) {
|
||||
foreach ($MSG as $msg) {
|
||||
$response['error'] .= ' ' . $msg['msg'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if it would be okay to show a rename page button for the given page and current user
|
||||
*
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
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;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this in your template to add a simple "move this page" link
|
||||
*
|
||||
* Alternatively give anything the class "plugin_move_page" - it will automatically be hidden and shown and
|
||||
* trigger the page move dialog.
|
||||
*/
|
||||
public function tpl() {
|
||||
echo '<a href="" class="plugin_move_page">';
|
||||
echo $this->getLang('renamepage');
|
||||
echo '</a>';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Move Plugin Page Rewrite Functionality
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
// must be run within Dokuwiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class action_plugin_move_rewrite
|
||||
*/
|
||||
class action_plugin_move_rewrite 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('IO_WIKIPAGE_READ', 'AFTER', $this, 'handle_read', array());
|
||||
$controller->register_hook('PARSER_CACHE_USE', 'BEFORE', $this, 'handle_cache', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite pages when they are read and they need to be updated.
|
||||
*
|
||||
* @param Doku_Event $event The event object
|
||||
* @param mixed $param Optional parameters (not used)
|
||||
*/
|
||||
function handle_read(Doku_Event $event, $param) {
|
||||
global $ACT, $conf;
|
||||
static $stack = array();
|
||||
// handle only reads of the current revision
|
||||
if($event->data[3]) return;
|
||||
|
||||
// only rewrite if not in move already
|
||||
$save = true;
|
||||
if(helper_plugin_move_rewrite::isLocked()) {
|
||||
$save = false;
|
||||
}
|
||||
|
||||
$id = $event->data[2];
|
||||
if($event->data[1]) $id = $event->data[1] . ':' . $id;
|
||||
|
||||
if(!$id) {
|
||||
// try to reconstruct the id from the filename
|
||||
$path = $event->data[0][0];
|
||||
if(strpos($path, $conf['datadir']) === 0) {
|
||||
$path = substr($path, strlen($conf['datadir']) + 1);
|
||||
$id = pathID($path);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($stack[$id])) return;
|
||||
|
||||
// Don't change the page when the user is currently changing the page content or the page is locked
|
||||
$forbidden_actions = array('save', 'preview', 'recover', 'revert');
|
||||
if((isset($ACT) && (
|
||||
in_array($ACT, $forbidden_actions) || (is_array($ACT) && in_array(key($ACT), $forbidden_actions)
|
||||
)))
|
||||
// checklock checks if the page lock hasn't expired and the page hasn't been locked by another user
|
||||
// the file exists check checks if the page is reported unlocked if a lock exists which means that
|
||||
// the page is locked by the current user
|
||||
|| checklock($id) !== false || @file_exists(wikiLockFN($id))
|
||||
) return;
|
||||
|
||||
/** @var helper_plugin_move_rewrite $helper */
|
||||
$helper = plugin_load('helper', 'move_rewrite', true);
|
||||
if(!is_null($helper)) {
|
||||
$stack[$id] = true;
|
||||
$event->result = $helper->rewritePage($id, $event->result, $save);
|
||||
unset($stack[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the cache events, it looks if a page needs to be rewritten so it can expire the cache of the page
|
||||
*
|
||||
* @param Doku_Event $event The even object
|
||||
* @param mixed $param Optional parameters (not used)
|
||||
*/
|
||||
function handle_cache(Doku_Event $event, $param) {
|
||||
global $conf;
|
||||
/** @var $cache cache_parser */
|
||||
$cache = $event->data;
|
||||
$id = $cache->page;
|
||||
if(!$id) {
|
||||
// try to reconstruct the id from the filename
|
||||
$path = $cache->file;
|
||||
if(strpos($path, $conf['datadir']) === 0) {
|
||||
$path = substr($path, strlen($conf['datadir']) + 1);
|
||||
$id = pathID($path);
|
||||
}
|
||||
}
|
||||
if($id) {
|
||||
/** @var helper_plugin_move_rewrite $helper */
|
||||
$helper = $this->loadHelper('move_rewrite');
|
||||
if(!is_null($helper)) {
|
||||
$meta = $helper->getMoveMeta($id);
|
||||
if($meta && ($meta['pages'] || $meta['media'])) {
|
||||
$file = wikiFN($id, '', false);
|
||||
if(is_writable($file))
|
||||
$cache->depends['purge'] = true;
|
||||
else // FIXME: print error here or fail silently?
|
||||
msg('Error: Page ' . hsc($id) . ' needs to be rewritten because of page renames but is not writable.', -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Move Plugin Tree Loading Functionality
|
||||
*
|
||||
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
*/
|
||||
// must be run within Dokuwiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
/**
|
||||
* Class action_plugin_move_rewrite
|
||||
*/
|
||||
class action_plugin_move_tree 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('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a subtree
|
||||
*
|
||||
* @param Doku_Event $event
|
||||
* @param $params
|
||||
*/
|
||||
public function handle_ajax_call(Doku_Event $event, $params) {
|
||||
if($event->data != 'plugin_move_tree') return;
|
||||
$event->preventDefault();
|
||||
$event->stopPropagation();
|
||||
|
||||
global $INPUT;
|
||||
global $USERINFO;
|
||||
|
||||
if(!auth_ismanager($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
|
||||
http_status(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
/** @var admin_plugin_move_tree $plugin */
|
||||
$plugin = plugin_load('admin', 'move_tree');
|
||||
|
||||
$ns = cleanID($INPUT->str('ns'));
|
||||
if($INPUT->bool('is_media')) {
|
||||
$type = admin_plugin_move_tree::TYPE_MEDIA;
|
||||
} else {
|
||||
$type = admin_plugin_move_tree::TYPE_PAGES;
|
||||
}
|
||||
|
||||
$data = $plugin->tree($type, $ns, $ns);
|
||||
|
||||
echo html_buildlist(
|
||||
$data, 'tree_list',
|
||||
array($plugin, 'html_list'),
|
||||
array($plugin, 'html_li')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user