Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php |
— | — | @@ -36,10 +36,9 @@ |
37 | 37 | * Constructor |
38 | 38 | */ |
39 | 39 | public function __construct() { |
| 40 | + global $smwgBrowseShowAll; |
40 | 41 | parent::__construct('Browse', '', true, false, 'default', true); |
41 | 42 | wfLoadExtensionMessages('SemanticMediaWiki'); |
42 | | - |
43 | | - global $smwgBrowseShowAll; |
44 | 43 | if ($smwgBrowseShowAll) { |
45 | 44 | SMWSpecialBrowse::$incomingvaluescount = 21; |
46 | 45 | SMWSpecialBrowse::$incomingpropertiescount = -1; |
— | — | @@ -53,7 +52,7 @@ |
54 | 53 | * @param[in] $query string Given by MediaWiki |
55 | 54 | */ |
56 | 55 | public function execute( $query ) { |
57 | | - global $wgRequest, $wgOut; |
| 56 | + global $wgRequest, $wgOut, $smwgBrowseShowAll; |
58 | 57 | $this->setHeaders(); |
59 | 58 | // get the GET parameters |
60 | 59 | $this->articletext = $wgRequest->getVal( 'article' ); |
— | — | @@ -65,13 +64,8 @@ |
66 | 65 | } |
67 | 66 | $this->subject = SMWDataValueFactory::newTypeIDValue('_wpg', $this->articletext); |
68 | 67 | $offsettext = $wgRequest->getVal( 'offset' ); |
69 | | - if ('' == $offsettext) { |
70 | | - $this->offset = 0; |
71 | | - } else { |
72 | | - $this->offset = intval($offsettext); |
73 | | - } |
| 68 | + $this->offset = ('' == $offsettext)?0:intval($offsettext); |
74 | 69 | $dir = $wgRequest->getVal( 'dir' ); |
75 | | - global $smwgBrowseShowAll; |
76 | 70 | if ($smwgBrowseShowAll) { |
77 | 71 | $this->showoutgoing = true; |
78 | 72 | $this->showincoming = true; |
— | — | @@ -85,8 +79,8 @@ |
86 | 80 | } |
87 | 81 | |
88 | 82 | /** |
89 | | - * Create an HTML including the complete factbox, based on the extracted parameters |
90 | | - * in the execute comment. |
| 83 | + * Create and output HTML including the complete factbox, based on the extracted |
| 84 | + * parameters in the execute comment. |
91 | 85 | * |
92 | 86 | * @return string A HTML string with the factbox |
93 | 87 | */ |
— | — | @@ -120,7 +114,7 @@ |
121 | 115 | } |
122 | 116 | |
123 | 117 | /** |
124 | | - * Creates the HTML displaying the data of one subject. |
| 118 | + * Creates the HTML table displaying the data of one subject. |
125 | 119 | * |
126 | 120 | * @param[in] $data SMWSemanticData The data to be displayed |
127 | 121 | * @param[in] $left bool Should properties be displayed on the left side? |
— | — | @@ -132,74 +126,52 @@ |
133 | 127 | $skin = $wgUser->getSkin(); |
134 | 128 | // Some of the CSS classes are different for the left or the right side. |
135 | 129 | // In this case, there is an "i" after the "smwb-". This is set here. |
136 | | - $inv = "i"; |
137 | | - if ($left) $inv = ""; |
138 | | - $html = "<table class=\"smwb-" . $inv . "factbox\" cellpadding=\"0\" cellspacing=\"0\">\n"; |
| 130 | + $inv = $left?'':'i'; |
| 131 | + $html = "<table class=\"smwb-" . $inv . "factbox\" cellpadding=\"0\" cellspacing=\"0\">\n"; |
139 | 132 | $properties = $data->getProperties(); |
140 | 133 | $noresult = true; |
141 | | - foreach ($properties as $property) { |
| 134 | + foreach ($properties as $property) { |
142 | 135 | $displayline = true; |
143 | 136 | if ($property->isVisible()) { |
144 | 137 | $property->setCaption($this->getPropertyLabel($property, $incoming)); |
145 | 138 | $proptext = $property->getShortHTMLText($skin) . "\n"; |
| 139 | + } elseif ($property->getPropertyID() == '_INST') { |
| 140 | + $proptext = $skin->specialLink( 'Categories' ); |
| 141 | + } elseif ($property->getPropertyID() == '_REDI') { |
| 142 | + $proptext = $skin->specialLink( 'Listredirects', 'isredirect' ); |
146 | 143 | } else { |
147 | | -// global $smwgContLang; |
148 | | -// $proptext = $smwgContLang->findSpecialPropertyLabel( $property ); |
149 | | -// if ($proptext != '') { |
150 | | -// $p = Title::newFromText($proptext, SMW_NS_PROPERTY); |
151 | | -// $proptext = $skin->makeLinkObj($p, $this->unbreak($proptext)); |
152 | | -// $displayline = true; |
153 | | -// } |
154 | | - if ($property->getPropertyID() == '_INST') { |
155 | | - $proptext = $skin->specialLink( 'Categories' ); |
156 | | - } elseif ($property->getPropertyID() == '_REDI') { |
157 | | - $proptext = $skin->specialLink( 'Listredirects', 'isredirect' ); |
158 | | - } else { |
159 | | - $displayline = false; |
160 | | - } |
| 144 | + $displayline = false; |
161 | 145 | } |
162 | 146 | if ($displayline) { |
163 | 147 | $head = "<th>" . $proptext . "</th>\n"; |
164 | | - |
165 | | - // display value |
| 148 | + // display values |
166 | 149 | $body = "<td>\n"; |
167 | 150 | $values = $data->getPropertyValues($property); |
168 | 151 | $count = count($values); |
169 | 152 | $more = ($count >= SMWSpecialBrowse::$incomingvaluescount); |
170 | 153 | foreach ($values as $value) { |
171 | | - if (($count==1) && $more && $incoming) { |
172 | | - // If there are more incoming values than a certain treshold, display a link to the rest instead |
| 154 | + if ( ($count==1) && $more && $incoming ) { |
| 155 | + // if there are more incoming values than a certain treshold, display a link to the rest instead |
173 | 156 | $body .= '<a href="' . $skin->makeSpecialUrl('SearchByProperty', 'property=' . urlencode($property->getWikiValue()) . '&value=' . urlencode($data->getSubject()->getWikiValue())) . '">' . wfMsg("smw_browse_more") . "</a>\n"; |
174 | 157 | } else { |
175 | | - $body .= "<span class=\"smwb-" . $inv . "value\">"; |
176 | | - $body .= $this->displayValue($property, $value, $incoming); |
177 | | - $body .= "</span>"; |
| 158 | + $body .= "<span class=\"smwb-" . $inv . "value\">" . |
| 159 | + $this->displayValue($property, $value, $incoming) . "</span>"; |
178 | 160 | } |
179 | 161 | $count--; |
180 | | - if ($count>0) $body .= ", \n"; else $body .= "\n"; |
| 162 | + $body .= ($count>0)?", \n":"\n"; |
181 | 163 | } // end foreach values |
182 | 164 | $body .= "</td>\n"; |
183 | 165 | |
184 | 166 | // display row |
185 | | - $html .= "<tr class=\"smwb-" . $inv . "propvalue\">\n"; |
186 | | - if ($left) { |
187 | | - $html .= $head; $html .= $body; |
188 | | - } else { |
189 | | - $html .= $body; $html .= $head; |
190 | | - } |
191 | | - $html .= "</tr>\n"; |
| 167 | + $html .= "<tr class=\"smwb-" . $inv . "propvalue\">\n" . |
| 168 | + ($left?($head . $body):($body . $head)) . "</tr>\n"; |
192 | 169 | $noresult = false; |
193 | 170 | } |
194 | 171 | } // end foreach properties |
195 | 172 | if ($noresult) { |
196 | | - if ($incoming) |
197 | | - $noresulttext = wfMsg('smw_browse_no_incoming'); |
198 | | - else |
199 | | - $noresulttext = wfMsg('smw_browse_no_outgoing'); |
200 | | - |
201 | | - $html .= "<tr class=\"smwb-propvalue\"><th> </th><td><em>" . $noresulttext . "</em></td></tr>\n"; |
| 173 | + $html .= "<tr class=\"smwb-propvalue\"><th> </th><td><em>" . |
| 174 | + wfMsg($incoming?'smw_browse_no_incoming':'smw_browse_no_outgoing') . "</em></td></tr>\n"; |
202 | 175 | } |
203 | | - |
204 | 176 | $html .= "</table>\n"; |
205 | 177 | return $html; |
206 | 178 | } |
— | — | @@ -249,18 +221,13 @@ |
250 | 222 | * @return string HTMl with the center bar |
251 | 223 | */ |
252 | 224 | private function displayCenter() { |
253 | | - $html = "<a name=\"smw_browse_incoming\"></a>\n"; |
254 | | - $html .= "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n"; |
255 | | - $html .= "<tr class=\"smwb-center\"><td colspan=\"2\">\n"; |
256 | | - if ($this->showincoming) { |
257 | | - $html .= $this->linkhere(wfMsg('smw_browse_hide_incoming'), true, false, 0); |
258 | | - } else { |
259 | | - $html .= $this->linkhere(wfMsg('smw_browse_show_incoming'), true, true, $this->offset); |
260 | | - } |
261 | | - $html .= " \n"; |
262 | | - $html .= "</td></tr>\n"; |
263 | | - $html .= "</table>\n"; |
264 | | - return $html; |
| 225 | + return "<a name=\"smw_browse_incoming\"></a>\n" . |
| 226 | + "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n" . |
| 227 | + "<tr class=\"smwb-center\"><td colspan=\"2\">\n" . |
| 228 | + ( $this->showincoming? |
| 229 | + $this->linkhere(wfMsg('smw_browse_hide_incoming'), true, false, 0): |
| 230 | + $this->linkhere(wfMsg('smw_browse_show_incoming'), true, true, $this->offset) ) . |
| 231 | + " \n" . "</td></tr>\n" . "</table>\n"; |
265 | 232 | } |
266 | 233 | |
267 | 234 | /** |
— | — | @@ -270,30 +237,22 @@ |
271 | 238 | * @return string HTMl with the bottom bar |
272 | 239 | */ |
273 | 240 | private function displayBottom($more) { |
274 | | - $html = "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n"; |
275 | | - $html .= "<tr class=\"smwb-center\"><td colspan=\"2\">\n"; |
| 241 | + $html = "<table class=\"smwb-factbox\" cellpadding=\"0\" cellspacing=\"0\">\n" . |
| 242 | + "<tr class=\"smwb-center\"><td colspan=\"2\">\n"; |
276 | 243 | $sometext = false; |
277 | 244 | global $smwgBrowseShowAll; |
278 | 245 | if (!$smwgBrowseShowAll) { |
279 | | - if (($this->offset > 0) || ($more)) { |
280 | | - $offset = max($this->offset-SMWSpecialBrowse::$incomingpropertiescount+1, 0); |
281 | | - if ($this->offset > 0) |
282 | | - $html .= $this->linkhere(wfMsg('smw_result_prev'), $this->showoutgoing, true, $offset); |
283 | | - else |
284 | | - $html .= wfMsg('smw_result_prev'); |
285 | | - $html .= " "; |
286 | | - $html .= " <strong>" . wfMsg('smw_result_results') . " " . ($this->offset+1) . " – " . ($this->offset + SMWSpecialBrowse::$incomingpropertiescount - 1) . "</strong> "; |
287 | | - $html .= " "; |
288 | | - $offset = $this->offset+SMWSpecialBrowse::$incomingpropertiescount-1; |
289 | | - if ($more) |
290 | | - $html .= $this->linkhere(wfMsg('smw_result_next'), $this->showoutgoing, true, $offset); |
291 | | - else |
292 | | - $html .= wfMsg('smw_result_next'); |
| 246 | + if ( ($this->offset > 0) || $more ) { |
| 247 | + $offset = max($this->offset - SMWSpecialBrowse::$incomingpropertiescount + 1, 0); |
| 248 | + $html .= ($this->offset == 0)?wfMsg('smw_result_prev'): |
| 249 | + $this->linkhere(wfMsg('smw_result_prev'), $this->showoutgoing, true, $offset); |
| 250 | + $offset = $this->offset + SMWSpecialBrowse::$incomingpropertiescount - 1; |
| 251 | + $html .= " <strong>" . wfMsg('smw_result_results') . " " . ($this->offset+1) . |
| 252 | + " – " . ($offset) . "</strong> "; |
| 253 | + $html .= $more?$this->linkhere(wfMsg('smw_result_next'), $this->showoutgoing, true, $offset):wfMsg('smw_result_next'); |
293 | 254 | } |
294 | 255 | } |
295 | | - $html .= " \n"; |
296 | | - $html .= "</td></tr>\n"; |
297 | | - $html .= "</table>\n"; |
| 256 | + $html .= " \n" . "</td></tr>\n" . "</table>\n"; |
298 | 257 | return $html; |
299 | 258 | } |
300 | 259 | |
— | — | @@ -309,16 +268,14 @@ |
310 | 269 | private function linkhere($text, $out, $in, $offset) { |
311 | 270 | global $wgUser; |
312 | 271 | $skin = $wgUser->getSkin(); |
313 | | - $dir = 'in'; |
314 | | - if ($out) $dir = 'out'; |
315 | | - if ($in && $out) $dir = 'both'; |
316 | | - $frag = ""; |
317 | | - if ($text == wfMsg('smw_browse_show_incoming')) $frag = "#smw_browse_incoming"; |
318 | | - return '<a href="' . htmlspecialchars($skin->makeSpecialUrl('Browse', 'offset=' . $offset . '&dir=' . $dir . '&article=' . urlencode($this->subject->getLongWikiText()) )) . $frag . '">' . $text . '</a>'; |
| 272 | + $dir = $out?($in?'both':'out'):'in'; |
| 273 | + $frag = ($text == wfMsg('smw_browse_show_incoming'))?'#smw_browse_incoming':''; |
| 274 | + return '<a href="' . htmlspecialchars( $skin->makeSpecialUrl('Browse', |
| 275 | + "offset={$offset}&dir={$dir}&article=" . urlencode($this->subject->getLongWikiText())) ) . "$frag\">$text</a>"; |
319 | 276 | } |
320 | 277 | |
321 | 278 | /** |
322 | | - * Creates a Semantic Data object with the inproperties instead of the |
| 279 | + * Creates a Semantic Data object with the incoming properties instead of the |
323 | 280 | * usual outproperties. |
324 | 281 | * |
325 | 282 | * @return array(SMWSemanticData, bool) The semantic data including all inproperties, and if there are more inproperties left |
— | — | @@ -332,10 +289,10 @@ |
333 | 290 | $inproperties = smwfGetStore()->getInProperties($this->subject, $options); |
334 | 291 | $more = (count($inproperties) == SMWSpecialBrowse::$incomingpropertiescount); |
335 | 292 | if ($more) array_pop($inproperties); // drop the last one |
| 293 | + $valoptions = new SMWRequestOptions(); |
| 294 | + $valoptions->sort = true; |
| 295 | + $valoptions->limit = SMWSpecialBrowse::$incomingvaluescount; |
336 | 296 | foreach ($inproperties as $property) { |
337 | | - $valoptions = new SMWRequestOptions(); |
338 | | - $valoptions->sort = true; |
339 | | - $valoptions->limit = SMWSpecialBrowse::$incomingvaluescount; |
340 | 297 | $values = smwfGetStore()->getPropertySubjects($property, $this->subject, $valoptions); |
341 | 298 | foreach ($values as $value) { |
342 | 299 | $indata->addPropertyObjectValue($property, $value); |
— | — | @@ -358,11 +315,8 @@ |
359 | 316 | if ($incoming && $smwgBrowseShowInverse) { |
360 | 317 | $oppositeprop = SMWPropertyValue::makeProperty(wfMsg('smw_inverse_label_property')); |
361 | 318 | $labelarray = &smwfGetStore()->getPropertyValues($property->getWikiPageValue(), $oppositeprop); |
362 | | - if (count($labelarray)>0) { |
363 | | - $rv = $labelarray[0]->getLongWikiText(); |
364 | | - } else { |
365 | | - $rv = wfMsg('smw_inverse_label_default', $property->getWikiValue()); |
366 | | - } |
| 319 | + $rv = (count($labelarray)>0)?$labelarray[0]->getLongWikiText(): |
| 320 | + wfMsg('smw_inverse_label_default', $property->getWikiValue()); |
367 | 321 | } else { |
368 | 322 | $rv = $property->getWikiValue(); |
369 | 323 | } |
— | — | @@ -376,13 +330,12 @@ |
377 | 331 | */ |
378 | 332 | private function queryForm() { |
379 | 333 | $title = Title::makeTitle( NS_SPECIAL, 'Browse' ); |
380 | | - $html = ' <form name="smwbrowse" action="' . $title->escapeLocalURL() . '" method="get">' . "\n"; |
381 | | - $html .= ' <input type="hidden" name="title" value="' . $title->getPrefixedText() . '"/>' ; |
382 | | - $html .= wfMsg('smw_browse_article') . "<br />\n"; |
383 | | - $html .= ' <input type="text" name="article" value="' . htmlspecialchars($this->articletext) . '" />' . "\n"; |
384 | | - $html .= ' <input type="submit" value="' . wfMsg('smw_browse_go') . "\"/>\n"; |
385 | | - $html .= " </form>\n"; |
386 | | - return $html; |
| 334 | + return ' <form name="smwbrowse" action="' . $title->escapeLocalURL() . '" method="get">' . "\n" . |
| 335 | + ' <input type="hidden" name="title" value="' . $title->getPrefixedText() . '"/>' . |
| 336 | + wfMsg('smw_browse_article') . "<br />\n" . |
| 337 | + ' <input type="text" name="article" value="' . htmlspecialchars($this->articletext) . '" />' . "\n" . |
| 338 | + ' <input type="submit" value="' . wfMsg('smw_browse_go') . "\"/>\n" . |
| 339 | + " </form>\n"; |
387 | 340 | } |
388 | 341 | |
389 | 342 | /** |