Improve documentation of wfDeprecated
[lhc/web/wiklou.git] / maintenance / importTextFiles.php
index 5531ffc..c99aa15 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup Maintenance
  */
 
+use MediaWiki\MediaWikiServices;
+
 require_once __DIR__ . '/Maintenance.php';
 
 /**
@@ -71,7 +73,7 @@ class ImportTextFiles extends Maintenance {
                                        $files[$filename] = file_get_contents( $filename );
                                }
                                if ( !$found ) {
-                                       $this->error( "Fatal error: The file '$arg' does not exist!", 1 );
+                                       $this->fatalError( "Fatal error: The file '$arg' does not exist!" );
                                }
                        }
                };
@@ -86,7 +88,7 @@ class ImportTextFiles extends Maintenance {
                }
 
                if ( !$user ) {
-                       $this->error( "Invalid username\n", true );
+                       $this->fatalError( "Invalid username\n" );
                }
                if ( $user->isAnon() ) {
                        $user->addToDatabase();
@@ -103,16 +105,16 @@ class ImportTextFiles extends Maintenance {
                        $timestamp = $useTimestamp ? wfTimestamp( TS_UNIX, filemtime( $file ) ) : wfTimestampNow();
 
                        $title = Title::newFromText( $pageName );
-                       $exists = $title->exists();
-                       $oldRevID = $title->getLatestRevID();
-                       $oldRev = $oldRevID ? Revision::newFromId( $oldRevID ) : null;
-
-                       if ( !$title ) {
+                       // Have to check for # manually, since it gets interpreted as a fragment
+                       if ( !$title || $title->hasFragment() ) {
                                $this->error( "Invalid title $pageName. Skipping.\n" );
                                $skipCount++;
                                continue;
                        }
 
+                       $exists = $title->exists();
+                       $oldRevID = $title->getLatestRevID();
+                       $oldRev = $oldRevID ? Revision::newFromId( $oldRevID ) : null;
                        $actualTitle = $title->getPrefixedText();
 
                        if ( $exists ) {
@@ -129,7 +131,7 @@ class ImportTextFiles extends Maintenance {
                                }
                        }
 
-                       $rev = new WikiRevision( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) );
+                       $rev = new WikiRevision( MediaWikiServices::getInstance()->getMainConfig() );
                        $rev->setText( rtrim( $text ) );
                        $rev->setTitle( $title );
                        $rev->setUserObj( $user );
@@ -197,10 +199,10 @@ class ImportTextFiles extends Maintenance {
 
                $this->output( "Done! $successCount succeeded, $skipCount skipped.\n" );
                if ( $exit ) {
-                       $this->error( "Import failed with $failCount failed pages.\n", $exit );
+                       $this->fatalError( "Import failed with $failCount failed pages.\n", $exit );
                }
        }
 }
 
-$maintClass = "ImportTextFiles";
+$maintClass = ImportTextFiles::class;
 require_once RUN_MAINTENANCE_IF_MAIN;