* 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
- $toolbar = "<div id='toolbar'>\n";
$script = '';
foreach ( $toolarray as $tool ) {
$script = '';
foreach ( $toolarray as $tool ) {
- $paramList = implode( ',',
- array_map( array( 'Xml', 'encodeJsVar' ), $params ) );
- $script .= "mw.toolbar.addButton($paramList);\n";
+ $script .= Xml::encodeJsCall( 'mw.toolbar.addButton', $params );
- $wgOut->addScript( Html::inlineScript(
- "if ( window.mediaWiki ) {{$script}}"
- ) );
+ $wgOut->addScript( Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ) );
- $toolbar .= "\n</div>";
+ $toolbar = '<div id="toolbar"></div>';
wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
wfRunHooks( 'EditPageBeforeEditToolbar', array( &$toolbar ) );
}
function buildCleanupScript() {
}
function buildCleanupScript() {
- global $wgRestrictionLevels, $wgGroupPermissions;
- $script = 'var wgCascadeableLevels=';
- $CascadeableLevels = array();
+ global $wgRestrictionLevels, $wgGroupPermissions, $wgOut;
+
+ $cascadeableLevels = array();
foreach( $wgRestrictionLevels as $key ) {
foreach( $wgRestrictionLevels as $key ) {
- if ( (isset($wgGroupPermissions[$key]['protect']) && $wgGroupPermissions[$key]['protect']) || $key == 'protect' ) {
- $CascadeableLevels[] = "'" . Xml::escapeJsString( $key ) . "'";
+ if ( ( isset( $wgGroupPermissions[$key]['protect'] ) && $wgGroupPermissions[$key]['protect'] )
+ || $key == 'protect'
+ ) {
+ $cascadeableLevels[] = $key;
- $script .= "[" . implode(',',$CascadeableLevels) . "];\n";
- $options = (object)array(
'tableId' => 'mwProtectSet',
'tableId' => 'mwProtectSet',
- 'labelText' => wfMsg( 'protect-unchain-permissions' ),
- 'numTypes' => count($this->mApplicableTypes),
- 'existingMatch' => 1 == count( array_unique( $this->mExistingExpiry ) ),
+ 'labelText' => wfMessage( 'protect-unchain-permissions' )->plain(),
+ 'numTypes' => count( $this->mApplicableTypes ),
+ 'existingMatch' => count( array_unique( $this->mExistingExpiry ) ) === 1,
- $encOptions = Xml::encodeJsVar( $options );
- $script .= "ProtectionForm.init($encOptions)";
- return Html::inlineScript( "if ( window.mediaWiki ) { $script }" );
+ $wgOut->addJsConfigVars( 'wgCascadeableLevels', $cascadeableLevels );
+ $script = Xml::encodeJsCall( 'ProtectionForm.init', array( $options ) );
+ return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) );
*/
public static function makeLoaderConditionalScript( $script ) {
$script = str_replace( "\n", "\n\t", trim( $script ) );
*/
public static function makeLoaderConditionalScript( $script ) {
$script = str_replace( "\n", "\n\t", trim( $script ) );
- return "if ( window.mediaWiki ) {\n\t$script\n}\n";
+ return "if(window.mw){\n\t$script\n}\n";