r83227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83226‎ | r83227 | r83228 >
Date:18:25, 4 March 2011
Author:mah
Status:resolved
Tags:
Comment:
* Bug 27823 - Re-enable functionality of --uploads option of importDump.php; introduce --namespaces filter option for importDump.php

Patch from Dmitriy Sintsov of which he writes:

I needed to selectively import files from URL's defined in
previousely made XML dump. This worked fine in 1.15, but to my
surprise wasn't working with 1.17, producing an error. I've
partially fixed upload code (including supplying of original User
instance for local upload) and introduced new option to
selectively import only the listed namespaces in importDump.php
command line.
Modified paths:
  • /trunk/phase3/maintenance/importDump.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importDump.php
@@ -22,7 +22,7 @@
2323 * @ingroup Maintenance
2424 */
2525
26 -$optionsWithArgs = array( 'report' );
 26+$optionsWithArgs = array( 'report', 'namespaces' );
2727
2828 require_once( dirname( __FILE__ ) . '/commandLine.inc' );
2929
@@ -38,11 +38,46 @@
3939 var $dryRun = false;
4040 var $debug = false;
4141 var $uploads = false;
 42+ var $nsFilter = false;
4243
4344 function __construct() {
4445 $this->stderr = fopen( "php://stderr", "wt" );
4546 }
4647
 48+ function setNsfilter( array $namespaces ) {
 49+ if ( count( $namespaces ) == 0 ) {
 50+ $this->nsFilter = false;
 51+ return;
 52+ }
 53+ $this->nsFilter = array_unique( array_map( array( $this, 'getNsIndex' ), $namespaces ) );
 54+ }
 55+
 56+ private function getNsIndex( $namespace ) {
 57+ global $wgContLang;
 58+ if ( ( $result = $wgContLang->getNsIndex( $namespace ) ) !== false ) {
 59+ return $result;
 60+ }
 61+ $ns = intval( $namespace );
 62+ if ( strval( $ns ) === $namespace && $wgContLang->getNsText( $ns ) !== false ) {
 63+ return $ns;
 64+ }
 65+ wfDie( "Unknown namespace text / index specified: $namespace\n" );
 66+ }
 67+
 68+ private function skippedNamespace( $obj ) {
 69+ if ( $obj instanceof Title ) {
 70+ $ns = $obj->getNamespace();
 71+ } elseif ( $obj instanceof Revision ) {
 72+ $ns = $obj->getTitle()->getNamespace();
 73+ } elseif ( $obj instanceof WikiRevision ) {
 74+ $ns = $obj->title->getNamespace();
 75+ } else {
 76+ echo wfBacktrace();
 77+ wfDie( "Cannot get namespace of object in " . __METHOD__ . "\n" );
 78+ }
 79+ return is_array( $this->nsFilter ) && !in_array( $ns, $this->nsFilter );
 80+ }
 81+
4782 function reportPage( $page ) {
4883 $this->pageCount++;
4984 }
@@ -54,6 +89,10 @@
5590 return;
5691 }
5792
 93+ if ( $this->skippedNamespace( $title ) ) {
 94+ return;
 95+ }
 96+
5897 $this->revCount++;
5998 $this->report();
6099
@@ -64,6 +103,9 @@
65104
66105 function handleUpload( $revision ) {
67106 if ( $this->uploads ) {
 107+ if ( $this->skippedNamespace( $revision ) ) {
 108+ return;
 109+ }
68110 $this->uploadCount++;
69111 // $this->report();
70112 $this->progress( "upload: " . $revision->getFilename() );
@@ -78,6 +120,9 @@
79121 }
80122
81123 function handleLogItem( $rev ) {
 124+ if ( $this->skippedNamespace( $rev ) ) {
 125+ return;
 126+ }
82127 $this->revCount++;
83128 $this->report();
84129
@@ -177,6 +222,8 @@
178223 echo "Options:\n";
179224 echo " --quiet Don't dump status reports to stderr.\n";
180225 echo " --report=n Report position and speed after every n pages processed.\n";
 226+ echo " --namespaces=a|b|..|z Import only the pages from namespaces belonging to\n";
 227+ echo " the list of pipe-separated namespace names or namespace indexes\n";
181228 echo " --dry-run Parse dump without actually importing pages.\n";
182229 echo " --debug Output extra verbose debug information\n";
183230 echo " --uploads Process file upload data if included (experimental)\n";
@@ -209,6 +256,9 @@
210257 if ( isset( $options['uploads'] ) ) {
211258 $reader->uploads = true; // experimental!
212259 }
 260+if ( isset( $options['namespaces'] ) ) {
 261+ $reader->setNsfilter( explode( '|', $options['namespaces'] ) );
 262+}
213263
214264 if ( isset( $options['help'] ) ) {
215265 $reader->showHelp();

Follow-up revisions

RevisionCommit summaryAuthorDate
r83233followup r83227 ... missed bits of patchmah19:19, 4 March 2011

Status & tagging log