* Use WikiPage instead of Article to call doEdit()
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 8 Jan 2012 20:42:22 +0000 (20:42 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 8 Jan 2012 20:42:22 +0000 (20:42 +0000)
* Pass the User doing the edit to doEdit()
* Check for invalid title before fecthing content and doing the edit

maintenance/importSiteScripts.php

index 849c7b1..527b3bd 100644 (file)
@@ -16,22 +16,29 @@ class ImportSiteScripts extends Maintenance {
        
        public function execute() {
                global $wgUser;
-               $wgUser = User::newFromName( $this->getOption( 'username', 'ScriptImporter' ) );
+
+               $user = User::newFromName( $this->getOption( 'username', 'ScriptImporter' ) );
+               $wgUser = $user;
                
                $baseUrl = $this->getArg( 1 );
                $pageList = $this->fetchScriptList();
                $this->output( 'Importing ' . count( $pageList ) . " pages\n" );
                
                foreach ( $pageList as $page ) {
+                       $title = Title::makeTitleSafe( NS_MEDIAWIKI, $page );
+                       if ( !$title ) {
+                               $this->error( "$page is an invalid title; it will not be imported\n" );
+                               continue;
+                       }
+
                        $this->output( "Importing $page\n" );
                        $url = wfAppendQuery( $baseUrl, array( 
                                'action' => 'raw', 
                                'title' => "MediaWiki:{$page}" ) );
                        $text = Http::get( $url );
-                       
-                       $title = Title::makeTitleSafe( NS_MEDIAWIKI, $page );
-                       $article = new Article( $title );
-                       $article->doEdit( $text, "Importing from $url", 0 );
+
+                       $wikiPage = WikiPage::factory( $title );
+                       $wikiPage->doEdit( $text, "Importing from $url", 0, false, $user );
                }
                
        }