r56440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56439‎ | r56440 | r56441 >
Date:20:40, 16 September 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
some code cleanup
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -36,10 +36,9 @@
3737 * Constructor
3838 */
3939 public function __construct() {
 40+ global $smwgBrowseShowAll;
4041 parent::__construct('Browse', '', true, false, 'default', true);
4142 wfLoadExtensionMessages('SemanticMediaWiki');
42 -
43 - global $smwgBrowseShowAll;
4443 if ($smwgBrowseShowAll) {
4544 SMWSpecialBrowse::$incomingvaluescount = 21;
4645 SMWSpecialBrowse::$incomingpropertiescount = -1;
@@ -53,7 +52,7 @@
5453 * @param[in] $query string Given by MediaWiki
5554 */
5655 public function execute( $query ) {
57 - global $wgRequest, $wgOut;
 56+ global $wgRequest, $wgOut, $smwgBrowseShowAll;
5857 $this->setHeaders();
5958 // get the GET parameters
6059 $this->articletext = $wgRequest->getVal( 'article' );
@@ -65,13 +64,8 @@
6665 }
6766 $this->subject = SMWDataValueFactory::newTypeIDValue('_wpg', $this->articletext);
6867 $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);
7469 $dir = $wgRequest->getVal( 'dir' );
75 - global $smwgBrowseShowAll;
7670 if ($smwgBrowseShowAll) {
7771 $this->showoutgoing = true;
7872 $this->showincoming = true;
@@ -85,8 +79,8 @@
8680 }
8781
8882 /**
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.
9185 *
9286 * @return string A HTML string with the factbox
9387 */
@@ -120,7 +114,7 @@
121115 }
122116
123117 /**
124 - * Creates the HTML displaying the data of one subject.
 118+ * Creates the HTML table displaying the data of one subject.
125119 *
126120 * @param[in] $data SMWSemanticData The data to be displayed
127121 * @param[in] $left bool Should properties be displayed on the left side?
@@ -132,74 +126,52 @@
133127 $skin = $wgUser->getSkin();
134128 // Some of the CSS classes are different for the left or the right side.
135129 // 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";
139132 $properties = $data->getProperties();
140133 $noresult = true;
141 - foreach ($properties as $property) {
 134+ foreach ($properties as $property) {
142135 $displayline = true;
143136 if ($property->isVisible()) {
144137 $property->setCaption($this->getPropertyLabel($property, $incoming));
145138 $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' );
146143 } 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;
161145 }
162146 if ($displayline) {
163147 $head = "<th>" . $proptext . "</th>\n";
164 -
165 - // display value
 148+ // display values
166149 $body = "<td>\n";
167150 $values = $data->getPropertyValues($property);
168151 $count = count($values);
169152 $more = ($count >= SMWSpecialBrowse::$incomingvaluescount);
170153 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
173156 $body .= '<a href="' . $skin->makeSpecialUrl('SearchByProperty', 'property=' . urlencode($property->getWikiValue()) . '&value=' . urlencode($data->getSubject()->getWikiValue())) . '">' . wfMsg("smw_browse_more") . "</a>\n";
174157 } 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>";
178160 }
179161 $count--;
180 - if ($count>0) $body .= ", \n"; else $body .= "\n";
 162+ $body .= ($count>0)?", \n":"\n";
181163 } // end foreach values
182164 $body .= "</td>\n";
183165
184166 // 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";
192169 $noresult = false;
193170 }
194171 } // end foreach properties
195172 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> &nbsp; </th><td><em>" . $noresulttext . "</em></td></tr>\n";
 173+ $html .= "<tr class=\"smwb-propvalue\"><th> &nbsp; </th><td><em>" .
 174+ wfMsg($incoming?'smw_browse_no_incoming':'smw_browse_no_outgoing') . "</em></td></tr>\n";
202175 }
203 -
204176 $html .= "</table>\n";
205177 return $html;
206178 }
@@ -249,18 +221,13 @@
250222 * @return string HTMl with the center bar
251223 */
252224 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 .= "&nbsp;\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+ "&nbsp;\n" . "</td></tr>\n" . "</table>\n";
265232 }
266233
267234 /**
@@ -270,30 +237,22 @@
271238 * @return string HTMl with the bottom bar
272239 */
273240 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";
276243 $sometext = false;
277244 global $smwgBrowseShowAll;
278245 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 .= " &nbsp;&nbsp;&nbsp; ";
286 - $html .= " <strong>" . wfMsg('smw_result_results') . " " . ($this->offset+1) . " &ndash; " . ($this->offset + SMWSpecialBrowse::$incomingpropertiescount - 1) . "</strong> ";
287 - $html .= " &nbsp;&nbsp;&nbsp; ";
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 .= " &nbsp;&nbsp;&nbsp; <strong>" . wfMsg('smw_result_results') . " " . ($this->offset+1) .
 252+ " &ndash; " . ($offset) . "</strong> &nbsp;&nbsp;&nbsp; ";
 253+ $html .= $more?$this->linkhere(wfMsg('smw_result_next'), $this->showoutgoing, true, $offset):wfMsg('smw_result_next');
293254 }
294255 }
295 - $html .= "&nbsp;\n";
296 - $html .= "</td></tr>\n";
297 - $html .= "</table>\n";
 256+ $html .= "&nbsp;\n" . "</td></tr>\n" . "</table>\n";
298257 return $html;
299258 }
300259
@@ -309,16 +268,14 @@
310269 private function linkhere($text, $out, $in, $offset) {
311270 global $wgUser;
312271 $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>";
319276 }
320277
321278 /**
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
323280 * usual outproperties.
324281 *
325282 * @return array(SMWSemanticData, bool) The semantic data including all inproperties, and if there are more inproperties left
@@ -332,10 +289,10 @@
333290 $inproperties = smwfGetStore()->getInProperties($this->subject, $options);
334291 $more = (count($inproperties) == SMWSpecialBrowse::$incomingpropertiescount);
335292 if ($more) array_pop($inproperties); // drop the last one
 293+ $valoptions = new SMWRequestOptions();
 294+ $valoptions->sort = true;
 295+ $valoptions->limit = SMWSpecialBrowse::$incomingvaluescount;
336296 foreach ($inproperties as $property) {
337 - $valoptions = new SMWRequestOptions();
338 - $valoptions->sort = true;
339 - $valoptions->limit = SMWSpecialBrowse::$incomingvaluescount;
340297 $values = smwfGetStore()->getPropertySubjects($property, $this->subject, $valoptions);
341298 foreach ($values as $value) {
342299 $indata->addPropertyObjectValue($property, $value);
@@ -358,11 +315,8 @@
359316 if ($incoming && $smwgBrowseShowInverse) {
360317 $oppositeprop = SMWPropertyValue::makeProperty(wfMsg('smw_inverse_label_property'));
361318 $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());
367321 } else {
368322 $rv = $property->getWikiValue();
369323 }
@@ -376,13 +330,12 @@
377331 */
378332 private function queryForm() {
379333 $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";
387340 }
388341
389342 /**

Status & tagging log