Merge "mediawiki.page.patrol.ajax: Rename file to match module name"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 22 Dec 2015 14:07:40 +0000 (14:07 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 22 Dec 2015 14:07:40 +0000 (14:07 +0000)
includes/jobqueue/jobs/RefreshLinksJob.php
includes/specials/SpecialMediaStatistics.php
languages/i18n/en.json
languages/i18n/qqq.json
resources/src/mediawiki/mediawiki.ForeignStructuredUpload.BookletLayout.js
resources/src/mediawiki/mediawiki.ForeignStructuredUpload.js
resources/src/mediawiki/mediawiki.Upload.BookletLayout.js
resources/src/mediawiki/mediawiki.template.js

index 183c1ee..c8a9892 100644 (file)
@@ -222,6 +222,24 @@ class RefreshLinksJob extends Job {
                        $parserOutput
                );
 
+               foreach ( $updates as $key => $update ) {
+                       // FIXME: This code probably shouldn't be here?
+                       // Needed by things like Echo notifications which need
+                       // to know which user caused the links update
+                       if ( $update instanceof LinksUpdate ) {
+                               if ( !empty( $this->params['triggeringUser'] ) ) {
+                                       $userInfo = $this->params['triggeringUser'];
+                                       if ( $userInfo['userId'] ) {
+                                               $user = User::newFromId( $userInfo['userId'] );
+                                       } else {
+                                               // Anonymous, use the username
+                                               $user = User::newFromName( $userInfo['userName'], false );
+                                       }
+                                       $update->setTriggeringUser( $user );
+                               }
+                       }
+               }
+
                $latestNow = $page->lockAndGetLatest();
                if ( !$latestNow || $revision->getId() != $latestNow ) {
                        // Do not clobber over newer updates with older ones. If all jobs where FIFO and
index e5ba8c6..aeebc42 100644 (file)
  */
 class MediaStatisticsPage extends QueryPage {
        protected $totalCount = 0, $totalBytes = 0;
+       /**
+       * @var integer $totalPerType Combined file size of all files in a section
+       */
+       protected $totalPerType = 0;
+       /**
+       * @var integer $totalSize Combined file size of all files
+       */
+       protected $totalSize = 0;
 
        function __construct( $name = 'MediaStatistics' ) {
                parent::__construct( $name );
@@ -123,6 +131,7 @@ class MediaStatisticsPage extends QueryPage {
                                        $this->outputTableEnd();
                                }
                                $this->outputMediaType( $mediaType );
+                               $this->totalPerType = 0;
                                $this->outputTableStart( $mediaType );
                                $prevMediaType = $mediaType;
                        }
@@ -130,6 +139,11 @@ class MediaStatisticsPage extends QueryPage {
                }
                if ( $prevMediaType !== null ) {
                        $this->outputTableEnd();
+                       $this->getOutput()->addWikiText(
+                               $this->msg( 'mediastatistics-allbytes' )
+                                       ->numParams( $this->totalSize )
+                                       ->text()
+                       );
                }
        }
 
@@ -138,6 +152,12 @@ class MediaStatisticsPage extends QueryPage {
         */
        protected function outputTableEnd() {
                $this->getOutput()->addHtml( Html::closeElement( 'table' ) );
+               $this->getOutput()->addWikiText(
+                               $this->msg( 'mediastatistics-bytespertype' )
+                                       ->numParams( $this->totalPerType )
+                                       ->text()
+               );
+               $this->totalSize += $this->totalPerType;
        }
 
        /**
@@ -180,7 +200,7 @@ class MediaStatisticsPage extends QueryPage {
                                ->numParams( $this->makePercentPretty( $bytes / $this->totalBytes ) )
                                ->parse()
                );
-
+               $this->totalPerType += $bytes;
                $this->getOutput()->addHTML( Html::rawElement( 'tr', array(), $row ) );
        }
 
index 000b4ae..3f761f6 100644 (file)
        "mediastatistics-summary": "Statistics about uploaded file types. This only includes the most recent version of a file. Old or deleted versions of files are excluded.",
        "mediastatistics-nfiles": "$1 ($2%)",
        "mediastatistics-nbytes": "{{PLURAL:$1|$1 byte|$1 bytes}} ($2; $3%)",
+       "mediastatistics-bytespertype": "Total file size for this section: $1 bytes.",
+       "mediastatistics-allbytes": "Total file size for all files: $1 bytes.",
        "mediastatistics-table-mimetype": "MIME type",
        "mediastatistics-table-extensions": "Possible extensions",
        "mediastatistics-table-count": "Number of files",
index d21718e..dab2adc 100644 (file)
        "mediastatistics-summary": "Used to explain that this page only does statistics over current versions of files. \"Old\" versions of files and deleted files are not counted.",
        "mediastatistics-nfiles": "{{optional}}\nEntry in table on [[Special:MediaStatistics]] that gives total number of files. $1 - number of files. $2 - percentage of total files that is this type (percent will be formatted to have about 3 interesting digits. e.g. 0.121 or 10.2)",
        "mediastatistics-nbytes": "Combined space of this type of file. Bytes and \"human units\" are shown so that users can better get a sense of magnitude when making comparisons.\n*$1 - total space in bytes.\n*$2 - total space in \"human units\" (i.e. KB, MB, GB, etc)\n*$3 - What percentage of the space all uploads take up does this file take up.",
+       "mediastatistics-bytespertype": "Combined space of one section of [[Special:MediaStatistics]]. \n*$1 - total space in bytes",
+       "mediastatistics-allbytes": "Combined space of all uploaded files. \n*$1 - total space in bytes",
        "mediastatistics-table-mimetype": "Header for table on Special:MediaStatistics. Column that lists MIME types (The values in this column will look like 'image/jpeg', and be linked to Special:MIMESearch).",
        "mediastatistics-table-extensions": "Header for column in tables on [[Special:MediaStatistics]] that lists possible extensions for a given file type. (The values in this column will be a comma separated list of file extensions, such as '.webm' or '.png, .apng').",
        "mediastatistics-table-count": "Column header on Special:MediaStatistics for the number of files column. The headers in this column use {{msg-mw|mediastatistics-nfiles}}.",
index 7ba73bf..aa2998b 100644 (file)
                } );
                this.descriptionWidget = new OO.ui.TextInputWidget( {
                        required: true,
-                       validate: /.+/,
+                       validate: /\S+/,
                        multiline: true,
                        autosize: true
                } );
index 768efc3..c03c0d1 100644 (file)
         * @return {string}
         */
        ForeignStructuredUpload.prototype.getUser = function () {
-               var username = mw.config.get( 'wgUserName' );
-               // Do not localise 'User:', we don't know the language of target wiki
-               return '[[User:' + username + '|' + username + ']]';
+               var username, namespace;
+               // Do not localise, we don't know the language of target wiki
+               namespace = 'User';
+               username = mw.config.get( 'wgUserName' );
+               if ( !username ) {
+                       // The user is not logged in locally. However, they might be logged in on the foreign wiki.
+                       // We should record their username there. (If they're not logged in there either, this will
+                       // record the IP address.) It's also possible that the user opened this dialog, got an error
+                       // about not being logged in, logged in in another browser tab, then continued uploading.
+                       username = '{{subst:REVISIONUSER}}';
+               }
+               return '[[' + namespace + ':' + username + '|' + username + ']]';
        };
 
        mw.ForeignStructuredUpload = ForeignStructuredUpload;
index e4197dc..54f3ab6 100644 (file)
                this.descriptionWidget = new OO.ui.TextInputWidget( {
                        indicator: 'required',
                        required: true,
-                       validate: /.+/,
+                       validate: /\S+/,
                        multiline: true,
                        autosize: true
                } );
index 91f1aff..5e0e343 100644 (file)
@@ -8,43 +8,47 @@
 
        mw.template = {
                /**
-                * Register a new compiler and template.
+                * Register a new compiler.
                 *
-                * @param {string} name of compiler. Should also match with any file extensions of templates that want to use it.
-                * @param {Function} compiler which must implement a compile function
+                * A compiler is any object that implements a compile() method. The compile() method must
+                * return a Template interface with a method render() that returns HTML.
+                *
+                * The compiler name must correspond with the name suffix of templates that use this compiler.
+                *
+                * @param {string} name Compiler name
+                * @param {Object} compiler
                 */
                registerCompiler: function ( name, compiler ) {
                        if ( !compiler.compile ) {
-                               throw new Error( 'Compiler must implement compile method.' );
+                               throw new Error( 'Compiler must implement a compile method' );
                        }
                        compilers[ name ] = compiler;
                },
 
                /**
-                * Get the name of the compiler associated with a template based on its name.
+                * Get the name of the associated compiler based on a template name.
                 *
-                * @param {string} templateName Name of template (including file suffix)
-                * @return {string} Name of compiler
+                * @param {string} templateName Name of a template (including suffix)
+                * @return {string} Name of compiler
                 */
                getCompilerName: function ( templateName ) {
-                       var templateParts = templateName.split( '.' );
-
-                       if ( templateParts.length < 2 ) {
-                               throw new Error( 'Unable to identify compiler. Template name must have a suffix.' );
+                       var nameParts = templateName.split( '.' );
+                       if ( nameParts.length < 2 ) {
+                               throw new Error( 'Template name must have a suffix' );
                        }
-                       return templateParts[ templateParts.length - 1 ];
+                       return nameParts[ nameParts.length - 1 ];
                },
 
                /**
-                * Get the compiler for a given compiler name.
+                * Get a compiler via its name.
                 *
-                * @param {string} compilerName Name of the compiler
-                * @return {Object} The compiler associated with that name
+                * @param {string} name Name of a compiler
+                * @return {Object} The compiler
                 */
-               getCompiler: function ( compilerName ) {
-                       var compiler = compilers[ compilerName ];
+               getCompiler: function ( name ) {
+                       var compiler = compilers[ name ];
                        if ( !compiler ) {
-                               throw new Error( 'Unknown compiler ' + compilerName );
+                               throw new Error( 'Unknown compiler ' + name );
                        }
                        return compiler;
                },
                /**
                 * Register a template associated with a module.
                 *
-                * Compiles the newly added template based on the suffix in its name.
+                * Precompiles the newly added template based on the suffix in its name.
                 *
-                * @param {string} moduleName Name of ResourceLoader module to get the template from
-                * @param {string} templateName Name of template to add including file extension
-                * @param {string} templateBody Contents of a template (e.g. html markup)
-                * @return {Function} Compiled template
+                * @param {string} moduleName Name of the ResourceLoader module the template is associated with
+                * @param {string} templateName Name of the template (including suffix)
+                * @param {string} templateBody Contents of the template (e.g. html markup)
+                * @return {Object} Compiled template
                 */
                add: function ( moduleName, templateName, templateBody ) {
-                       var compiledTemplate,
-                               compilerName = this.getCompilerName( templateName );
-
+                       // Precompile and add to cache
+                       var compiled = this.compile( templateBody, this.getCompilerName( templateName ) );
                        if ( !compiledTemplates[ moduleName ] ) {
                                compiledTemplates[ moduleName ] = {};
                        }
+                       compiledTemplates[ moduleName ][ templateName ] = compiled;
 
-                       compiledTemplate = this.compile( templateBody, compilerName );
-                       compiledTemplates[ moduleName ][ templateName ] = compiledTemplate;
-                       return compiledTemplate;
+                       return compiled;
                },
 
                /**
-                * Retrieve a template by module and template name.
+                * Get a compiled template by module and template name.
                 *
                 * @param {string} moduleName Name of the module to retrieve the template from
                 * @param {string} templateName Name of template to be retrieved
                 * @return {Object} Compiled template
                 */
                get: function ( moduleName, templateName ) {
-                       var moduleTemplates, compiledTemplate;
+                       var moduleTemplates;
 
-                       // Check if the template has already been compiled, compile it if not
-                       if ( !compiledTemplates[ moduleName ] || !compiledTemplates[ moduleName ][ templateName ] ) {
-                               moduleTemplates = mw.templates.get( moduleName );
-                               if ( !moduleTemplates || !moduleTemplates[ templateName ] ) {
-                                       throw new Error( 'Template ' + templateName + ' not found in module ' + moduleName );
-                               }
+                       // Try cache first
+                       if ( compiledTemplates[ moduleName ] && compiledTemplates[ moduleName ][ templateName ] ) {
+                               return compiledTemplates[ moduleName ][ templateName ];
+                       }
 
-                               // Add compiled version
-                               compiledTemplate = this.add( moduleName, templateName, moduleTemplates[ templateName ] );
-                       } else {
-                               compiledTemplate = compiledTemplates[ moduleName ][ templateName ];
+                       moduleTemplates = mw.templates.get( moduleName );
+                       if ( !moduleTemplates || !moduleTemplates[ templateName ] ) {
+                               throw new Error( 'Template ' + templateName + ' not found in module ' + moduleName );
                        }
-                       return compiledTemplate;
+
+                       // Compiled and add to cache
+                       return this.add( moduleName, templateName, moduleTemplates[ templateName ] );
                },
 
                /**
-                * Wrap our template engine of choice.
+                * Compile a string of template markup with an engine of choice.
                 *
                 * @param {string} templateBody Template body
                 * @param {string} compilerName The name of a registered compiler
-                * @return {Object} Template interface
+                * @return {Object} Compiled template
                 */
                compile: function ( templateBody, compilerName ) {
                        return this.getCompiler( compilerName ).compile( templateBody );