r92953 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92952‎ | r92953 | r92954 >
Date:18:28, 23 July 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
proper escaping of values, at least for some of the output
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php
@@ -70,37 +70,33 @@
7171
7272 if ( $pr->getMode() != SMWPrintRequest::PRINT_THIS ) {
7373 $values = array();
74 - $finalvalues = '';
 74+ $jsonObject = array();
7575
7676 while ( ( $dataValue = $field->getNextDataValue() ) !== false ) {
77 - $finalvalues = '';
7877 switch ( $dataValue->getTypeID() ) {
7978 case '_geo':
 79+ $jsonObject[] = $dataValue->getDataItem()->getCoordinateSet();
8080 $values[] = FormatJson::encode( $dataValue->getDataItem()->getCoordinateSet() );
8181 break;
8282 case '_num':
83 - $values[] = $dataValue->getDataItem()->getNumber();
 83+ $jsonObject[] = $dataValue->getDataItem()->getNumber();
8484 break;
8585 case '_dat':
86 - $values[] =
87 - '"' . $dataValue->getYear() . '-' .
 86+ $jsonObject[] =
 87+ $dataValue->getYear() . '-' .
8888 str_pad( $dataValue->getMonth(), 2, '0', STR_PAD_LEFT ) . '-' .
8989 str_pad( $dataValue->getDay(), 2, '0', STR_PAD_LEFT ) . ' ' .
90 - $dataValue->getTimeString() . '"';
 90+ $dataValue->getTimeString();
9191 break;
9292 default:
93 - $values[] = '"' . $dataValue->getShortText( $outputmode, null ) . '"';
 93+ $jsonObject[] = $dataValue->getShortText( $outputmode, null );
9494 }
95 -
96 - if ( sizeof( $values ) > 1 ) {
97 - $finalvalues = '[' . implode( ',', $values ) . ']';
98 - } else {
99 - $finalvalues = $values[0];
100 - }
10195 }
10296
103 - if ( $finalvalues != '' ) {
104 - $valuestack[] = '"' . str_replace( ' ', '_', strtolower( $pr->getLabel() ) ) . '": ' . $finalvalues . '';
 97+ if ( !is_array( $jsonObject ) || count( $jsonObject ) > 0 ) {
 98+ $valuestack[] =
 99+ '"' . str_replace( ' ', '_', strtolower( $pr->getLabel() ) )
 100+ . '": ' . FormatJson::encode( $jsonObject ) . '';
105101 }
106102 }
107103 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r92954fu r92953jeroendedauw18:30, 23 July 2011