Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php |
— | — | @@ -31,74 +31,72 @@ |
32 | 32 | |
33 | 33 | public function execute( $query ) { |
34 | 34 | global $wgRequest, $wgOut, $wgUser; |
35 | | - |
36 | 35 | $skin = $wgUser->getSkin(); |
37 | 36 | $this->setHeaders(); |
38 | 37 | |
39 | | - // get the GET parameters |
40 | | - $from = $wgRequest->getVal( 'from' ); |
41 | | - $type = $wgRequest->getVal( 'type' ); |
42 | | - // no GET parameters? Then try the URL |
43 | | - if (('' == $type) && ('' == $from)) { |
| 38 | + // Get parameters |
| 39 | + $pagename = $wgRequest->getVal( 'from' ); |
| 40 | + $propname = $wgRequest->getVal( 'type' ); |
| 41 | + $limit = $wgRequest->getVal( 'limit' ); |
| 42 | + if ('' == $limit) $limit = 20; |
| 43 | + $offset = $wgRequest->getVal( 'offset' ); |
| 44 | + if ('' == $offset) $offset = 0; |
| 45 | + if ('' == $propname) { // No GET parameters? Try the URL: |
44 | 46 | $queryparts = explode('::', $query); |
45 | | - $type = $query; |
| 47 | + $propname = $query; |
46 | 48 | if (count($queryparts) > 1) { |
47 | | - $from = $queryparts[0]; |
48 | | - $type = implode('::', array_slice($queryparts, 1)); |
| 49 | + $pagename = $queryparts[0]; |
| 50 | + $propname = implode('::', array_slice($queryparts, 1)); |
49 | 51 | } |
50 | 52 | } |
51 | 53 | |
52 | | - $subject = SMWDataValueFactory::newTypeIDValue('_wpg', $from ); |
53 | | - $from = $subject->isValid()?$subject->getText():''; |
54 | | - $property = SMWPropertyValue::makeUserProperty($type); |
55 | | - if ($property->isvalid()) { |
56 | | - $type = $property->getWikiValue(); |
57 | | - } else { |
58 | | - $type = ''; |
59 | | - } |
| 54 | + $subject = SMWDataValueFactory::newTypeIDValue('_wpg', $pagename ); |
| 55 | + $pagename = $subject->isValid()?$subject->getText():''; |
| 56 | + $property = SMWPropertyValue::makeUserProperty($propname); |
| 57 | + $propname = $property->isvalid()?$property->getWikiValue():''; |
60 | 58 | |
61 | | - $limit = $wgRequest->getVal( 'limit' ); |
62 | | - if ('' == $limit) $limit = 20; |
63 | | - $offset = $wgRequest->getVal( 'offset' ); |
64 | | - if ('' == $offset) $offset = 0; |
| 59 | + // Produce output |
65 | 60 | $html = ''; |
66 | | - $spectitle = Title::makeTitle( NS_SPECIAL, 'PageProperty' ); |
67 | | - |
68 | 61 | wfLoadExtensionMessages('SemanticMediaWiki'); |
69 | | - |
70 | | - if (('' == $type)) { // No relation or subject given. |
| 62 | + if (('' == $propname)) { // no property given, show a message |
71 | 63 | $html .= wfMsg('smw_pp_docu') . "\n"; |
72 | | - } else { // everything is given |
73 | | - $wgOut->setPagetitle( ($subject->isValid()?'':$subject->getPrefixedText() . ' ') . $property->getWikiValue()); |
| 64 | + } else { // property given, find and display results |
| 65 | + $wgOut->setPagetitle( ($pagename!=''?$pagename . ' ':'') . $property->getWikiValue() ); |
| 66 | + |
| 67 | + // get results (get one more, to see if we have to add a link to more) |
74 | 68 | $options = new SMWRequestOptions(); |
75 | 69 | $options->limit = $limit+1; |
76 | 70 | $options->offset = $offset; |
77 | 71 | $options->sort = true; |
78 | | - // get results (get one more, to see if we have to add a link to more) |
79 | | - $results = &smwfGetStore()->getPropertyValues($subject, $property, $options); |
| 72 | + $results = &smwfGetStore()->getPropertyValues($pagename!=''?$subject:NULL, $property, $options); |
80 | 73 | |
81 | | - // prepare navigation bar |
82 | | - if ($offset > 0) |
83 | | - $navigation = '<a href="' . htmlspecialchars($skin->makeSpecialUrl('PageProperty','offset=' . max(0,$offset-$limit) . '&limit=' . $limit . '&type=' . urlencode($type) .'&from=' . urlencode($from))) . '">' . wfMsg('smw_result_prev') . '</a>'; |
84 | | - else |
85 | | - $navigation = wfMsg('smw_result_prev'); |
| 74 | + // prepare navigation bar if needed |
| 75 | + if ( ($offset>0) || (count($results)>$limit) ) { |
| 76 | + if ($offset > 0) { |
| 77 | + $navigation = '<a href="' . htmlspecialchars($skin->makeSpecialUrl('PageProperty','offset=' . max(0,$offset-$limit) . '&limit=' . $limit . '&type=' . urlencode($propname) .'&from=' . urlencode($pagename))) . '">' . wfMsg('smw_result_prev') . '</a>'; |
| 78 | + } else { |
| 79 | + $navigation = wfMsg('smw_result_prev'); |
| 80 | + } |
86 | 81 | |
87 | | - $navigation .= ' <b>' . wfMsg('smw_result_results') . ' ' . ($offset+1) . '– ' . ($offset + min(count($results), $limit)) . '</b> '; |
| 82 | + $navigation .= ' <b>' . wfMsg('smw_result_results') . ' ' . ($offset+1) . '– ' . ($offset + min(count($results), $limit)) . '</b> '; |
| 83 | + if ( count($results)==($limit+1) ) { |
| 84 | + $navigation .= ' <a href="' . htmlspecialchars($skin->makeSpecialUrl('PageProperty', 'offset=' . ($offset+$limit) . '&limit=' . $limit . '&type=' . urlencode($propname) . '&from=' . urlencode($pagename))) . '">' . wfMsg('smw_result_next') . '</a>'; |
| 85 | + } else { |
| 86 | + $navigation .= wfMsg('smw_result_next'); |
| 87 | + } |
| 88 | + } else { |
| 89 | + $navigation = ''; |
| 90 | + } |
88 | 91 | |
89 | | - if (count($results)==($limit+1)) |
90 | | - $navigation .= ' <a href="' . htmlspecialchars($skin->makeSpecialUrl('PageProperty', 'offset=' . ($offset+$limit) . '&limit=' . $limit . '&type=' . urlencode($type) . '&from=' . urlencode($from))) . '">' . wfMsg('smw_result_next') . '</a>'; |
91 | | - else |
92 | | - $navigation .= wfMsg('smw_result_next'); |
93 | | - |
94 | | - // no need to show the navigation bars when there is not enough to navigate |
95 | | - if (($offset>0) || (count($results)>$limit)) $html .= '<br />' . $navigation; |
| 92 | + // display results |
| 93 | + $html .= '<br />' . $navigation; |
96 | 94 | if (count($results) == 0) { |
97 | 95 | $html .= wfMsg( 'smw_result_noresults' ); |
98 | 96 | } else { |
99 | 97 | $html .= "<ul>\n"; |
100 | 98 | $count = $limit+1; |
101 | 99 | foreach ($results as $result) { |
102 | | - $count -= 1; |
| 100 | + $count--; |
103 | 101 | if ($count < 1) continue; |
104 | 102 | $html .= '<li>' . $result->getLongHTMLText($skin); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below) |
105 | 103 | if ($result->getTypeID() == '_wpg') { |
— | — | @@ -109,15 +107,16 @@ |
110 | 108 | } |
111 | 109 | $html .= "</ul>\n"; |
112 | 110 | } |
113 | | - if (($offset>0) || (count($results)>$limit)) $html .= $navigation; |
| 111 | + $html .= $navigation; |
114 | 112 | } |
115 | 113 | |
116 | | - // display query form |
| 114 | + // Display query form |
| 115 | + $spectitle = Title::makeTitle( NS_SPECIAL, 'PageProperty' ); |
117 | 116 | $html .= '<p> </p>'; |
118 | 117 | $html .= '<form name="pageproperty" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" . |
119 | 118 | '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>' ; |
120 | | - $html .= wfMsg('smw_pp_from') . ' <input type="text" name="from" value="' . htmlspecialchars($from) . '" />' . " \n"; |
121 | | - $html .= wfMsg('smw_pp_type') . ' <input type="text" name="type" value="' . htmlspecialchars($type) . '" />' . "\n"; |
| 119 | + $html .= wfMsg('smw_pp_from') . ' <input type="text" name="from" value="' . htmlspecialchars($pagename) . '" />' . " \n"; |
| 120 | + $html .= wfMsg('smw_pp_type') . ' <input type="text" name="type" value="' . htmlspecialchars($propname) . '" />' . "\n"; |
122 | 121 | $html .= '<input type="submit" value="' . wfMsg('smw_pp_submit') . "\"/>\n</form>\n"; |
123 | 122 | |
124 | 123 | $wgOut->addHTML($html); |