$( function () {
    if( mw.config.get( "wgAction" ) === "history" ) {
        mw.loader.using( , function () {
            var param = mw.util.getParamValue( "revdel_select" );
            if( param ) {
                var pageHistory = document.getElementById( "pagehistory" );
                var oldids = param.split( "|" ).filter( Boolean );
                if( oldids.some( function ( oldid ) { return oldid.indexOf( ".." ) >= 0; } ) ) {
                    var allCheckboxes = Array.prototype.slice.call( pageHistory.querySelectorAll( "input" ) );
                }
                function expandRange ( range ) {
                    var start = range,
                        end = range,
                        startCheckbox = pageHistory.querySelector( "input']" ),
                        endCheckbox = pageHistory.querySelector( "input']" ),
                        startIdx = allCheckboxes.indexOf( startCheckbox ),
                        endIdx = allCheckboxes.indexOf( endCheckbox ),
                        checkboxes = ;
                    if( !startCheckbox ) throw( "No checkbox found for revision " + start );
                    if( !endCheckbox ) throw( "No checkbox found for revision " + end );
                    for( var idx = startIdx, inc = Math.sign( endIdx - startIdx );
                            idx != endIdx; idx += inc ) {
                        checkboxes.push( allCheckboxes );
                    }
                    checkboxes.push( endCheckbox );
                    return checkboxes;
                }
                var singletonSelectors = ;
                function makeChecked( box ) { box.checked = true; }
                for( var i = 0, n = oldids.length; i < n; i++ ) {
                    if( oldids.indexOf( ".." ) >= 0 ) {
                        expandRange( oldids.split( ".." ) ).forEach( makeChecked );
                    } else {
                        singletonSelectors.push( "input + "]']" );
                    }
                }
                if( singletonSelectors.length ) {
                    Array.prototype.slice.call( document.querySelectorAll(
                            singletonSelectors.join( "," ) ) ).forEach( makeChecked );
                }
            }
        } );
    }
} );