r98379 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98378‎ | r98379 | r98380 >
Date:22:47, 28 September 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
clean up Html::inlineScript usage
* ResourceLoader::makeLoaderConditionalScript:
-- window.mediaWiki -> window.mw; Not just because it's shorter but because that's the variable that is actually being used inside the script.
* ProtectionForm::buildCleanupScript
-- Use a single quote string and no new line
-- Use ResourceLoader::makeLoaderConditionalScript instead of duplicating this logic everywhere
* ProtectionForm::buildCleanupScript:
-- Use Xml::encodeJsCall to render javascript code
-- Use ResourceLoader::makeLoaderConditionalScript
-- Fix bug 31230 by using the new OutputPage->addJsConfigVars( r98374 )
(had to use $wgOut for now since there wasn't an obvious route to a context that I could find here (Article has context, but ProtectionForm::__construct takes any WikiPage, not just Article)
* EditPage::getEditToolbar:
-- Use Xml::encodeJsCall
-- Use ResourceLoader::makeLoaderConditionalScript

Fixes:
* (bug 31230) ProtectionForm should set wgCascadeableLevels in mw.confg instead of globally
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ProtectionForm.php
@@ -576,25 +576,26 @@
577577 }
578578
579579 function buildCleanupScript() {
580 - global $wgRestrictionLevels, $wgGroupPermissions;
581 - $script = 'var wgCascadeableLevels=';
582 - $CascadeableLevels = array();
 580+ global $wgRestrictionLevels, $wgGroupPermissions, $wgOut;
 581+
 582+ $cascadeableLevels = array();
583583 foreach( $wgRestrictionLevels as $key ) {
584 - if ( (isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect']) || $key == 'protect' ) {
585 - $CascadeableLevels[] = "'" . Xml::escapeJsString( $key ) . "'";
 584+ if ( ( isset( $wgGroupPermissions[$key]['protect'] ) && $wgGroupPermissions[$key]['protect'] )
 585+ || $key == 'protect'
 586+ ) {
 587+ $cascadeableLevels[] = $key;
586588 }
587589 }
588 - $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
589 - $options = (object)array(
 590+ $options = array(
590591 'tableId' => 'mwProtectSet',
591 - 'labelText' => wfMsg( 'protect-unchain-permissions' ),
592 - 'numTypes' => count($this->mApplicableTypes),
593 - 'existingMatch' => 1 == count( array_unique( $this->mExistingExpiry ) ),
 592+ 'labelText' => wfMessage( 'protect-unchain-permissions' )->plain(),
 593+ 'numTypes' => count( $this->mApplicableTypes ),
 594+ 'existingMatch' => count( array_unique( $this->mExistingExpiry ) ) === 1,
594595 );
595 - $encOptions = Xml::encodeJsVar( $options );
596596
597 - $script .= "ProtectionForm.init($encOptions)";
598 - return Html::inlineScript( "if ( window.mediaWiki ) { $script }" );
 597+ $wgOut->addJsConfigVars( 'wgCascadeableLevels', $cascadeableLevels );
 598+ $script = Xml::encodeJsCall( 'ProtectionForm.init', array( $options ) );
 599+ return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) );
599600 }
600601
601602 /**
Index: trunk/phase3/includes/EditPage.php
@@ -2539,7 +2539,6 @@
25402540 'key' => 'R'
25412541 )
25422542 );
2543 - $toolbar = "<div id='toolbar'>\n";
25442543
25452544 $script = '';
25462545 foreach ( $toolarray as $tool ) {
@@ -2560,15 +2559,11 @@
25612560 $cssId = $tool['id'],
25622561 );
25632562
2564 - $paramList = implode( ',',
2565 - array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
2566 - $script .= "mw.toolbar.addButton($paramList);\n";
 2563+ $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
25672564 }
2568 - $wgOut->addScript( Html::inlineScript(
2569 - "if ( window.mediaWiki ) {{$script}}"
2570 - ) );
 2565+ $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
25712566
2572 - $toolbar .= "\n</div>";
 2567+ $toolbar = '<div id="toolbar"></div>';
25732568
25742569 wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
25752570
Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -812,7 +812,7 @@
813813 */
814814 public static function makeLoaderConditionalScript( $script ) {
815815 $script = str_replace( "\n", "\n\t", trim( $script ) );
816 - return "if ( window.mediaWiki ) {\n\t$script\n}\n";
 816+ return "if(window.mw){\n\t$script\n}\n";
817817 }
818818
819819 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r99989REL1_18:...reedy22:24, 16 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98374New OutputPage::addJsConfigVars() method (bug 31233)...krinkle22:08, 28 September 2011

Comments

#Comment by Krinkle (talk | contribs)   22:50, 28 September 2011

Because of bug 31230 (which first occurred in 1.18), should be back ported to REL1_18. Not needed in 1.18wmf1.

I'm not sure how it merges though...

#Comment by Catrope (talk | contribs)   15:19, 3 October 2011

This is definitely not gonna merge without r98374, which was not tagged 1.18

Status & tagging log