Index: trunk/extensions/SemanticResultFormats/Exhibit/SRF_Exhibit.js |
— | — | @@ -119,6 +119,53 @@ |
120 | 120 | window.exhibit.configureFromDOM(); |
121 | 121 | } |
122 | 122 | |
123 | | -addOnloadHook(createExhibit); |
| 123 | +// add any onload functions in this hook (please don't hard-code any events in the xhtml source) |
| 124 | +var doneExhibitOnloadHook; |
124 | 125 | |
| 126 | +if (!window.exhibitOnloadFuncts) { |
| 127 | + var exhibitOnloadFuncts = []; |
| 128 | +} |
125 | 129 | |
| 130 | +function addExhibitOnloadHook(hookFunct) { |
| 131 | + // Allows add-on scripts to add onload functions |
| 132 | + if(!doneExhibitOnloadHook) { |
| 133 | + exhibitOnloadFuncts[exhibitOnloadFuncts.length] = hookFunct; |
| 134 | + } else { |
| 135 | + hookFunct(); // bug in MSIE script loading |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +addExhibitOnloadHandler(window, "load", |
| 140 | + function () { |
| 141 | + // don't run anything below this for non-dom browsers |
| 142 | + if (doneExhibitOnloadHook || !(document.getElementById && document.getElementsByTagName)) { |
| 143 | + return; |
| 144 | + } |
| 145 | + |
| 146 | + // set this before running any hooks, since any errors below |
| 147 | + // might cause the function to terminate prematurely |
| 148 | + doneExhibitOnloadHook = true; |
| 149 | + |
| 150 | + // Run any added-on functions |
| 151 | + for (var i = 0; i < exhibitOnloadFuncts.length; i++) { |
| 152 | + exhibitOnloadFuncts[i](); |
| 153 | + } |
| 154 | + } |
| 155 | +); |
| 156 | + |
| 157 | +/** |
| 158 | + * Add an event handler to an element |
| 159 | + * |
| 160 | + * @param Element element Element to add handler to |
| 161 | + * @param String attach Event to attach to |
| 162 | + * @param callable handler Event handler callback |
| 163 | + */ |
| 164 | +function addExhibitOnloadHandler( element, attach, handler ) { |
| 165 | + if( window.addEventListener ) { |
| 166 | + element.addEventListener( attach, handler, false ); |
| 167 | + } else if( window.attachEvent ) { |
| 168 | + element.attachEvent( 'on' + attach, handler ); |
| 169 | + } |
| 170 | +} |
| 171 | + |
| 172 | +addExhibitOnloadHook(createExhibit); |
Index: trunk/extensions/SemanticResultFormats/Exhibit/SRF_Exhibit.php |
— | — | @@ -12,26 +12,33 @@ |
13 | 13 | * @ingroup SMWQuery |
14 | 14 | */ |
15 | 15 | class SRFExhibit extends SMWResultPrinter { |
16 | | - // /mapping between SMW's and Exhibit's the data types |
17 | | - protected $m_types = array( "_wpg" => "text", "_num" => "number", "_dat" => "date", "_geo" => "text", "_uri" => "url" ); |
| 16 | + |
| 17 | + // mapping between SMW's and Exhibit's the data types |
| 18 | + protected $m_types = array( |
| 19 | + '_wpg' => 'text', |
| 20 | + '_num' => 'number', |
| 21 | + '_dat' => 'date', |
| 22 | + '_geo' => 'text', |
| 23 | + '_uri' => 'url' |
| 24 | + ); |
18 | 25 | |
19 | 26 | protected static $exhibitRunningNumber = 0; // not sufficient since there might be multiple pages rendered within one PHP run; but good enough now |
20 | 27 | |
21 | | - // /overwrite function to allow execution of result printer even if no results are available (in case remote query yields no results in local wiki) |
22 | | - public function getResult( $results, $params, $outputmode ) { |
| 28 | + // Overwrite function to allow execution of result printer even if no results are available (in case remote query yields no results in local wiki) |
| 29 | + public function getResult( SMWQueryResult $results, array $params, $outputmode ) { |
23 | 30 | $this->readParameters( $params, $outputmode ); |
24 | | - $result = $this->getResultText( $results, $outputmode ); |
25 | | - return $result; |
| 31 | + return $this->getResultText( $results, $outputmode ); |
26 | 32 | } |
27 | 33 | |
28 | | - // /function aligns the format of SMW's property names to Exhibit's format |
| 34 | + // Function aligns the format of SMW's property names to Exhibit's format |
29 | 35 | protected function encodePropertyName( $property ) { |
30 | | - return strtolower( str_replace( " ", "_", trim( $property ) ) ); |
| 36 | + return strtolower( str_replace( ' ', '_', trim( $property ) ) ); |
31 | 37 | } |
32 | 38 | |
33 | | - // /Tries to determine the namespace in the event it got lost |
| 39 | + // Tries to determine the namespace in the event it got lost |
34 | 40 | protected function determineNamespace( $res ) { |
35 | 41 | $row = $res->getNext(); |
| 42 | + |
36 | 43 | if ( $row != null ) { |
37 | 44 | $tmp = clone $row[0]; |
38 | 45 | $object = efSRFGetNextDV( $tmp ); |
— | — | @@ -43,13 +50,14 @@ |
44 | 51 | return $value[0] . ':'; |
45 | 52 | } |
46 | 53 | } |
47 | | - return ""; |
| 54 | + |
| 55 | + return ''; |
48 | 56 | } |
49 | 57 | } |
50 | 58 | |
51 | 59 | protected function getResultText( SMWQueryResult $res, $outputmode ) { |
52 | 60 | |
53 | | - global $smwgIQRunningNumber, $wgScriptPath, $wgGoogleMapsKey, $srfgScriptPath; |
| 61 | + global $smwgIQRunningNumber, $wgScriptPath, $srfgScriptPath; |
54 | 62 | |
55 | 63 | // ////////////////////////////// |
56 | 64 | // ///////REMOTE STUFF/////////// |
— | — | @@ -210,24 +218,30 @@ |
211 | 219 | $viewstack[] = 'ex:role=\'view\' ex:viewClass=\'Timeline\' ex:label=\'Timeline\' ex:showSummary=\'false\' ' . implode( " ", $tlparams ); |
212 | 220 | break; |
213 | 221 | case 'map':// map view |
214 | | - if ( isset( $wgGoogleMapsKey ) ) { |
215 | | - $map = true; |
216 | | - $exparams = array( 'latlng', 'colorkey' ); |
217 | | - $usparams = array( 'type', 'center', 'zoom', 'size', 'scalecontrol', 'overviewcontrol', 'mapheight' ); |
218 | | - $mapparams = array(); |
219 | | - foreach ( $exparams as $param ) { |
220 | | - if ( array_key_exists( $param, $this->m_params ) ) $mapparams[] = 'ex:' . $param . '=\'.' . $this->encodePropertyName( $this->m_params[$param] ) . '\' '; |
221 | | - } |
222 | | - foreach ( $usparams as $param ) { |
223 | | - if ( array_key_exists( $param, $this->m_params ) ) $mapparams[] = 'ex:' . $param . '=\'' . $this->encodePropertyName( $this->m_params[$param] ) . '\' '; |
224 | | - } |
225 | | - if ( !array_key_exists( 'start', $this->m_params ) && !array_key_exists( 'end', $this->m_params ) ) { // find out if a geographic coordinate is available |
226 | | - foreach ( $res->getPrintRequests() as $pr ) { |
227 | | - if ( $pr->getTypeID() == '_geo' ) { |
228 | | - $mapparams[] = 'ex:latlng=\'.' . $this->encodePropertyName( $pr->getLabel() ) . '\' '; |
229 | | - break; |
| 222 | + global $egGoogleMapsKey; |
| 223 | + |
| 224 | + if ( isset( $egGoogleMapsKey ) ) { |
| 225 | + |
| 226 | + $map = true; |
| 227 | + $exparams = array( 'latlng', 'colorkey' ); |
| 228 | + $usparams = array( 'type', 'center', 'zoom', 'size', 'scalecontrol', 'overviewcontrol', 'mapheight' ); |
| 229 | + $mapparams = array(); |
| 230 | + |
| 231 | + foreach ( $exparams as $param ) { |
| 232 | + if ( array_key_exists( $param, $this->m_params ) ) $mapparams[] = 'ex:' . $param . '=\'.' . $this->encodePropertyName( $this->m_params[$param] ) . '\' '; |
| 233 | + } |
| 234 | + |
| 235 | + foreach ( $usparams as $param ) { |
| 236 | + if ( array_key_exists( $param, $this->m_params ) ) $mapparams[] = 'ex:' . $param . '=\'' . $this->encodePropertyName( $this->m_params[$param] ) . '\' '; |
| 237 | + } |
| 238 | + |
| 239 | + if ( !array_key_exists( 'start', $this->m_params ) && !array_key_exists( 'end', $this->m_params ) ) { // find out if a geographic coordinate is available |
| 240 | + foreach ( $res->getPrintRequests() as $pr ) { |
| 241 | + if ( $pr->getTypeID() == '_geo' ) { |
| 242 | + $mapparams[] = 'ex:latlng=\'.' . $this->encodePropertyName( $pr->getLabel() ) . '\' '; |
| 243 | + break; |
| 244 | + } |
230 | 245 | } |
231 | | - } |
232 | 246 | } |
233 | 247 | $viewstack[] .= 'ex:role=\'view\' ex:viewClass=\'Map\' ex:showSummary=\'false\' ex:label=\'Map\' ' . implode( " ", $mapparams ); |
234 | 248 | } |
— | — | @@ -341,23 +355,10 @@ |
342 | 356 | $stringtoedit = substr( $stringtoedit[0], 3 ); |
343 | 357 | $JSONlinksrc = "var JSONlink = '" . $stringtoedit . "';"; |
344 | 358 | |
| 359 | + $this->includeJS( $timeline, $map ); |
| 360 | + |
345 | 361 | // create script header with variables containing the Exhibit markup |
346 | 362 | $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>"; |
347 | | - |
348 | | - |
349 | | - // To run Exhibit some links to the scripts of the API need to be included in the header |
350 | | - |
351 | | - $ExhibitScriptSrc1 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/exhibit/exhibit-api.js?autoCreate=false&safe=true&bundle=false'; |
352 | | - if ( $timeline ) $ExhibitScriptSrc1 .= '&views=timeline'; |
353 | | - if ( $map ) $ExhibitScriptSrc1 .= '&gmapkey=' . $wgGoogleMapsKey; |
354 | | - $ExhibitScriptSrc1 .= '"></script>'; |
355 | | - $ExhibitScriptSrc2 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.js"></script>'; |
356 | | - $CSSSrc = '<link rel="stylesheet" type="text/css" href="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.css"></link>'; |
357 | | - |
358 | | - SMWOutputs::requireHeadItem( 'CSS', $CSSSrc ); // include CSS |
359 | | - SMWOutputs::requireHeadItem( 'EXHIBIT1', $ExhibitScriptSrc1 ); // include Exhibit API |
360 | | - SMWOutputs::requireHeadItem( 'EXHIBIT2', $ExhibitScriptSrc2 ); // includes javascript overwriting the Exhibit start-up functions |
361 | | - SMWOutputs::requireHeadItem( 'SOURCES' . $smwgIQRunningNumber, $sourcesrc );// include sources variable |
362 | 363 | SMWOutputs::requireHeadItem( 'VIEWSFACETS', $headervars );// include views and facets variable |
363 | 364 | |
364 | 365 | |
— | — | @@ -435,18 +436,75 @@ |
436 | 437 | } |
437 | 438 | $result .= "</table>\n"; } |
438 | 439 | |
439 | | - if ( SRFExhibit::$exhibitRunningNumber == 0 ) $result .= "<div id=\"exhibitLocation\"></div>"; // print placeholder (just print it one time) |
| 440 | + if ( SRFExhibit::$exhibitRunningNumber == 0 ) { |
| 441 | + $result .= "<div id=\"exhibitLocation\"></div>"; // print placeholder (just print it one time) |
| 442 | + } |
| 443 | + |
440 | 444 | $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed |
441 | 445 | SRFExhibit::$exhibitRunningNumber++; |
| 446 | + |
442 | 447 | return $result; |
443 | 448 | } |
444 | 449 | |
445 | 450 | public function getParameters() { |
446 | 451 | $params = parent::getParameters(); |
| 452 | + |
447 | 453 | $params[] = array( 'name' => 'views', 'type' => 'enum-list', 'description' => wfMsg( 'srf_paramdesc_views' ), 'values' => array( 'tiles', 'tabular', 'timeline', 'maps' ) ); |
448 | 454 | $params[] = array( 'name' => 'facets', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_facets' ) ); |
449 | 455 | $params[] = array( 'name' => 'lens', 'type' => 'string', 'description' => wfMsg( 'srf_paramdesc_lens' ) ); |
| 456 | + |
450 | 457 | return $params; |
451 | 458 | } |
452 | 459 | |
| 460 | + /** |
| 461 | + * Includes the JavaScript required for the timeline and eventline formats. |
| 462 | + * |
| 463 | + * @since 1.6 |
| 464 | + */ |
| 465 | + protected function includeJS( $timeline, $map ) { |
| 466 | + global $srfgScriptPath, $egGoogleMapsKey; |
| 467 | + |
| 468 | + $ExhibitScriptSrc1 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/exhibit/exhibit-api.js?autoCreate=false&safe=true&bundle=false'; |
| 469 | + if ( $timeline ) $ExhibitScriptSrc1 .= '&views=timeline'; |
| 470 | + if ( $map ) $ExhibitScriptSrc1 .= '&gmapkey=' . $egGoogleMapsKey; |
| 471 | + $ExhibitScriptSrc1 .= '"></script>'; |
| 472 | + |
| 473 | + SMWOutputs::requireHeadItem( 'EXHIBIT1', $ExhibitScriptSrc1 ); // include Exhibit API |
| 474 | + |
| 475 | + // MediaWiki 1.17 introduces the Resource Loader. |
| 476 | + $realFunction = array( 'SMWOutputs', 'requireResource' ); |
| 477 | + if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) && is_callable( $realFunction ) ) { |
| 478 | + SMWOutputs::requireResource( 'ext.srf.exhibit' ); |
| 479 | + } |
| 480 | + else { |
| 481 | + $ExhibitScriptSrc2 = '<script type="text/javascript" src="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.js"></script>'; |
| 482 | + $CSSSrc = '<link rel="stylesheet" type="text/css" href="' . $srfgScriptPath . '/Exhibit/SRF_Exhibit.css"></link>'; |
| 483 | + |
| 484 | + SMWOutputs::requireHeadItem( 'CSS', $CSSSrc ); // include CSS |
| 485 | + SMWOutputs::requireHeadItem( 'EXHIBIT2', $ExhibitScriptSrc2 ); // includes javascript overwriting the Exhibit start-up functions |
| 486 | + SMWOutputs::requireHeadItem( 'SOURCES' . $smwgIQRunningNumber, $sourcesrc );// include sources variable |
| 487 | + } |
| 488 | + } |
| 489 | + |
| 490 | + /** |
| 491 | + * Register the resource modules used by this result printer. |
| 492 | + * |
| 493 | + * @since 1.6 |
| 494 | + */ |
| 495 | + public static function registerResourceModules() { |
| 496 | + global $wgResourceModules, $srfgScriptPath; |
| 497 | + |
| 498 | + $moduleTemplate = array( |
| 499 | + 'localBasePath' => dirname( __FILE__ ), |
| 500 | + 'remoteBasePath' => $srfgScriptPath . '/Exhibit', |
| 501 | + 'group' => 'ext.srf' |
| 502 | + ); |
| 503 | + |
| 504 | + $wgResourceModules['ext.srf.exhibit'] = $moduleTemplate + array( |
| 505 | + 'scripts' => array( 'SRF_Exhibit.js' ), |
| 506 | + 'styles' => array( 'SRF_Exhibit.css' ), |
| 507 | + 'dependencies' => array( 'mediawiki.legacy.wikibits' ) |
| 508 | + ); |
| 509 | + } |
| 510 | + |
453 | 511 | } |
Index: trunk/extensions/SemanticResultFormats/Timeline/SRF_Timeline.php |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | |
126 | 126 | // MediaWiki 1.17 introduces the Resource Loader. |
127 | 127 | $realFunction = array( 'SMWOutputs', 'requireResource' ); |
128 | | - if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) && is_callable( $realFunction ) ) { |
| 128 | + if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) && is_callable( $realFunction ) ) { |
129 | 129 | SMWOutputs::requireResource( 'ext.srf.timeline' ); |
130 | 130 | } |
131 | 131 | else { |