1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SRF\Outline\TemplateBuilder; |
4
|
|
|
use SRF\Outline\ListTreeBuilder; |
5
|
|
|
use SRF\Outline\OutlineTree; |
6
|
|
|
use SRF\Outline\OutlineItem; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* A class to print query results in an outline format, along with some |
10
|
|
|
* helper classes to handle the aggregation |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.4.3 |
14
|
|
|
* |
15
|
|
|
* @author Yaron Koren |
16
|
|
|
*/ |
17
|
|
|
class SRFOutline extends SMWResultPrinter { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see ResultPrinter::getName |
21
|
|
|
* |
22
|
|
|
* {@inheritDoc} |
23
|
|
|
*/ |
24
|
|
|
public function getName() { |
25
|
|
|
return wfMessage( 'srf_printername_outline' )->text(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @see SMWResultPrinter::getParamDefinitions |
30
|
|
|
* |
31
|
|
|
* @since 1.8 |
32
|
|
|
* |
33
|
|
|
* {@inheritDoc} |
34
|
|
|
*/ |
35
|
2 |
|
public function getParamDefinitions( array $definitions ) { |
36
|
2 |
|
$params = parent::getParamDefinitions( $definitions ); |
37
|
|
|
|
38
|
2 |
|
$params['outlineproperties'] = [ |
39
|
|
|
'islist' => true, |
40
|
|
|
'default' => [], |
41
|
|
|
'message' => 'srf_paramdesc_outlineproperties', |
42
|
|
|
]; |
43
|
|
|
|
44
|
2 |
|
$params[] = [ |
45
|
|
|
'name' => 'template', |
46
|
|
|
'message' => 'smw-paramdesc-template', |
47
|
|
|
'default' => '', |
48
|
|
|
]; |
49
|
|
|
|
50
|
2 |
|
$params[] = [ |
51
|
|
|
'name' => 'userparam', |
52
|
|
|
'message' => 'smw-paramdesc-userparam', |
53
|
|
|
'default' => '', |
54
|
|
|
]; |
55
|
|
|
|
56
|
2 |
|
$params[] = [ |
57
|
|
|
'name' => 'named args', |
58
|
|
|
'type' => 'boolean', |
59
|
|
|
'message' => 'smw-paramdesc-named_args', |
60
|
|
|
'default' => true, |
61
|
|
|
]; |
62
|
|
|
|
63
|
2 |
|
return $params; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @see ResultPrinter::getResultText |
68
|
|
|
* |
69
|
|
|
* {@inheritDoc} |
70
|
|
|
*/ |
71
|
2 |
|
protected function getResultText( SMWQueryResult $res, $outputMode ) { |
72
|
|
|
|
73
|
|
|
// for each result row, create an array of the row itself |
74
|
|
|
// and all its sorted-on fields, and add it to the initial |
75
|
|
|
// 'tree' |
76
|
2 |
|
$outlineTree = new OutlineTree(); |
77
|
2 |
|
while ( $row = $res->getNext() ) { |
78
|
2 |
|
$outlineItem = new OutlineItem( $row ); |
79
|
|
|
|
80
|
2 |
|
foreach ( $row as $field ) { |
81
|
2 |
|
$field_name = $field->getPrintRequest()->getText( SMW_OUTPUT_HTML ); |
82
|
|
|
|
83
|
2 |
|
if ( in_array( $field_name, $this->params['outlineproperties'] ) ) { |
84
|
2 |
|
while ( ( $object = $field->getNextDataValue() ) !== false ) { |
85
|
2 |
|
$field_val = $object->getLongWikiText( $this->getLinker() ); |
86
|
2 |
|
$outlineItem->addFieldValue( $field_name, $field_val ); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
$outlineTree->addItem( $outlineItem ); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// now, cycle through the outline properties, creating the |
95
|
|
|
// tree |
96
|
2 |
|
foreach ( $this->params['outlineproperties'] as $property ) { |
97
|
2 |
|
$outlineTree->addProperty( $property ); |
98
|
|
|
} |
99
|
|
|
|
100
|
2 |
|
if ( $this->params['template'] !== '' ) { |
101
|
1 |
|
$this->hasTemplates = true; |
102
|
1 |
|
$templateBuilder = new TemplateBuilder( |
103
|
1 |
|
$this->params |
104
|
|
|
); |
105
|
|
|
|
106
|
1 |
|
$templateBuilder->setLinker( $this->mLinker ); |
107
|
1 |
|
$result = $templateBuilder->build( $outlineTree ); |
108
|
|
|
} else { |
109
|
1 |
|
$listTreeBuilder = new ListTreeBuilder( |
110
|
1 |
|
$this->params + [ 'showHeaders' => $this->mShowHeaders ] |
111
|
|
|
); |
112
|
|
|
|
113
|
1 |
|
$listTreeBuilder->setLinker( $this->mLinker ); |
114
|
1 |
|
$result = $listTreeBuilder->build( $outlineTree ); |
115
|
|
|
} |
116
|
|
|
|
117
|
2 |
|
if ( $this->linkFurtherResults( $res ) ) { |
118
|
|
|
$link = $this->getFurtherResultsLink( $res, $outputMode ); |
119
|
|
|
|
120
|
|
|
$result .= $link->getText( $outputMode, $this->mLinker ) . "\n"; |
121
|
|
|
} |
122
|
|
|
|
123
|
2 |
|
return $result; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|