From c805e14eec7bd0922351562de748bf99a83c0eeb Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Fri, 29 Aug 2014 23:40:10 +0100 Subject: [PATCH] Clean up mediawiki.legacy.protect a bit. Also kills some inline JS stuff in ProtectionForm Bug: 33871 Change-Id: Ie43c80bf5ebd6107458d5284cc68b7128f29359a --- includes/ProtectionForm.php | 24 +- resources/Resources.php | 2 +- resources/src/mediawiki.legacy/protect.js | 325 ++++++---------------- 3 files changed, 93 insertions(+), 258 deletions(-) diff --git a/includes/ProtectionForm.php b/includes/ProtectionForm.php index 4aa65d9403..35352d63e3 100644 --- a/includes/ProtectionForm.php +++ b/includes/ProtectionForm.php @@ -352,7 +352,7 @@ class ProtectionForm { $output->addJsConfigVars( 'wgCascadeableLevels', $cascadingRestrictionLevels ); $out .= Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=protect' ), - 'id' => 'mw-Protect-Form', 'onsubmit' => 'ProtectionForm.enableUnchainedInputs(true)' ) ); + 'id' => 'mw-Protect-Form' ) ); } $out .= Xml::openElement( 'fieldset' ) . @@ -426,16 +426,13 @@ class ProtectionForm { array( 'id' => "mwProtectExpirySelection-$action", 'name' => "wpProtectExpirySelection-$action", - 'onchange' => "ProtectionForm.updateExpiryList(this)", 'tabindex' => '2' ) + $this->disabledAttrib, $expiryFormOptions ) . " "; } # Add custom expiry field - $attribs = array( 'id' => "mwProtect-$action-expires", - 'onkeyup' => 'ProtectionForm.updateExpiry(this)', - 'onchange' => 'ProtectionForm.updateExpiry(this)' ) + $this->disabledAttrib; + $attribs = array( 'id' => "mwProtect-$action-expires" ) + $this->disabledAttrib; $out .= "' ).append( $cell ); - if ( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) ) { + if ( !$( '#mwProtectSet' ).length ) { return false; } - box = document.getElementById( opts.tableId ); - if ( !box ) { - return false; + if ( mw.config.get( 'wgCascadeableLevels' ) !== undefined ) { + $( 'form#mw-Protect-Form' ).submit( this.toggleUnchainedInputs.bind( ProtectionForm, true ) ); } + this.getExpirySelectors().each( function () { + $( this ).change( ProtectionForm.updateExpiryList.bind( ProtectionForm, this ) ); + } ); + this.getExpiryInputs().each( function () { + $( this ).on( 'keyup change', ProtectionForm.updateExpiry.bind( ProtectionForm, this ) ); + } ); + this.getLevelSelectors().each( function () { + $( this ).change( ProtectionForm.updateLevels.bind( ProtectionForm, this ) ); + } ); - boxbody = box.getElementsByTagName( 'tbody' )[0]; - row = document.createElement( 'tr' ); - boxbody.insertBefore( row, boxbody.firstChild.nextSibling ); - - this.existingMatch = opts.existingMatch; + $( '#mwProtectSet > tbody > tr:first' ).after( $row ); - cell = document.createElement( 'td' ); - row.appendChild( cell ); // If there is only one protection type, there is nothing to chain - if ( opts.numTypes > 1 ) { - check = document.createElement( 'input' ); - check.id = 'mwProtectUnchained'; - check.type = 'checkbox'; - $( check ).click( function () { - ProtectionForm.onChainClick(); - } ); - - label = document.createElement( 'label' ); - label.htmlFor = 'mwProtectUnchained'; - label.appendChild( document.createTextNode( opts.labelText ) ); - - cell.appendChild( check ); - cell.appendChild( document.createTextNode( ' ' ) ); - cell.appendChild( label ); + if ( $( '[id ^= mw-protect-table-]' ).length > 1 ) { + $cell.append( + $( '' ) + .attr( { id: 'mwProtectUnchained', type: 'checkbox' } ) + .click( this.onChainClick.bind( this ) ) + .prop( 'checked', !this.areAllTypesMatching() ), + document.createTextNode( ' ' ), + $( '
" . $mProtectother . @@ -556,7 +553,6 @@ class ProtectionForm { $user->getEditToken( array( 'protect', $this->mTitle->getPrefixedDBkey() ) ) ); $out .= Xml::closeElement( 'form' ); - $output->addScript( $this->buildCleanupScript() ); } return $out; @@ -581,8 +577,7 @@ class ProtectionForm { 'id' => $id, 'name' => $id, 'size' => count( $levels ), - 'onchange' => 'ProtectionForm.updateLevels(this)', - ) + $this->disabledAttrib; + ) + $this->disabledAttrib; $out = Xml::openElement( 'select', $attribs ); foreach ( $levels as $key ) { @@ -611,19 +606,6 @@ class ProtectionForm { } } - function buildCleanupScript() { - $options = array( - 'tableId' => 'mwProtectSet', - 'labelText' => wfMessage( 'protect-unchain-permissions' )->plain(), - 'numTypes' => count( $this->mApplicableTypes ), - 'existingMatch' => count( array_unique( $this->mExistingExpiry ) ) === 1, - ); - - $script = Xml::encodeJsCall( 'ProtectionForm.init', array( $options ) ); - - return Html::inlineScript( ResourceLoader::makeLoaderConditionalScript( $script ) ); - } - /** * Show protection long extracts for this page * diff --git a/resources/Resources.php b/resources/Resources.php index 49f62b48d5..166dd7e8a8 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1430,7 +1430,7 @@ return array( 'dependencies' => array( 'jquery.byteLimit', ), - 'position' => 'top', + 'messages' => array( 'protect-unchain-permissions' ) ), 'mediawiki.legacy.shared' => array( // Used in the web installer. Test it after modifying this definition! diff --git a/resources/src/mediawiki.legacy/protect.js b/resources/src/mediawiki.legacy/protect.js index dc142ca967..f9069b6fd0 100644 --- a/resources/src/mediawiki.legacy/protect.js +++ b/resources/src/mediawiki.legacy/protect.js @@ -1,116 +1,82 @@ ( function ( mw, $ ) { var ProtectionForm = window.ProtectionForm = { - existingMatch: false, - /** * Set up the protection chaining interface (i.e. "unlock move permissions" checkbox) * on the protection form - * - * @param opts Object : parameters with members: - * tableId Identifier of the table containing UI bits - * labelText Text to use for the checkbox label - * numTypes The number of protection types - * existingMatch True if all the existing expiry times match */ - init: function ( opts ) { - var box, boxbody, row, cell, check, label; + init: function () { + var $cell = $( '' ), $row = $( '