Index: trunk/phase3/maintenance/importDump.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | * @ingroup Maintenance |
24 | 24 | */ |
25 | 25 | |
26 | | -$optionsWithArgs = array( 'report' ); |
| 26 | +$optionsWithArgs = array( 'report', 'namespaces' ); |
27 | 27 | |
28 | 28 | require_once( dirname( __FILE__ ) . '/commandLine.inc' ); |
29 | 29 | |
— | — | @@ -38,11 +38,46 @@ |
39 | 39 | var $dryRun = false; |
40 | 40 | var $debug = false; |
41 | 41 | var $uploads = false; |
| 42 | + var $nsFilter = false; |
42 | 43 | |
43 | 44 | function __construct() { |
44 | 45 | $this->stderr = fopen( "php://stderr", "wt" ); |
45 | 46 | } |
46 | 47 | |
| 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 | + |
47 | 82 | function reportPage( $page ) { |
48 | 83 | $this->pageCount++; |
49 | 84 | } |
— | — | @@ -54,6 +89,10 @@ |
55 | 90 | return; |
56 | 91 | } |
57 | 92 | |
| 93 | + if ( $this->skippedNamespace( $title ) ) { |
| 94 | + return; |
| 95 | + } |
| 96 | + |
58 | 97 | $this->revCount++; |
59 | 98 | $this->report(); |
60 | 99 | |
— | — | @@ -64,6 +103,9 @@ |
65 | 104 | |
66 | 105 | function handleUpload( $revision ) { |
67 | 106 | if ( $this->uploads ) { |
| 107 | + if ( $this->skippedNamespace( $revision ) ) { |
| 108 | + return; |
| 109 | + } |
68 | 110 | $this->uploadCount++; |
69 | 111 | // $this->report(); |
70 | 112 | $this->progress( "upload: " . $revision->getFilename() ); |
— | — | @@ -78,6 +120,9 @@ |
79 | 121 | } |
80 | 122 | |
81 | 123 | function handleLogItem( $rev ) { |
| 124 | + if ( $this->skippedNamespace( $rev ) ) { |
| 125 | + return; |
| 126 | + } |
82 | 127 | $this->revCount++; |
83 | 128 | $this->report(); |
84 | 129 | |
— | — | @@ -177,6 +222,8 @@ |
178 | 223 | echo "Options:\n"; |
179 | 224 | echo " --quiet Don't dump status reports to stderr.\n"; |
180 | 225 | 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"; |
181 | 228 | echo " --dry-run Parse dump without actually importing pages.\n"; |
182 | 229 | echo " --debug Output extra verbose debug information\n"; |
183 | 230 | echo " --uploads Process file upload data if included (experimental)\n"; |
— | — | @@ -209,6 +256,9 @@ |
210 | 257 | if ( isset( $options['uploads'] ) ) { |
211 | 258 | $reader->uploads = true; // experimental! |
212 | 259 | } |
| 260 | +if ( isset( $options['namespaces'] ) ) { |
| 261 | + $reader->setNsfilter( explode( '|', $options['namespaces'] ) ); |
| 262 | +} |
213 | 263 | |
214 | 264 | if ( isset( $options['help'] ) ) { |
215 | 265 | $reader->showHelp(); |