logo       

[MediaWiki-CVS] SVN: [54096] trunk/extensions/SemanticMediaWiki/includes: msg#01474

mediawiki-cvs

Subject: [MediaWiki-CVS] SVN: [54096] trunk/extensions/SemanticMediaWiki/includes

http://www.mediawiki.org/wiki/Special:Code/MediaWiki/54096

Revision: 54096
Author: mkroetzsch
Date: 2009-07-31 13:20:10 +0000 (Fri, 31 Jul 2009)

Log Message:
-----------
Support empty output formats (equivalently: format string "-") in queries to
obtain unformatted, plain outputs.
This addresses Bug 19086, but more generally allows for better control in
output formatting for all types.

Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Temperature.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php

trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Linear.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -103,7 +103,7 @@

$value = false;
if ($this->m_unit === $this->m_mainunit) { // only try if
conversion worked
- if ( ($value === false) && $this->m_outformat) { //
first try given output unit
+ if ( ($value === false) && ($this->m_outformat) &&
($this->m_outformat != '-') ) { // first try given output unit
$unit =
$this->normalizeUnit($this->m_outformat);
$printunit = $unit;
if (array_key_exists($unit, $this->m_unitids))
{ // find id for output unit

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -94,7 +94,7 @@

public function getShortWikiText($linked = NULL) {
$this->unstub();
- if (($linked === NULL) || ($linked === false)) {
+ if (($linked === NULL) || ($linked === false) ||
($this->m_outformat == '-') ) {
return $this->m_caption;
}
$this->makeConversionValues();
@@ -140,11 +140,14 @@
} elseif ($i > 1) {
$result .= ', ';
}
- $result .= smwfNumberFormat($value);
+ $result .= ($this->m_outformat !=
'-'?smwfNumberFormat($value):$value);
if ($unit != '') {
$result .= ' ' . $unit;
}
$i++;
+ if ($this->m_outformat == '-') { // no further
conversions for plain output format
+ break;
+ }
}
if ($i > 1) {
$result .= ')';
@@ -268,7 +271,7 @@
*/
protected function makeUserValue() {
$this->convertToMainUnit();
- $this->m_caption = smwfNumberFormat($this->m_value);
+ $this->m_caption = ($this->m_outformat !=
'-'?smwfNumberFormat($this->m_value):$this->m_value);
if ($this->m_unit != '') {
$this->m_caption .= ' ' . $this->m_unit;
}

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -47,7 +47,7 @@
/// If the property is predefined, its internal key is stored here.
Otherwise FALSE.
protected $m_propertyid;
/// If the property is associated with a wikipage, it is stored here.
Otherwise NULL.
- protected $m_wikipage;
+ protected $m_wikipage = NULL;

private $prop_typevalue; // once calculated, remember the type of this
property
private $prop_typeid; // once calculated, remember the type of this
property
@@ -123,6 +123,7 @@
if ($label != '') {
$this->m_wikipage =
SMWDataValueFactory::newTypeIDValue('_wpp');
$this->m_wikipage->setDBkeys(array(str_replace(' ',
'_',$label),SMW_NS_PROPERTY,'',''));
+ $this->m_wikipage->setOutputFormat($this->m_outformat);
$this->m_caption = $label;
$this->addError($this->m_wikipage->getErrors()); //
NOTE: this unstubs the wikipage, should we rather ignore errors here to prevent
this?
} else { // predefined property without label
@@ -173,6 +174,13 @@

SMWPropertyvalue::$m_propertytypes[$this->m_propertyid][1]) );
}

+ public function setOutputFormat($formatstring) {
+ $this->m_outformat = $formatstring;
+ if ($this->m_wikipage !== NULL) { // do not unstub if not needed
+ $this->m_wikipage->setOutputFormat($formatstring);
+ }
+ }
+
public function getShortWikiText($linked = NULL) {
return
$this->isVisible()?$this->highlightText($this->m_wikipage->getShortWikiText($linked)):'';
}

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Temperature.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Temperature.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Temperature.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -17,7 +17,7 @@
* Converts the current m_value and m_unit to the main unit, if
possible.
* This means, it changes the fileds m_value and m_unit accordingly, and
* that it stores the ID of the originally given unit in
$this->m_unitin.
- * This should obviously not be done more than once, so it is advisable
to
+ * This should obviously not be done more than once, so it is advisable
to
* first check if m_unitin is non-false. Also, it should be checked if
the
* value is valid before trying to calculate with its contents.
*/
@@ -62,8 +62,8 @@
* The result is stored in $this->m_unitvalues. Again, any class that
* requires effort for doing this should first check whether the array
* is already set (i.e. not false) before doing any work.
- * Note that the values should be plain numbers. Output formatting is
done
- * later when needed. Also, it should be checked if the value is valid
+ * Note that the values should be plain numbers. Output formatting is
done
+ * later when needed. Also, it should be checked if the value is valid
* before trying to calculate with its contents.
* This method also must call or implement convertToMainUnit().
*/
@@ -89,7 +89,7 @@
$this->convertToMainUnit();

$value = false;
- if (($this->m_unit === 'K') && $this->m_outformat) { // try
given output unit (only if conversion worked)
+ if (($this->m_unit === 'K') && $this->m_outformat &&
($this->m_outformat != '-') ) { // try given output unit (only if conversion
worked)
$unit =
$this->getUnitID($this->normalizeUnit($this->m_outformat));
$printunit = $this->m_outformat;
switch ($unit) {
@@ -150,7 +150,7 @@
}

/**
- * Return an array of major unit strings (ids only recommended)
supported by
+ * Return an array of major unit strings (ids only recommended)
supported by
* this datavalue.
*/
public function getUnitList() {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php 2009-07-31
12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php 2009-07-31
13:20:10 UTC (rev 54096)
@@ -430,8 +430,8 @@
protected function makePrintoutValue() {
global $smwgContLang;
if ($this->m_printvalue === false) {
- //MediaWiki date function is not applicable any more
(no support for BC Dates)
- if ( strtoupper($this->m_outformat) == 'ISO') { //
ISO8601 date formatting
+ //MediaWiki date function is not applicable any more
(no support for BC dates)
+ if ( (strtoupper($this->m_outformat) == 'ISO') ||
($this->m_outformat == '-')) { // ISO8601 date formatting
if ($this->m_year > 0) {
$this->m_printvalue =
str_pad($this->m_year, 4, "0", STR_PAD_LEFT);
} else {

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php 2009-07-31
12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php 2009-07-31
13:20:10 UTC (rev 54096)
@@ -163,7 +163,7 @@

public function getShortWikiText($linked = NULL) {
$this->unstub();
- if ( ($linked === NULL) || ($linked === false) || ($this->m_url
== '') || ($this->m_caption == '') ) {
+ if ( ($linked === NULL) || ($linked === false) ||
($this->m_outformat == '-') || ($this->m_url == '') || ($this->m_caption == '')
) {
return $this->m_caption;
} else {
return '[' . $this->m_url . ' ' . $this->m_caption .
']';
@@ -172,7 +172,7 @@

public function getShortHTMLText($linker = NULL) {
$this->unstub();
- if (($linker === NULL) || (!$this->isValid()) || ($this->m_url
== '') || ($this->m_caption == '')) {
+ if (($linker === NULL) || (!$this->isValid()) ||
($this->m_outformat == '-') || ($this->m_url == '') || ($this->m_caption ==
'')) {
return $this->m_caption;
} else {
return $linker->makeExternalLink($this->m_url,
$this->m_caption);
@@ -183,7 +183,7 @@
if (!$this->isValid()) {
return $this->getErrorText();
}
- if ( ($linked === NULL) || ($linked === false) || ($this->m_url
== '') ) {
+ if ( ($linked === NULL) || ($linked === false) ||
($this->m_outformat == '-') || ($this->m_url == '') ) {
return $this->m_value;
} else {
return '[' . $this->m_url . ' ' . $this->m_value . ']';
@@ -194,7 +194,7 @@
if (!$this->isValid()) {
return $this->getErrorText();
}
- if (($linker === NULL) || ($this->m_url == '') ) {
+ if (($linker === NULL) || ($this->m_outformat == '-') ||
($this->m_url == '') ) {
return htmlspecialchars($this->m_value);
} else {
return $linker->makeExternalLink($this->m_url,
$this->m_value);

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -126,7 +126,7 @@

public function getShortWikiText($linked = NULL) {
$this->unstub();
- if ( ($linked === NULL) || ($linked === false) ||
(!$this->isValid()) || ($this->m_caption === '') ) {
+ if ( ($linked === NULL) || ($linked === false) ||
($this->m_outformat == '-') || (!$this->isValid()) || ($this->m_caption === '')
) {
return $this->getCaption();
} else {
return '[[:' . str_replace("'", ''',
$this->getPrefixedText()) .
@@ -136,8 +136,8 @@

public function getShortHTMLText($linker = NULL) {
$this->unstub();
- if ( ($linker !== NULL) && ($this->m_caption !== '') ) {
$this->getTitle(); } // init the Title object, may reveal hitherto unnoticed
errors
- if ( ($linker === NULL) || (!$this->isValid()) ||
($this->m_caption === '') ) {
+ if ( ($linker !== NULL) && ($this->m_caption !== '') &&
($this->m_outformat != '-') ) { $this->getTitle(); } // init the Title object,
may reveal hitherto unnoticed errors
+ if ( ($linker === NULL) || (!$this->isValid()) ||
($this->m_outformat == '-') || ($this->m_caption === '') ) {
return htmlspecialchars($this->getCaption());
} else {
if ($this->getNamespace() == NS_MEDIA) { /// NOTE: this
extra case is indeed needed
@@ -158,7 +158,7 @@
if (!$this->isValid()) {
return $this->getErrorText();
}
- if ( ($linked === NULL) || ($linked === false) ) {
+ if ( ($linked === NULL) || ($linked === false) ||
($this->m_outformat == '-') ) {
return $this->getPrefixedText();
} elseif ($this->m_namespace == NS_IMAGE) { // embed images
instead of linking to their page
return '[[' . str_replace("'", ''',
$this->getPrefixedText()) . '|' . $this->m_textform .
'|frameless|border|text-top]]';
@@ -169,11 +169,11 @@

public function getLongHTMLText($linker = NULL) {
$this->unstub();
- if ($linker !== NULL) { $this->getTitle(); } // init the Title
object, may reveal hitherto unnoticed errors
+ if ( ($linker !== NULL) && ($this->m_outformat != '-') ) {
$this->getTitle(); } // init the Title object, may reveal hitherto unnoticed
errors
if (!$this->isValid()) {
return $this->getErrorText();
}
- if ($linker === NULL) {
+ if ( ($linker === NULL) || ($this->m_outformat == '-') ) {
return htmlspecialchars($this->getPrefixedText());
} else {
if ($this->getNamespace() == NS_MEDIA) { // this extra
case is really needed

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -192,6 +192,14 @@
* a desired output unit. In other cases, the output format might be
built-in
* and subject to internationalisation (which the datavalue has to
implement).
* In any case, an empty string resets the output format to the default.
+ *
+ * There is one predeeind output format that all datavalues should
respect: the
+ * format '-' indicates "plain" output that is most useful for further
processing
+ * the value in a template. It should not use any wiki markup or
beautification,
+ * and it should also avoid localization to the current language. When
users
+ * explicitly specify an empty format string in a query, it is
normalized to "-"
+ * to avoid confusion. Note that empty format strings are not
interpreted in
+ * this way when directly passed to this function.
*/
public function setOutputFormat($formatstring) {
$this->m_outformat = $formatstring; // just store it,
subclasses may or may not use this

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -93,7 +93,7 @@
if ($namespace === null)
{
$namespace = $wgServerName;
- }
+ }

if ( !$complete && ($smwgNamespace !== '') ) {
$smwgNamespace = '.' . $namespace;

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -218,7 +218,9 @@
} //else?
}
if (count($propparts) == 1) { // no
outputformat found, leave empty
- $propparts[] = '';
+ $propparts[] = false;
+ } elseif (trim($propparts[1]) == '') { //
"plain printout", avoid empty string to avoid confusions with "false"
+ $propparts[1] = '-';
}
if (count($parts) > 1) { // label found, use
this instead of default
$label = trim($parts[1]);

Modified:
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
2009-07-31 12:45:29 UTC (rev 54095)
+++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -36,12 +36,12 @@
* @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
*/
- public function __construct($mode, $label, $data = NULL, $outputformat
= '') {
+ public function __construct($mode, $label, $data = NULL, $outputformat
= false) {
$this->m_mode = $mode;
$this->m_label = $label;
$this->m_data = $data;
$this->m_outputformat = $outputformat;
- if ( ($mode == SMWPrintRequest::PRINT_CCAT) && ($outputformat
=== '') ) {
+ if ( ($mode == SMWPrintRequest::PRINT_CCAT) && ($outputformat
== false) ) {
$this->m_outputformat = 'x'; // changed default for
Boolean case
}
if ($this->m_data instanceof SMWDataValue) {

Modified:
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
===================================================================
---
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
2009-07-31 12:45:29 UTC (rev 54095)
+++
trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
2009-07-31 13:20:10 UTC (rev 54096)
@@ -300,6 +300,9 @@
foreach ($prs as $pr) {
switch ($pr->getMode()) {
case SMWPrintRequest::PRINT_THIS:
+ if ($pr->getOutputFormat()) {
+
$qt->setOutputFormat($pr->getOutputFormat());
+ }
$row[] = new SMWResultArray(array($qt),
$pr);
break;
case SMWPrintRequest::PRINT_CATS:



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@xxxxxxxxxxxxxxxxxxx
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise