r56295 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56294‎ | r56295 | r56296 >
Date:08:30, 14 September 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
fix for case where page is not given (Bug 20559); some code clean-up
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php
@@ -31,74 +31,72 @@
3232
3333 public function execute( $query ) {
3434 global $wgRequest, $wgOut, $wgUser;
35 -
3635 $skin = $wgUser->getSkin();
3736 $this->setHeaders();
3837
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:
4446 $queryparts = explode('::', $query);
45 - $type = $query;
 47+ $propname = $query;
4648 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));
4951 }
5052 }
5153
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():'';
6058
61 - $limit = $wgRequest->getVal( 'limit' );
62 - if ('' == $limit) $limit = 20;
63 - $offset = $wgRequest->getVal( 'offset' );
64 - if ('' == $offset) $offset = 0;
 59+ // Produce output
6560 $html = '';
66 - $spectitle = Title::makeTitle( NS_SPECIAL, 'PageProperty' );
67 -
6861 wfLoadExtensionMessages('SemanticMediaWiki');
69 -
70 - if (('' == $type)) { // No relation or subject given.
 62+ if (('' == $propname)) { // no property given, show a message
7163 $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)
7468 $options = new SMWRequestOptions();
7569 $options->limit = $limit+1;
7670 $options->offset = $offset;
7771 $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);
8073
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+ }
8681
87 - $navigation .= '&nbsp;&nbsp;&nbsp;&nbsp; <b>' . wfMsg('smw_result_results') . ' ' . ($offset+1) . '&ndash; ' . ($offset + min(count($results), $limit)) . '</b>&nbsp;&nbsp;&nbsp;&nbsp;';
 82+ $navigation .= '&nbsp;&nbsp;&nbsp;&nbsp; <b>' . wfMsg('smw_result_results') . ' ' . ($offset+1) . '&ndash; ' . ($offset + min(count($results), $limit)) . '</b>&nbsp;&nbsp;&nbsp;&nbsp;';
 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+ }
8891
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;
9694 if (count($results) == 0) {
9795 $html .= wfMsg( 'smw_result_noresults' );
9896 } else {
9997 $html .= "<ul>\n";
10098 $count = $limit+1;
10199 foreach ($results as $result) {
102 - $count -= 1;
 100+ $count--;
103101 if ($count < 1) continue;
104102 $html .= '<li>' . $result->getLongHTMLText($skin); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below)
105103 if ($result->getTypeID() == '_wpg') {
@@ -109,15 +107,16 @@
110108 }
111109 $html .= "</ul>\n";
112110 }
113 - if (($offset>0) || (count($results)>$limit)) $html .= $navigation;
 111+ $html .= $navigation;
114112 }
115113
116 - // display query form
 114+ // Display query form
 115+ $spectitle = Title::makeTitle( NS_SPECIAL, 'PageProperty' );
117116 $html .= '<p>&nbsp;</p>';
118117 $html .= '<form name="pageproperty" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" .
119118 '<input type="hidden" name="title" value="' . $spectitle->getPrefixedText() . '"/>' ;
120 - $html .= wfMsg('smw_pp_from') . ' <input type="text" name="from" value="' . htmlspecialchars($from) . '" />' . "&nbsp;&nbsp;&nbsp;\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) . '" />' . "&nbsp;&nbsp;&nbsp;\n";
 120+ $html .= wfMsg('smw_pp_type') . ' <input type="text" name="type" value="' . htmlspecialchars($propname) . '" />' . "\n";
122121 $html .= '<input type="submit" value="' . wfMsg('smw_pp_submit') . "\"/>\n</form>\n";
123122
124123 $wgOut->addHTML($html);

Status & tagging log