Index: trunk/extensions/SemanticMediaWiki/includes/SMW_OldDataValue.php |
— | — | @@ -314,6 +314,7 @@ |
315 | 315 | } |
316 | 316 | // add tooltip (only if "linking" is enabled) |
317 | 317 | if ( ($linked !== NULL) && ($linked !==false) && ($this->getTooltip() != '') ) { |
| 318 | + smwfRequireHeadItem(SMW_SCRIPT_TOOLTIP); |
318 | 319 | $result = '<span class="smwttinline">' . $result . '<span class="smwttcontent">' . $this->getTooltip() . '</span></span>'; |
319 | 320 | } |
320 | 321 | return $result; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Table.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | |
13 | 13 | protected function getHTML($res) { |
14 | 14 | global $smwgIQRunningNumber; |
| 15 | + smwfRequireHeadItem(SMW_SCRIPT_SORTTABLE); |
15 | 16 | |
16 | 17 | // print header |
17 | 18 | if ('broadtable' == $this->mFormat) |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php |
— | — | @@ -115,6 +115,7 @@ |
116 | 116 | if ( ($linked === NULL)||($linked === false) ) { |
117 | 117 | return mb_substr($this->m_value, 0, 42) . ' <span class="smwwarning">…</span> ' . mb_substr($this->m_value, $len - 42); |
118 | 118 | } else { |
| 119 | + smwfRequireHeadItem(SMW_SCRIPT_TOOLTIP); |
119 | 120 | return mb_substr($this->m_value, 0, 42) . ' <span class="smwttpersist"> … <span class="smwttcontent">' . $this->m_value . '</span></span> ' . mb_substr($this->m_value, $len - 42); |
120 | 121 | } |
121 | 122 | } else { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_Timeline.php |
— | — | @@ -46,6 +46,7 @@ |
47 | 47 | |
48 | 48 | public function getHTML($res) { |
49 | 49 | global $smwgIQRunningNumber; |
| 50 | + smwfRequireHeadItem(SMW_SCRIPT_TIMELINE); //make sure JavaScripts are available |
50 | 51 | |
51 | 52 | $eventline = ('eventline' == $this->mFormat); |
52 | 53 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -26,6 +26,13 @@ |
27 | 27 | define('SMW_FACTBOX_NONEMPTY', 3); |
28 | 28 | define('SMW_FACTBOX_SHOWN', 5); |
29 | 29 | |
| 30 | +// constants for identifying javascripts as used in smwfRequireHeadItem |
| 31 | +define('SMW_SCRIPT_TIMELINE', 1); |
| 32 | +define('SMW_SCRIPT_TOOLTIP', 2); |
| 33 | +define('SMW_SCRIPT_SORTTABLE', 3); |
| 34 | +// HTML items to load in current page; format: "idtext => "<script ... " |
| 35 | +$smwgHeadItems = array(); |
| 36 | + |
30 | 37 | /** |
31 | 38 | * Switch on Semantic MediaWiki. This function must be called in LocalSettings.php |
32 | 39 | * after incldung this file. It is used to ensure that required parameters for SMW |
— | — | @@ -119,6 +126,7 @@ |
120 | 127 | $wgHooks['ParserBeforeStrip'][] = 'smwfRegisterInlineQueries'; // a hook for registering the <ask> parser hook |
121 | 128 | $wgHooks['ArticleFromTitle'][] = 'smwfShowListPage'; |
122 | 129 | $wgHooks['LoadAllMessages'][] = 'smwfLoadAllMessages'; // enable a complete display of all messages when requested by MW |
| 130 | + $wgHooks['ParserAfterTidy'][] = 'smwfInsertHTMLHeaders'; |
123 | 131 | |
124 | 132 | ///// credits (see "Special:Version") ///// |
125 | 133 | $wgExtensionCredits['parserhook'][]= array('name'=>'Semantic MediaWiki', 'version'=>SMW_VERSION, 'author'=>"Klaus Lassleben, Markus Krötzsch, Denny Vrandecic, S Page, and others. Maintained by [http://www.aifb.uni-karlsruhe.de/Forschungsgruppen/WBS/english AIFB Karlsruhe].", 'url'=>'http://ontoworld.org/wiki/Semantic_MediaWiki', 'description' => 'Making your wiki more accessible – for machines \'\'and\'\' humans. [http://ontoworld.org/wiki/Help:Semantics View online documentation.]'); |
— | — | @@ -140,7 +148,7 @@ |
141 | 149 | /** |
142 | 150 | * The <ask> parser hook processing part. |
143 | 151 | */ |
144 | | -function smwfProcessInlineQuery($text, $param) { |
| 152 | +function smwfProcessInlineQuery($text, $param, &$parser) { |
145 | 153 | global $smwgQEnabled, $smwgIP; |
146 | 154 | if ($smwgQEnabled) { |
147 | 155 | require_once($smwgIP . '/includes/SMW_QueryProcessor.php'); |
— | — | @@ -154,6 +162,50 @@ |
155 | 163 | /***** Header modifications *****/ |
156 | 164 | /**********************************************/ |
157 | 165 | |
| 166 | +/** |
| 167 | + * Hook function to insert HTML headers into parser output. |
| 168 | + */ |
| 169 | +function smwfInsertHTMLHeaders(&$parser, &$text) { |
| 170 | + global $smwgHeadItems; |
| 171 | + foreach ($smwgHeadItems as $item) { |
| 172 | + $parser->mOutput->addHeadItem($item); |
| 173 | + } |
| 174 | + $smwgHeadItems = array(); // flush array |
| 175 | + return true; |
| 176 | +} |
| 177 | + |
| 178 | +/** |
| 179 | + * Add a head item (e.g. JavaScript) to the current list of things that |
| 180 | + * SMW will add to the output page. This works only while a page is parsed. |
| 181 | + * The $id can be one of SMW's internal numerical IDs for builtin scripts, |
| 182 | + * or a non-numerical tag that uniquely identifies this item, followed by |
| 183 | + * the full HTML-text $item that is to be added. |
| 184 | + */ |
| 185 | +function smwfRequireHeadItem($id, $item='') { |
| 186 | + global $smwgHeadItems; |
| 187 | + if (is_numeric($id)) { //builtin head items |
| 188 | + global $smwgScriptPath; |
| 189 | + // Note: currently all scripts need the sorttable-script to work, and some tooltips require the timeline. |
| 190 | + // This is bad and will change. |
| 191 | + switch ($id) { |
| 192 | + case SMW_SCRIPT_TIMELINE: |
| 193 | + smwfRequireHeadItem(SMW_SCRIPT_SORTTABLE); |
| 194 | + $smwgHeadItems['smw_tl'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SimileTimeline/timeline-api.js"></script>'; |
| 195 | + $smwgHeadItems['smw_tlhelper'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_timeline.js"></script>'; |
| 196 | + return; |
| 197 | + case SMW_SCRIPT_TOOLTIP: |
| 198 | + smwfRequireHeadItem(SMW_SCRIPT_TIMELINE); |
| 199 | + $smwgHeadItems['smw_tt'] = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
| 200 | + return; |
| 201 | + case SMW_SCRIPT_SORTTABLE: |
| 202 | + $smwgHeadItems['smw_st'] ='<script type="text/javascript" id="SMW_sorttable_script_inclusion" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
| 203 | + return; |
| 204 | + } |
| 205 | + } else { // custom head items |
| 206 | + $smwgHeadItems[$id] = $item; |
| 207 | + } |
| 208 | +} |
| 209 | + |
158 | 210 | /** |
159 | 211 | * This method is in charge of inserting additional CSS, JScript, and meta tags |
160 | 212 | * into the html header of each page. It is either called after initialising wgout |
— | — | @@ -169,20 +221,31 @@ |
170 | 222 | global $smwgArticleHeadersInPlace; // record whether article name specific headers are already there |
171 | 223 | global $smwgScriptPath; |
172 | 224 | |
| 225 | + global $smwgHeadItems; |
| 226 | + |
| 227 | + // Fallback: add scripts to output if not done already (should happen only if we are |
| 228 | + // not using a parser, e.g on special pages. |
| 229 | + $i = 0; |
| 230 | + foreach ($smwgHeadItems as $item) { |
| 231 | + $out->addHeadItem("smw_$i", $item); |
| 232 | + $i++; |
| 233 | + } |
| 234 | + $smwgHeadItems = array(); // flush array |
| 235 | + |
173 | 236 | if (!$smwgHeadersInPlace) { |
174 | | - $sortTableScript = '<script type="text/javascript" id="SMW_sorttable_script_inclusion" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
175 | | - // The above id is essential for the JavaScript to find out the $smwgScriptPath to |
176 | | - // include images. Changes in the above must always be coordinated with the script! |
177 | | - $out->addScript($sortTableScript); |
| 237 | +// $sortTableScript = '<script type="text/javascript" id="SMW_sorttable_script_inclusion" src="' . $smwgScriptPath . '/skins/SMW_sorttable.js"></script>'; |
| 238 | +// // The above id is essential for the JavaScript to find out the $smwgScriptPath to |
| 239 | +// // include images. Changes in the above must always be coordinated with the script! |
| 240 | +// $out->addScript($sortTableScript); |
178 | 241 | |
179 | | - $toolTipScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
180 | | - $out->addScript($toolTipScript); |
| 242 | +// $toolTipScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_tooltip.js"></script>'; |
| 243 | +// $out->addScript($toolTipScript); |
181 | 244 | |
182 | 245 | // TODO: we should rather have a script that only pulls the whole Timeline on demand, if possible |
183 | | - $TimelineScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SimileTimeline/timeline-api.js"></script>'; |
184 | | - $SMWTimelineScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_timeline.js"></script>'; |
185 | | - $out->addScript($TimelineScript); |
186 | | - $out->addScript($SMWTimelineScript); |
| 246 | +// $TimelineScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SimileTimeline/timeline-api.js"></script>'; |
| 247 | +// $SMWTimelineScript = '<script type="text/javascript" src="' . $smwgScriptPath . '/skins/SMW_timeline.js"></script>'; |
| 248 | +// $out->addScript($TimelineScript); |
| 249 | +// $out->addScript($SMWTimelineScript); |
187 | 250 | |
188 | 251 | // Also we add a custom CSS file for our needs |
189 | 252 | $customCssUrl = $smwgScriptPath . '/skins/SMW_custom.css'; |
— | — | @@ -416,6 +479,7 @@ |
417 | 480 | */ |
418 | 481 | function smwfEncodeMessages($msgarray) { |
419 | 482 | if (count($msgarray) > 0) { |
| 483 | + smwfRequireHeadItem(SMW_SCRIPT_TOOLTIP); |
420 | 484 | $msgs = implode(' ', $msgarray); |
421 | 485 | return '<span class="smwttpersist"><span class="smwtticon">warning.png</span><span class="smwttcontent">' . $msgs . '</span></span>'; |
422 | 486 | } else { |