Index: trunk/mwdumper/src/org/mediawiki/importer/RevisionListFilter.java |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +/* |
| 3 | + * MediaWiki import/export processing tools |
| 4 | + * Copyright 2006 by Tim Starling |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + * |
| 24 | + * $Id$ |
| 25 | + */ |
| 26 | + |
| 27 | +package org.mediawiki.importer; |
| 28 | + |
| 29 | +import java.lang.Integer; |
| 30 | +import java.io.BufferedReader; |
| 31 | +import java.io.FileInputStream; |
| 32 | +import java.io.IOException; |
| 33 | +import java.io.InputStreamReader; |
| 34 | +import java.util.TreeSet; |
| 35 | + |
| 36 | +public class RevisionListFilter implements DumpWriter { |
| 37 | + DumpWriter sink; |
| 38 | + protected TreeSet revIds; |
| 39 | + protected Page currentPage; |
| 40 | + protected boolean pageWritten; |
| 41 | + |
| 42 | + public RevisionListFilter(DumpWriter sink, String sourceFileName) throws IOException { |
| 43 | + this.sink = sink; |
| 44 | + revIds = new TreeSet(); |
| 45 | + BufferedReader input = new BufferedReader(new InputStreamReader( |
| 46 | + new FileInputStream(sourceFileName), "utf-8")); |
| 47 | + String line = input.readLine(); |
| 48 | + while (line != null) { |
| 49 | + line = line.trim(); |
| 50 | + if (line.length() > 0 && !line.startsWith("#")) { |
| 51 | + revIds.add(new Integer(line)); |
| 52 | + } |
| 53 | + line = input.readLine(); |
| 54 | + } |
| 55 | + input.close(); |
| 56 | + } |
| 57 | + |
| 58 | + public void close() throws IOException { |
| 59 | + sink.close(); |
| 60 | + } |
| 61 | + |
| 62 | + public void writeStartWiki() throws IOException { |
| 63 | + sink.writeStartWiki(); |
| 64 | + } |
| 65 | + |
| 66 | + public void writeEndWiki() throws IOException { |
| 67 | + sink.writeEndWiki(); |
| 68 | + } |
| 69 | + |
| 70 | + public void writeSiteinfo(Siteinfo info) throws IOException { |
| 71 | + sink.writeSiteinfo(info); |
| 72 | + } |
| 73 | + |
| 74 | + public void writeStartPage(Page page) throws IOException { |
| 75 | + currentPage = page; |
| 76 | + pageWritten = false; |
| 77 | + } |
| 78 | + |
| 79 | + public void writeEndPage() throws IOException { |
| 80 | + if (pageWritten) { |
| 81 | + sink.writeEndPage(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public void writeRevision(Revision revision) throws IOException { |
| 86 | + if (revIds.contains(new Integer(revision.Id))) { |
| 87 | + if (!pageWritten) { |
| 88 | + sink.writeStartPage(currentPage); |
| 89 | + pageWritten = true; |
| 90 | + } |
| 91 | + sink.writeRevision(revision); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
Property changes on: trunk/mwdumper/src/org/mediawiki/importer/RevisionListFilter.java |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 95 | + native |
Added: svn:keywords |
2 | 96 | + Author Date Id Revision |
Index: trunk/mwdumper/src/org/mediawiki/dumper/Dumper.java |
— | — | @@ -253,6 +253,8 @@ |
254 | 254 | return new ListFilter(sink, param); |
255 | 255 | else if (filter.equals("exactlist")) |
256 | 256 | return new ExactListFilter(sink, param); |
| 257 | + else if (filter.equals("revlist")) |
| 258 | + return new RevisionListFilter(sink, param); |
257 | 259 | else |
258 | 260 | throw new IllegalArgumentException("Filter unknown: " + filter); |
259 | 261 | } |
Index: trunk/mwdumper/Makefile |
— | — | @@ -28,6 +28,7 @@ |
29 | 29 | src/org/mediawiki/importer/ExactListFilter.java \ |
30 | 30 | src/org/mediawiki/importer/LatestFilter.java \ |
31 | 31 | src/org/mediawiki/importer/ListFilter.java \ |
| 32 | + src/org/mediawiki/importer/RevisionListFilter.java \ |
32 | 33 | src/org/mediawiki/importer/MultiWriter.java \ |
33 | 34 | src/org/mediawiki/importer/NamespaceFilter.java \ |
34 | 35 | src/org/mediawiki/importer/NamespaceSet.java \ |
Index: trunk/mwdumper/README |
— | — | @@ -96,6 +96,8 @@ |
97 | 97 | ignored. Talk and subject pages of given titles are both matched. |
98 | 98 | --filter=exactlist:<list-filename> |
99 | 99 | As above, but does not try to match associated talk/subject pages. |
| 100 | + --filter=revlist:<list-filename> |
| 101 | + Includes only the revisions specified by ID in the given file. |
100 | 102 | --filter=namespace:[!]<NS_KEY,NS_OTHERKEY,100,...> |
101 | 103 | Includes only pages in (or not in, with "!") the given namespaces. |
102 | 104 | You can use the NS_* constant names or the raw numeric keys. |
Index: trunk/mwdumper/build.xml |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | </target> |
29 | 29 | |
30 | 30 | <target name="jar" depends="compile"> |
| 31 | + <mkdir dir="build" /> |
31 | 32 | <jar jarfile="build/mwdumper.jar" compress="true"> |
32 | 33 | <manifest> |
33 | 34 | <attribute name="Main-Class" value="org.mediawiki.dumper.Dumper" /> |