Index: trunk/extensions/SemanticMaps/includes/forminputs/SM_FormInput.php |
— | — | @@ -108,23 +108,8 @@ |
109 | 109 | // TODO |
110 | 110 | $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() ); |
111 | 111 | |
112 | | - $validator = new Validator( 'form' ); // TODO |
| 112 | + $validator = new Validator( 'form', false ); // TODO |
113 | 113 | |
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 | | - |
129 | 114 | $validator->setParameters( $mapProperties, $parameterInfo ); |
130 | 115 | |
131 | 116 | $validator->validateParameters(); |
— | — | @@ -397,8 +382,6 @@ |
398 | 383 | ) |
399 | 384 | ); |
400 | 385 | |
401 | | - //$params['foobar'] = new Parameter('foobar'); |
402 | | - |
403 | 386 | // TODO |
404 | 387 | //$params['geoservice']->setDefault( $egMapsDefaultGeoService ); |
405 | 388 | //$params['mappingservice']->setDefault( $egMapsDefaultServices['fi'] ); |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_MapPrinter.php |
— | — | @@ -170,29 +170,8 @@ |
171 | 171 | // TODO |
172 | 172 | $parameterInfo = array_merge_recursive( $parameterInfo, $this->getSpecificParameterInfo() ); |
173 | 173 | |
174 | | - $validator = new Validator( $this->getName() ); |
| 174 | + $validator = new Validator( $this->getName(), false ); |
175 | 175 | |
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 | | - |
197 | 176 | $validator->setParameters( $mapProperties, $parameterInfo ); |
198 | 177 | |
199 | 178 | $validator->validateParameters(); |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_QueryHandler.php |
— | — | @@ -21,6 +21,13 @@ |
22 | 22 | |
23 | 23 | protected $locations = false; |
24 | 24 | |
| 25 | + /** |
| 26 | + * @since 0.7.4 |
| 27 | + * |
| 28 | + * @var array |
| 29 | + */ |
| 30 | + protected $params; |
| 31 | + |
25 | 32 | // TODO: add system to properly handle query parameters |
26 | 33 | public $template = false; |
27 | 34 | public $icon = ''; |
— | — | @@ -29,6 +36,8 @@ |
30 | 37 | public $propNameLink = self::LINK_NONE; |
31 | 38 | public $propValueLink = self::LINK_NONE; |
32 | 39 | |
| 40 | + public $titleLinkSeperate = true; |
| 41 | + |
33 | 42 | /** |
34 | 43 | * Constructor. |
35 | 44 | * |
— | — | @@ -37,9 +46,16 @@ |
38 | 47 | * @param SMWQueryResult $queryResult |
39 | 48 | * @param integer $outputmode |
40 | 49 | */ |
41 | | - public function __construct( SMWQueryResult $queryResult, $outputmode ) { |
| 50 | + public function __construct( SMWQueryResult $queryResult, $outputmode, array $params ) { |
42 | 51 | $this->queryResult = $queryResult; |
43 | 52 | $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; |
44 | 60 | } |
45 | 61 | |
46 | 62 | /** |
— | — | @@ -77,7 +93,7 @@ |
78 | 94 | /** |
79 | 95 | * Returns the locations found in the provided result row. |
80 | 96 | * |
81 | | - * TODO: split up this method if possible |
| 97 | + * TODO: split up this method if possible (!) |
82 | 98 | * TODO: fix template handling |
83 | 99 | * TODO: clean up link type handling |
84 | 100 | * |
— | — | @@ -109,7 +125,7 @@ |
110 | 126 | // Loop throught all the parts of the field value. |
111 | 127 | while ( ( /* SMWDataValue */ $object = $resultArray->getNextObject() ) !== false ) { |
112 | 128 | if ( $object->getTypeID() == '_wpg' && $i == 0 ) { |
113 | | - if ( $this->titleLink == self::LINK_ABSOLUTE ) { |
| 129 | + if ( !$this->titleLinkSeperate && $this->titleLink == self::LINK_ABSOLUTE ) { |
114 | 130 | $title = Html::element( |
115 | 131 | 'a', |
116 | 132 | array( 'href' => $object->getTitle()->getFullUrl() ), |
— | — | @@ -117,24 +133,77 @@ |
118 | 134 | ); |
119 | 135 | } |
120 | 136 | 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 | + ); |
122 | 141 | } |
| 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 | + } |
123 | 150 | } |
124 | 151 | |
125 | 152 | 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; |
133 | 175 | } |
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 />'; |
139 | 208 | } |
140 | 209 | |
141 | 210 | if ( $printRequest->getMode() == SMWPrintRequest::PRINT_PROP && $printRequest->getTypeID() == '_geo' ) { |
— | — | @@ -143,13 +212,6 @@ |
144 | 213 | } |
145 | 214 | } |
146 | 215 | |
147 | | - /* |
148 | | - if ( $this->template ) { |
149 | | - // New parser object to render the templates with. |
150 | | - $parser = new Parser(); |
151 | | - } |
152 | | - */ |
153 | | - |
154 | 216 | foreach ( $coords as $coord ) { |
155 | 217 | if ( count( $coord ) >= 2 ) { |
156 | 218 | if ( $smgUseSpatialExtensions ) { |
— | — | @@ -161,16 +223,6 @@ |
162 | 224 | |
163 | 225 | if ( $lat != '' && $lon != '' ) { |
164 | 226 | $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 | | - */ |
175 | 227 | |
176 | 228 | $location = new MapsLocation(); |
177 | 229 | |
— | — | @@ -191,13 +243,6 @@ |
192 | 244 | } |
193 | 245 | |
194 | 246 | /** |
195 | | - * Get |
196 | | - */ |
197 | | - protected function getDataValueLink() { |
198 | | - |
199 | | - } |
200 | | - |
201 | | - /** |
202 | 247 | * Get the icon for a row. |
203 | 248 | * |
204 | 249 | * @since 0.7.3 |
Index: trunk/extensions/SemanticMaps/includes/queryprinters/SM_KMLPrinter.php |
— | — | @@ -23,24 +23,68 @@ |
24 | 24 | * @return array |
25 | 25 | */ |
26 | 26 | 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 | + } |
28 | 49 | } |
29 | 50 | |
30 | 51 | /** |
| 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 | + /** |
31 | 74 | * Returns the KML for the query result. |
32 | 75 | * |
33 | 76 | * @since 0.7.3 |
34 | 77 | * |
35 | 78 | * @param SMWQueryResult $res |
36 | 79 | * @param integer $outputmode |
| 80 | + * @param array $params |
37 | 81 | * |
38 | 82 | * @return string |
39 | 83 | */ |
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 ); |
42 | 86 | $locations = $queryHandler->getLocations(); |
43 | 87 | |
44 | | - $formatter = new MapsKMLFormatter(); |
| 88 | + $formatter = new MapsKMLFormatter( $params ); |
45 | 89 | $formatter->addPlacemarks( $locations ); |
46 | 90 | |
47 | 91 | return $formatter->getKML(); |
— | — | @@ -53,23 +97,22 @@ |
54 | 98 | * |
55 | 99 | * @param SMWQueryResult $res |
56 | 100 | * @param integer $outputmode |
| 101 | + * @param array $params |
57 | 102 | * |
58 | 103 | * @return string |
59 | 104 | */ |
60 | | - protected function getLink( SMWQueryResult $res, $outputmode ) { |
| 105 | + protected function getLink( SMWQueryResult $res, $outputmode, array $params ) { |
61 | 106 | $searchLabel = $this->getSearchLabel( $outputmode ); |
62 | 107 | $link = $res->getQueryLink( $searchLabel ? $searchLabel : wfMsgForContent( 'semanticmaps-kml-link' ) ); |
63 | 108 | $link->setParameter( 'kml', 'format' ); |
64 | 109 | |
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' ); |
69 | 114 | |
70 | | - if ( $this->m_description !== '' ) { |
71 | | - $link->setParameter( $this->m_description, 'description' ); |
72 | | - } |
73 | | - */ |
| 115 | + $link->setParameter( $params['pagelinktext'], 'pagelinktext' ); |
| 116 | + |
74 | 117 | if ( array_key_exists( 'limit', $this->m_params ) ) { |
75 | 118 | $link->setParameter( $this->m_params['limit'], 'limit' ); |
76 | 119 | } else { // Use a reasonable default limit. |
— | — | @@ -77,7 +120,7 @@ |
78 | 121 | } |
79 | 122 | |
80 | 123 | $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); |
81 | | - |
| 124 | + |
82 | 125 | return $link->getText( $outputmode, $this->mLinker ); |
83 | 126 | } |
84 | 127 | |
Index: trunk/extensions/SemanticMaps/SemanticMaps.i18n.php |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | 'semanticmaps-unrecognizeddistance' => 'The value $1 is not a valid distance.', |
25 | 25 | 'semanticmaps-kml-link' => 'View the KML file', |
26 | 26 | 'semanticmaps-kml' => 'KML', |
| 27 | + 'semanticmaps-default-kml-pagelink' => 'View article $1', |
27 | 28 | |
28 | 29 | // Forms |
29 | 30 | 'semanticmaps_lookupcoordinates' => 'Look up coordinates', |
Index: trunk/extensions/SemanticMaps/SemanticMaps.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | |
40 | 40 | // Only initialize the extension when all dependencies are present. |
41 | 41 | if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) { |
42 | | - define( 'SM_VERSION', '0.7.3' ); |
| 42 | + define( 'SM_VERSION', '0.7.4 alpha' ); |
43 | 43 | |
44 | 44 | $useExtensionPath = version_compare( $wgVersion, '1.16', '>=' ) && isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath; |
45 | 45 | $smgScriptPath = ( $useExtensionPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps'; |