1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @ingroup SMWSpecialPage |
4
|
|
|
* @ingroup SpecialPage |
5
|
|
|
* |
6
|
|
|
* Special page to show object relation pairs. |
7
|
|
|
* |
8
|
|
|
* @author Denny Vrandecic |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This special page for Semantic MediaWiki implements a |
13
|
|
|
* view on a object-relation pair, i.e. a page that shows |
14
|
|
|
* all the fillers of a property for a certain page. |
15
|
|
|
* This is typically used for overflow results from other |
16
|
|
|
* dynamic output pages. |
17
|
|
|
* |
18
|
|
|
* @ingroup SMWSpecialPage |
19
|
|
|
* @ingroup SpecialPage |
20
|
|
|
*/ |
21
|
|
|
class SMWPageProperty extends SpecialPage { |
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Constructor |
25
|
|
|
*/ |
26
|
|
|
public function __construct() { |
27
|
|
|
parent::__construct( 'PageProperty', '', false ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function execute( $query ) { |
31
|
|
|
global $wgRequest, $wgOut; |
|
|
|
|
32
|
|
|
$this->setHeaders(); |
33
|
|
|
|
34
|
|
|
// Get parameters |
35
|
|
|
$pagename = $wgRequest->getVal( 'from' ); |
36
|
|
|
$propname = $wgRequest->getVal( 'type' ); |
37
|
|
|
$limit = $wgRequest->getVal( 'limit', 20 ); |
38
|
|
|
$offset = $wgRequest->getVal( 'offset', 0 ); |
39
|
|
|
|
40
|
|
|
if ( $propname == '' ) { // No GET parameters? Try the URL: |
41
|
|
|
$queryparts = explode( '::', $query ); |
42
|
|
|
$propname = $query; |
43
|
|
|
if ( count( $queryparts ) > 1 ) { |
44
|
|
|
$pagename = $queryparts[0]; |
45
|
|
|
$propname = implode( '::', array_slice( $queryparts, 1 ) ); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$subject = \SMW\DataValueFactory::getInstance()->newTypeIDValue( '_wpg', $pagename ); |
|
|
|
|
50
|
|
|
$pagename = $subject->isValid() ? $subject->getPrefixedText() : ''; |
51
|
|
|
$property = SMWPropertyValue::makeUserProperty( $propname ); |
52
|
|
|
$propname = $property->isValid() ? $property->getWikiValue() : ''; |
53
|
|
|
|
54
|
|
|
// Produce output |
55
|
|
|
$html = ''; |
56
|
|
|
if ( ( $propname === '' ) ) { // no property given, show a message |
57
|
|
|
$html .= wfMessage( 'smw_pp_docu' )->text() . "\n"; |
58
|
|
|
} else { // property given, find and display results |
59
|
|
|
// @todo FIXME: very ugly, needs i18n |
60
|
|
|
$wgOut->setPagetitle( ( $pagename !== '' ? $pagename . ' ':'' ) . $property->getWikiValue() ); |
61
|
|
|
|
62
|
|
|
// get results (get one more, to see if we have to add a link to more) |
63
|
|
|
$options = new SMWRequestOptions(); |
64
|
|
|
$options->limit = $limit + 1; |
65
|
|
|
$options->offset = $offset; |
66
|
|
|
$options->sort = true; |
67
|
|
|
$results = \SMW\StoreFactory::getStore()->getPropertyValues( $pagename !== '' ? $subject->getDataItem() : null, $property->getDataItem(), $options ); |
|
|
|
|
68
|
|
|
|
69
|
|
|
// prepare navigation bar if needed |
70
|
|
|
$navigation = ''; |
71
|
|
|
if ( ( $offset > 0 ) || ( count( $results ) > $limit ) ) { |
72
|
|
|
if ( $offset > 0 ) { |
73
|
|
|
$navigation .= Html::element( |
74
|
|
|
'a', |
75
|
|
|
array( |
76
|
|
|
'href' => $this->getTitle()->getLocalURL( array( |
77
|
|
|
'offset' => max( 0, $offset - $limit ), |
78
|
|
|
'limit' => $limit, |
79
|
|
|
'type' => $propname, |
80
|
|
|
'from' => $pagename |
81
|
|
|
) ) |
82
|
|
|
), |
83
|
|
|
wfMessage( 'smw_result_prev' )->text() |
84
|
|
|
); |
85
|
|
|
} else { |
86
|
|
|
$navigation = wfMessage( 'smw_result_prev' )->text(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// @todo FIXME: i18n patchwork. |
90
|
|
|
$navigation .= |
91
|
|
|
'     <b>' . |
92
|
|
|
wfMessage( 'smw_result_results' )->text() . ' ' . |
93
|
|
|
( $offset + 1 ) . '– ' . ( $offset + min( count( $results ), $limit ) ) . |
94
|
|
|
'</b>    '; |
95
|
|
|
|
96
|
|
|
if ( count( $results ) == ( $limit + 1 ) ) { |
97
|
|
|
$navigation .= Html::element( |
98
|
|
|
'a', |
99
|
|
|
array( |
100
|
|
|
'href' => $this->getTitle()->getLocalURL( array( |
101
|
|
|
'offset' => ( $offset + $limit ), |
102
|
|
|
'limit' => $limit, |
103
|
|
|
'type' => $propname, |
104
|
|
|
'from' => $pagename |
105
|
|
|
) ) |
106
|
|
|
), |
107
|
|
|
wfMessage( 'smw_result_next' )->text() |
108
|
|
|
); |
109
|
|
|
} else { |
110
|
|
|
$navigation .= wfMessage( 'smw_result_next' )->text(); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// display results |
115
|
|
|
$html .= '<br />' . $navigation; |
116
|
|
|
if ( count( $results ) == 0 ) { |
117
|
|
|
$html .= wfMessage( 'smw_result_noresults' )->text(); |
118
|
|
|
} else { |
119
|
|
|
$linker = smwfGetLinker(); |
120
|
|
|
$html .= "<ul>\n"; |
121
|
|
|
$count = $limit + 1; |
122
|
|
|
|
123
|
|
|
foreach ( $results as $di ) { |
124
|
|
|
$count--; |
125
|
|
|
if ( $count < 1 ) { |
126
|
|
|
continue; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$dv = \SMW\DataValueFactory::getInstance()->newDataValueByItem( $di, $property->getDataItem() ); |
|
|
|
|
130
|
|
|
$html .= '<li>' . $dv->getLongHTMLText( $linker ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below) |
131
|
|
|
|
132
|
|
|
if ( $property->getDataItem()->findPropertyTypeID() == '_wpg' ) { |
|
|
|
|
133
|
|
|
$browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() ); |
134
|
|
|
$html .= '  ' . $browselink->getHTML( $linker ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$html .= "</li> \n"; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$html .= "</ul>\n"; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$html .= $navigation; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// Deprecated: Use of SpecialPage::getTitle was deprecated in MediaWiki 1.23 |
147
|
|
|
$spectitle = method_exists( $this, 'getPageTitle') ? $this->getPageTitle() : $this->getTitle(); |
148
|
|
|
|
149
|
|
|
// Display query form |
150
|
|
|
$html .= '<p> </p>'; |
151
|
|
|
$html .= '<form name="pageproperty" action="' . htmlspecialchars( $spectitle->getLocalURL() ) . '" method="get">' . "\n" . |
152
|
|
|
'<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>'; |
153
|
|
|
$html .= wfMessage( 'smw_pp_from' )->text() . ' <input type="text" name="from" value="' . htmlspecialchars( $pagename ) . '" />' . "   \n"; |
154
|
|
|
$html .= wfMessage( 'smw_pp_type' )->text() . ' <input type="text" name="type" value="' . htmlspecialchars( $propname ) . '" />' . "\n"; |
155
|
|
|
$html .= '<input type="submit" value="' . wfMessage( 'smw_pp_submit' )->text() . "\"/>\n</form>\n"; |
156
|
|
|
|
157
|
|
|
$wgOut->addHTML( $html ); |
158
|
|
|
SMWOutputs::commitToOutputPage( $wgOut ); // make sure locally collected output data is pushed to the output! |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
protected function getGroupName() { |
162
|
|
|
return 'smw_group'; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.