Merge "Absolutely position legend only on new RCFilters"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 12 Dec 2017 20:13:21 +0000 (20:13 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 12 Dec 2017 20:13:21 +0000 (20:13 +0000)
12 files changed:
includes/DefaultSettings.php
includes/Linker.php
includes/Preferences.php
includes/htmlform/fields/HTMLUsersMultiselectField.php
includes/parser/Parser.php
includes/specials/SpecialEmailuser.php
includes/specials/SpecialListgrouprights.php
languages/i18n/en.json
languages/i18n/qqq.json
maintenance/storage/checkStorage.php
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js [new file with mode: 0644]

index a7b34a1..e50b7a7 100644 (file)
@@ -4851,6 +4851,7 @@ $wgDefaultUserOptions = [
        'editfont' => 'monospace',
        'editondblclick' => 0,
        'editsectiononrightclick' => 0,
+       'email-allow-new-users' => 1,
        'enotifminoredits' => 0,
        'enotifrevealaddr' => 0,
        'enotifusertalkpages' => 1,
index a0332cf..48be3bf 100644 (file)
@@ -1192,12 +1192,12 @@ class Linker {
                                                $section = str_replace( '[[', '', $section );
                                                $section = str_replace( ']]', '', $section );
 
-                                               $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # T24784
+                                               $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
                                                if ( $local ) {
-                                                       $sectionTitle = Title::newFromText( '#' . $section );
+                                                       $sectionTitle = Title::makeTitleSafe( NS_MAIN, '', $section );
                                                } else {
                                                        $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
-                                                               $title->getDBkey(), Sanitizer::decodeCharReferences( $section ) );
+                                                               $title->getDBkey(), $section );
                                                }
                                                if ( $sectionTitle ) {
                                                        $link = Linker::makeCommentLink( $sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses' );
index 878462d..33a975d 100644 (file)
@@ -534,12 +534,22 @@ class Preferences {
 
                        if ( $config->get( 'EnableUserEmail' ) && $user->isAllowed( 'sendemail' ) ) {
                                $defaultPreferences['disablemail'] = [
+                                       'id' => 'wpAllowEmail',
                                        'type' => 'toggle',
                                        'invert' => true,
                                        'section' => 'personal/email',
                                        'label-message' => 'allowemail',
                                        'disabled' => $disableEmailPrefs,
                                ];
+
+                               $defaultPreferences['email-allow-new-users'] = [
+                                       'id' => 'wpAllowEmailFromNewUsers',
+                                       'type' => 'toggle',
+                                       'section' => 'personal/email',
+                                       'label-message' => 'email-allow-new-users-label',
+                                       'disabled' => $disableEmailPrefs,
+                               ];
+
                                $defaultPreferences['ccmeonemails'] = [
                                        'type' => 'toggle',
                                        'section' => 'personal/email',
@@ -547,10 +557,7 @@ class Preferences {
                                        'disabled' => $disableEmailPrefs,
                                ];
 
-                               if ( $config->get( 'EnableUserEmailBlacklist' )
-                                        && !$disableEmailPrefs
-                                        && !(bool)$user->getOption( 'disablemail' )
-                               ) {
+                               if ( $config->get( 'EnableUserEmailBlacklist' ) ) {
                                        $lookup = CentralIdLookup::factory();
                                        $ids = $user->getOption( 'email-blacklist', [] );
                                        $names = $ids ? $lookup->namesFromCentralIds( $ids, $user ) : [];
@@ -560,6 +567,7 @@ class Preferences {
                                                'label-message' => 'email-blacklist-label',
                                                'section' => 'personal/email',
                                                'default' => implode( "\n", $names ),
+                                               'disabled' => $disableEmailPrefs,
                                        ];
                                }
                        }
index f094745..46cc6d3 100644 (file)
@@ -56,6 +56,14 @@ class HTMLUsersMultiselectField extends HTMLUserTextField {
        public function getInputOOUI( $value ) {
                $params = [ 'name' => $this->mName ];
 
+               if ( isset( $this->mParams['id'] ) ) {
+                       $params['id'] = $this->mParams['id'];
+               }
+
+               if ( isset( $this->mParams['disabled'] ) ) {
+                       $params['disabled'] = $this->mParams['disabled'];
+               }
+
                if ( isset( $this->mParams['default'] ) ) {
                        $params['default'] = $this->mParams['default'];
                }
index ea58acc..2b03a70 100644 (file)
@@ -4207,7 +4207,7 @@ class Parser {
                        # Decode HTML entities
                        $safeHeadline = Sanitizer::decodeCharReferences( $safeHeadline );
 
-                       $safeHeadline = $this->normalizeSectionName( $safeHeadline );
+                       $safeHeadline = self::normalizeSectionName( $safeHeadline );
 
                        $fallbackHeadline = Sanitizer::escapeIdForAttribute( $safeHeadline, Sanitizer::ID_FALLBACK );
                        $linkAnchor = Sanitizer::escapeIdForLink( $safeHeadline );
@@ -5756,23 +5756,42 @@ class Parser {
                return $this->mDefaultSort;
        }
 
+       private static function getSectionNameFromStrippedText( $text ) {
+               $text = Sanitizer::normalizeSectionNameWhitespace( $text );
+               $text = Sanitizer::decodeCharReferences( $text );
+               $text = self::normalizeSectionName( $text );
+               return $text;
+       }
+
+       private static function makeAnchor( $sectionName ) {
+               return '#' . Sanitizer::escapeIdForLink( $sectionName );
+       }
+
+       private static function makeLegacyAnchor( $sectionName ) {
+               global $wgFragmentMode;
+               if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
+                       // ForAttribute() and ForLink() are the same for legacy encoding
+                       $id = Sanitizer::escapeIdForAttribute( $text, Sanitizer::ID_FALLBACK );
+               } else {
+                       $id = Sanitizer::escapeIdForLink( $text );
+               }
+
+               return "#$id";
+       }
+
        /**
         * Try to guess the section anchor name based on a wikitext fragment
         * presumably extracted from a heading, for example "Header" from
         * "== Header ==".
         *
         * @param string $text
-        *
-        * @return string
+        * @return string Anchor (starting with '#')
         */
        public function guessSectionNameFromWikiText( $text ) {
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
-               $text = Sanitizer::normalizeSectionNameWhitespace( $text );
-               $text = Sanitizer::decodeCharReferences( $text );
-               $text = $this->normalizeSectionName( $text );
-
-               return '#' . Sanitizer::escapeIdForLink( $text );
+               $sectionName = self::getSectionNameFromStrippedText( $text );
+               return self::makeAnchor( $sectionName );
        }
 
        /**
@@ -5782,25 +5801,23 @@ class Parser {
         * than UTF-8, resulting in breakage.
         *
         * @param string $text The section name
-        * @return string An anchor
+        * @return string Anchor (starting with '#')
         */
        public function guessLegacySectionNameFromWikiText( $text ) {
-               global $wgFragmentMode;
-
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
-               $text = Sanitizer::normalizeSectionNameWhitespace( $text );
-               $text = Sanitizer::decodeCharReferences( $text );
-               $text = $this->normalizeSectionName( $text );
-
-               if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
-                       // ForAttribute() and ForLink() are the same for legacy encoding
-                       $id = Sanitizer::escapeIdForAttribute( $text, Sanitizer::ID_FALLBACK );
-               } else {
-                       $id = Sanitizer::escapeIdForLink( $text );
-               }
+               $sectionName = self::getSectionNameFromStrippedText( $text );
+               return self::makeLegacyAnchor( $sectionName );
+       }
 
-               return "#$id";
+       /**
+        * Like guessSectionNameFromWikiText(), but takes already-stripped text as input.
+        * @param string $text Section name (plain text)
+        * @return string Anchor (starting with '#')
+        */
+       public static function guessSectionNameFromStrippedText( $text ) {
+               $sectionName = self::getSectionNameFromStrippedText( $text );
+               return self::makeAnchor( $sectionName );
        }
 
        /**
@@ -5809,7 +5826,7 @@ class Parser {
         * @param string $text
         * @return string
         */
-       private function normalizeSectionName( $text ) {
+       private static function normalizeSectionName( $text ) {
                # T90902: ensure the same normalization is applied for IDs as to links
                $titleParser = MediaWikiServices::getInstance()->getTitleParser();
                try {
index d57ba09..06ca04f 100644 (file)
@@ -238,9 +238,8 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        return 'nowikiemail';
                }
 
-               if (
-                       $target->getEditCount() === 0
-                       && ( $sender === null || !$sender->isAllowed( 'sendemail-new-users' ) )
+               if ( $target->getEditCount() === 0 &&
+                       ( $sender === null || !$sender->isAllowed( 'sendemail-new-users' ) )
                ) {
                        // Determine if target has any other logged actions.
                        $dbr = wfGetDB( DB_REPLICA );
@@ -262,6 +261,14 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                        }
                }
 
+               if ( $sender !== null && !$target->getOption( 'email-allow-new-users' ) &&
+                       $sender->isNewbie()
+               ) {
+                               wfDebug( "User does not allow user emails from new users.\n" );
+
+                               return 'nowikiemail';
+               }
+
                if ( $sender !== null ) {
                        $blacklist = $target->getOption( 'email-blacklist', [] );
                        if ( $blacklist ) {
index 2ca4190..cc62d61 100644 (file)
@@ -137,7 +137,7 @@ class SpecialListGroupRights extends SpecialPage {
        }
 
        private function outputNamespaceProtectionInfo() {
-               global $wgParser, $wgContLang;
+               global $wgContLang;
                $out = $this->getOutput();
                $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
 
@@ -145,11 +145,11 @@ class SpecialListGroupRights extends SpecialPage {
                        return;
                }
 
-               $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
+               $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->text();
                $out->addHTML(
                        Html::rawElement( 'h2', [], Html::element( 'span', [
                                'class' => 'mw-headline',
-                               'id' => $wgParser->guessSectionNameFromWikiText( $header )
+                               'id' => substr( Parser::guessSectionNameFromStrippedText( $header ), 1 )
                        ], $header ) ) .
                        Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
                        Html::element(
index 1c2bab9..5e7c8cb 100644 (file)
        "timezoneregion-indian": "Indian Ocean",
        "timezoneregion-pacific": "Pacific Ocean",
        "allowemail": "Allow other users to email me",
+       "email-allow-new-users-label": "Allow emails from brand-new users",
        "email-blacklist-label": "Prohibit these users from emailing me:",
        "prefs-searchoptions": "Search",
        "prefs-namespaces": "Namespaces",
index a527ed0..f3f44c8 100644 (file)
        "timezoneregion-indian": "Used in \"Time zone\" listbox in [[Special:Preferences#mw-prefsection-datetime|preferences]], \"date and time\" tab.\n{{Related|Timezoneregion}}",
        "timezoneregion-pacific": "Used in \"Time zone\" listbox in [[Special:Preferences#mw-prefsection-datetime|preferences]], \"date and time\" tab.\n{{Related|Timezoneregion}}",
        "allowemail": "Used in [[Special:Preferences]] > {{int:prefs-personal}} > {{int:email}}.",
+       "email-allow-new-users-label": "Used in [[Special:Preferences]] > {{int:prefs-prohibit}} > {{int:email}}.",
        "email-blacklist-label": "Used in [[Special:Preferences]] > {{int:prefs-prohibit}} > {{int:email}}.",
        "prefs-searchoptions": "{{Identical|Search}}",
        "prefs-namespaces": "Shown as legend of the second fieldset of the tab 'Search' in [[Special:Preferences]]\n{{Identical|Namespace}}",
index acf0103..4071a06 100644 (file)
@@ -100,8 +100,12 @@ class CheckStorage {
                        $missingTextRows = array_flip( $this->oldIdMap );
                        $externalRevs = [];
                        $objectRevs = [];
-                       $res = $dbr->select( 'text', [ 'old_id', 'old_flags' ],
-                               'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', __METHOD__ );
+                       $res = $dbr->select(
+                               'text',
+                               [ 'old_id', 'old_flags' ],
+                               [ 'old_id' => $this->oldIdMap ],
+                               __METHOD__
+                       );
                        foreach ( $res as $row ) {
                                /**
                                 * @var $flags int
@@ -158,8 +162,12 @@ class CheckStorage {
                        $externalConcatBlobs = [];
                        $externalNormalBlobs = [];
                        if ( count( $externalRevs ) ) {
-                               $res = $dbr->select( 'text', [ 'old_id', 'old_flags', 'old_text' ],
-                                       [ 'old_id IN (' . implode( ',', $externalRevs ) . ')' ], __METHOD__ );
+                               $res = $dbr->select(
+                                       'text',
+                                       [ 'old_id', 'old_flags', 'old_text' ],
+                                       [ 'old_id' => $externalRevs ],
+                                       __METHOD__
+                               );
                                foreach ( $res as $row ) {
                                        $urlParts = explode( '://', $row->old_text, 2 );
                                        if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) {
@@ -224,7 +232,7 @@ class CheckStorage {
                                $res = $dbr->select(
                                        'text',
                                        [ 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ],
-                                       [ 'old_id IN (' . implode( ',', $objectRevs ) . ')' ],
+                                       [ 'old_id' => $objectRevs ],
                                        __METHOD__
                                );
                                foreach ( $res as $row ) {
@@ -283,7 +291,7 @@ class CheckStorage {
                                $res = $dbr->select(
                                        'text',
                                        [ 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ],
-                                       [ 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ],
+                                       [ 'old_id' => array_keys( $concatBlobs ) ],
                                        __METHOD__
                                );
                                foreach ( $res as $row ) {
index 3d075e2..b494429 100644 (file)
@@ -2117,6 +2117,7 @@ return [
                        'resources/src/mediawiki.special/mediawiki.special.preferences.convertmessagebox.js',
                        'resources/src/mediawiki.special/mediawiki.special.preferences.tabs.js',
                        'resources/src/mediawiki.special/mediawiki.special.preferences.timezone.js',
+                       'resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js',
                ],
                'messages' => [
                        'prefs-tabs-navigation-hint',
diff --git a/resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js b/resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js
new file mode 100644 (file)
index 0000000..f934d59
--- /dev/null
@@ -0,0 +1,24 @@
+/*!
+ * JavaScript for Special:Preferences: Email preferences better UX
+ */
+( function ( $ ) {
+       $( function () {
+               var allowEmail, allowEmailFromNewUsers;
+
+               allowEmail = $( '#wpAllowEmail' );
+               allowEmailFromNewUsers = $( '#wpAllowEmailFromNewUsers' );
+
+               function toggleDisabled() {
+                       if ( allowEmail.is( ':checked' ) && allowEmail.is( ':enabled' ) ) {
+                               allowEmailFromNewUsers.prop( 'disabled', false );
+                       } else {
+                               allowEmailFromNewUsers.prop( 'disabled', true );
+                       }
+               }
+
+               if ( allowEmail ) {
+                       allowEmail.on( 'change', toggleDisabled );
+                       toggleDisabled();
+               }
+       } );
+}( jQuery ) );