はじまりの大地

This commit is contained in:
miteruzo
2024-07-08 03:32:47 +09:00
commit c616a96f53
7749 changed files with 478270 additions and 0 deletions
+270
View File
@@ -0,0 +1,270 @@
<?php
/**
* Plugin : Move
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Michael Hamann <michael@content-space.de>
* @author Gary Owen,
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
/**
* Admin component of the move plugin. Provides the user interface.
*/
class admin_plugin_move_main extends DokuWiki_Admin_Plugin {
/** @var helper_plugin_move_plan $plan */
protected $plan;
public function __construct() {
$this->plan = plugin_load('helper', 'move_plan');
}
/**
* @param $language
* @return string
*/
public function getMenuText($language) {
$label = $this->getLang('menu');
if($this->plan->isCommited()) $label .= ' '.$this->getLang('inprogress');
return $label;
}
/**
* Get the sort number that defines the position in the admin menu.
*
* @return int The sort number
*/
function getMenuSort() {
return 1011;
}
/**
* If this admin plugin is for admins only
*
* @return bool false
*/
function forAdminOnly() {
return false;
}
/**
* Handle the input
*/
function handle() {
global $INPUT;
// create a new plan if possible and sufficient data was given
$this->createPlanFromInput();
// handle workflow button presses
if($this->plan->isCommited()) {
helper_plugin_move_rewrite::addLock(); //todo: right place?
switch($INPUT->str('ctl')) {
case 'continue':
$this->plan->nextStep();
break;
case 'skip':
$this->plan->nextStep(true);
break;
case 'abort':
$this->plan->abort();
break;
}
}
}
/**
* Display the interface
*/
function html() {
// decide what to do based on the plan's state
if($this->plan->isCommited()) {
$this->GUI_progress();
} else {
// display form
$this->GUI_simpleForm();
}
}
/**
* Get input variables and create a move plan from them
*
* @return bool
*/
protected function createPlanFromInput() {
global $INPUT;
global $ID;
if($this->plan->isCommited()) return false;
$this->plan->setOption('autoskip', $INPUT->bool('autoskip'));
$this->plan->setOption('autorewrite', $INPUT->bool('autorewrite'));
if($ID && $INPUT->has('dst')) {
$dst = trim($INPUT->str('dst'));
if($dst == '') {
msg($this->getLang('nodst'), -1);
return false;
}
// input came from form
if($INPUT->str('class') == 'namespace') {
$src = getNS($ID);
if($INPUT->str('type') == 'both') {
$this->plan->addPageNamespaceMove($src, $dst);
$this->plan->addMediaNamespaceMove($src, $dst);
} else if($INPUT->str('type') == 'page') {
$this->plan->addPageNamespaceMove($src, $dst);
} else if($INPUT->str('type') == 'media') {
$this->plan->addMediaNamespaceMove($src, $dst);
}
} else {
$this->plan->addPageMove($ID, $INPUT->str('dst'));
}
$this->plan->commit();
return true;
} elseif($INPUT->has('json')) {
// input came via JSON from tree manager
$json = new JSON(JSON_LOOSE_TYPE);
$data = $json->decode($INPUT->str('json'));
foreach((array) $data as $entry) {
if($entry['class'] == 'ns') {
if($entry['type'] == 'page') {
$this->plan->addPageNamespaceMove($entry['src'], $entry['dst']);
} elseif($entry['type'] == 'media') {
$this->plan->addMediaNamespaceMove($entry['src'], $entry['dst']);
}
} elseif($entry['class'] == 'doc') {
if($entry['type'] == 'page') {
$this->plan->addPageMove($entry['src'], $entry['dst']);
} elseif($entry['type'] == 'media') {
$this->plan->addMediaMove($entry['src'], $entry['dst']);
}
}
}
$this->plan->commit();
return true;
}
return false;
}
/**
* Display the simple move form
*/
protected function GUI_simpleForm() {
global $ID;
echo $this->locale_xhtml('move');
$treelink = wl($ID, array('do'=>'admin', 'page'=>'move_tree'));
echo '<p id="plugin_move__treelink">';
printf($this->getLang('treelink'), $treelink);
echo '</p>';
$form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => 'plugin_move_form'));
$form->addHidden('page', 'move_main');
$form->addHidden('id', $ID);
$form->startFieldset($this->getLang('legend'));
$form->addElement(form_makeRadioField('class', 'page', $this->getLang('movepage') . ' <code>' . $ID . '</code>', '', 'block radio click-page', array('checked' => 'checked')));
$form->addElement(form_makeRadioField('class', 'namespace', $this->getLang('movens') . ' <code>' . getNS($ID) . '</code>', '', 'block radio click-ns'));
$form->addElement(form_makeTextField('dst', $ID, $this->getLang('dst'), '', 'block indent'));
$form->addElement(form_makeMenuField('type', array('pages' => $this->getLang('move_pages'), 'media' => $this->getLang('move_media'), 'both' => $this->getLang('move_media_and_pages')), 'both', $this->getLang('content_to_move'), '', 'block indent select'));
$form->addElement(form_makeCheckboxField('autoskip', '1', $this->getLang('autoskip'), '', 'block', ($this->getConf('autoskip') ? array('checked' => 'checked') : array())));
$form->addElement(form_makeCheckboxField('autorewrite', '1', $this->getLang('autorewrite'), '', 'block', ($this->getConf('autorewrite') ? array('checked' => 'checked') : array())));
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('btn_start')));
$form->endFieldset();
$form->printForm();
}
/**
* Display the GUI while the move progresses
*/
protected function GUI_progress() {
echo '<div id="plugin_move__progress">';
echo $this->locale_xhtml('progress');
$progress = $this->plan->getProgress();
if(!$this->plan->inProgress()) {
echo '<div id="plugin_move__preview">';
echo '<p>';
echo '<strong>' . $this->getLang('intro') . '</strong> ';
echo '<span>' . $this->getLang('preview') . '</span>';
echo '</p>';
echo $this->plan->previewHTML();
echo '</div>';
}
echo '<div class="progress" data-progress="' . $progress . '">' . $progress . '%</div>';
echo '<div class="output">';
if($this->plan->getLastError()) {
echo '<p><div class="error">' . $this->plan->getLastError() . '</div></p>';
} elseif ($this->plan->inProgress()) {
echo '<p><div class="info">' . $this->getLang('inexecution') . '</div></p>';
}
echo '</div>';
// display all buttons but toggle visibility according to state
echo '<p></p>';
echo '<div class="controls">';
echo '<img src="' . DOKU_BASE . 'lib/images/throbber.gif" class="hide" />';
$this->btn('start', !$this->plan->inProgress());
$this->btn('retry', $this->plan->getLastError());
$this->btn('skip', $this->plan->getLastError());
$this->btn('continue', $this->plan->inProgress() && !$this->plan->getLastError());
$this->btn('abort');
echo '</div>';
echo '</div>';
}
/**
* Display a move workflow button
*
* continue, start, retry - continue next steps
* abort - abort the whole move
* skip - skip error and continue
*
* @param string $control
* @param bool $show should this control be visible?
*/
protected function btn($control, $show = true) {
global $ID;
$skip = 0;
$label = $this->getLang('btn_' . $control);
$id = $control;
if($control == 'start') $control = 'continue';
if($control == 'retry') {
$control = 'continue';
$skip = 0;
}
$class = 'move__control ctlfrm-' . $id;
if(!$show) $class .= ' hide';
$form = new Doku_Form(array('action' => wl($ID), 'method' => 'post', 'class' => $class));
$form->addHidden('page', 'move_main');
$form->addHidden('id', $ID);
$form->addHidden('ctl', $control);
$form->addHidden('skip', $skip);
$form->addElement(form_makeButton('submit', 'admin', $label, array('class' => 'btn ctl-' . $control)));
$form->printForm();
}
}
+189
View File
@@ -0,0 +1,189 @@
<?php
class admin_plugin_move_tree extends DokuWiki_Admin_Plugin {
const TYPE_PAGES = 1;
const TYPE_MEDIA = 2;
/**
* @param $language
* @return bool
*/
public function getMenuText($language) {
return false; // do not show in Admin menu
}
/**
* If this admin plugin is for admins only
*
* @return bool false
*/
function forAdminOnly() {
return false;
}
/**
* no-op
*/
public function handle() {
}
public function html() {
global $ID;
echo $this->locale_xhtml('tree');
echo '<noscript><div class="error">' . $this->getLang('noscript') . '</div></noscript>';
echo '<div id="plugin_move__tree">';
echo '<div class="tree_root tree_pages">';
echo '<h3>' . $this->getLang('move_pages') . '</h3>';
$this->htmlTree(self::TYPE_PAGES);
echo '</div>';
echo '<div class="tree_root tree_media">';
echo '<h3>' . $this->getLang('move_media') . '</h3>';
$this->htmlTree(self::TYPE_MEDIA);
echo '</div>';
/** @var helper_plugin_move_plan $plan */
$plan = plugin_load('helper', 'move_plan');
echo '<div class="controls">';
if($plan->isCommited()) {
echo '<div class="error">' . $this->getLang('moveinprogress') . '</div>';
} else {
$form = new Doku_Form(array('action' => wl($ID), 'id' => 'plugin_move__tree_execute'));
$form->addHidden('id', $ID);
$form->addHidden('page', 'move_main');
$form->addHidden('json', '');
$form->addElement(form_makeCheckboxField('autoskip', '1', $this->getLang('autoskip'), '', '', ($this->getConf('autoskip') ? array('checked' => 'checked') : array())));
$form->addElement('<br />');
$form->addElement(form_makeCheckboxField('autorewrite', '1', $this->getLang('autorewrite'), '', '', ($this->getConf('autorewrite') ? array('checked' => 'checked') : array())));
$form->addElement('<br />');
$form->addElement('<br />');
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('btn_start')));
$form->printForm();
}
echo '</div>';
echo '</div>';
}
/**
* print the HTML tree structure
*
* @param int $type
*/
protected function htmlTree($type = self::TYPE_PAGES) {
$data = $this->tree($type);
// wrap a list with the root level around the other namespaces
array_unshift(
$data, array(
'level' => 0, 'id' => '*', 'type' => 'd',
'open' => 'true', 'label' => $this->getLang('root')
)
);
echo html_buildlist(
$data, 'tree_list idx',
array($this, 'html_list'),
array($this, 'html_li')
);
}
/**
* Build a tree info structure from media or page directories
*
* @param int $type
* @param string $open The hierarchy to open FIXME not supported yet
* @param string $base The namespace to start from
* @return array
*/
public function tree($type = self::TYPE_PAGES, $open = '', $base = '') {
global $conf;
$opendir = utf8_encodeFN(str_replace(':', '/', $open));
$basedir = utf8_encodeFN(str_replace(':', '/', $base));
$opts = array(
'pagesonly' => ($type == self::TYPE_PAGES),
'listdirs' => true,
'listfiles' => true,
'sneakyacl' => $conf['sneaky_index'],
'showmsg' => false,
'depth' => 1,
'showhidden' => true
);
$data = array();
if($type == self::TYPE_PAGES) {
search($data, $conf['datadir'], 'search_universal', $opts, $basedir);
} elseif($type == self::TYPE_MEDIA) {
search($data, $conf['mediadir'], 'search_universal', $opts, $basedir);
}
return $data;
}
/**
* Item formatter for the tree view
*
* User function for html_buildlist()
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function html_list($item) {
$ret = '';
// what to display
if(!empty($item['label'])) {
$base = $item['label'];
} else {
$base = ':' . $item['id'];
$base = substr($base, strrpos($base, ':') + 1);
}
if($item['id'] == '*') $item['id'] = '';
if ($item['id']) {
$ret .= '<input type="checkbox" /> ';
}
// namespace or page?
if($item['type'] == 'd') {
$ret .= '<a href="' . $item['id'] . '" class="idx_dir">';
$ret .= $base;
$ret .= '</a>';
} else {
$ret .= '<a class="wikilink1">';
$ret .= noNS($item['id']);
$ret .= '</a>';
}
if($item['id']) $ret .= '<img class="rename" src="'. DOKU_BASE .'lib/plugins/move/images/rename.png" />';
else $ret .= '<img class="add" src="' . DOKU_BASE . 'lib/plugins/move/images/folder_add.png" />';
return $ret;
}
/**
* print the opening LI for a list item
*
* @param array $item
* @return string
*/
function html_li($item) {
if($item['id'] == '*') $item['id'] = '';
$params = array();
$params['class'] = ' type-' . $item['type'];
if($item['type'] == 'd') $params['class'] .= ' ' . ($item['open'] ? 'open' : 'closed');
$params['data-name'] = noNS($item['id']);
$params['data-id'] = $item['id'];
$attr = buildAttributes($params);
return "<li $attr>";
}
}