r77579 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77578‎ | r77579 | r77580 >
Date:15:37, 2 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.7.4 - new options for the kml format + some cleanup
Modified paths:
  • /trunk/extensions/SemanticMaps/SemanticMaps.i18n.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/forminputs/SM_FormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/queryprinters/SM_KMLPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/queryprinters/SM_MapPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryHandler.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/includes/forminputs/SM_FormInput.php
@@ -108,23 +108,8 @@
109109 // TODO
110110 $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() );
111111
112 - $validator = new Validator( 'form' ); // TODO
 112+ $validator = new Validator( 'form', false ); // TODO
113113
114 - $paramsToFilter = array(
115 - 'service_name',
116 - 'part_of_multiple',
117 - 'possible_values',
118 - 'is_list',
119 - 'semantic_property',
120 - 'value_labels'
121 - );
122 -
123 - foreach ( $paramsToFilter as $paramName ) {
124 - if ( array_key_exists( $paramName, $mapProperties ) ) {
125 - unset( $mapProperties[$paramName] );
126 - }
127 - }
128 -
129114 $validator->setParameters( $mapProperties, $parameterInfo );
130115
131116 $validator->validateParameters();
@@ -397,8 +382,6 @@
398383 )
399384 );
400385
401 - //$params['foobar'] = new Parameter('foobar');
402 -
403386 // TODO
404387 //$params['geoservice']->setDefault( $egMapsDefaultGeoService );
405388 //$params['mappingservice']->setDefault( $egMapsDefaultServices['fi'] );
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_MapPrinter.php
@@ -170,29 +170,8 @@
171171 // TODO
172172 $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() );
173173
174 - $validator = new Validator( $this->getName() );
 174+ $validator = new Validator( $this->getName(), false );
175175
176 - $paramsToFilter = array(
177 - 'limit',
178 - 'offset',
179 - 'sort',
180 - 'order',
181 - 'headers',
182 - 'mainlabel',
183 - 'link',
184 - 'default',
185 - 'intro',
186 - 'outro',
187 - 'searchlabel',
188 - 'distance'
189 - );
190 -
191 - foreach ( $paramsToFilter as $paramName ) {
192 - if ( array_key_exists( $paramName, $mapProperties ) ) {
193 - unset( $mapProperties[$paramName] );
194 - }
195 - }
196 -
197176 $validator->setParameters( $mapProperties, $parameterInfo );
198177
199178 $validator->validateParameters();
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryHandler.php
@@ -21,6 +21,13 @@
2222
2323 protected $locations = false;
2424
 25+ /**
 26+ * @since 0.7.4
 27+ *
 28+ * @var array
 29+ */
 30+ protected $params;
 31+
2532 // TODO: add system to properly handle query parameters
2633 public $template = false;
2734 public $icon = '';
@@ -29,6 +36,8 @@
3037 public $propNameLink = self::LINK_NONE;
3138 public $propValueLink = self::LINK_NONE;
3239
 40+ public $titleLinkSeperate = true;
 41+
3342 /**
3443 * Constructor.
3544 *
@@ -37,9 +46,16 @@
3847 * @param SMWQueryResult $queryResult
3948 * @param integer $outputmode
4049 */
41 - public function __construct( SMWQueryResult $queryResult, $outputmode ) {
 50+ public function __construct( SMWQueryResult $queryResult, $outputmode, array $params ) {
4251 $this->queryResult = $queryResult;
4352 $this->outputmode = $outputmode;
 53+ $this->params = $params;
 54+
 55+ $linkType = $params['linkabsolute'] ? self::LINK_ABSOLUTE : self::LINK_RELATIVE;
 56+
 57+ $this->titleLink = $params['linkpage'] ? $linkType : self::LINK_NONE;
 58+ $this->propNameLink = $params['linkpropnames'] ? $linkType : self::LINK_NONE;
 59+ $this->propValueLink = $params['linkpropvalues'] ? $linkType : self::LINK_NONE;
4460 }
4561
4662 /**
@@ -77,7 +93,7 @@
7894 /**
7995 * Returns the locations found in the provided result row.
8096 *
81 - * TODO: split up this method if possible
 97+ * TODO: split up this method if possible (!)
8298 * TODO: fix template handling
8399 * TODO: clean up link type handling
84100 *
@@ -109,7 +125,7 @@
110126 // Loop throught all the parts of the field value.
111127 while ( ( /* SMWDataValue */ $object = $resultArray->getNextObject() ) !== false ) {
112128 if ( $object->getTypeID() == '_wpg' && $i == 0 ) {
113 - if ( $this->titleLink == self::LINK_ABSOLUTE ) {
 129+ if ( !$this->titleLinkSeperate && $this->titleLink == self::LINK_ABSOLUTE ) {
114130 $title = Html::element(
115131 'a',
116132 array( 'href' => $object->getTitle()->getFullUrl() ),
@@ -117,24 +133,77 @@
118134 );
119135 }
120136 else {
121 - $title = $object->getLongText( $this->outputmode, $this->titleLink == self::LINK_RELATIVE ? $skin : NULL );
 137+ $title = $object->getLongText(
 138+ $this->outputmode,
 139+ ( $this->titleLink == self::LINK_RELATIVE && !$this->titleLinkSeperate ) ? $skin : NULL
 140+ );
122141 }
 142+
 143+ if ( $this->titleLinkSeperate && $this->titleLink != self::LINK_NONE ) {
 144+ $text .= Html::element(
 145+ 'a',
 146+ array( 'href' => $object->getTitle()->getFullUrl() ),
 147+ str_replace( '$1', $object->getTitle()->getText(), $this->params['pagelinktext'] )
 148+ ) . '<br />';
 149+ }
123150 }
124151
125152 if ( $object->getTypeID() != '_geo' && $i != 0 ) {
126 - /*
127 - if ( $this->template ) {
128 - if ( $object instanceof SMWWikiPageValue ) {
129 - $label[] = $object->getTitle()->getPrefixedText();
130 - } else {
131 - $label[] = $object->getLongText( $this->outputmode, $this->makeLinks ? $skin : NULL );
132 - }
 153+ switch ( $this->propNameLink ) {
 154+ case self::LINK_NONE:
 155+ $propertyName = $printRequest->getHTMLText( NULL );
 156+ break;
 157+ case self::LINK_RELATIVE:
 158+ $propertyName = $printRequest->getHTMLText( $skin );
 159+ break;
 160+ case self::LINK_ABSOLUTE:
 161+ $t = Title::newFromText( $printRequest->getHTMLText( NULL ), SMW_NS_PROPERTY );
 162+
 163+ if ( $t->exists() ) {
 164+
 165+ $propertyName = $propertyName = Html::element(
 166+ 'a',
 167+ array( 'href' => $t->getFullUrl() ),
 168+ $printRequest->getHTMLText( NULL )
 169+ );
 170+ }
 171+ else {
 172+ $propertyName = $printRequest->getHTMLText( NULL );
 173+ }
 174+ break;
133175 }
134 - else { */
135 - $propertyName = $printRequest->getHTMLText( $this->propNameLink == self::LINK_RELATIVE ? $skin : NULL );
136 - if ( $propertyName != '' ) $propertyName .= ': ';
137 - $text .= $propertyName . $object->getLongText( $this->outputmode, $this->propValueLink == self::LINK_RELATIVE ? $skin : NULL ) . '<br />';
138 - //}
 176+
 177+ if ( $propertyName != '' ) $propertyName .= ': ';
 178+
 179+ switch ( $this->propNameLink ) {
 180+ case self::LINK_NONE:
 181+ $propertyValue = $object->getLongText( $this->outputmode, NULL );
 182+ break;
 183+ case self::LINK_RELATIVE:
 184+ $propertyValue = $object->getLongText( $this->outputmode, $skin );
 185+ break;
 186+ case self::LINK_ABSOLUTE:
 187+ $hasPage = $object->getTypeID() == '_wpg';
 188+
 189+ if ( $hasPage ) {
 190+ $t = Title::newFromText( $object->getLongText( $this->outputmode, NULL ), NS_MAIN );
 191+ $hasPage = $t->exists();
 192+ }
 193+
 194+ if ( $hasPage ) {
 195+ $propertyValue = Html::element(
 196+ 'a',
 197+ array( 'href' => $t->getFullUrl() ),
 198+ $object->getLongText( $this->outputmode, NULL )
 199+ );
 200+ }
 201+ else {
 202+ $propertyValue = $object->getLongText( $this->outputmode, NULL );
 203+ }
 204+ break;
 205+ }
 206+
 207+ $text .= $propertyName . $propertyValue . '<br />';
139208 }
140209
141210 if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' ) {
@@ -143,13 +212,6 @@
144213 }
145214 }
146215
147 - /*
148 - if ( $this->template ) {
149 - // New parser object to render the templates with.
150 - $parser = new Parser();
151 - }
152 - */
153 -
154216 foreach ( $coords as $coord ) {
155217 if ( count( $coord ) >= 2 ) {
156218 if ( $smgUseSpatialExtensions ) {
@@ -161,16 +223,6 @@
162224
163225 if ( $lat != '' && $lon != '' ) {
164226 $icon = $this->getLocationIcon( $row );
165 - /*
166 - if ( $this->template ) {
167 - $segments = array_merge(
168 - array( $this->template, 'title=' . $titleForTemplate, 'latitude=' . $lat, 'longitude=' . $lon ),
169 - $label
170 - );
171 -
172 - $text = $parser->parse( '{{' . implode( '|', $segments ) . '}}', $wgTitle, new ParserOptions() )->getText();
173 - }
174 - */
175227
176228 $location = new MapsLocation();
177229
@@ -191,13 +243,6 @@
192244 }
193245
194246 /**
195 - * Get
196 - */
197 - protected function getDataValueLink() {
198 -
199 - }
200 -
201 - /**
202247 * Get the icon for a row.
203248 *
204249 * @since 0.7.3
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_KMLPrinter.php
@@ -23,24 +23,68 @@
2424 * @return array
2525 */
2626 public function getResultText( /* SMWQueryResult */ $res, $outputmode ) {
27 - return $outputmode == SMW_OUTPUT_FILE ? $this->getKML( $res, $outputmode ) : $this->getLink( $res, $outputmode );
 27+ $validator = new Validator( $this->getName(), false );
 28+
 29+ $validator->setParameters( $this->m_params, $this->getParameterInfo() );
 30+
 31+ $validator->validateParameters();
 32+
 33+ $fatalError = $validator->hasFatalError();
 34+
 35+ if ( $fatalError !== false ) {
 36+ return '<span class="errorbox">' .
 37+ htmlspecialchars( wfMsgExt( 'validator-fatal-error', 'parsemag', $fatalError->getMessage() ) ) .
 38+ '</span>';
 39+ }
 40+
 41+ $params = $validator->getParameterValues();
 42+
 43+ if ( $outputmode == SMW_OUTPUT_FILE ) {
 44+ return $this->getKML( $res, $outputmode, $params );
 45+ }
 46+ else {
 47+ return $this->getLink( $res, $outputmode, $params );
 48+ }
2849 }
2950
3051 /**
 52+ * Returns a list of parameter definitions.
 53+ *
 54+ * @since 0.7.4
 55+ *
 56+ * @return array
 57+ */
 58+ protected function getParameterInfo() {
 59+ $params = array();
 60+
 61+ $params[] = new Parameter( 'linkpage', Parameter::TYPE_BOOLEAN, true );
 62+
 63+ $params[] = new Parameter( 'linkpropnames', Parameter::TYPE_BOOLEAN, false );
 64+ $params[] = new Parameter( 'linkpropvalues', Parameter::TYPE_BOOLEAN, false );
 65+
 66+ $params[] = new Parameter( 'linkabsolute', Parameter::TYPE_BOOLEAN, true );
 67+
 68+ $params['pagelinktext'] = new Parameter( 'pagelinktext', Parameter::TYPE_STRING, wfMsg( 'semanticmaps-default-kml-pagelink' ) );
 69+
 70+ return $params;
 71+ }
 72+
 73+ /**
3174 * Returns the KML for the query result.
3275 *
3376 * @since 0.7.3
3477 *
3578 * @param SMWQueryResult $res
3679 * @param integer $outputmode
 80+ * @param array $params
3781 *
3882 * @return string
3983 */
40 - protected function getKML( SMWQueryResult $res, $outputmode ) {
41 - $queryHandler = new SMQueryHandler( $res, $outputmode );
 84+ protected function getKML( SMWQueryResult $res, $outputmode, array $params ) {
 85+ $queryHandler = new SMQueryHandler( $res, $outputmode, $params );
4286 $locations = $queryHandler->getLocations();
4387
44 - $formatter = new MapsKMLFormatter();
 88+ $formatter = new MapsKMLFormatter( $params );
4589 $formatter->addPlacemarks( $locations );
4690
4791 return $formatter->getKML();
@@ -53,23 +97,22 @@
5498 *
5599 * @param SMWQueryResult $res
56100 * @param integer $outputmode
 101+ * @param array $params
57102 *
58103 * @return string
59104 */
60 - protected function getLink( SMWQueryResult $res, $outputmode ) {
 105+ protected function getLink( SMWQueryResult $res, $outputmode, array $params ) {
61106 $searchLabel = $this->getSearchLabel( $outputmode );
62107 $link = $res->getQueryLink( $searchLabel ? $searchLabel : wfMsgForContent( 'semanticmaps-kml-link' ) );
63108 $link->setParameter( 'kml', 'format' );
64109
65 - /*
66 - if ( $this->m_title !== '' ) {
67 - $link->setParameter( $this->m_title, 'title' );
68 - }
 110+ $link->setParameter( $params['linkpage'] ? 'yes' : 'no', 'linkpage' );
 111+ $link->setParameter( $params['linkpropnames'] ? 'yes' : 'no', 'linkpropnames' );
 112+ $link->setParameter( $params['linkpropvalues'] ? 'yes' : 'no', 'linkpropvalues' );
 113+ $link->setParameter( $params['linkabsolute'] ? 'yes' : 'no', 'linkabsolute' );
69114
70 - if ( $this->m_description !== '' ) {
71 - $link->setParameter( $this->m_description, 'description' );
72 - }
73 - */
 115+ $link->setParameter( $params['pagelinktext'], 'pagelinktext' );
 116+
74117 if ( array_key_exists( 'limit', $this->m_params ) ) {
75118 $link->setParameter( $this->m_params['limit'], 'limit' );
76119 } else { // Use a reasonable default limit.
@@ -77,7 +120,7 @@
78121 }
79122
80123 $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML );
81 -
 124+
82125 return $link->getText( $outputmode, $this->mLinker );
83126 }
84127
Index: trunk/extensions/SemanticMaps/SemanticMaps.i18n.php
@@ -23,6 +23,7 @@
2424 'semanticmaps-unrecognizeddistance' => 'The value $1 is not a valid distance.',
2525 'semanticmaps-kml-link' => 'View the KML file',
2626 'semanticmaps-kml' => 'KML',
 27+ 'semanticmaps-default-kml-pagelink' => 'View article $1',
2728
2829 // Forms
2930 'semanticmaps_lookupcoordinates' => 'Look up coordinates',
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -38,7 +38,7 @@
3939
4040 // Only initialize the extension when all dependencies are present.
4141 if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) {
42 - define( 'SM_VERSION', '0.7.3' );
 42+ define( 'SM_VERSION', '0.7.4 alpha' );
4343
4444 $useExtensionPath = version_compare( $wgVersion, '1.16', '>=' ) && isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath;
4545 $smgScriptPath = ( $useExtensionPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps';

Status & tagging log