http://www.mediawiki.org/wiki/Special:Code/MediaWiki/56360
Revision: 56360
Author: vrandezo
Date: 2009-09-15 15:13:56 +0000 (Tue, 15 Sep 2009)
Log Message:
-----------
added the print request parameter infrastructure
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
2009-09-15 12:51:09 UTC (rev 56359)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php
2009-09-15 15:13:56 UTC (rev 56360)
@@ -22,6 +22,10 @@
global $smwgIQRunningNumber;
SMWOutputs::requireHeadItem(SMW_HEADER_SORTTABLE);
+ $printrequestparameters = array();
+ foreach ($res->getPrintRequests() as $pr)
+ $printrequestparameters[] = $pr->getParams();
+
// print header
$result = '<table class="smwtable"' .
('broadtable' == $this->mFormat?' width="100%"':'') .
@@ -38,8 +42,19 @@
while ( $row = $res->getNext() ) {
$result .= "\t<tr>\n";
$firstcol = true;
+ $fieldcount = -1;
foreach ($row as $field) {
- $result .= "\t\t<td>";
+ $fieldcount = $fieldcount + 1;
+
+ $result .= "\t\t<td";
+ if (array_key_exists('align',
$printrequestparameters[$fieldcount])) {
+ $alignment =
$printrequestparameters[$fieldcount]['align'];
+ // check the content, otherwise evil
people could inject here anything they wanted
+ if (($alignment == 'right') ||
($alignment == 'left'))
+ $result .= "
style=\"text-align:" . $printrequestparameters[$fieldcount]['align'] . ";\"";
+ }
+ $result .= ">";
+
$first = true;
while ( ($object = $field->getNextObject()) !==
false ) {
if ($first) {
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
2009-09-15 12:51:09 UTC (rev 56359)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
2009-09-15 15:13:56 UTC (rev 56360)
@@ -181,6 +181,7 @@
global $wgContLang;
$querystring = '';
$printouts = array();
+ $lastprintout = NULL;
$params = array();
foreach ($rawparams as $name => $param) {
if ( is_string($name) && ($name != '') ) { // accept
'name' => 'value' just as '' => 'name=value'
@@ -225,7 +226,14 @@
if (count($parts) > 1) { // label found, use
this instead of default
$label = trim($parts[1]);
}
- $printouts[] = new SMWPrintRequest($printmode,
$label, $data, trim($propparts[1]));
+ $lastprintout = new SMWPrintRequest($printmode,
$label, $data, trim($propparts[1]));
+ $printouts[] = $lastprintout;
+ } elseif ($param[0] == '+') { // print request parameter
+ if ($lastprintout != NULL) {
+ $param = substr($param,1);
+ $parts = explode('=',$param,2);
+ $lastprintout->setParam($parts[0],
$parts[1]);
+ }
} else { // parameter or query
$parts = explode('=',$param,2);
if (count($parts) >= 2) {
Modified:
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
2009-09-15 12:51:09 UTC (rev 56359)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
2009-09-15 15:13:56 UTC (rev 56360)
@@ -28,15 +28,17 @@
protected $m_typeid = false; // id of the datatype of the printed
objects, if applicable
protected $m_outputformat; // output format string for formatting
results, if applicable
protected $m_hash = false; // cache your hash (currently useful since
SMWQueryResult accesses the hash many times, might be dropped at some point)
-
+ protected $m_params = array();
+
/**
* Create a print request.
* @param $mode a constant defining what to printout
* @param $label the string label to describe this printout
* @param $data optional data for specifying some request, might be a
property object, title, or something else; interpretation depends on $mode
* @param $outputformat optional string for specifying an output
format, e.g. an output unit
+ * @param $params optional array of further, named parameters for the
print request
*/
- public function __construct($mode, $label, $data = NULL, $outputformat
= false) {
+ public function __construct($mode, $label, $data = NULL, $outputformat
= false, $params = NULL) {
$this->m_mode = $mode;
$this->m_label = $label;
$this->m_data = $data;
@@ -47,6 +49,7 @@
if ($this->m_data instanceof SMWDataValue) {
$this->m_data->setCaption($label);
}
+ if (NULL != $params) $m_params = $params;
}
public function getMode() {
@@ -139,6 +142,9 @@
* print requests. The hash also includes the chosen label,
* so it is possible to print the same date with different
* labels.
+ * TODO: For now, the params are not part of the Hash, but
+ * maybe they should? But the hash is used for some things,
+ * check that first!
*/
public function getHash() {
if ($this->m_hash === false) {
@@ -155,8 +161,14 @@
/**
* Serialise this object like print requests given in \#ask.
+ * @param $params boolean that sets if the serialization should
+ * include the extra print request parameters
*/
- public function getSerialisation() {
+ public function getSerialisation($showparams = false) {
+ $parameters = '';
+ if ($showparams) foreach ( $this->m_params as $key => $value ) {
+ $parameters .= "|+" . $key . "=" . $value;
+ }
switch ($this->m_mode) {
case SMWPrintRequest::PRINT_CATS:
global $wgContLang;
@@ -165,7 +177,7 @@
if ($this->m_label != $catlabel) {
$result .= '=' . $this->m_label;
}
- return $result;
+ return $result . $parameters;
case SMWPrintRequest::PRINT_PROP: case
SMWPrintRequest::PRINT_CCAT:
if ($this->m_mode ==
SMWPrintRequest::PRINT_CCAT) {
$printname =
$this->m_data->getPrefixedText();
@@ -183,9 +195,46 @@
if ( $printname != $this->m_label ) {
$result .= '=' . $this->m_label;
}
- return $result;
+ return $result . $parameters;
case SMWPrintRequest::PRINT_THIS: default: return '';
// no current serialisation
}
}
+ /**
+ * Returns the value of a named parameter.
+ * @param $key string the name of the parameter key
+ * @return string Value of the paramer, if set (else '')
+ */
+ public function getParam($key) {
+ if (array_key_exists($key, $this->m_params))
+ return $this->m_params[$key];
+ else
+ return '';
+ }
+
+ /**
+ * Returns if a named parameter is set.
+ * @param $key string the name of the parameter
+ * @return boolean True if the parameter is set, false otherwise
+ */
+ public function hasParam($key) {
+ return array_key_exists($key, $this->m_params);
+ }
+
+ /**
+ * Returns the array of parameters, where a string is mapped to a
string.
+ * @return array Map of parameter names to values.
+ */
+ public function getParams() {
+ return $this->m_params;
+ }
+
+ /**
+ * Sets a print request parameter.
+ * @param $key string Name of the parameter
+ * @param $value string Value for the parameter
+ */
+ public function setParam($key, $value) {
+ $this->m_params[$key] = $value;
+ }
}
\ No newline at end of file
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs