r98086 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98085‎ | r98086 | r98087 >
Date:22:05, 25 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
migrate param handling
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_CSV.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_List.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_CSV.php
@@ -7,20 +7,28 @@
88
99 /**
1010 * Printer class for generating CSV output
 11+ *
1112 * @author Nathan R. Yergler
1213 * @author Markus Krötzsch
 14+ *
1315 * @ingroup SMWQuery
1416 */
1517 class SMWCsvResultPrinter extends SMWResultPrinter {
 18+
1619 protected $m_sep;
1720
18 - protected function readParameters( $params, $outputmode ) {
19 - parent::readParameters( $params, $outputmode );
20 - if ( array_key_exists( 'sep', $params ) ) {
21 - $this->m_sep = str_replace( '_', ' ', $params['sep'] );
22 - } else {
23 - $this->m_sep = ',';
24 - }
 21+ /**
 22+ * @see SMWResultPrinter::handleParameters
 23+ *
 24+ * @since 1.6.3
 25+ *
 26+ * @param array $params
 27+ * @param $outputmode
 28+ */
 29+ protected function handleParameters( array $params, $outputmode ) {
 30+ parent::handleParameters( $params, $outputmode );
 31+
 32+ $this->m_sep = str_replace( '_', ' ', $params['sep'] );
2533 }
2634
2735 public function getMimeType( $res ) {
@@ -32,7 +40,7 @@
3341 }
3442
3543 public function getQueryMode( $context ) {
36 - return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES:SMWQuery::MODE_NONE;
 44+ return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE;
3745 }
3846
3947 public function getName() {
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_List.php
@@ -24,11 +24,6 @@
2525 protected $mColumns;
2626 protected $mIntroTemplate;
2727 protected $mOutroTemplate;
28 -
29 - public function __construct( $format, $inline, $useValidator = true ) {
30 - parent::__construct( $format, $inline );
31 - $this->useValidator = $useValidator;
32 - }
3328
3429 /**
3530 * @see SMWResultPrinter::handleParameters
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php
@@ -7,7 +7,11 @@
88
99 /**
1010 * Printer class for generating RDF output
 11+ *
 12+ * @since 1.6
 13+ *
1114 * @author Markus Krötzsch
 15+ *
1216 * @ingroup SMWQuery
1317 */
1418 class SMWRDFResultPrinter extends SMWResultPrinter {
@@ -17,13 +21,17 @@
1822 */
1923 protected $syntax;
2024
21 - protected function readParameters( $params, $outputmode ) {
22 - parent::readParameters( $params, $outputmode );
23 - if ( array_key_exists( 'syntax', $params ) ) {
24 - $this->syntax = $params['syntax'];
25 - } else {
26 - $this->syntax = 'rdfxml';
27 - }
 25+ /**
 26+ * @see SMWResultPrinter::handleParameters
 27+ *
 28+ * @since 1.6.3
 29+ *
 30+ * @param array $params
 31+ * @param $outputmode
 32+ */
 33+ protected function handleParameters( array $params, $outputmode ) {
 34+ parent::handleParameters( $params, $outputmode );
 35+ $this->syntax = $params['syntax'];
2836 }
2937
3038 public function getMimeType( $res ) {
@@ -48,12 +56,15 @@
4957 $serializer = $this->syntax == 'turtle' ? new SMWTurtleSerializer() : new SMWRDFXMLSerializer();
5058 $serializer->startSerialization();
5159 $serializer->serializeExpData( SMWExporter::getOntologyExpData( '' ) );
 60+
5261 while ( $row = $res->getNext() ) {
5362 $subjectDi = reset( $row )->getResultSubject();
5463 $data = SMWExporter::makeExportDataForSubject( $subjectDi );
 64+
5565 foreach ( $row as $resultarray ) {
5666 $printreq = $resultarray->getPrintRequest();
5767 $property = null;
 68+
5869 switch ( $printreq->getMode() ) {
5970 case SMWPrintRequest::PRINT_PROP:
6071 $property = $printreq->getData();
@@ -68,13 +79,16 @@
6980 // ignored here (object is always included in export)
7081 break;
7182 }
 83+
7284 if ( $property !== null ) {
7385 SMWExporter::addPropertyValues( $property, $resultarray->getContent() , $data, $subjectDi );
7486 }
7587 }
7688 $serializer->serializeExpData( $data );
7789 }
 90+
7891 $serializer->finishSerialization();
 92+
7993 return $serializer->flushContent();
8094 } else { // just make link to feed
8195 if ( $this->getSearchLabel( $outputmode ) ) {
@@ -87,12 +101,15 @@
88102 $link = $res->getQueryLink( $label );
89103 $link->setParameter( 'rdf', 'format' );
90104 $link->setParameter( $this->syntax, 'syntax' );
 105+
91106 if ( array_key_exists( 'limit', $this->m_params ) ) {
92107 $link->setParameter( $this->m_params['limit'], 'limit' );
93108 } else { // use a reasonable default limit
94109 $link->setParameter( 100, 'limit' );
95110 }
 111+
96112 $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed
 113+
97114 return $link->getText( $outputmode, $this->mLinker );
98115 }
99116 }