r108365 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108364‎ | r108365 | r108366 >
Date:20:42, 8 January 2012
Author:ialex
Status:ok
Tags:
Comment:
* Use WikiPage instead of Article to call doEdit()
* Pass the User doing the edit to doEdit()
* Check for invalid title before fecthing content and doing the edit
Modified paths:
  • /trunk/phase3/maintenance/importSiteScripts.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importSiteScripts.php
@@ -16,22 +16,29 @@
1717
1818 public function execute() {
1919 global $wgUser;
20 - $wgUser = User::newFromName( $this->getOption( 'username', 'ScriptImporter' ) );
 20+
 21+ $user = User::newFromName( $this->getOption( 'username', 'ScriptImporter' ) );
 22+ $wgUser = $user;
2123
2224 $baseUrl = $this->getArg( 1 );
2325 $pageList = $this->fetchScriptList();
2426 $this->output( 'Importing ' . count( $pageList ) . " pages\n" );
2527
2628 foreach ( $pageList as $page ) {
 29+ $title = Title::makeTitleSafe( NS_MEDIAWIKI, $page );
 30+ if ( !$title ) {
 31+ $this->error( "$page is an invalid title; it will not be imported\n" );
 32+ continue;
 33+ }
 34+
2735 $this->output( "Importing $page\n" );
2836 $url = wfAppendQuery( $baseUrl, array(
2937 'action' => 'raw',
3038 'title' => "MediaWiki:{$page}" ) );
3139 $text = Http::get( $url );
32 -
33 - $title = Title::makeTitleSafe( NS_MEDIAWIKI, $page );
34 - $article = new Article( $title );
35 - $article->doEdit( $text, "Importing from $url", 0 );
 40+
 41+ $wikiPage = WikiPage::factory( $title );
 42+ $wikiPage->doEdit( $text, "Importing from $url", 0, false, $user );
3643 }
3744
3845 }

Status & tagging log