Update git submodules
[lhc/web/wiklou.git] / maintenance / createCommonPasswordCdb.php
index c678712..ef5a30d 100644 (file)
@@ -26,9 +26,11 @@ require_once __DIR__ . '/Maintenance.php';
 /**
  * Maintenance script to create common password cdb database.
  *
- * Meant to take a file like
- * https://github.com/danielmiessler/SecLists/blob/master/Passwords/rockyou.txt?raw=true
- * as input.
+ * Meant to take a file like those from
+ * https://github.com/danielmiessler/SecLists
+ * For example:
+ * https://github.com/danielmiessler/SecLists/blob/fe2b40dd84/Passwords/rockyou.txt?raw=true
+ *
  * @see serialized/commonpasswords.cdb and PasswordPolicyChecks::checkPopularPasswordBlacklist
  * @since 1.27
  * @ingroup Maintenance
@@ -37,7 +39,7 @@ class GenerateCommonPassword extends Maintenance {
        public function __construct() {
                global $IP;
                parent::__construct();
-               $this->mDescription = "Generate CDB file of common passwords";
+               $this->addDescription( 'Generate CDB file of common passwords' );
                $this->addOption( 'limit', "Max number of passwords to write", false, true, 'l' );
                $this->addArg( 'inputfile', 'List of passwords (one per line) to use or - for stdin', true );
                $this->addArg(
@@ -58,18 +60,18 @@ class GenerateCommonPassword extends Maintenance {
                $outfile = $this->getArg( 1 );
 
                if ( !is_readable( $infile ) && $infile !== 'php://stdin' ) {
-                       $this->error( "Cannot open input file $infile for reading", 1 );
+                       $this->fatalError( "Cannot open input file $infile for reading" );
                }
 
                $file = fopen( $infile, 'r' );
                if ( $file === false ) {
-                       $this->error( "Cannot read input file $infile", 1 );
+                       $this->fatalError( "Cannot read input file $infile" );
                }
 
                try {
                        $db = \Cdb\Writer::open( $outfile );
 
-                       $alreadyWritten = array();
+                       $alreadyWritten = [];
                        $skipped = 0;
                        for ( $i = 0; ( $i - $skipped ) < $limit; $i++ ) {
                                if ( feof( $file ) ) {
@@ -107,11 +109,10 @@ class GenerateCommonPassword extends Maintenance {
                                " (out of $i) passwords to $outfile\n"
                        );
                } catch ( \Cdb\Exception $e ) {
-                       $this->error( "Error writing cdb file: " . $e->getMessage(), 2 );
+                       $this->fatalError( "Error writing cdb file: " . $e->getMessage(), 2 );
                }
-
        }
 }
 
-$maintClass = "GenerateCommonPassword";
+$maintClass = GenerateCommonPassword::class;
 require_once RUN_MAINTENANCE_IF_MAIN;