Pass phpcs-strict on maintenance/ (4/8)
authorSiebrand Mazeland <siebrand@kitano.nl>
Tue, 22 Apr 2014 21:25:04 +0000 (23:25 +0200)
committerSiebrand Mazeland <siebrand@kitano.nl>
Wed, 23 Apr 2014 08:26:09 +0000 (10:26 +0200)
Change-Id: Ib9ee255740681f0d32d76b75ef33b369bc87bcc1

maintenance/importImages.php
maintenance/initSiteStats.php
maintenance/install.php
maintenance/lag.php
maintenance/mergeMessageFileList.php
maintenance/moveBatch.php
maintenance/orphans.php
maintenance/parse.php
maintenance/patchSql.php
maintenance/populateCategory.php

index 54fd4e2..ba77354 100644 (file)
@@ -4,7 +4,8 @@
  * using the web-based interface.
  *
  * "Smart import" additions:
- * - aim: preserve the essential metadata (user, description) when importing medias from an existing wiki
+ * - aim: preserve the essential metadata (user, description) when importing media
+ *   files from an existing wiki.
  * - process:
  *      - interface with the source wiki, don't use bare files only (see --source-wiki-url).
  *      - fetch metadata from source wiki for each file to import.
@@ -87,16 +88,24 @@ if ( isset( $options['check-userblock'] ) ) {
 }
 
 # Get --from
-$from = @$options['from'];
+wfSuppressWarnings();
+$from = $options['from'];
+wfRestoreWarnings();
 
 # Get sleep time.
-$sleep = @$options['sleep'];
+wfSuppressWarnings();
+$sleep = $options['sleep'];
+wfRestoreWarnings();
+
 if ( $sleep ) {
        $sleep = (int)$sleep;
 }
 
 # Get limit number
-$limit = @$options['limit'];
+wfSuppressWarnings();
+$limit = $options['limit'];
+wfRestoreWarnings();
+
 if ( $limit ) {
        $limit = (int)$limit;
 }
@@ -167,7 +176,8 @@ if ( $count > 0 ) {
                } else {
                        if ( isset( $options['skip-dupes'] ) ) {
                                $repo = $image->getRepo();
-                               $sha1 = File::sha1Base36( $file ); # XXX: we end up calculating this again when actually uploading. that sucks.
+                               # XXX: we end up calculating this again when actually uploading. that sucks.
+                               $sha1 = File::sha1Base36( $file );
 
                                $dupes = $repo->findBySha1( $sha1 );
 
@@ -210,7 +220,8 @@ if ( $count > 0 ) {
                        if ( $commentExt ) {
                                $f = findAuxFile( $file, $commentExt );
                                if ( !$f ) {
-                                       echo " No comment file with extension {$commentExt} found for {$file}, using default comment. ";
+                                       echo " No comment file with extension {$commentExt} found "
+                                               . "for {$file}, using default comment. ";
                                } else {
                                        $commentText = file_get_contents( $f );
                                        if ( !$commentText ) {
@@ -254,7 +265,13 @@ if ( $count > 0 ) {
 
                if ( isset( $options['dry'] ) ) {
                        echo "done.\n";
-               } elseif ( $image->recordUpload2( $archive->value, $summary, $commentText, $props, $timestamp ) ) {
+               } elseif ( $image->recordUpload2(
+                       $archive->value,
+                       $summary,
+                       $commentText,
+                       $props,
+                       $timestamp
+               ) ) {
                        # We're done!
                        echo "done.\n";
 
@@ -337,28 +354,37 @@ USAGE: php importImages.php [options] <dir>
 <dir> : Path to the directory containing images to be imported
 
 Options:
---extensions=<exts>     Comma-separated list of allowable extensions, defaults to \$wgFileExtensions
---overwrite             Overwrite existing images with the same name (default is to skip them)
---limit=<num>           Limit the number of images to process. Ignored or skipped images are not counted.
---from=<name>           Ignore all files until the one with the given name. Useful for resuming
-                        aborted imports. <name> should be the file's canonical database form.
---skip-dupes            Skip images that were already uploaded under a different name (check SHA1)
---search-recursively    Search recursively for files in subdirectories
+--extensions=<exts>     Comma-separated list of allowable extensions, defaults
+                        to \$wgFileExtensions.
+--overwrite             Overwrite existing images with the same name (default
+                        is to skip them).
+--limit=<num>           Limit the number of images to process. Ignored or
+                        skipped images are not counted.
+--from=<name>           Ignore all files until the one with the given name.
+                        Useful for resuming aborted imports. <name> should be
+                        the file's canonical database form.
+--skip-dupes            Skip images that were already uploaded under a different
+                        name (check SHA1).
+--search-recursively    Search recursively for files in subdirectories.
 --sleep=<sec>           Sleep between files. Useful mostly for debugging.
---user=<username>       Set username of uploader, default 'Maintenance script'
+--user=<username>       Set username of uploader, default 'Maintenance script'.
 --check-userblock       Check if the user got blocked during import.
 --comment=<text>        Set file description, default 'Importing file'.
 --comment-file=<file>   Set description to the content of <file>.
---comment-ext=<ext>     Causes the description for each file to be loaded from a file with the same name
-                        but the extension <ext>. If a global description is also given, it is appended.
---license=<code>        Use an optional license template
---dry                   Dry run, don't import anything
---protect=<protect>     Specify the protect value (autoconfirmed,sysop)
---summary=<summary>     Upload summary, description will be used if not provided
---timestamp=<timestamp> Override upload time/date, all MediaWiki timestamp formats are accepted
---unprotect             Unprotects all uploaded images
---source-wiki-url       If specified, take User and Comment data for each imported file from this URL.
-                        For example, --source-wiki-url="http://en.wikipedia.org/"
+--comment-ext=<ext>     Causes the description for each file to be loaded from a
+                        file with the same name, but the extension <ext>. If a
+                        global description is also given, it is appended.
+--license=<code>        Use an optional license template.
+--dry                   Dry run, don't import anything.
+--protect=<protect>     Specify the protect value (autoconfirmed,sysop).
+--summary=<summary>     Upload summary, description will be used if not
+                        provided.
+--timestamp=<timestamp> Override upload time/date, all MediaWiki timestamp
+                        formats are accepted.
+--unprotect             Unprotects all uploaded images.
+--source-wiki-url       If specified, take User and Comment data for each
+                        imported file from this URL. For example,
+                        --source-wiki-url="http://en.wikipedia.org/."
 
 TEXT;
        exit( 1 );
index 92268b3..c368c3f 100644 (file)
@@ -34,7 +34,10 @@ class InitSiteStats extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Re-initialise the site statistics tables";
-               $this->addOption( 'update', 'Update the existing statistics (preserves the ss_total_views field)' );
+               $this->addOption(
+                       'update',
+                       'Update the existing statistics (preserves the ss_total_views field)'
+               );
                $this->addOption( 'noviews', "Don't update the page view counter" );
                $this->addOption( 'active', 'Also update active users count' );
                $this->addOption( 'use-master', 'Count using the master database' );
index 44c117e..6fc4782 100644 (file)
@@ -45,9 +45,19 @@ class CommandLineInstaller extends Maintenance {
 
                $this->addArg( 'admin', 'The username of the wiki administrator (WikiSysop)', true );
                $this->addOption( 'pass', 'The password for the wiki administrator.', false, true );
-               $this->addOption( 'passfile', 'An alternative way to provide pass option, as the contents of this file', false, true );
+               $this->addOption(
+                       'passfile',
+                       'An alternative way to provide pass option, as the contents of this file',
+                       false,
+                       true
+               );
                /* $this->addOption( 'email', 'The email for the wiki administrator', false, true ); */
-               $this->addOption( 'scriptpath', 'The relative path of the wiki in the web server (/wiki)', false, true );
+               $this->addOption(
+                       'scriptpath',
+                       'The relative path of the wiki in the web server (/wiki)',
+                       false,
+                       true
+               );
 
                $this->addOption( 'lang', 'The language to use (en)', false, true );
                /* $this->addOption( 'cont-lang', 'The content language (en)', false, true ); */
@@ -62,22 +72,32 @@ class CommandLineInstaller extends Maintenance {
                $this->addOption( 'installdbpass', 'The pasword for the DB user to install as.', false, true );
                $this->addOption( 'dbuser', 'The user to use for normal operations (wikiuser)', false, true );
                $this->addOption( 'dbpass', 'The pasword for the DB user for normal operations', false, true );
-               $this->addOption( 'dbpassfile', 'An alternative way to provide dbpass option, as the contents of this file', false, true );
+               $this->addOption(
+                       'dbpassfile',
+                       'An alternative way to provide dbpass option, as the contents of this file',
+                       false,
+                       true
+               );
                $this->addOption( 'confpath', "Path to write LocalSettings.php to, default $IP", false, true );
-               /* $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true ); */
-               /* $this->addOption( 'namespace', 'The project namespace (same as the name)', false, true ); */
+               /*
+               $this->addOption( 'dbschema', 'The schema for the MediaWiki DB in pg (mediawiki)', false, true );
+               $this->addOption( 'namespace', 'The project namespace (same as the name)', false, true );
+               */
                $this->addOption( 'env-checks', "Run environment checks only, don't change anything" );
        }
 
        function execute() {
                global $IP;
-               $siteName = isset( $this->mArgs[0] ) ? $this->mArgs[0] : "Don't care"; // Will not be set if used with --env-checks
+
+               // Will not be set if used with --env-checks
+               $siteName = isset( $this->mArgs[0] ) ? $this->mArgs[0] : "Don't care";
                $adminName = isset( $this->mArgs[1] ) ? $this->mArgs[1] : null;
 
                $dbpassfile = $this->getOption( 'dbpassfile', false );
                if ( $dbpassfile !== false ) {
                        if ( $this->getOption( 'dbpass', false ) !== false ) {
-                               $this->error( 'WARNING: You provide the options "dbpass" and "dbpassfile". The content of "dbpassfile" overwrites "dbpass".' );
+                               $this->error( 'WARNING: You provide the options "dbpass" and "dbpassfile". '
+                                       . 'The content of "dbpassfile" overwrites "dbpass".' );
                        }
                        wfSuppressWarnings();
                        $dbpass = file_get_contents( $dbpassfile );
@@ -91,7 +111,8 @@ class CommandLineInstaller extends Maintenance {
                $passfile = $this->getOption( 'passfile', false );
                if ( $passfile !== false ) {
                        if ( $this->getOption( 'pass', false ) !== false ) {
-                               $this->error( 'WARNING: You provide the options "pass" and "passfile". The content of "passfile" overwrites "pass".' );
+                               $this->error( 'WARNING: You provide the options "pass" and "passfile". '
+                                       . 'The content of "passfile" overwrites "pass".' );
                        }
                        wfSuppressWarnings();
                        $pass = file_get_contents( $passfile );
index 410bf75..52f8201 100644 (file)
@@ -39,7 +39,9 @@ class DatabaseLag extends Maintenance {
                if ( $this->hasOption( 'r' ) ) {
                        $lb = wfGetLB();
                        echo 'time     ';
-                       for ( $i = 1; $i < $lb->getServerCount(); $i++ ) {
+
+                       $serverCount = $lb->getServerCount();
+                       for ( $i = 1; $i < $serverCount; $i++ ) {
                                $hostname = $lb->getServerName( $i );
                                printf( "%-12s ", $hostname );
                        }
index a63c45b..f016a2c 100644 (file)
@@ -43,7 +43,12 @@ class MergeMessageFileList extends Maintenance {
 
        function __construct() {
                parent::__construct();
-               $this->addOption( 'list-file', 'A file containing a list of extension setup files, one per line.', false, true );
+               $this->addOption(
+                       'list-file',
+                       'A file containing a list of extension setup files, one per line.',
+                       false,
+                       true
+               );
                $this->addOption( 'extensions-dir', 'Path where extensions can be found.', false, true );
                $this->addOption( 'output', 'Send output to this file (omit for stdout)', false, true );
                $this->mDescription = 'Merge $wgExtensionMessagesFiles and $wgMessagesDirs from ' .
@@ -51,7 +56,10 @@ class MergeMessageFileList extends Maintenance {
        }
 
        public function execute() {
-               global $mmfl, $wgExtensionEntryPointListFiles;
+               // @codingStandardsIgnoreStart Ignore error: Global variable "$mmfl" is lacking 'wg' prefix
+               global $mmfl;
+               // @codingStandardsIgnoreEnd
+               global $wgExtensionEntryPointListFiles;
 
                if ( !count( $wgExtensionEntryPointListFiles )
                        && !$this->hasOption( 'list-file' )
index 5171b17..713753f 100644 (file)
@@ -82,7 +82,9 @@ class MoveBatch extends Maintenance {
 
                # Setup complete, now start
                $dbw = wfGetDB( DB_MASTER );
+               // @codingStandardsIgnoreStart Ignore avoid function calls in a FOR loop test part warning
                for ( $linenum = 1; !feof( $file ); $linenum++ ) {
+                       // @codingStandardsIgnoreEnd
                        $line = fgets( $file );
                        if ( $line === false ) {
                                break;
index 044003e..1a8052b 100644 (file)
@@ -79,7 +79,8 @@ class Orphans extends Maintenance {
                        $this->lockTables( $dbw );
                }
 
-               $this->output( "Checking for orphan revision table entries... (this may take a while on a large wiki)\n" );
+               $this->output( "Checking for orphan revision table entries... "
+                       . "(this may take a while on a large wiki)\n" );
                $result = $dbw->query( "
                        SELECT *
                        FROM $revision LEFT OUTER JOIN $page ON rev_page=page_id
@@ -88,8 +89,13 @@ class Orphans extends Maintenance {
                $orphans = $result->numRows();
                if ( $orphans > 0 ) {
                        global $wgContLang;
+
                        $this->output( "$orphans orphan revisions...\n" );
-                       $this->output( sprintf( "%10s %10s %14s %20s %s\n", 'rev_id', 'rev_page', 'rev_timestamp', 'rev_user_text', 'rev_comment' ) );
+                       $this->output( sprintf(
+                               "%10s %10s %14s %20s %s\n",
+                               'rev_id', 'rev_page', 'rev_timestamp', 'rev_user_text', 'rev_comment'
+                       ) );
+
                        foreach ( $result as $row ) {
                                $comment = ( $row->rev_comment == '' )
                                        ? ''
@@ -131,7 +137,8 @@ class Orphans extends Maintenance {
                        $this->lockTables( $dbw );
                }
 
-               $this->output( "\nChecking for childless page table entries... (this may take a while on a large wiki)\n" );
+               $this->output( "\nChecking for childless page table entries... "
+                       . "(this may take a while on a large wiki)\n" );
                $result = $dbw->query( "
                        SELECT *
                        FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id
@@ -176,7 +183,8 @@ class Orphans extends Maintenance {
                        $this->lockTables( $dbw, array( 'user', 'text' ) );
                }
 
-               $this->output( "\nChecking for pages whose page_latest links are incorrect... (this may take a while on a large wiki)\n" );
+               $this->output( "\nChecking for pages whose page_latest links are incorrect... "
+                       . "(this may take a while on a large wiki)\n" );
                $result = $dbw->query( "
                        SELECT *
                        FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id
index 7765784..0ec1de9 100644 (file)
@@ -62,7 +62,12 @@ class CLIParser extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Parse a given wikitext";
-               $this->addOption( 'title', 'Title name for the given wikitext (Default: \'CLIParser\')', false, true );
+               $this->addOption(
+                       'title',
+                       'Title name for the given wikitext (Default: \'CLIParser\')',
+                       false,
+                       true
+               );
                $this->addArg( 'file', 'File containing wikitext (Default: stdin)', false );
        }
 
@@ -90,7 +95,8 @@ class CLIParser extends Maintenance {
 
                if ( $input_file === $php_stdin ) {
                        $ctrl = wfIsWindows() ? 'CTRL+Z' : 'CTRL+D';
-                       $this->error( basename( __FILE__ ) . ": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
+                       $this->error( basename( __FILE__ )
+                               . ": warning: reading wikitext from STDIN. Press $ctrl to parse.\n" );
                }
 
                return file_get_contents( $input_file );
index 31ce156..5d9fc1b 100644 (file)
@@ -33,7 +33,10 @@ class PatchSql extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Run an SQL file into the DB, replacing prefix and charset vars";
-               $this->addArg( 'patch-name', 'Name of the patch file, either full path or in maintenance/archives' );
+               $this->addArg(
+                       'patch-name',
+                       'Name of the patch file, either full path or in maintenance/archives'
+               );
        }
 
        public function getDbType() {
index 4c8cdaa..15087f8 100644 (file)
@@ -51,9 +51,24 @@ When the script has finished, it will make a note of this in the database, and
 will not run again without the --force option.
 TEXT;
 # '
-               $this->addOption( 'begin', 'Only do categories whose names are alphabetically after the provided name', false, true );
-               $this->addOption( 'max-slave-lag', 'If slave lag exceeds this many seconds, wait until it drops before continuing.  Default: 10', false, true );
-               $this->addOption( 'throttle', 'Wait this many milliseconds after each category.  Default: 0', false, true );
+               $this->addOption(
+                       'begin',
+                       'Only do categories whose names are alphabetically after the provided name',
+                       false,
+                       true
+               );
+               $this->addOption(
+                       'max-slave-lag',
+                       'If slave lag exceeds this many seconds, wait until it drops before continuing. Default: 10',
+                       false,
+                       true
+               );
+               $this->addOption(
+                       'throttle',
+                       'Wait this many milliseconds after each category. Default: 0',
+                       false,
+                       true
+               );
                $this->addOption( 'force', 'Run regardless of whether the database says it\'s been run already' );
        }