}
if( !is_null( $all ) )
+ # Please make sure the 'namespacesall' is the first or you will break
+ # such an assumption (ex js: mw.special.recentchanges.updateCheckboxes)
$namespaces = array( $all => wfMsg( 'namespacesall' ) ) + $namespaces;
foreach( $namespaces as $index => $name ) {
if( $index < NS_MAIN ) {
$opts = $this->getOptions();
$this->setHeaders();
$this->outputHeader();
+ $this->addRecentChangesJS();
// Fetch results, prepare a batch link existence check query
$conds = $this->buildMainQueryConds( $opts );
$rclistfrom = wfMsgExt( 'rclistfrom', array( 'parseinline', 'replaceafter' ), $tl );
return "{$note}$rclinks<br />$rclistfrom";
}
+
+ /**
+ * add javascript specific to the [[Special:RecentChanges]] page
+ */
+ function addRecentChangesJS() {
+ global $wgOut;
+ $wgOut->addModules( array(
+ 'mediawiki.special.recentchanges',
+ ) );
+ }
}
'scripts' => 'resources/mediawiki.special/mediawiki.special.movePage.js',
'dependencies' => 'jquery.byteLimit',
),
+ 'mediawiki.special' => array(
+ 'scripts' => 'resources/mediawiki/mediawiki.special.js',
+ ),
+ 'mediawiki.special.recentchanges' => array(
+ 'scripts' => 'resources/mediawiki.special/mediawiki.special.recentchanges.js',
+ 'dependencies' => array( 'mediawiki.special' ),
+ ),
'mediawiki.special.upload' => array(
// @TODO: merge in remainder of mediawiki.legacy.upload
'scripts' => 'resources/mediawiki.special/mediawiki.special.upload.js',
--- /dev/null
+/* JavaScript for Special:RecentChanges */
+( function( $, mw ) {
+
+mw.special.recentchanges = {
+ // -- Variables
+ 'select' : false,
+ 'checkboxes' : [ 'nsassociated', 'nsinvert' ],
+
+ // -- Methods
+ 'init' : function() {
+ this.select = $( 'select#namespace' );
+
+ // Register an onChange trigger for the <select> element
+ this.select.change( function() {
+ mw.special.recentchanges.updateCheckboxes();
+ });
+ // on load, trigger the event to eventually update checkboxes statuses
+ this.select.change();
+ },
+
+ /**
+ * handler to disable/enable the namespace selector checkboxes when the
+ * special 'all' namespace is selected/unselected respectively.
+ */
+ 'updateCheckboxes' : function() {
+ // The 'all' namespace is the FIRST in the list.
+ var isAllNS = this.select.find( 'option' ).first().is( ':selected' );
+
+ // Iterates over checkboxes and propagate the selected option
+ $.map( this.checkboxes, function(id) {
+ $( 'input#'+id ).attr( 'disabled', isAllNS );
+ });
+ },
+};
+
+mw.special.recentchanges.init();
+
+}(jQuery, mediaWiki ) );
<script src="../../resources/jquery/jquery.tabIndex.js"></script>
<script src="../../resources/jquery/jquery.tablesorter.js"></script>
<script src="../../resources/mediawiki/mediawiki.Title.js"></script>
+ <script src="../../resources/mediawiki/mediawiki.special.js"></script>
+ <script src="../../resources/mediawiki.special/mediawiki.special.recentchanges.js"></script>
<!-- QUnit: Load framework -->
<link rel="stylesheet" href="../../resources/jquery/jquery.qunit.css" />
<script src="suites/resources/jquery/jquery.tabIndex.js"></script>
<script src="suites/resources/jquery/jquery.tablesorter.test.js" charset="UTF-8"></script>
<script src="suites/resources/mediawiki/mediawiki.Title.js"></script>
+ <script src="suites/resources/mediawiki.special/mediawiki.special.recentchanges.js"></script>
<!-- TestSwarm: If a test swarm is running this,
the following script will allow it to extract the results.
--- /dev/null
+module( 'mediawiki.special.preferences.js' );
+
+test( '-- Initial check', function() {
+ expect( 2 );
+ ok( mediaWiki.special.recentchanges.init,
+ 'mediaWiki.special.recentchanges.init defined'
+ );
+ ok( mediaWiki.special.recentchanges.updateCheckboxes,
+ 'mediaWiki.special.recentchanges.updateCheckboxes defined'
+ );
+ // TODO: verify checkboxes == [ 'nsassociated', 'nsinvert' ]
+});
+
+test( 'foobar', function() {
+
+ // from Special:Recentchanges
+ var select =
+ '<select id="namespace" name="namespace" class="namespaceselector">'
+ + '<option value="" selected="selected">all</option>'
+ + '<option value="0">(Main)</option>'
+ + '<option value="1">Talk</option>'
+ + '<option value="2">User</option>'
+ + '<option value="3">User talk</option>'
+ + '<option value="4">ProjectName</option>'
+ + '<option value="5">ProjectName talk</option>'
+ + '</select>'
+ + '<input name="invert" type="checkbox" value="1" id="nsinvert" title="no title" />'
+ + '<label for="nsinvert" title="no title">Invert selection</label>'
+ + '<input name="associated" type="checkbox" value="1" id="nsassociated" title="no title" />'
+ + '<label for="nsassociated" title="no title">Associated namespace</label>'
+ + '<input type="submit" value="Go" />'
+ + '<input type="hidden" value="Special:RecentChanges" name="title" />'
+ ;
+
+ var $env = $( '<div>' ).html( select ).appendTo( 'body' );
+ var enabled = undefined;
+
+ // TODO abstract the double strictEquals
+
+ // At first checkboxes are enabled
+ strictEqual( $('input#nsinvert').attr('disabled'), enabled);
+ strictEqual( $('input#nsassociated').attr('disabled'), enabled);
+
+ // load our magic code to disable them
+ mediaWiki.special.recentchanges.init();
+ strictEqual( $('#nsinvert').attr('disabled'), 'disabled');
+ strictEqual( $('#nsassociated').attr('disabled'), 'disabled' );
+
+ // select second option...
+ $('select#namespace option:nth-child(1)').removeAttr( 'selected' );
+ $('select#namespace option:nth-child(2)').attr( 'selected', 'selected' );
+ $('select#namespace').change();
+ // ... and checkboxes should be enabled again
+ strictEqual( $('input#nsinvert').attr('disabled'), enabled);
+ strictEqual( $('input#nsassociated').attr('disabled'), enabled);
+
+ // select first option ('all' namespace)...
+ $('select#namespace option:nth-child(1)').attr( 'selected', 'selected' );
+ $('select#namespace option:nth-child(2)').removeAttr( 'selected' );
+ $('select#namespace').change();
+ // ... and checkboxes should now be disabled
+ strictEqual( $('#nsinvert').attr('disabled'), 'disabled');
+ strictEqual( $('#nsassociated').attr('disabled'), 'disabled' );
+
+ // DOM cleanup
+ $env.remove();
+});