Merge "resourceloader: Rename ResourceLoaderImageModule::ensureStuffLoaded to loadFro...
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sun, 24 May 2015 11:30:30 +0000 (11:30 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 24 May 2015 11:30:30 +0000 (11:30 +0000)
autoload.php
includes/Sanitizer.php
includes/api/ApiResult.php
includes/installer/Installer.php
includes/installer/LocalSettingsGenerator.php
includes/installer/WebInstallerPage.php
includes/installer/i18n/en.json
includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php [new file with mode: 0644]
resources/Resources.php
resources/src/mediawiki/mediawiki.jqueryMsg.js

index f8b1681..4bb1d92 100644 (file)
@@ -995,6 +995,7 @@ $wgAutoloadLocalClasses = array(
        'ResourceLoaderFilePath' => __DIR__ . '/includes/resourceloader/ResourceLoaderFilePath.php',
        'ResourceLoaderImage' => __DIR__ . '/includes/resourceloader/ResourceLoaderImage.php',
        'ResourceLoaderImageModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderImageModule.php',
+       'ResourceLoaderJqueryMsgDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php',
        'ResourceLoaderLanguageDataModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageDataModule.php',
        'ResourceLoaderLanguageNamesModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderLanguageNamesModule.php',
        'ResourceLoaderModule' => __DIR__ . '/includes/resourceloader/ResourceLoaderModule.php',
index 96193a7..8256db9 100644 (file)
@@ -359,20 +359,13 @@ class Sanitizer {
        }
 
        /**
-        * Cleans up HTML, removes dangerous tags and attributes, and
-        * removes HTML comments
-        * @param string $text
-        * @param callable $processCallback Callback to do any variable or parameter
-        *   replacements in HTML attribute values
-        * @param array|bool $args Arguments for the processing callback
+        * Return the various lists of recognized tags
         * @param array $extratags For any extra tags to include
         * @param array $removetags For any tags (default or extra) to exclude
-        * @return string
+        * @return array
         */
-       public static function removeHTMLtags( $text, $processCallback = null,
-               $args = array(), $extratags = array(), $removetags = array()
-       ) {
-               global $wgUseTidy, $wgAllowMicrodataAttributes, $wgAllowImageTag;
+       public static function getRecognizedTagData( $extratags = array(), $removetags = array() ) {
+               global $wgAllowMicrodataAttributes, $wgAllowImageTag;
 
                static $htmlpairsStatic, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags,
                        $htmllist, $listtags, $htmlsingleallowed, $htmlelementsStatic, $staticInitialised;
@@ -431,12 +424,44 @@ class Sanitizer {
                        }
                        $staticInitialised = $globalContext;
                }
+
                # Populate $htmlpairs and $htmlelements with the $extratags and $removetags arrays
                $extratags = array_flip( $extratags );
                $removetags = array_flip( $removetags );
                $htmlpairs = array_merge( $extratags, $htmlpairsStatic );
                $htmlelements = array_diff_key( array_merge( $extratags, $htmlelementsStatic ), $removetags );
 
+               return array(
+                       'htmlpairs' => $htmlpairs,
+                       'htmlsingle' => $htmlsingle,
+                       'htmlsingleonly' => $htmlsingleonly,
+                       'htmlnest' => $htmlnest,
+                       'tabletags' => $tabletags,
+                       'htmllist' => $htmllist,
+                       'listtags' => $listtags,
+                       'htmlsingleallowed' => $htmlsingleallowed,
+                       'htmlelements' => $htmlelements,
+               );
+       }
+
+       /**
+        * Cleans up HTML, removes dangerous tags and attributes, and
+        * removes HTML comments
+        * @param string $text
+        * @param callable $processCallback Callback to do any variable or parameter
+        *   replacements in HTML attribute values
+        * @param array|bool $args Arguments for the processing callback
+        * @param array $extratags For any extra tags to include
+        * @param array $removetags For any tags (default or extra) to exclude
+        * @return string
+        */
+       public static function removeHTMLtags( $text, $processCallback = null,
+               $args = array(), $extratags = array(), $removetags = array()
+       ) {
+               global $wgUseTidy;
+
+               extract( self::getRecognizedTagData( $extratags, $removetags ) );
+
                # Remove HTML comments
                $text = Sanitizer::removeHTMLcomments( $text );
                $bits = explode( '<', $text );
index 044b6e0..7c573a8 100644 (file)
@@ -832,11 +832,13 @@ class ApiResult implements ApiSerializable {
                                isset( $metadata[self::META_BC_SUBELEMENTS] )
                        ) {
                                foreach ( $metadata[self::META_BC_SUBELEMENTS] as $k ) {
-                                       $data[$k] = array(
-                                               '*' => $data[$k],
-                                               self::META_CONTENT => '*',
-                                               self::META_TYPE => 'assoc',
-                                       );
+                                       if ( isset( $data[$k] ) ) {
+                                               $data[$k] = array(
+                                                       '*' => $data[$k],
+                                                       self::META_CONTENT => '*',
+                                                       self::META_TYPE => 'assoc',
+                                               );
+                                       }
                                }
                        }
 
index f9c885d..5ae499d 100644 (file)
@@ -224,7 +224,7 @@ abstract class Installer {
 
                // $wgLogo is probably wrong (bug 48084); set something that will work.
                // Single quotes work fine here, as LocalSettingsGenerator outputs this unescaped.
-               'wgLogo' => '$wgScriptPath/resources/assets/wiki.png',
+               'wgLogo' => '$wgResourceBasePath/resources/assets/wiki.png',
        );
 
        /**
@@ -285,27 +285,27 @@ abstract class Installer {
        public $licenses = array(
                'cc-by' => array(
                        'url' => 'https://creativecommons.org/licenses/by/3.0/',
-                       'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-by.png',
+                       'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by.png',
                ),
                'cc-by-sa' => array(
                        'url' => 'https://creativecommons.org/licenses/by-sa/3.0/',
-                       'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-by-sa.png',
+                       'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-sa.png',
                ),
                'cc-by-nc-sa' => array(
                        'url' => 'https://creativecommons.org/licenses/by-nc-sa/3.0/',
-                       'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-by-nc-sa.png',
+                       'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-by-nc-sa.png',
                ),
                'cc-0' => array(
                        'url' => 'https://creativecommons.org/publicdomain/zero/1.0/',
-                       'icon' => '{$wgResourceBasePath}/resources/assets/licenses/cc-0.png',
+                       'icon' => '$wgResourceBasePath/resources/assets/licenses/cc-0.png',
                ),
                'pd' => array(
                        'url' => '',
-                       'icon' => '{$wgResourceBasePath}/resources/assets/licenses/public-domain.png',
+                       'icon' => '$wgResourceBasePath/resources/assets/licenses/public-domain.png',
                ),
                'gfdl' => array(
                        'url' => 'https://www.gnu.org/copyleft/fdl.html',
-                       'icon' => '{$wgResourceBasePath}/resources/assets/licenses/gnu-fdl.png',
+                       'icon' => '$wgResourceBasePath/resources/assets/licenses/gnu-fdl.png',
                ),
                'none' => array(
                        'url' => '',
index 737c996..162a789 100644 (file)
@@ -335,6 +335,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
 ${serverSetting}
 ## The relative URL path to the skins directory
 \$wgStylePath = \"\$wgScriptPath/skins\";
+\$wgResourceBasePath = \$wgScriptPath;
 
 ## The relative URL path to the logo.  Make sure you change this from the default,
 ## or else you'll overwrite your logo when you upgrade!
index 6e41514..98f3ae8 100644 (file)
@@ -1183,7 +1183,7 @@ class WebInstallerOptions extends WebInstallerPage {
                ) );
                $styleUrl = $server . dirname( dirname( $this->parent->getUrl() ) ) .
                        '/mw-config/config-cc.css';
-               $iframeUrl = 'https://creativecommons.org/license/?' .
+               $iframeUrl = '//creativecommons.org/license/?' .
                        wfArrayToCgi( array(
                                'partner' => 'MediaWiki',
                                'exit_url' => $exitUrl,
index 0dc8e88..c19e3ee 100644 (file)
@@ -57,7 +57,7 @@
        "config-magic-quotes-sybase": "<strong>Fatal: [http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-sybase magic_quotes_sybase] is active!</strong>\nThis option corrupts data input unpredictably.\nYou cannot install or use MediaWiki unless this option is disabled.",
        "config-mbstring": "<strong>Fatal: [http://www.php.net/manual/en/ref.mbstring.php#mbstring.overload mbstring.func_overload] is active!</strong>\nThis option causes errors and may corrupt data unpredictably.\nYou cannot install or use MediaWiki unless this option is disabled.",
        "config-safe-mode": "<strong>Warning:</strong> PHP's [http://www.php.net/features.safe-mode safe mode] is active.\nIt may cause problems, particularly if using file uploads and <code>math</code> support.",
-       "config-xml-bad": "PHP's XML module is missing.\nMediaWiki requires functions in this module and will not work in this configuration.\nIf you're running Mandrake, install the php-xml package.",
+       "config-xml-bad": "PHP's XML module is missing.\nMediaWiki requires functions in this module and will not work in this configuration.\nYou may need to install the php-xml RPM package.",
        "config-pcre-old": "<strong>Fatal:</strong> PCRE $1 or later is required.\nYour PHP binary is linked with PCRE $2.\n[https://www.mediawiki.org/wiki/Manual:Errors_and_symptoms/PCRE More information].",
        "config-pcre-no-utf8": "<strong>Fatal:</strong> PHP's PCRE module seems to be compiled without PCRE_UTF8 support.\nMediaWiki requires UTF-8 support to function correctly.",
        "config-memory-raised": "PHP's <code>memory_limit</code> is $1, raised to $2.",
diff --git a/includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php b/includes/resourceloader/ResourceLoaderJqueryMsgDataModule.php
new file mode 100644 (file)
index 0000000..fda3faa
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Resource loader module for populating mediawiki.jqueryMsg data.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @author Brad Jorsch
+ */
+
+/**
+ * ResourceLoader module for populating mediawiki.jqueryMsg data.
+ */
+class ResourceLoaderJqueryMsgDataModule extends ResourceLoaderModule {
+
+       protected $targets = array( 'desktop', 'mobile' );
+
+       /**
+        * @param ResourceLoaderContext $context
+        * @return string JavaScript code
+        */
+       public function getScript( ResourceLoaderContext $context ) {
+               $jsData = array();
+
+               $tagData = Sanitizer::getRecognizedTagData();
+               $jsData['allowedHtmlElements'] = array_merge(
+                       array_keys( $tagData['htmlpairs'] ),
+                       array_diff(
+                               array_keys( $tagData['htmlsingle'] ),
+                               array_keys( $tagData['htmlsingleonly'] )
+                       )
+               );
+
+               return "if ( !mw.jqueryMsg ) {\n" .
+                       "\tmw.jqueryMsg = {};\n" .
+                       "}\n" .
+                       "mw.jqueryMsg.data = " . Xml::encodeJsVar( $jsData ) . ";\n";
+       }
+
+       /**
+        * @param ResourceLoaderContext $context
+        * @return array|null
+        */
+       public function getDefinitionSummary( ResourceLoaderContext $context ) {
+               $ret = parent::getDefinitionSummary( $context );
+               $ret['hash'] = md5( $this->getScript( $context ) );
+               return $ret;
+       }
+}
index 237addc..71a8f29 100644 (file)
@@ -58,6 +58,9 @@ return array(
        // Scripts for the dynamic language specific data, like grammar forms.
        'mediawiki.language.data' => array( 'class' => 'ResourceLoaderLanguageDataModule' ),
 
+       // Dynamic data for mediawiki.jqueryMsg, such as allowed tags
+       'mediawiki.jqueryMsg.data' => array( 'class' => 'ResourceLoaderJqueryMsgDataModule' ),
+
        /* MediaWiki base skinning modules */
 
        /**
@@ -1270,6 +1273,7 @@ return array(
        'mediawiki.jqueryMsg' => array(
                'scripts' => 'resources/src/mediawiki/mediawiki.jqueryMsg.js',
                'dependencies' => array(
+                       'mediawiki.jqueryMsg.data',
                        'mediawiki.util',
                        'mediawiki.language',
                        'dom-level2-shim',
index 79939f6..98148d5 100644 (file)
                        magic: {
                                'SITENAME': mw.config.get( 'wgSiteName' )
                        },
-                       // This is a whitelist based on, but simpler than, Sanitizer.php.
+                       // This is a whitelist like Sanitizer.php.
                        // Self-closing tags are not currently supported.
+                       // The simplified default here is overridden below by data supplied
+                       // by the mediawiki.jqueryMsg.data module.
                        allowedHtmlElements: [
                                'b',
                                'i'
                };
        }
 
+       // Use data from mediawiki.jqueryMsg.data to override defaults, if
+       // available
+       if ( mw.jqueryMsg && mw.jqueryMsg.data ) {
+               if ( mw.jqueryMsg.data.allowedHtmlElements ) {
+                       parserDefaults.allowedHtmlElements = mw.jqueryMsg.data.allowedHtmlElements;
+               }
+       }
+
        mw.jqueryMsg = {};
 
        /**