Merge "RCFilters UI: Read default states of filters"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 25 Jan 2017 05:54:43 +0000 (05:54 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 25 Jan 2017 05:54:43 +0000 (05:54 +0000)
resources/Resources.php
resources/src/mediawiki.rcfilters/mw.rcfilters.init.js
resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less [deleted file]
tests/phpunit/includes/OutputPageTest.php

index bd7f68e..cd5e3b9 100644 (file)
@@ -1747,7 +1747,6 @@ return [
                        'resources/src/mediawiki.rcfilters/mw.rcfilters.init.js',
                ],
                'styles' => [
-                       'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less',
                        'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterItemWidget.less',
                        'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FilterGroupWidget.less',
                        'resources/src/mediawiki.rcfilters/styles/mw.rcfilters.ui.FiltersListWidget.less',
index 1f02bc4..7b29d4b 100644 (file)
@@ -24,7 +24,7 @@
                                                        description: mw.msg( 'rcfilters-filter-registered-description' )
                                                },
                                                {
-                                                       name: 'hideanon',
+                                                       name: 'hideanons',
                                                        label: mw.msg( 'rcfilters-filter-unregistered-label' ),
                                                        description: mw.msg( 'rcfilters-filter-unregistered-description' )
                                                }
                        // Initialize values
                        controller.initialize();
 
+                       // HACK: Remove old-style filter links for filters handled by the widget
+                       // Ideally the widget would handle all filters and we'd just remove .rcshowhide entirely
+                       $( '.rcshowhide' ).children().each( function () {
+                               // HACK: Interpret the class name to get the filter name
+                               // This should really be set as a data attribute
+                               var i,
+                                       name = null,
+                                       // Some of the older browsers we support don't have .classList,
+                                       // so we have to interpret the class attribute manually.
+                                       classes = this.getAttribute( 'class' ).split( ' ' );
+                               for ( i = 0; i < classes.length; i++ ) {
+                                       if ( classes[ i ].substr( 0, 'rcshow'.length ) === 'rcshow' ) {
+                                               name = classes[ i ].substr( 'rcshow'.length );
+                                               break;
+                                       }
+                               }
+                               if ( name === null ) {
+                                       return;
+                               }
+                               if ( name === 'hidemine' ) {
+                                       // HACK: the span for hidemyself is called hidemine
+                                       name = 'hidemyself';
+                               }
+                               // This span corresponds to a filter that's in our model, so remove it
+                               if ( model.getItemByName( name ) ) {
+                                       // HACK: Remove the text node after the span.
+                                       // If there isn't one, we're at the end, so remove the text node before the span.
+                                       // This would be unnecessary if we added separators with CSS.
+                                       if ( this.nextSibling && this.nextSibling.nodeType === Node.TEXT_NODE ) {
+                                               this.parentNode.removeChild( this.nextSibling );
+                                       } else if ( this.previousSibling && this.previousSibling.nodeType === Node.TEXT_NODE ) {
+                                               this.parentNode.removeChild( this.previousSibling );
+                                       }
+                                       // Remove the span itself
+                                       this.parentNode.removeChild( this );
+                               }
+                       } );
+
                        $( '.rcoptions form' ).submit( function () {
                                var $form = $( this );
 
diff --git a/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less b/resources/src/mediawiki.rcfilters/styles/mw.rcfilters.less
deleted file mode 100644 (file)
index 7f71c0c..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-.rcshowhidemine {
-       // HACK: Hide this filter since it already appears in
-       // the new filter drop-down.
-       display: none;
-}
index 0e83006..371731b 100644 (file)
@@ -12,6 +12,45 @@ class OutputPageTest extends MediaWikiTestCase {
        const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)';
        const SCREEN_ONLY_MEDIA_QUERY = 'only screen and (min-width: 982px)';
 
+       /**
+        * @covers OutputPage::addMeta
+        * @covers OutputPage::getMetaTags
+        * @covers OutputPage::getHeadLinksArray
+        */
+       public function testMetaTags() {
+               $outputPage = $this->newInstance();
+               $outputPage->addMeta( 'http:expires', '0' );
+               $outputPage->addMeta( 'keywords', 'first' );
+               $outputPage->addMeta( 'keywords', 'second' );
+
+               $expected = [
+                       [ 'http:expires', '0' ],
+                       [ 'keywords', 'first' ],
+                       [ 'keywords', 'second' ],
+               ];
+               $this->assertSame( $expected, $outputPage->getMetaTags() );
+
+               $links = $outputPage->getHeadLinksArray();
+               $this->assertContains( '<meta http-equiv="expires" content="0"/>', $links );
+               $this->assertContains( '<meta name="keywords" content="first"/>', $links );
+               $this->assertContains( '<meta name="keywords" content="second"/>', $links );
+               $this->assertArrayNotHasKey( 'meta-robots', $links );
+       }
+
+       /**
+        * @covers OutputPage::setIndexPolicy
+        * @covers OutputPage::setFollowPolicy
+        * @covers OutputPage::getHeadLinksArray
+        */
+       public function testRobotsPolicies() {
+               $outputPage = $this->newInstance();
+               $outputPage->setIndexPolicy( 'noindex' );
+               $outputPage->setFollowPolicy( 'nofollow' );
+
+               $links = $outputPage->getHeadLinksArray();
+               $this->assertContains( '<meta name="robots" content="noindex,nofollow"/>', $links );
+       }
+
        /**
         * Tests a particular case of transformCssMedia, using the given input, globals,
         * expected return, and message
@@ -374,6 +413,29 @@ class OutputPageTest extends MediaWikiTestCase {
                $this->assertEquals( [ 0 => 'Test2' ], $outputPage->getCategories( 'normal' ) );
                $this->assertEquals( [ 0 => 'Test' ], $outputPage->getCategories( 'hidden' ) );
        }
+
+       /**
+        * @return OutputPage
+        */
+       private function newInstance() {
+               $context = new RequestContext();
+
+               $context->setConfig( new HashConfig( [
+                       'AppleTouchIcon' => false,
+                       'DisableLangConversion' => true,
+                       'EnableAPI' => false,
+                       'EnableCanonicalServerLink' => false,
+                       'Favicon' => false,
+                       'Feed' => false,
+                       'LanguageCode' => false,
+                       'ReferrerPolicy' => false,
+                       'RightsPage' => false,
+                       'RightsUrl' => false,
+                       'UniversalEditButton' => false,
+               ] ) );
+
+               return new OutputPage( $context );
+       }
 }
 
 /**