line endings
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 5 Jan 2007 03:37:19 +0000 (03:37 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 5 Jan 2007 03:37:19 +0000 (03:37 +0000)
maintenance/importTextFile.php

index a29d879..92c31fd 100644 (file)
@@ -1,84 +1,84 @@
-<?php\r
-\r
-/**\r
- * Maintenance script allows creating or editing pages using\r
- * the contents of a text file\r
- *\r
- * @package MediaWiki\r
- * @subpackage Maintenance\r
- * @author Rob Church <robchur@gmail.com>\r
- */\r
\r
-$options = array( 'help', 'nooverwrite' ); \r
-$optionsWithArgs = array( 'title', 'user', 'comment' );\r
-require_once( 'commandLine.inc' );\r
-echo( "Import Text File\n\n" );\r
-\r
-if( isset( $options['help'] ) ) {\r
-       showHelp();\r
-} else {\r
-\r
-       $filename = $args[0];\r
-       echo( "Using {$filename}..." );\r
-       if( is_file( $filename ) ) {\r
-               \r
-               $title = isset( $options['title'] ) ? $options['title'] : titleFromFilename( $filename );\r
-               $title = Title::newFromUrl( $title );\r
-               echo( "\nUsing title '" . $title->getPrefixedText() . "'..." );\r
-               \r
-               if( is_object( $title ) ) {\r
-                       \r
-                       if( !$title->exists() || !isset( $options['nooverwrite'] ) ) {\r
-                       \r
-                               $text = file_get_contents( $filename );\r
-                               $user = isset( $options['user'] ) ? $options['user'] : 'MediaWiki default';\r
-                               $user = User::newFromName( $user );\r
-                               echo( "\nUsing username '" . $user->getName() . "'..." );\r
-                               \r
-                               if( is_object( $user ) ) {\r
-                               \r
-                                       $wgUser =& $user;\r
-                                       $comment = isset( $options['comment'] ) ? $options['comment'] : 'Importing text file';\r
-                                       $comment = str_replace( '_', ' ', $comment );\r
-                                       \r
-                                       echo( "\nPerforming edit..." );\r
-                                       $article = new Article( $title );\r
-                                       $article->doEdit( $text, $comment );\r
-                                       echo( "done.\n" );\r
-                               \r
-                               } else {\r
-                                       echo( "invalid username.\n" );\r
-                               }\r
-                       \r
-                       } else {\r
-                               echo( "page exists.\n" );\r
-                       }\r
-                       \r
-               } else {\r
-                       echo( "invalid title.\n" );\r
-               }\r
-               \r
-       } else {\r
-               echo( "does not exist.\n" );\r
-       }\r
-\r
-}\r
-\r
-function titleFromFilename( $filename ) {\r
-       $parts = explode( '/', $filename );\r
-       $parts = explode( '.', $parts[ count( $parts ) - 1 ] );\r
-       return $parts[0];\r
-}\r
-\r
-function showHelp() {\r
-       echo( "Import the contents of a text file into a wiki page.\n\n" );\r
-       echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>|--nooverwrite] <filename>\n\n" );\r
-       echo( "              --help: Show this help information\n" );\r
-       echo( "    --title <title> : Title for the new page; if not supplied, the filename is used as a base for the title\n" );\r
-       echo( "      --user <user> : User to be associated with the edit; if not supplied, a default is used\n" );\r
-       echo( "--comment <comment> : Edit summary to be associated with the edit; underscores are transformed into spaces; if not supplied, a default is used\n" );\r
-       echo( "      --nooverwrite : Don't overwrite existing page content\n" );\r
-       echo( "         <filename> : Path to the file containing the wikitext to import\n\n" );\r
-}\r
-\r
+<?php
+
+/**
+ * Maintenance script allows creating or editing pages using
+ * the contents of a text file
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ * @author Rob Church <robchur@gmail.com>
+ */
+$options = array( 'help', 'nooverwrite' ); 
+$optionsWithArgs = array( 'title', 'user', 'comment' );
+require_once( 'commandLine.inc' );
+echo( "Import Text File\n\n" );
+
+if( isset( $options['help'] ) ) {
+       showHelp();
+} else {
+
+       $filename = $args[0];
+       echo( "Using {$filename}..." );
+       if( is_file( $filename ) ) {
+               
+               $title = isset( $options['title'] ) ? $options['title'] : titleFromFilename( $filename );
+               $title = Title::newFromUrl( $title );
+               echo( "\nUsing title '" . $title->getPrefixedText() . "'..." );
+               
+               if( is_object( $title ) ) {
+                       
+                       if( !$title->exists() || !isset( $options['nooverwrite'] ) ) {
+                       
+                               $text = file_get_contents( $filename );
+                               $user = isset( $options['user'] ) ? $options['user'] : 'MediaWiki default';
+                               $user = User::newFromName( $user );
+                               echo( "\nUsing username '" . $user->getName() . "'..." );
+                               
+                               if( is_object( $user ) ) {
+                               
+                                       $wgUser =& $user;
+                                       $comment = isset( $options['comment'] ) ? $options['comment'] : 'Importing text file';
+                                       $comment = str_replace( '_', ' ', $comment );
+                                       
+                                       echo( "\nPerforming edit..." );
+                                       $article = new Article( $title );
+                                       $article->doEdit( $text, $comment );
+                                       echo( "done.\n" );
+                               
+                               } else {
+                                       echo( "invalid username.\n" );
+                               }
+                       
+                       } else {
+                               echo( "page exists.\n" );
+                       }
+                       
+               } else {
+                       echo( "invalid title.\n" );
+               }
+               
+       } else {
+               echo( "does not exist.\n" );
+       }
+
+}
+
+function titleFromFilename( $filename ) {
+       $parts = explode( '/', $filename );
+       $parts = explode( '.', $parts[ count( $parts ) - 1 ] );
+       return $parts[0];
+}
+
+function showHelp() {
+       echo( "Import the contents of a text file into a wiki page.\n\n" );
+       echo( "USAGE: php importTextFile.php [--help|--title <title>|--user <user>|--comment <comment>|--nooverwrite] <filename>\n\n" );
+       echo( "              --help: Show this help information\n" );
+       echo( "    --title <title> : Title for the new page; if not supplied, the filename is used as a base for the title\n" );
+       echo( "      --user <user> : User to be associated with the edit; if not supplied, a default is used\n" );
+       echo( "--comment <comment> : Edit summary to be associated with the edit; underscores are transformed into spaces; if not supplied, a default is used\n" );
+       echo( "      --nooverwrite : Don't overwrite existing page content\n" );
+       echo( "         <filename> : Path to the file containing the wikitext to import\n\n" );
+}
+
 ?>
\ No newline at end of file