Skip to content

Commit 33c80c4

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 048aed8 + 31a7eed commit 33c80c4

33 files changed

+895
-435
lines changed

action/rename.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public function addsvgbutton(Doku_Event $event) {
9494

9595
/**
9696
* Rename a single page
97+
*
98+
* This creates a plan and executes it right away. If the user selected to move media with the page,
99+
* all media files used in the original page that are located in the same namespace are moved with the page
100+
* to the new namespace.
101+
*
97102
*/
98103
public function handle_ajax(Doku_Event $event) {
99104
if($event->data != 'plugin_move_rename') return;
@@ -105,22 +110,59 @@ public function handle_ajax(Doku_Event $event) {
105110

106111
$src = cleanID($INPUT->str('id'));
107112
$dst = cleanID($INPUT->str('newid'));
108-
109-
/** @var helper_plugin_move_op $MoveOperator */
110-
$MoveOperator = plugin_load('helper', 'move_op');
113+
$doMedia = $INPUT->bool('media');
111114

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

114-
if($this->renameOkay($src) && $MoveOperator->movePage($src, $dst)) {
115-
// all went well, redirect
117+
if(!$this->renameOkay($src)) {
118+
echo json_encode(['error' => $this->getLang('cantrename')]);
119+
return;
120+
}
121+
122+
/** @var helper_plugin_move_plan $plan */
123+
$plan = plugin_load('helper', 'move_plan');
124+
if($plan->isCommited()) {
125+
echo json_encode(['error' => $this->getLang('cantrename')]);
126+
return;
127+
}
128+
$plan->setOption('autorewrite', true);
129+
$plan->addPageMove($src, $dst); // add the page move to the plan
130+
131+
if($doMedia) { // move media with the page?
132+
$srcNS = getNS($src);
133+
$dstNS = getNS($dst);
134+
$srcNSLen = strlen($srcNS);
135+
// we don't do this for root namespace or if namespace hasn't changed
136+
if ($srcNS != '' && $srcNS != $dstNS) {
137+
$media = p_get_metadata($src, 'relation media');
138+
if (is_array($media)) {
139+
foreach ($media as $file => $exists) {
140+
if(!$exists) continue;
141+
$mediaNS = getNS($file);
142+
if ($mediaNS == $srcNS) {
143+
$plan->addMediaMove($file, $dstNS . substr($file, $srcNSLen));
144+
}
145+
}
146+
}
147+
}
148+
}
149+
150+
try {
151+
// commit and execute the plan
152+
$plan->commit();
153+
do {
154+
$next = $plan->nextStep();
155+
if ($next === false) throw new \Exception('Move plan failed');
156+
} while ($next > 0);
116157
echo json_encode(array('redirect_url' => wl($dst, '', true, '&')));
117-
} else {
158+
} catch (\Exception $e) {
159+
// error should be in $MSG
118160
if(isset($MSG[0])) {
119161
$error = $MSG[0]; // first error
120162
} else {
121-
$error = $this->getLang('cantrename');
163+
$error = $this->getLang('cantrename') . ' ' . $e->getMessage();
122164
}
123-
echo json_encode(array('error' => $error));
165+
echo json_encode(['error' => $error]);
124166
}
125167
}
126168

action/tree.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ public function handle_ajax_call(Doku_Event $event, $params) {
5151
$type = admin_plugin_move_tree::TYPE_PAGES;
5252
}
5353

54-
$data = $plugin->tree($type, $ns, $ns);
54+
header('Content-Type: application/json');
5555

56-
echo html_buildlist(
57-
$data, 'tree_list',
58-
array($plugin, 'html_list'),
59-
array($plugin, 'html_li')
60-
);
56+
$data = $plugin->tree($type, $ns, $ns);
57+
echo json_encode($data);
6158
}
6259

63-
}
60+
}

admin/tree.php

Lines changed: 83 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,146 @@
11
<?php
22

3-
class admin_plugin_move_tree extends DokuWiki_Admin_Plugin {
4-
5-
const TYPE_PAGES = 1;
6-
const TYPE_MEDIA = 2;
3+
class admin_plugin_move_tree extends DokuWiki_Admin_Plugin
4+
{
5+
public const TYPE_PAGES = 1;
6+
public const TYPE_MEDIA = 2;
77

88
/**
99
* @param $language
1010
* @return bool
1111
*/
12-
public function getMenuText($language) {
12+
public function getMenuText($language)
13+
{
1314
return false; // do not show in Admin menu
1415
}
1516

16-
1717
/**
1818
* If this admin plugin is for admins only
1919
*
2020
* @return bool false
2121
*/
22-
function forAdminOnly() {
22+
public function forAdminOnly()
23+
{
2324
return false;
2425
}
2526

2627
/**
2728
* no-op
2829
*/
29-
public function handle() {
30+
public function handle()
31+
{
3032
}
3133

32-
public function html() {
33-
global $ID;
3434

35+
public function html()
36+
{
37+
global $ID;
38+
global $INPUT;
3539
echo $this->locale_xhtml('tree');
3640

37-
echo '<noscript><div class="error">' . $this->getLang('noscript') . '</div></noscript>';
38-
39-
echo '<div id="plugin_move__tree">';
40-
41-
echo '<div class="tree_root tree_pages">';
42-
echo '<h3>' . $this->getLang('move_pages') . '</h3>';
43-
$this->htmlTree(self::TYPE_PAGES);
44-
echo '</div>';
45-
46-
echo '<div class="tree_root tree_media">';
47-
echo '<h3>' . $this->getLang('move_media') . '</h3>';
48-
$this->htmlTree(self::TYPE_MEDIA);
49-
echo '</div>';
41+
$dual = $INPUT->bool('dual', $this->getConf('dual'));
5042

5143
/** @var helper_plugin_move_plan $plan */
5244
$plan = plugin_load('helper', 'move_plan');
53-
echo '<div class="controls">';
54-
if($plan->isCommited()) {
45+
if ($plan->isCommited()) {
5546
echo '<div class="error">' . $this->getLang('moveinprogress') . '</div>';
5647
} else {
57-
$form = new Doku_Form(array('action' => wl($ID), 'id' => 'plugin_move__tree_execute'));
58-
$form->addHidden('id', $ID);
59-
$form->addHidden('page', 'move_main');
60-
$form->addHidden('json', '');
61-
$form->addElement(form_makeCheckboxField('autoskip', '1', $this->getLang('autoskip'), '', '', ($this->getConf('autoskip') ? array('checked' => 'checked') : array())));
62-
$form->addElement('<br />');
63-
$form->addElement(form_makeCheckboxField('autorewrite', '1', $this->getLang('autorewrite'), '', '', ($this->getConf('autorewrite') ? array('checked' => 'checked') : array())));
64-
$form->addElement('<br />');
65-
$form->addElement('<br />');
66-
$form->addElement(form_makeButton('submit', 'admin', $this->getLang('btn_start')));
67-
$form->printForm();
48+
echo '<noscript><div class="error">' . $this->getLang('noscript') . '</div></noscript>';
49+
50+
echo '<ul class="tabs">';
51+
foreach ([1, 0] as $set) {
52+
echo '<li>';
53+
if ($set == $dual) {
54+
echo '<strong>';
55+
echo $this->getLang('dual' . $set);
56+
echo '</strong>';
57+
} else {
58+
echo '<a href="' . wl($ID, ['do' => 'admin', 'page' => 'move_tree', 'dual' => $set]) . '">';
59+
echo $this->getLang('dual' . $set);
60+
echo '</a>';
61+
}
62+
echo '</li>';
63+
}
64+
echo '</ul>';
65+
66+
echo '<div id="plugin_move__tree">';
67+
echo '<div class="trees">';
68+
if ($dual) {
69+
$this->printTreeRoot('move-pages');
70+
$this->printTreeRoot('move-media');
71+
} else {
72+
$this->printTreeRoot('move-pages move-media');
73+
}
74+
echo '</div>';
75+
76+
77+
$form = new dokuwiki\Form\Form(['method' => 'post']);
78+
$form->setHiddenField('page', 'move_main');
79+
80+
$cb = $form->addCheckbox('autoskip', $this->getLang('autoskip'));
81+
if ($this->getConf('autoskip')) $cb->attr('checked', 'checked');
82+
83+
$cb = $form->addCheckbox('autorewrite', $this->getLang('autorewrite'));
84+
if ($this->getConf('autorewrite')) $cb->attr('checked', 'checked');
85+
86+
$form->addButton('submit', $this->getLang('btn_start'));
87+
echo $form->toHTML();
88+
echo '</div>';
6889
}
69-
echo '</div>';
70-
71-
echo '</div>';
7290
}
7391

7492
/**
75-
* print the HTML tree structure
93+
* Print the root of the tree
7694
*
77-
* @param int $type
95+
* @param string $classes The classes to apply to the root
96+
* @return void
7897
*/
79-
protected function htmlTree($type = self::TYPE_PAGES) {
80-
$data = $this->tree($type);
81-
82-
// wrap a list with the root level around the other namespaces
83-
array_unshift(
84-
$data, array(
85-
'level' => 0, 'id' => '*', 'type' => 'd',
86-
'open' => 'true', 'label' => $this->getLang('root')
87-
)
88-
);
89-
echo html_buildlist(
90-
$data, 'tree_list idx',
91-
array($this, 'html_list'),
92-
array($this, 'html_li')
93-
);
98+
protected function printTreeRoot($classes) {
99+
echo '<ul>';
100+
echo '<li class="'.$classes.' move-ns open tree-root" data-id="" data-orig="" >';
101+
echo '<div class="li">';
102+
echo '<i class="icon">';
103+
echo inlineSVG(DOKU_PLUGIN . 'move/images/folder-home.svg');
104+
echo '</i>';
105+
echo '<span>:</span>';
106+
echo '</div>';
107+
echo '<ul class="'.$classes.' move-ns open" data-id="" data-orig=""></ul>';
108+
echo '</li>';
109+
echo '</ul>';
94110
}
95111

96112
/**
97113
* Build a tree info structure from media or page directories
98114
*
99-
* @param int $type
115+
* @param int $type
100116
* @param string $open The hierarchy to open FIXME not supported yet
101117
* @param string $base The namespace to start from
102118
* @return array
103119
*/
104-
public function tree($type = self::TYPE_PAGES, $open = '', $base = '') {
120+
public function tree($type = self::TYPE_PAGES, $open = '', $base = '')
121+
{
105122
global $conf;
106123

107124
$opendir = utf8_encodeFN(str_replace(':', '/', $open));
108125
$basedir = utf8_encodeFN(str_replace(':', '/', $base));
109126

110127
$opts = array(
111-
'pagesonly' => ($type == self::TYPE_PAGES),
112-
'listdirs' => true,
113-
'listfiles' => true,
114-
'sneakyacl' => $conf['sneaky_index'],
115-
'showmsg' => false,
116-
'depth' => 1,
128+
'pagesonly' => ($type == self::TYPE_PAGES),
129+
'listdirs' => true,
130+
'listfiles' => true,
131+
'sneakyacl' => $conf['sneaky_index'],
132+
'showmsg' => false,
133+
'depth' => 1,
117134
'showhidden' => true
118135
);
119136

120137
$data = array();
121-
if($type == self::TYPE_PAGES) {
138+
if ($type == self::TYPE_PAGES) {
122139
search($data, $conf['datadir'], 'search_universal', $opts, $basedir);
123-
} elseif($type == self::TYPE_MEDIA) {
140+
} elseif ($type == self::TYPE_MEDIA) {
124141
search($data, $conf['mediadir'], 'search_universal', $opts, $basedir);
125142
}
126143

127144
return $data;
128145
}
129-
130-
/**
131-
* Item formatter for the tree view
132-
*
133-
* User function for html_buildlist()
134-
*
135-
* @author Andreas Gohr <[email protected]>
136-
*/
137-
function html_list($item) {
138-
$ret = '';
139-
// what to display
140-
if(!empty($item['label'])) {
141-
$base = $item['label'];
142-
} else {
143-
$base = ':' . $item['id'];
144-
$base = substr($base, strrpos($base, ':') + 1);
145-
}
146-
147-
if($item['id'] == '*') $item['id'] = '';
148-
149-
if ($item['id']) {
150-
$ret .= '<input type="checkbox" /> ';
151-
}
152-
153-
// namespace or page?
154-
if($item['type'] == 'd') {
155-
$ret .= '<a href="' . $item['id'] . '" class="idx_dir">';
156-
$ret .= $base;
157-
$ret .= '</a>';
158-
} else {
159-
$ret .= '<a class="wikilink1">';
160-
$ret .= noNS($item['id']);
161-
$ret .= '</a>';
162-
}
163-
164-
if($item['id']) $ret .= '<img class="rename" src="'. DOKU_BASE .'lib/plugins/move/images/rename.png" />';
165-
else $ret .= '<img class="add" src="' . DOKU_BASE . 'lib/plugins/move/images/folder_add.png" />';
166-
167-
return $ret;
168-
}
169-
170-
/**
171-
* print the opening LI for a list item
172-
*
173-
* @param array $item
174-
* @return string
175-
*/
176-
function html_li($item) {
177-
if($item['id'] == '*') $item['id'] = '';
178-
179-
$params = array();
180-
$params['class'] = ' type-' . $item['type'];
181-
if($item['type'] == 'd') $params['class'] .= ' ' . ($item['open'] ? 'open' : 'closed');
182-
$params['data-name'] = noNS($item['id']);
183-
$params['data-id'] = $item['id'];
184-
$attr = buildAttributes($params);
185-
186-
return "<li $attr>";
187-
}
188-
189146
}

conf/default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
$conf['allowrename'] = '@user';
44
$conf['minor'] = 1;
5+
$conf['dual'] = 1;
56
$conf['autoskip'] = 0;
67
$conf['autorewrite'] = 1;
78
$conf['pagetools_integration'] = 1;

conf/metadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
$meta['allowrename'] = array('string');
44
$meta['minor'] = array('onoff');
5+
$meta['dual'] = array('onoff');
56
$meta['autoskip'] = array('onoff');
67
$meta['autorewrite'] = array('onoff');
78
$meta['pagetools_integration'] = array('onoff');

images/folder-home.svg

Lines changed: 1 addition & 0 deletions
Loading

lang/cs/lang.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
$lang['js']['complete'] = 'Přesun byl dokončen.';
6565
$lang['js']['renameitem'] = 'Přejmenovat tuto položku';
6666
$lang['js']['add'] = 'Vytvořit nový jmenný prostor';
67-
$lang['js']['duplicate'] = 'Lituji, ale \'%s\' již existuje ve jmenném prosoru.';
6867
$lang['js']['moveButton'] = 'Přesunout soubor';
6968
$lang['js']['dialogIntro'] = 'Zadejte nový cíl souboru. Můžete změnit jmenný prostor, ale ne příponu souboru.';
7069
$lang['root'] = '[Kořen]';

0 commit comments

Comments
 (0)