r95177 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95176‎ | r95177 | r95178 >
Date:19:37, 21 August 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
use SMWOutputs instead of directly writing to wgOut (and using additional variables for avoiding duplicated scripts)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUI.php
@@ -171,16 +171,12 @@
172172 }
173173
174174 /**
175 - * Enable auto completion scripts and styles for the current output
176 - * page $wgOut.
177 - *
178 - * @global OutputPage $wgOut
 175+ * Enable auto completion scripts and styles.
179176 */
180177 protected function enableAutocompletion() {
181 - global $wgOut;
182 - if ( $this->autoCompleteEnabled == false ) {
183 - SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
184 - $javascriptAutocompleteText = <<<END
 178+ SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
 179+
 180+ $javascriptAutocompleteText = <<<END
185181 <script type="text/javascript">
186182 function smw_split( val ) {
187183 return val.split( '\\n' );
@@ -226,9 +222,8 @@
227223 </script>
228224 END;
229225
230 - $wgOut->addScript( $javascriptAutocompleteText );
231 - $this->autoCompleteEnabled = true;
232 - }
 226+ SMWOutputs::requireScript( 'smwAutocompleteQueryUICore', $javascriptAutocompleteText );
 227+
233228 }
234229
235230 /**
@@ -326,12 +321,11 @@
327322 * complement processQueryFormBox() to decode data sent through these elements.
328323 * UI's may overload both to change form parameters.
329324 *
330 - * @global OutputPage $wgOut
331325 * @global string $smwgScriptPath
332326 * @return string
333327 */
334328 protected function getQueryFormBox() {
335 - global $wgOut, $smwgScriptPath;
 329+ global $smwgScriptPath;
336330 $this->setUrlArgs( array( 'q' => $this->uiCore->getQueryString() ) );
337331 $result = '<div>' .
338332 Html::element( 'textarea',
@@ -499,14 +493,13 @@
500494 * @global boolean $smwgQSortingSupport
501495 * @global boolean $smwgQRandSortingSupport
502496 * @global WebRequest $wgRequest
503 - * @global OutputPage $wgOut
504497 * @global string $smwgScriptPath
505498 * @global integer $smwgQPrintoutLimit
506499 * @param mixed $enableAutocomplete
507500 * @return string
508501 */
509502 protected function getPoSortFormBox( $enableAutocomplete = SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
510 - global $smwgQSortingSupport, $wgRequest, $wgOut, $smwgScriptPath;
 503+ global $smwgQSortingSupport, $wgRequest, $smwgScriptPath;
511504 global $smwgQRandSortingSupport, $smwgQPrintoutLimit;
512505
513506 SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
@@ -1407,7 +1400,7 @@
14081401
14091402 EOT;
14101403
1411 - $wgOut->addScript( $javascriptText );
 1404+ SMWOutputs::requireScript( 'smwAutocompleteQueryUI', $javascriptText );
14121405 $result .= '</span>';
14131406 return $result;
14141407 }
@@ -1419,13 +1412,12 @@
14201413 *
14211414 * @global boolean $smwgQSortingSupport
14221415 * @global WebRequest $wgRequest
1423 - * @global OutputPage $wgOut
14241416 * @return string
14251417 *
14261418 * @todo This code is not used anywhere in SMW.
14271419 */
14281420 protected function getSortingFormBox() {
1429 - global $smwgQSortingSupport, $wgRequest, $wgOut;
 1421+ global $smwgQSortingSupport, $wgRequest;
14301422
14311423 if ( !$smwgQSortingSupport ) return '';
14321424 $params = $this->uiCore->getParameters();
@@ -1523,7 +1515,7 @@
15241516
15251517 EOT;
15261518
1527 - $wgOut->addScript( $javascriptText );
 1519+ SMWOutputs::requireScript( 'smwPrintoutControlsQueryUI', $javascriptText );
15281520 return $result;
15291521 }
15301522
@@ -1574,8 +1566,6 @@
15751567 * @return string The HTML code
15761568 */
15771569 protected function getPOFormBox( $enableAutocomplete = SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
1578 - global $wgOut;
1579 -
15801570 if ( $enableAutocomplete ) {
15811571 $this->enableAutocompletion();
15821572 $javascriptAutocompleteText = <<<EOT
@@ -1613,7 +1603,7 @@
16141604 </script>
16151605 EOT;
16161606
1617 - $wgOut->addScript( $javascriptAutocompleteText );
 1607+ SMWOutputs::requireScript( 'smwPrintoutAutocompleteQueryUI', $javascriptAutocompleteText );
16181608
16191609 }
16201610 $this->setUrlArgs( array( 'po' => $this->getPOStrings() ) );
@@ -1790,7 +1780,7 @@
17911781 * @return array The first element contains the format selector, while the second contains the Format options
17921782 */
17931783 protected function getFormatSelectBoxSep( $defaultFormat = 'broadtable' ) {
1794 - global $smwgResultFormats, $wgOut;
 1784+ global $smwgResultFormats;
17951785
17961786 SMWOutputs::requireResource( 'jquery' );
17971787
@@ -1843,7 +1833,7 @@
18441834 </script>
18451835 END;
18461836
1847 - $wgOut->addScript( $javascript );
 1837+ SMWOutputs::requireScript( 'smwUpdateOptionsQueryUI', $javascript );
18481838 // END: add javascript for updating formating options by ajax
18491839
18501840 return $result;
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -102,13 +102,9 @@
103103 /**
104104 * Create the search form.
105105 *
106 - * @global OutputPage $wgOut
107 - * @global string $smwgScriptPath
108106 * @return string HTML code for search form
109107 */
110108 protected function makeForm() {
111 - global $wgOut, $smwgScriptPath;
112 -
113109 SMWOutputs::requireResource( 'jquery' );
114110
115111 $specTitle = $this->getTitle();
@@ -185,7 +181,7 @@
186182 } );
187183 </script>
188184 EOT;
189 - $wgOut->addScript( $javascriptText );
 185+ SMWOutputs::requireScript( 'smwToggleAskSyntaxQC', $javascriptText );
190186 }
191187
192188 $result .= '<input type="hidden" name="eq" value="no"/>' .
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialSearchByProperty.php
@@ -416,8 +416,6 @@
417417 *
418418 */
419419 protected static function addAutoComplete() {
420 - global $wgOut;
421 -
422420 SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
423421
424422 $javascript_autocomplete_text = <<<END
@@ -438,7 +436,7 @@
439437
440438 END;
441439
442 - $wgOut->addScript( $javascript_autocomplete_text );
 440+ SMWOutputs::requireScript( 'smwAutocompleteSpecialSearchByProperty', $javascript_autocomplete_text );
443441 }
444442
445443 }
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -393,8 +393,6 @@
394394 * MW API to fetch suggestions.
395395 */
396396 private static function addAutoComplete(){
397 - global $wgOut;
398 -
399397 SMWOutputs::requireResource( 'jquery.ui.autocomplete' );
400398
401399 $javascript_autocomplete_text = <<<END
@@ -413,7 +411,7 @@
414412
415413 END;
416414
417 - $wgOut->addScript( $javascript_autocomplete_text );
 415+ SMWOutputs::requireScript( 'smwAutocompleteSpecialBrowse', $javascript_autocomplete_text );
418416 }
419417
420418 /**