r58420 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58419‎ | r58420 | r58421 >
Date:09:01, 2 November 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
improved/shortened Denny's implementation of additional printout parameters
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
@@ -22,10 +22,6 @@
2323 global $smwgIQRunningNumber;
2424 SMWOutputs::requireHeadItem(SMW_HEADER_SORTTABLE);
2525
26 - $printrequestparameters = array();
27 - foreach ($res->getPrintRequests() as $pr)
28 - $printrequestparameters[] = $pr->getParams();
29 -
3026 // print header
3127 $result = '<table class="smwtable"' .
3228 ('broadtable' == $this->mFormat?' width="100%"':'') .
@@ -47,11 +43,9 @@
4844 $fieldcount = $fieldcount + 1;
4945
5046 $result .= "\t\t<td";
51 - if (array_key_exists('align', $printrequestparameters[$fieldcount])) {
52 - $alignment = $printrequestparameters[$fieldcount]['align'];
53 - // check the content, otherwise evil people could inject here anything they wanted
54 - if (($alignment == 'right') || ($alignment == 'left'))
55 - $result .= " style=\"text-align:" . $printrequestparameters[$fieldcount]['align'] . ";\"";
 47+ $alignment = trim($field->getPrintRequest()->getParameter('align'));
 48+ if (($alignment == 'right') || ($alignment == 'left') || ($alignment == 'center')) {
 49+ $result .= ' style="text-align:' . $alignment . ';"';
5650 }
5751 $result .= ">";
5852
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
@@ -29,7 +29,7 @@
3030 protected $m_outputformat; // output format string for formatting results, if applicable
3131 protected $m_hash = false; // cache your hash (currently useful since SMWQueryResult accesses the hash many times, might be dropped at some point)
3232 protected $m_params = array();
33 -
 33+
3434 /**
3535 * Create a print request.
3636 * @param $mode a constant defining what to printout
@@ -201,40 +201,28 @@
202202 }
203203
204204 /**
205 - * Returns the value of a named parameter.
 205+ * Returns the value of a named parameter.
206206 * @param $key string the name of the parameter key
207 - * @return string Value of the paramer, if set (else '')
 207+ * @return string Value of the paramer, if set (else FALSE)
208208 */
209 - public function getParam($key) {
210 - if (array_key_exists($key, $this->m_params))
211 - return $this->m_params[$key];
212 - else
213 - return '';
 209+ public function getParameter($key) {
 210+ return (array_key_exists($key, $this->m_params))?$this->m_params[$key]:false;
214211 }
215212
216213 /**
217 - * Returns if a named parameter is set.
218 - * @param $key string the name of the parameter
219 - * @return boolean True if the parameter is set, false otherwise
220 - */
221 - public function hasParam($key) {
222 - return array_key_exists($key, $this->m_params);
223 - }
224 -
225 - /**
226 - * Returns the array of parameters, where a string is mapped to a string.
 214+ * Returns the array of parameters, where a string is mapped to a string.
227215 * @return array Map of parameter names to values.
228216 */
229 - public function getParams() {
 217+ public function getParameters() {
230218 return $this->m_params;
231219 }
232 -
 220+
233221 /**
234222 * Sets a print request parameter.
235223 * @param $key string Name of the parameter
236 - * @param $value string Value for the parameter
 224+ * @param $value string Value for the parameter
237225 */
238 - public function setParam($key, $value) {
 226+ public function setParameter($key, $value) {
239227 $this->m_params[$key] = $value;
240228 }
241229 }
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -229,10 +229,10 @@
230230 $lastprintout = new SMWPrintRequest($printmode, $label, $data, trim($propparts[1]));
231231 $printouts[] = $lastprintout;
232232 } elseif ($param[0] == '+') { // print request parameter
233 - if ($lastprintout != NULL) {
 233+ if ($lastprintout !== NULL) {
234234 $param = substr($param,1);
235235 $parts = explode('=',$param,2);
236 - $lastprintout->setParam($parts[0], $parts[1]);
 236+ if (count($parts) == 2) $lastprintout->setParameter(trim($parts[0]), $parts[1]);
237237 }
238238 } else { // parameter or query
239239 $parts = explode('=',$param,2);
@@ -314,14 +314,14 @@
315315 */
316316 static protected function getResultFormat($params) {
317317 global $smwgResultAliases;
318 -
 318+
319319 $format = 'auto';
320320 if (array_key_exists('format', $params)) {
321321 $format = strtolower(trim($params['format']));
322322 global $smwgResultFormats;
323323
324324 if ( !array_key_exists($format, $smwgResultFormats) ) {
325 -
 325+
326326 foreach($smwgResultAliases as $mainFormat => $aliases) {
327327 if (in_array($format, $aliases)) {
328328 $format = $mainFormat;
@@ -329,7 +329,7 @@
330330 continue;
331331 }
332332 }
333 -
 333+
334334 if (! $isAlias) $format = 'auto'; // If it is an unknown format, defaults to list/table again
335335 }
336336 }

Status & tagging log