Make legend on Special:RecentChanges and Special:Watchlist collapsible
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 13 Dec 2013 20:56:02 +0000 (21:56 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Wed, 18 Dec 2013 16:40:03 +0000 (17:40 +0100)
Some of the code added here is duplicated, redundant or would be
better off placed somewhere else. I know about this, but this is not
the time to fix that (and nobody would review such patches anyway…).

Bug: 52005
Change-Id: I02f2ced42f33649b6c972d35a4739372ca265e10

includes/changes/ChangesList.php
includes/changes/EnhancedChangesList.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialWatchlist.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc
resources/Resources.php
resources/mediawiki.special/mediawiki.special.changeslist.css
resources/mediawiki.special/mediawiki.special.changeslist.js [new file with mode: 0644]

index 470b150..107e2c4 100644 (file)
@@ -161,6 +161,7 @@ class ChangesList extends ContextSource {
                $this->lastdate = '';
                $this->rclistOpen = false;
                $this->getOutput()->addModuleStyles( 'mediawiki.special.changeslist' );
+               $this->getOutput()->addModules( 'mediawiki.special.changeslist.js' );
 
                return '<div class="mw-changeslist">';
        }
index 1c3a0fb..99cf0de 100644 (file)
@@ -41,6 +41,7 @@ class EnhancedChangesList extends ChangesList {
                $this->getOutput()->addModules( array(
                        'jquery.makeCollapsible',
                        'mediawiki.icon',
+                       'mediawiki.special.changeslist.js',
                ) );
 
                return '<div class="mw-changeslist">';
index 3b1291b..3b121fb 100644 (file)
@@ -664,7 +664,7 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                global $wgRecentChangesFlags;
                $user = $context->getUser();
                # The legend showing what the letters and stuff mean
-               $legend = Xml::openElement( 'dl', array( 'class' => 'mw-changeslist-legend' ) ) . "\n";
+               $legend = Xml::openElement( 'dl' ) . "\n";
                # Iterates through them and gets the messages for both letter and tooltip
                $legendItems = $wgRecentChangesFlags;
                if ( !$user->useRCPatrol() ) {
@@ -700,6 +700,14 @@ class SpecialRecentChanges extends IncludableSpecialPage {
                        $context->msg( 'recentchanges-label-plusminus' )->text()
                ) . "\n";
                $legend .= Xml::closeElement( 'dl' ) . "\n";
+
+               # Collapsibility
+               $legend =
+                       '<div class="mw-changeslist-legend">' .
+                               $context->msg( 'recentchanges-legend-heading' )->parse() .
+                               '<div class="mw-collapsible-content">' . $legend . '</div>' .
+                       '</div>';
+
                return $legend;
        }
 
index 9e93881..4d86744 100644 (file)
@@ -40,6 +40,7 @@ class SpecialWatchlist extends SpecialPage {
                $user = $this->getUser();
                $output = $this->getOutput();
                $output->addModuleStyles( 'mediawiki.special.changeslist' );
+               $output->addModules( 'mediawiki.special.changeslist.js' );
 
                # Anons don't get a watchlist
                $this->requireLogin( 'watchlistanontext' );
index 225aa07..23b989a 100644 (file)
@@ -2186,6 +2186,7 @@ Your email address is not revealed when other users contact you.',
 'recentchanges-label-bot'           => 'This edit was performed by a bot',
 'recentchanges-label-unpatrolled'   => 'This edit has not yet been patrolled',
 'recentchanges-label-plusminus'     => 'The page size changed by this number of bytes',
+'recentchanges-legend-heading'      => "'''Legend:'''",
 'recentchanges-legend-newpage'      => '(also see [[Special:NewPages|list of new pages]])',
 'recentchanges-legend-plusminus'    => "(''±123'')",
 'rcnotefrom'                        => "Below are the changes since '''$2''' (up to '''$1''' shown).",
index fb260b5..807bedd 100644 (file)
@@ -3592,6 +3592,7 @@ See also:
 'recentchanges-label-plusminus' => 'Legend item for plus/minus.
 
 Preceded by legend example {{msg-mw|Recentchanges-legend-plusminus}}.',
+'recentchanges-legend-heading' => 'Used as a heading for legend box on [[Special:RecentChanges]] and [[Special:Watchlist]].',
 'recentchanges-legend-newpage' => 'Used as legend in [[Special:RecentChanges]]. Preceded by {{msg-mw|Recentchanges-label-newpage}}.',
 'recentchanges-legend-plusminus' => 'A plus/minus sign with a number for the legend.',
 'rcnotefrom' => 'This message is displayed at [[Special:RecentChanges]] when viewing recentchanges from some specific time.
index 4ca74f7..dab977e 100644 (file)
@@ -1308,6 +1308,7 @@ $wgMessageStructure = array(
                'recentchanges-label-bot',
                'recentchanges-label-unpatrolled',
                'recentchanges-label-plusminus',
+               'recentchanges-legend-heading',
                'recentchanges-legend-newpage',
                'recentchanges-legend-plusminus',
                'rcnotefrom',
index d2a06b7..ceacee6 100644 (file)
@@ -1013,6 +1013,13 @@ return array(
        'mediawiki.special.changeslist' => array(
                'styles' => 'resources/mediawiki.special/mediawiki.special.changeslist.css',
        ),
+       'mediawiki.special.changeslist.js' => array(
+               'scripts' => 'resources/mediawiki.special/mediawiki.special.changeslist.js',
+               'dependencies' => array(
+                       'jquery.makeCollapsible',
+                       'jquery.cookie',
+               ),
+       ),
        'mediawiki.special.changeslist.enhanced' => array(
                'styles' => 'resources/mediawiki.special/mediawiki.special.changeslist.enhanced.css',
        ),
index b96a26e..b1af745 100644 (file)
        border: 1px solid #ddd;
 }
 
+.mw-changeslist-legend dl {
+       /* Parent element defines sufficient padding */
+       margin-bottom: 0;
+}
+
 .mw-changeslist-legend dt {
        float: left;
 }
diff --git a/resources/mediawiki.special/mediawiki.special.changeslist.js b/resources/mediawiki.special/mediawiki.special.changeslist.js
new file mode 100644 (file)
index 0000000..df606f5
--- /dev/null
@@ -0,0 +1,21 @@
+/* Remember the collapse state of the legend on recent changes and watchlist pages. */
+jQuery( document ).ready( function ( $ ) {
+       var
+               cookieName = 'changeslist-state',
+               cookieOptions = {
+                       expires: 30,
+                       path: '/'
+               },
+               isCollapsed = $.cookie( cookieName ) === 'collapsed';
+
+       $( '.mw-changeslist-legend' )
+               .makeCollapsible( {
+                       collapsed: isCollapsed
+               } )
+               .on( 'beforeExpand.mw-collapsible', function () {
+                       $.cookie( cookieName, 'expanded', cookieOptions );
+               } )
+               .on( 'beforeCollapse.mw-collapsible', function () {
+                       $.cookie( cookieName, 'collapsed', cookieOptions );
+               } );
+} );