Skip to content

Commit 15b9cc3

Browse files
committed
Values for page and title are always absolute
_resolveData always resolves the id from title and page fields starting from the root namespace, since it doesn't know about the namespace of the corresponding dataentry. Hence the dataentry dialog should always consider the entered ids to be absolute and link them accordingly.
1 parent 05d8102 commit 15b9cc3

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

_test/db.test.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,34 @@ function test_title_input_Heading () {
116116
$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
117117
}
118118

119+
function test_title_input_stackns () {
120+
121+
$test_table = "---- datatable Testtable ----\n"
122+
. "cols: %pageid%, test1\n";
123+
124+
global $ID;
125+
$ID = 'foo:bar:start';
126+
127+
/** @var syntax_plugin_data_entry $plugin */
128+
$plugin = plugin_load('syntax','data_table');
129+
130+
$handler = new Doku_Handler();
131+
$data = $plugin->handle($test_table, 0, 0, $handler);
132+
$renderer = new Doku_Renderer_xhtml();
133+
$plugin->render('xhtml',$renderer,$data);
134+
135+
$result = $renderer->doc;
136+
137+
$actual_value = substr($result,strpos($result,'<td class="align test1">')+24);
138+
$actual_value = substr($actual_value,0,strpos($actual_value,'</td>'));
139+
$expected_value = 'foo|bar';
140+
$this->assertSame($expected_value,$actual_value);
141+
142+
$actual_link = substr($result,strpos($result,'<td class="align pageid">')+25);
143+
$actual_link = substr($actual_link,strpos($actual_link,'doku.php'));
144+
$actual_link = substr($actual_link,0,strpos($actual_link,'</a>'));
145+
146+
$this->assertSame('doku.php?id=testpage" class="wikilink1" title="testpage">testpage',$actual_link);
147+
}
148+
119149
}

_test/helper.test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ function testFormatData() {
136136
$this->assertEquals('value1, value2, val',
137137
$helper->_formatData(array('type' => ''), "value1\n value2\n val", $renderer));
138138

139-
$this->assertEquals('link: page ',
139+
$this->assertEquals('link: :page ',
140140
$helper->_formatData(array('type' => 'page'), "page", $renderer));
141141

142-
$this->assertEquals('link: page title',
142+
$this->assertEquals('link: :page title',
143143
$helper->_formatData(array('type' => 'title'), "page|title", $renderer));
144144

145145
$this->assertEquals('link: page title',

_test/syntax_plugin_data_entry.test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function test_pageEntry_noTitle() {
100100
$result = substr($result,strpos($result,'<internallink>')+14);
101101
$result = unserialize($result);
102102

103-
$this->assertSame('foo',$result['id']);
103+
$this->assertSame(':foo',$result['id']);
104104
$this->assertSame(null,$result['name'], 'page does not accept a title. useheading decides');
105105
}
106106

@@ -121,7 +121,7 @@ function test_pageEntry_withTitle() {
121121
$result = substr($result,strpos($result,'<internallink>')+14);
122122
$result = unserialize($result);
123123

124-
$this->assertSame('foo_bar',$result['id'], 'for type page a title becomes part of the id');
124+
$this->assertSame(':foo_bar',$result['id'], 'for type page a title becomes part of the id');
125125
$this->assertSame(null,$result['name'], 'page never accepts a title. useheading decides');
126126
}
127127

@@ -184,7 +184,7 @@ function test_titleEntry_noTitle() {
184184
$result = substr($result,strpos($result,'<internallink>')+14);
185185
$result = unserialize($result);
186186

187-
$this->assertSame('foo',$result['id']);
187+
$this->assertSame(':foo',$result['id']);
188188
$this->assertSame(null,$result['name'], 'no title should be given to internal link. Let useheading decide.');
189189
}
190190

@@ -206,7 +206,7 @@ function test_titleEntry_withTitle() {
206206
$result = substr($result,strpos($result,'<internallink>')+14);
207207
$result = unserialize($result);
208208

209-
$this->assertSame('link:to:page',$result['id']);
209+
$this->assertSame(':link:to:page',$result['id']);
210210
$this->assertSame('TitleOfPage',$result['name'], 'The Title provided should be the title shown.');
211211
}
212212

helper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ function _resolveData($value, $colname) {
205205
return $value;
206206
}
207207

208+
public function ensureAbsoluteId($id) {
209+
if (substr($id,0,1) !== ':') {
210+
$id = ':' . $id;
211+
}
212+
return $id;
213+
}
214+
208215
/**
209216
* Return XHTML formated data, depending on column type
210217
*
@@ -232,11 +239,13 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
232239
switch($type) {
233240
case 'page':
234241
$val = $this->_addPrePostFixes($column['type'], $val);
242+
$val = $this->ensureAbsoluteId($val);
235243
$outs[] = $R->internallink($val, null, null, true);
236244
break;
237245
case 'title':
238246
list($id, $title) = explode('|', $val, 2);
239247
$id = $this->_addPrePostFixes($column['type'], $id);
248+
$id = $this->ensureAbsoluteId($id);
240249
$outs[] = $R->internallink($id, $title, null, true);
241250
break;
242251
case 'pageid':
@@ -253,6 +262,7 @@ function _formatData($column, $value, Doku_Renderer_xhtml $R) {
253262
}
254263

255264
$id = $this->_addPrePostFixes($column['type'], $id);
265+
256266
$outs[] = $R->internallink($id, $title, null, true);
257267
break;
258268
case 'nspage':

0 commit comments

Comments
 (0)