+ # Check Protection
+ if (isset($options['protect']) && isset($options['unprotect']))
+ die("Cannot specify both protect and unprotect. Only 1 is allowed.\n");
+
+if (isset($options['protect']) && $options['protect'] == 1)
+ die("You must specify a protection option.\n");
+
+ # Prepare the list of allowed extensions
+ global $wgFileExtensions;
+ $extensions = isset( $options['extensions'] )
+ ? explode( ',', strtolower( $options['extensions'] ) )
+ : $wgFileExtensions;
+
+ # Search the path provided for candidates for import
+ $files = findFiles( $dir, $extensions );
+
+ # Initialise the user for this operation
+ $user = isset( $options['user'] )
+ ? User::newFromName( $options['user'] )
+ : User::newFromName( 'Maintenance script' );
+ if( !$user instanceof User )
+ $user = User::newFromName( 'Maintenance script' );
+ $wgUser = $user;
+
+ # Get block check. If a value is given, this specified how often the check is performed
+ if ( isset( $options['check-userblock'] ) ) {
+ if ( !$options['check-userblock'] ) $checkUserBlock = 1;
+ else $checkUserBlock = (int)$options['check-userblock'];
+ } else {
+ $checkUserBlock = false;
+ }
+
+ # Get --from
+ $from = @$options['from'];
+
+ # Get sleep time.
+ $sleep = @$options['sleep'];
+ if ( $sleep ) $sleep = (int)$sleep;
+
+ # Get limit number
+ $limit = @$options['limit'];
+ if ( $limit ) $limit = (int)$limit;
+
+ # Get the upload comment
+ $comment = NULL;
+
+ if ( isset( $options['comment-file'] ) ) {
+ $comment = file_get_contents( $options['comment-file'] );
+ if ( $comment === false || $comment === NULL ) {
+ die( "failed to read comment file: {$options['comment-file']}\n" );
+ }
+ }
+ else if ( isset( $options['comment'] ) ) {
+ $comment = $options['comment'];
+ }
+
+ $commentExt = isset( $options['comment-ext'] ) ? $options['comment-ext'] : false;
+
+ # Get the license specifier
+ $license = isset( $options['license'] ) ? $options['license'] : '';