Completed
Push — master ( cb17e1...aaf96d )
by Stephan
08:23 queued 06:10
created

formats/Exhibit/SRF_Exhibit.php (27 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Use Exhibit to print query results.
4
 * @author Fabian Howahl
5
 * @file
6
 * @ingroup SMWQuery
7
 */
8
9
/**
10
 * Result printer using Exhibit to display query results
11
 *
12
 * @ingroup SMWQuery
13
 */
14
class SRFExhibit extends SMWResultPrinter {
15
	// /mapping between SMW's and Exhibit's the data types
16
	protected $m_types = [ "_wpg" => "text", "_num" => "number", "_dat" => "date", "_geo" => "text", "_uri" => "url" ];
17
18
	protected static $exhibitRunningNumber = 0; // not sufficient since there might be multiple pages rendered within one PHP run; but good enough now
19
20
	// /overwrite function to allow execution of result printer even if no results are available (in case remote query yields no results in local wiki)
21
	public function getResult( $results, $params, $outputmode ) {
22
		$this->readParameters( $params, $outputmode );
23
		$result = $this->getResultText( $results, $outputmode );
24
		return $result;
25
	}
26
27
	// /function aligns the format of SMW's property names to Exhibit's format
28
	protected function encodePropertyName( $property ) {
29
		return strtolower( str_replace( " ", "_", trim( $property ) ) );
30
	}
31
32
	// /Tries to determine the namespace in the event it got lost
33
	protected function determineNamespace( $res ) {
34
		$row = $res->getNext();
35
		if ( $row != null ) {
36
			$tmp = clone $row[0];
37
			$object = $tmp->getNextDataValue();
38
39
			if ( $object instanceof SMWWikiPageValue ) {
40
				$value = $object->getPrefixedText();
41
				if ( strpos( $value, ':' ) ) {
42
					$value = explode( ':', $value, 2 );
43
					return $value[0] . ':';
44
				}
45
			}
46
		}
47
48
		return "";
49
	}
50
51
	protected function getResultText( SMWQueryResult $res, $outputmode ) {
52
53
		global $smwgIQRunningNumber, $wgScriptPath, $wgGoogleMapsKey, $srfgScriptPath;
54
55
		if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
56
			SMWOutputs::requireHeadItem( 'exhibit-compat', Html::linkedScript( "$wgScriptPath/common/wikibits.js" ) );
57
		}
58
		
59
		// //////////////////////////////
60
		// ///////REMOTE STUFF///////////
61
		// //////////////////////////////
62
63
		$remote = false;
64
65
		// in case the remote parameter is set, a link to the JSON export of the remote wiki is included in the header as data source for Exhibit
66
		// this section creates the link
67
		if ( array_key_exists( 'remote', $this->m_params ) && srfgExhibitRemote == true ) {
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
68
69
			$remote = true;
70
71
			// fetch interwiki link
72
			$dbr  = &wfGetDB( DB_SLAVE );
73
			$cl   = $dbr->tableName( 'interwiki' );
74
			$dbres  = $dbr->select( $cl, 'iw_url', "iw_prefix='" . $this->m_params['remote'] . "'", __METHOD__, [] );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
75
			$row = $dbr->fetchRow( $dbres );
76
			$extlinkpattern = $row[iw_url];
77
			$dbr->freeResult( $dbres );
78
79
			$newheader = '<link rel="exhibit/data" type="application/jsonp" href="';
80
			$link = $res->getQueryLink( 'JSON Link' );
0 ignored issues
show
Deprecated Code introduced by
The method SMWQueryResult::getQueryLink() has been deprecated with message: since SMW 1.8

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
81
			$link->setParameter( 'json', 'format' );
82
83
			if ( array_key_exists( 'callback', $this->m_params ) ) { // check if a special name for the callback function is set, if not stick with 'callback'
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
84
				$callbackfunc = $this->m_params['callback'];
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
85
			} else {
86
				$callbackfunc = 'callback';
87
			}
88
89
			if ( array_key_exists( 'limit', $this->m_params ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
90
				$link->setParameter( $this->m_params['limit'], 'limit' );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
91
			}
92
93
			$link->setParameter( $callbackfunc, 'callback' );
94
			$link = $link->getText( 2, $this->mLinker );
95
96
			list( $link, $trash ) = explode( '|', $link );
97
			$link = str_replace( '[[:', '', $link );
98
99
			$newheader .= str_replace( '$1', $link, $extlinkpattern );
100
			$newheader .= '" ex:jsonp-callback="' . $callbackfunc . '"';
101
			$newheader .= '/>';
102
103
			SMWOutputs::requireHeadItem( 'REMOTE', $newheader );
104
		}
105
106
107
108
		// the following variables indicate the use of special views
109
		// the variable's values define the way Exhibit is called
110
		$timeline = false;
111
		$map = false;
112
113
114
		/*The javascript file adopted from Wibbit uses a bunch of javascript variables in the header to store information about the Exhibit markup.
115
		 The following code sequence creates these variables*/
116
117
		// prepare sources (the sources holds information about the table which contains the information)
118
		$colstack = [];
119
		foreach ( $res->getPrintRequests() as $pr ) {
120
			$colstack[] = $this->encodePropertyName( $pr->getLabel() ) . ':' . ( array_key_exists( $pr->getTypeID(), $this->m_types ) ? $this->m_types[$pr->getTypeID()]:'text' ) ;
121
		}
122
		array_shift( $colstack );
123
		array_unshift( $colstack, 'label' );
124
125
		if ( SRFExhibit::$exhibitRunningNumber == 0 ) {
126
			$sourcesrc = "var ex_sources = { source" . ( $smwgIQRunningNumber -1 ) . ": { id:  'querytable" . $smwgIQRunningNumber . "' , columns: '" . implode( ',', $colstack ) . "'.split(','), hideTable: '1', type: 'Item', label: 'Item', pluralLabel: 'Items' } };";
127
		}
128
		else {
129
			$sourcesrc = "sources.source" . $smwgIQRunningNumber . " =  { id:  'querytable" . $smwgIQRunningNumber . "' , columns: '" . implode( ',', $colstack ) . "'.split(','), hideTable: '1', type: 'Item', label: 'Item', pluralLabel: 'Items' };";
130
		}
131
		$sourcesrc = "<script type=\"text/javascript\">" . $sourcesrc . "</script>";
132
133
		// prepare facets
134
		$facetcounter = 0;
135
		if ( array_key_exists( 'facets', $this->m_params ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
136
			$facets = explode( ',', $this->m_params['facets'] );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
137
			$facetstack = [];
138
			$params = [ 'height' ];
139
			$facparams = [];
140
			foreach ( $params as $param ) {
141
				if ( array_key_exists( $param, $this->m_params ) ) $facparams[] = 'ex:' . $param . '="' . $this->encodePropertyName( $this->m_params[$param] ) . '" ';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
142
			}
143
			foreach ( $facets as $facet ) {
144
				$facet = trim( $facet );
145
				$fieldcounter = 0;
146
				if ( strtolower( $facet ) == "search" ) { // special facet (text search)
147
					$facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ex:facetClass="TextSearch" ex:facetLabel="' . $facet . '"\'}';
148
				} else { // usual facet
149
					foreach ( $res->getPrintRequests() as $pr ) {
150
						if ( $this->encodePropertyName( $pr->getLabel() ) == $this->encodePropertyName( $facet ) ) {
151
							switch( $pr->getTypeID() ) {
152
								case '_num':
153
									$facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ex:expression=".' . $this->encodePropertyName( $facet ) . '" ex:facetLabel="' . $facet . '" ex:facetClass="Slider"\'}';
154
									break;
155
								default:
156
									$facetstack[] = ' facet' . $facetcounter++ . ': { position : "right", innerHTML: \'ex:role="facet" ex:showMissing="false" ' . implode( " ", $facparams ) . ' ex:expression=".' . $this->encodePropertyName( $facet ) . '" ex:facetLabel="' . $facet . '"\'}';
157
							}
158
						}
159
160
					}
161
				}
162
				$fieldcounter++;
163
			}
164
			$facetstring = implode( ',', $facetstack );
165
		}
166
		else $facetstring = '';
167
		$facetsrc = "var ex_facets = {" . $facetstring . " };";
168
169
170
		// prepare views
171
		$stylesrc = '';
172
		$viewcounter = 0;
173
		if ( array_key_exists( 'views', $this->m_params ) ) $views = explode( ',', $this->m_params['views'] );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
174
		else $views[] = 'tiles';
175
176
		foreach ( $views as $view ) {
177
			switch( trim( $view ) ) {
178
				case 'tabular':// table view (the columns are automatically defined by the selected properties)
179
					$thstack = [];
180
					foreach ( $res->getPrintRequests() as $pr ) {
181
						$thstack[] = "." . $this->encodePropertyName( $pr->getLabel() );
182
					}
183
					array_shift( $thstack );
184
					array_unshift( $thstack, '.label' );
185
					$stylesrc = 'var myStyler = function(table, database) {table.className=\'smwtable\';};'; // assign SMWtable CSS to Exhibit tabular view
186
					$viewstack[] = 'ex:role=\'view\' ex:viewClass=\'Tabular\' ex:showSummary=\'false\' ex:sortAscending=\'true\' ex:tableStyler=\'myStyler\'  ex:label=\'Table\' ex:columns=\'' . implode( ',', $thstack ) . '\' ex:sortAscending=\'false\'' ;
187
					break;
188
				case 'timeline':// timeline view
189
					$timeline = true;
190
					$exparams = [ 'start', 'end', 'proxy', 'colorkey' ]; // parameters expecting an Exhibit graph expression
191
					$usparams = [ 'timelineheight', 'topbandheight', 'bottombandheight', 'bottombandunit', 'topbandunit' ]; // parametes expecting a textual or numeric value
192
					$tlparams = [];
193
					foreach ( $exparams as $param ) {
194
						if ( array_key_exists( $param, $this->m_params ) ) $tlparams[] = 'ex:' . $param . '=\'.' . $this->encodePropertyName( $this->m_params[$param] ) . '\' ';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
195
					}
196
					foreach ( $usparams as $param ) {
197
						if ( array_key_exists( $param, $this->m_params ) ) $tlparams[] = 'ex:' . $param . '=\'' . $this->encodePropertyName( $this->m_params[$param] ) . '\' ';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
198
					}
199
					if ( !array_key_exists( 'start', $this->m_params ) ) {// find out if a start and/or end date is specified
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
200
						$dates = [];
201
						foreach ( $res->getPrintRequests() as $pr ) {
202
							if ( $pr->getTypeID() == '_dat' ) {
203
								$dates[] = $pr;
204
								if ( sizeof( $dates ) > 2 ) break;
205
							}
206
						}
207
						if ( sizeof( $dates ) == 1 ) {
208
							$tlparams[] = 'ex:start=\'.' . $this->encodePropertyName( $dates[0]->getLabel() ) . '\' ';
209
						}
210
						elseif ( sizeof( $dates ) == 2 ) {
211
							$tlparams[] = 'ex:start=\'.' . $this->encodePropertyName( $dates[0]->getLabel() ) . '\' ';
212
							$tlparams[] = 'ex:end=\'.' . $this->encodePropertyName( $dates[1]->getLabel() ) . '\' ';
213
						}
214
					}
215
					$viewstack[] = 'ex:role=\'view\' ex:viewClass=\'Timeline\' ex:label=\'Timeline\' ex:showSummary=\'false\' ' . implode( " ", $tlparams );
216
					break;
217
				case 'map':// map view
218
					if ( isset( $wgGoogleMapsKey ) ) {
219
					   $map = true;
220
					   $exparams = [ 'latlng', 'colorkey' ];
221
					   $usparams = [ 'type', 'center', 'zoom', 'size', 'scalecontrol', 'overviewcontrol', 'mapheight' ];
222
					   $mapparams = [];
223
					   foreach ( $exparams as $param ) {
224
						if ( array_key_exists( $param, $this->m_params ) ) $mapparams[] = 'ex:' . $param . '=\'.' . $this->encodePropertyName( $this->m_params[$param] ) . '\' ';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
225
					   }
226
					   foreach ( $usparams as $param ) {
227
						if ( array_key_exists( $param, $this->m_params ) ) $mapparams[] = 'ex:' . $param . '=\'' . $this->encodePropertyName( $this->m_params[$param] ) . '\' ';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
228
					   }
229
					   if ( !array_key_exists( 'start', $this->m_params ) && !array_key_exists( 'end', $this->m_params ) ) { // find out if a geographic coordinate is available
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
230
						foreach ( $res->getPrintRequests() as $pr ) {
231
							if ( $pr->getTypeID() == '_geo' ) {
232
								$mapparams[] = 'ex:latlng=\'.' . $this->encodePropertyName( $pr->getLabel() ) . '\' ';
233
								break;
234
							}
235
						}
236
					   }
237
					   $viewstack[] .= 'ex:role=\'view\' ex:viewClass=\'Map\' ex:showSummary=\'false\' ex:label=\'Map\' ' . implode( " ", $mapparams );
238
					}
239
					break;
240
				default: case 'tiles':// tile view
241
					$sortstring = '';
242
					if ( array_key_exists( 'sort', $this->m_params ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
243
						$sortfields = explode( ",", $this->m_params['sort'] );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
244
						foreach ( $sortfields as $field ) {
245
							$sortkeys[] = "." . $this->encodePropertyName( trim( $field ) );
246
						}
247
						$sortstring = 'ex:orders=\'' . implode( ",", $sortkeys ) . '\' ';
248
						if ( array_key_exists( 'order', $this->m_params ) ) $sortstring .= ' ex:directions=\'' . $this->encodePropertyName( $this->m_params['order'] ) . '\'';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
249
						if ( array_key_exists( 'grouped', $this->m_params ) ) $sortstring .= ' ex:grouped=\'' . $this->encodePropertyName( $this->m_params['grouped'] ) . '\'';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
250
					}
251
					$viewstack[] = 'ex:role=\'view\' ex:showSummary=\'false\' ' . $sortstring;
252
					break;
253
			}
254
		}
255
256
		$viewsrc = 'var ex_views = "' . implode( "/", $viewstack ) . '".split(\'/\');;';
257
258
259
260
		// prepare automatic lenses
261
262
		global $wgParser;
263
		$lenscounter = 0;
264
		$linkcounter = 0;
265
		$imagecounter = 0;
266
267
		if ( array_key_exists( 'lens', $this->m_params ) ) {// a customized lens is specified via the lens parameter within the query
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
268
			$lenstitle    = Title::newFromText( "Template:" . $this->m_params['lens'] );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
269
			$lensarticle  = new Article( $lenstitle );
270
			$lenswikitext = $lensarticle->getContent();
271
272
			if ( preg_match_all( "/[\[][\[][Ii][m][a][g][e][:][{][{][{][1-9A-z\-[:space:]]*[}][}][}][\]][\]]/u", $lenswikitext, $matches ) ) {
273
                                foreach ( $matches as $match ) {
274
                                        foreach ( $match as $value ) {
275
                                                $strippedvalue = trim( substr( $value, 8 ), "[[{}]]" );
276
                                                $lenswikitext = str_replace( $value, '<div class="inlines" id="imagecontent' . $imagecounter . '">' . $this->encodePropertyName( strtolower( str_replace( "\n", "", $strippedvalue ) ) ) . '</div>', $lenswikitext );
277
                                                $imagecounter++;
278
                                        }
279
                                }
280
                        }
281
282
			if ( preg_match_all( "/[\[][\[][{][{][{][1-9A-z\-[:space:]]*[}][}][}][\]][\]]/u", $lenswikitext, $matches ) ) {
283
				foreach ( $matches as $match ) {
284
					foreach ( $match as $value ) {
285
						$strippedvalue = trim( $value, "[[{}]]" );
286
						$lenswikitext = str_replace( $value, '<div class="inlines" id="linkcontent' . $linkcounter . '">' . $this->encodePropertyName( strtolower( str_replace( "\n", "", $strippedvalue ) ) ) . '</div>', $lenswikitext );
287
						$linkcounter++;
288
					}
289
				}
290
			}
291
292
			if ( preg_match_all( "/[{][{][{][1-9A-z\:\|\/\=\-[:space:]]*[}][}][}]/u", $lenswikitext, $matches ) ) {
293
				foreach ( $matches as $match ) {
294
					foreach ( $match as $value ) {
295
						$strippedvalue = trim( $value, "{}" );
296
						$lenswikitext = str_replace( $value, '<div class="inlines" id="lenscontent' . $lenscounter . '">' . $this->encodePropertyName( strtolower( str_replace( "\n", "", $strippedvalue ) ) ) . '</div>', $lenswikitext );
297
						$lenscounter++;
298
					}
299
				}
300
			}
301
302
			$lenshtml = $wgParser->internalParse( $lenswikitext );// $wgParser->parse($lenswikitext, $lenstitle, new ParserOptions(), true, true)->getText();
303
304
			$lenssrc = "var ex_lens = '" . str_replace( "\n", "", $lenshtml ) . "';ex_lenscounter =" . $lenscounter . ";ex_linkcounter=" . $linkcounter . ";ex_imagecounter=" . $imagecounter . ";";
305
		} else {// generic lens (creates links to further content (property-pages, pages about values)
306
			foreach ( $res->getPrintRequests() as $pr ) {
307
				if ( $remote ) {
308
					$wikiurl = str_replace( "$1", "", $extlinkpattern );
309
				} else {
310
					$wikiurl = $wgScriptPath . "/index.php?title=";
311
				}
312
				if ( $pr->getTypeID() == '_wpg' ) {
313
					$prefix = '';
314
					if ( $pr->getLabel() == 'Category' ) $prefix = "Category:";
315
					$lensstack[] = '<tr ex:if-exists=".' . $this->encodePropertyName( $pr->getLabel() ) . '"><td width="20%">' . $pr->getText( 0, $this->mLinker ) . '</td><td width="80%" ex:content=".' . $this->encodePropertyName( $pr->getLabel() ) . '"><a ex:href-subcontent="' . $wikiurl . $prefix . '{{urlencval(value)}}"><div ex:content="value" class="name"></div></a></td></tr>';
316
				}
317
				else {
318
					$lensstack[] = '<tr ex:if-exists=".' . $this->encodePropertyName( $pr->getLabel() ) . '"><td width="20%">' . $pr->getText( 0, $this->mLinker ) . '</td><td width="80%"><div ex:content=".' . $this->encodePropertyName( $pr->getLabel() ) . '" class="name"></div></td></tr>';
319
				}
320
			}
321
			array_shift( $lensstack );
322
			$lenssrc = 'var ex_lens = \'<table width=100% cellpadding=3><tr><th class="head" align=left bgcolor="#DDDDDD"><a ex:href-subcontent="' . $wikiurl . $this->determineNamespace( clone $res ) . '{{urlenc(.label)}}" class="linkhead"><div ex:content=".label" class="name"></div></a></th></tr></table><table width="100%" cellpadding=3>' . implode( "", $lensstack ) . '</table>\'; ex_lenscounter = 0; ex_linkcounter=0; ex_imagecounter=0;';
323
		}
324
325
		if ( $remote ) {
326
                         $varremote = 'true';
327
                } else {
328
                        $varremote = 'false';
329
                }
330
331
		// Handling special formats like date
332
		$formatssrc = 'var formats =\'\'';
333
		if ( array_key_exists( 'date', $this->m_params ) ) $formatssrc = 'var formats = \'ex:formats="date { mode:' . $this->m_params['date'] . '; show:date }"\';';
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
334
335
		// create a URL pointing to the corresponding JSON feed
336
        $label = '';
337
		$JSONlink = $res->getQueryLink( $label );
0 ignored issues
show
Deprecated Code introduced by
The method SMWQueryResult::getQueryLink() has been deprecated with message: since SMW 1.8

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
338
		if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) { // used as a file name
339
			$link->setParameter( $this->getSearchLabel( SMW_OUTPUT_WIKI ), 'searchlabel' );
340
		}
341
		if ( array_key_exists( 'limit', $this->m_params ) ) {
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
342
			$JSONlink->setParameter( htmlspecialchars( $this->m_params['limit'] ), 'limit' );
0 ignored issues
show
Deprecated Code introduced by
The property SMW\ResultPrinter::$m_params has been deprecated with message: Use $params instead. Will be removed in 1.10.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
343
		}
344
		$JSONlink->setParameter( 'json', 'format' );
345
		$stringtoedit = explode( "|", $JSONlink->getText( $outputmode, $this->mLinker ) );
346
		$stringtoedit = substr( $stringtoedit[0], 3 );
347
		$JSONlinksrc = "var JSONlink = '" . $stringtoedit . "';";
348
349
		// create script header with variables containing the Exhibit markup
350
		$headervars = "<script type='text/javascript'>\n\t\t\t" . $facetsrc . "\n\t\t\t" . $viewsrc . "\n\t\t\t" . $lenssrc . "\n\t\t\t" . $stylesrc . "\n\t\t\t" . $formatssrc . "\n\t\t\t" . $JSONlinksrc . "\n\t\t\t var remote=" . $varremote . ";</script>";
351
352
353
		// To run Exhibit some links to the scripts of the API need to be included in the header
354
355
		$ExhibitScriptSrc1 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/exhibit/exhibit-api.js?autoCreate=false&safe=true&bundle=false';
356
		if ( $timeline ) $ExhibitScriptSrc1 .= '&views=timeline';
357
		if ( $map ) $ExhibitScriptSrc1 .= '&gmapkey=' . $wgGoogleMapsKey;
358
		$ExhibitScriptSrc1 .= '"></script>';
359
		$ExhibitScriptSrc2 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.js"></script>';
360
		$CSSSrc = '<link rel="stylesheet" type="text/css" href="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.css"></link>';
361
362
		SMWOutputs::requireHeadItem( 'CSS', $CSSSrc ); // include CSS
363
		SMWOutputs::requireHeadItem( 'EXHIBIT1', $ExhibitScriptSrc1 ); // include Exhibit API
364
		SMWOutputs::requireHeadItem( 'EXHIBIT2', $ExhibitScriptSrc2 ); // includes javascript overwriting the Exhibit start-up functions
365
		SMWOutputs::requireHeadItem( 'SOURCES' . $smwgIQRunningNumber, $sourcesrc );// include sources variable
366
		SMWOutputs::requireHeadItem( 'VIEWSFACETS', $headervars );// include views and facets variable
367
368
369
		if ( !$remote ) {
370
371
		// print input table
372
		// print header
373
		if ( 'broadtable' == $this->mFormat ) $widthpara = ' width="100%"';
374
		else $widthpara = '';
375
		$result = "<table style=\"display:none\" class=\"smwtable\" id=\"querytable" . $smwgIQRunningNumber . "\">\n";
376
		if ( $this->mShowHeaders ) { // building headers
377
			$result .= "\t<tr>\n";
378
			foreach ( $res->getPrintRequests() as $pr ) {
379
				if ( $pr->getText( $outputmode, $this->getLinker( 0 ) ) == '' ) $headerlabel = "Name";
380
				else $headerlabel = $pr->getText( $outputmode, $this->getLinker( 0 ) );
381
				$result .= "\t\t<th>" . $headerlabel . "</th>\n";
382
			}
383
			$result .= "\t</tr>\n";
384
		}
385
386
		// print all result rows
387
		while ( $row = $res->getNext() ) {
388
			$result .= "\t<tr>\n";
389
			foreach ( $row as $field ) {
390
				$result .= "\t\t<td>";
391
				$textstack = [];
392
				while ( ( $object = $field->getNextDataValue() ) !== false ) {
393
					switch( $object->getTypeID() ) {
394
						case '_wpg':
395
							$textstack[] = $object->getLongText( $outputmode, $this->getLinker( 0 ) );
396
							break;
397
						case '_geo':
398
							$c = $object->getDBKeys();
399
							$textstack[] = $c[0] . "," . $c[1];
400
							break;
401
						case '_num':
402
							if ( method_exists( $object, 'getValueKey' ) ) {
403
								$textstack[] = $object->getValueKey( $outputmode, $this->getLinker( 0 ) );
404
							}
405
							else {
406
								$textstack[] = $object->getNumericValue( $outputmode, $this->getLinker( 0 ) );
407
							}
408
							break;
409
						case '_dat':
410
							$textstack[] = $object->getYear() . "-" . str_pad( $object->getMonth(), 2, '0', STR_PAD_LEFT ) . "-" . str_pad( $object->getDay(), 2, '0', STR_PAD_LEFT ) . " " . $object->getTimeString();
411
							break;
412
						case '_ema':
413
							$textstack[] =  $object->getShortWikiText( $this->getLinker( 0 ) );
414
							break;
415
						case '_tel': case '_anu': case '_uri':
416
							$textstack[] = $object->getWikiValue();
417
							break;
418
						case '__sin':
419
							$tmp = $object->getShortText( $outputmode, null );
420
							if ( strpos( $tmp, ":" ) ) {
421
								$tmp = explode( ":", $tmp, 2 );
422
								$tmp = $tmp[1];
423
							}
424
							$textstack[] = $tmp;
425
							break;
426
						case '_txt': case '_cod': case '_str':
427
							$textstack[] = $object->getWikiValue();
428
							break;
429
						default:
430
							$textstack[] = $object->getLongHTMLText( $this->getLinker( 0 ) );
431
					}
432
				}
433
434
				if ( $textstack != null ) {
435
					$result .= implode( ';', $textstack ) . "</td>\n";
436
				}
437
				else $result .= "</td>\n";
438
			}
439
			$result .= "\t</tr>\n";
440
		}
441
		$result .= "</table>\n"; }
442
443
		if ( SRFExhibit::$exhibitRunningNumber == 0 ) $result .= "<div id=\"exhibitLocation\"></div>"; // print placeholder (just print it one time)
444
		$this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed
445
		SRFExhibit::$exhibitRunningNumber++;
446
		return $result;
447
	}
448
449
	/**
450
	 * @see SMWResultPrinter::getParamDefinitions
451
	 *
452
	 * @since 1.8
453
	 *
454
	 * @param $definitions array of IParamDefinition
455
	 *
456
	 * @return array of IParamDefinition|array
457
	 */
458
	public function getParamDefinitions( array $definitions ) {
459
		$params = parent::getParamDefinitions( $definitions );
460
461
		$params[] = [ 'name' => 'views', 'message' => 'srf_paramdesc_views', 'islist' => true, 'values' => [ 'tiles', 'tabular', 'timeline', 'maps' ] ];
462
		$params[] = [ 'name' => 'facets', 'message' => 'srf_paramdesc_facets' ];
463
		$params[] = [ 'name' => 'lens', 'message' => 'srf_paramdesc_lens' ];
464
465
		return $params;
466
	}
467
468
}
469