Merge "Fix contradictory RC filters and add back-compat"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 4 May 2017 18:16:36 +0000 (18:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 4 May 2017 18:16:36 +0000 (18:16 +0000)
includes/interwiki/Interwiki.php
includes/interwiki/InterwikiLookup.php
includes/interwiki/InterwikiLookupAdapter.php
includes/libs/rdbms/database/DBConnRef.php
includes/parser/Parser.php
includes/specialpage/ChangesListSpecialPage.php
resources/src/mediawiki.special/mediawiki.special.apisandbox.js
tests/phpunit/includes/interwiki/InterwikiLookupAdapterTest.php

index 558e32c..8dd6193 100644 (file)
@@ -92,12 +92,12 @@ class Interwiki {
        }
 
        /**
-        * Returns all interwiki prefixes
+        * Returns all interwiki prefix definitions.
         *
         * @deprecated since 1.28, unused. Use InterwikiLookup instead.
         *
         * @param string|null $local If set, limits output to local/non-local interwikis
-        * @return array List of prefixes
+        * @return array[] List of interwiki rows
         * @since 1.19
         */
        public static function getAllPrefixes( $local = null ) {
index d0a7719..697e39d 100644 (file)
@@ -47,10 +47,21 @@ interface InterwikiLookup {
        public function fetch( $prefix );
 
        /**
-        * Returns all interwiki prefixes
+        * Returns information about all interwiki prefixes, in the form of rows
+        * of the interwiki table. Each row may have the following keys:
+        *
+        * - iw_prefix: the prefix. Always present.
+        * - iw_url: the URL to use for linking, with $1 as a placeholder for the target page.
+        *           Always present.
+        * - iw_api: the URL of the API. Optional.
+        * - iw_wikiid: the wiki ID (usually the database name for local wikis). Optional.
+        * - iw_local: whether the wiki is local, and the "magic redirect" mechanism should apply.
+        *             Defaults to false.
+        * - iw_trans: whether "scary transclusion" is allowed for this site.
+        *             Defaults to false.
         *
         * @param string|null $local If set, limits output to local/non-local interwikis
-        * @return string[] List of prefixes
+        * @return array[] interwiki rows.
         */
        public function getAllPrefixes( $local = null );
 
index 60d6f43..3baea1a 100644 (file)
@@ -87,16 +87,20 @@ class InterwikiLookupAdapter implements InterwikiLookup {
         * See InterwikiLookup::getAllPrefixes
         *
         * @param string|null $local If set, limits output to local/non-local interwikis
-        * @return string[] List of prefixes
+        * @return array[] interwiki rows
         */
        public function getAllPrefixes( $local = null ) {
-               if ( $local === null ) {
-                       return array_keys( $this->getInterwikiMap() );
-               }
                $res = [];
                foreach ( $this->getInterwikiMap() as $interwikiId => $interwiki ) {
-                       if ( $interwiki->isLocal() === $local ) {
-                               $res[] = $interwikiId;
+                       if ( $local === null || $interwiki->isLocal() === $local ) {
+                               $res[] = [
+                                       'iw_prefix' => $interwikiId,
+                                       'iw_url' => $interwiki->getURL(),
+                                       'iw_api' => $interwiki->getAPI(),
+                                       'iw_wikiid' => $interwiki->getWikiID(),
+                                       'iw_local' => $interwiki->isLocal(),
+                                       'iw_trans' => $interwiki->isTranscludable(),
+                               ];
                        }
                }
                return $res;
index 6481c92..c15572c 100644 (file)
@@ -8,7 +8,7 @@ use InvalidArgumentException;
  * Helper class to handle automatically marking connections as reusable (via RAII pattern)
  * as well handling deferring the actual network connection until the handle is used
  *
- * @note: proxy methods are defined explicity to avoid interface errors
+ * @note: proxy methods are defined explicitly to avoid interface errors
  * @ingroup Database
  * @since 1.22
  */
index 19f368a..5b1e86d 100644 (file)
@@ -3476,7 +3476,7 @@ class Parser {
 
                if ( !$title->equals( $cacheTitle ) ) {
                        $this->mTplRedirCache[$cacheTitle->getPrefixedDBkey()] =
-                               [ $title->getNamespace(), $cdb = $title->getDBkey() ];
+                               [ $title->getNamespace(), $title->getDBkey() ];
                }
 
                return [ $dom, $title ];
index 27e278b..268f0b0 100644 (file)
@@ -255,79 +255,79 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                        // reviewStatus (conditional)
 
                        [
-                               'name' => 'lastRevision',
-                               'title' => 'rcfilters-filtergroup-lastRevision',
+                               'name' => 'significance',
+                               'title' => 'rcfilters-filtergroup-significance',
                                'class' => ChangesListBooleanFilterGroup::class,
-                               'priority' => -7,
+                               'priority' => -6,
                                'filters' => [
                                        [
-                                               'name' => 'hidelastrevision',
-                                               'label' => 'rcfilters-filter-lastrevision-label',
-                                               'description' => 'rcfilters-filter-lastrevision-description',
+                                               'name' => 'hideminor',
+                                               'label' => 'rcfilters-filter-minor-label',
+                                               'description' => 'rcfilters-filter-minor-description',
+                                               // rcshowhideminor-show, rcshowhideminor-hide,
+                                               // wlshowhideminor
+                                               'showHideSuffix' => 'showhideminor',
                                                'default' => false,
                                                'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
                                                        &$query_options, &$join_conds ) {
-                                                       $conds[] = 'rc_this_oldid <> page_latest';
+
+                                                       $conds[] = 'rc_minor = 0';
                                                },
-                                               'cssClassSuffix' => 'last',
+                                               'cssClassSuffix' => 'minor',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                                       return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
+                                                       return $rc->getAttribute( 'rc_minor' );
                                                }
                                        ],
                                        [
-                                               'name' => 'hidepreviousrevisions',
-                                               'label' => 'rcfilters-filter-previousrevision-label',
-                                               'description' => 'rcfilters-filter-previousrevision-description',
+                                               'name' => 'hidemajor',
+                                               'label' => 'rcfilters-filter-major-label',
+                                               'description' => 'rcfilters-filter-major-description',
                                                'default' => false,
                                                'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
                                                        &$query_options, &$join_conds ) {
-                                                       $conds[] = 'rc_this_oldid = page_latest';
+
+                                                       $conds[] = 'rc_minor = 1';
                                                },
-                                               'cssClassSuffix' => 'previous',
+                                               'cssClassSuffix' => 'major',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                                       return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
+                                                       return !$rc->getAttribute( 'rc_minor' );
                                                }
                                        ]
                                ]
                        ],
 
                        [
-                               'name' => 'significance',
-                               'title' => 'rcfilters-filtergroup-significance',
+                               'name' => 'lastRevision',
+                               'title' => 'rcfilters-filtergroup-lastRevision',
                                'class' => ChangesListBooleanFilterGroup::class,
-                               'priority' => -6,
+                               'priority' => -7,
                                'filters' => [
                                        [
-                                               'name' => 'hideminor',
-                                               'label' => 'rcfilters-filter-minor-label',
-                                               'description' => 'rcfilters-filter-minor-description',
-                                               // rcshowhideminor-show, rcshowhideminor-hide,
-                                               // wlshowhideminor
-                                               'showHideSuffix' => 'showhideminor',
+                                               'name' => 'hidelastrevision',
+                                               'label' => 'rcfilters-filter-lastrevision-label',
+                                               'description' => 'rcfilters-filter-lastrevision-description',
                                                'default' => false,
                                                'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
                                                        &$query_options, &$join_conds ) {
-
-                                                       $conds[] = 'rc_minor = 0';
+                                                       $conds[] = 'rc_this_oldid <> page_latest';
                                                },
-                                               'cssClassSuffix' => 'minor',
+                                               'cssClassSuffix' => 'last',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                                       return $rc->getAttribute( 'rc_minor' );
+                                                       return $rc->getAttribute( 'rc_this_oldid' ) === $rc->getAttribute( 'page_latest' );
                                                }
                                        ],
                                        [
-                                               'name' => 'hidemajor',
-                                               'label' => 'rcfilters-filter-major-label',
-                                               'description' => 'rcfilters-filter-major-description',
+                                               'name' => 'hidepreviousrevisions',
+                                               'label' => 'rcfilters-filter-previousrevision-label',
+                                               'description' => 'rcfilters-filter-previousrevision-description',
                                                'default' => false,
                                                'queryCallable' => function ( $specialClassName, $ctx, $dbr, &$tables, &$fields, &$conds,
                                                        &$query_options, &$join_conds ) {
-
-                                                       $conds[] = 'rc_minor = 1';
+                                                       $conds[] = 'rc_this_oldid = page_latest';
                                                },
-                                               'cssClassSuffix' => 'major',
+                                               'cssClassSuffix' => 'previous',
                                                'isRowApplicableCallable' => function ( $ctx, $rc ) {
-                                                       return !$rc->getAttribute( 'rc_minor' );
+                                                       return $rc->getAttribute( 'rc_this_oldid' ) !== $rc->getAttribute( 'page_latest' );
                                                }
                                        ]
                                ]
index f3eef7c..f53850a 100644 (file)
 
                Util.fetchModuleInfo( this.apiModule )
                        .done( function ( pi ) {
-                               var prefix, i, j, descriptionContainer, widget, $widgetLabel, widgetField, helpField, tmp, flag, count,
+                               var prefix, i, j, descriptionContainer, widget, widgetField, helpField, tmp, flag, count,
                                        items = [],
                                        deprecatedItems = [],
                                        buttons = [],
                                                        }
                                                );
 
-                                               $widgetLabel = $( '<span>' );
                                                widgetField = new OO.ui.FieldLayout(
                                                        widget,
                                                        {
                                                                align: 'left',
                                                                classes: [ 'mw-apisandbox-widget-field' ],
-                                                               label: prefix + pi.parameters[ i ].name,
-                                                               $label: $widgetLabel
+                                                               label: prefix + pi.parameters[ i ].name
                                                        }
                                                );
 
-                                               // FieldLayout only does click for InputElement
-                                               // widgets. So supply our own click handler.
-                                               $widgetLabel.on( 'click', widgetLabelOnClick.bind( widgetField ) );
+                                               // We need our own click handler on the widget label to
+                                               // turn off the disablement.
+                                               widgetField.$label.on( 'click', widgetLabelOnClick.bind( widgetField ) );
 
                                                // Don't grey out the label when the field is disabled,
                                                // it makes it too hard to read and our "disabled"
index 4754b04..1d62a78 100644 (file)
@@ -60,20 +60,37 @@ class InterwikiLookupAdapterTest extends MediaWikiTestCase {
        }
 
        public function testGetAllPrefixes() {
+               $foo = [
+                       'iw_prefix' => 'foo',
+                       'iw_url' => '',
+                       'iw_api' => '',
+                       'iw_wikiid' => 'foobar',
+                       'iw_local' => false,
+                       'iw_trans' => false,
+               ];
+               $enwt = [
+                       'iw_prefix' => 'enwt',
+                       'iw_url' => 'https://en.wiktionary.org/wiki/$1',
+                       'iw_api' => 'https://en.wiktionary.org/w/api.php',
+                       'iw_wikiid' => 'enwiktionary',
+                       'iw_local' => true,
+                       'iw_trans' => false,
+               ];
+
                $this->assertEquals(
-                       [ 'foo', 'enwt' ],
+                       [ $foo, $enwt ],
                        $this->interwikiLookup->getAllPrefixes(),
                        'getAllPrefixes()'
                );
 
                $this->assertEquals(
-                       [ 'foo' ],
+                       [ $foo ],
                        $this->interwikiLookup->getAllPrefixes( false ),
                        'get external prefixes'
                );
 
                $this->assertEquals(
-                       [ 'enwt' ],
+                       [ $enwt ],
                        $this->interwikiLookup->getAllPrefixes( true ),
                        'get local prefixes'
                );