r13834 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13833‎ | r13834 | r13835 >
Date:03:44, 24 April 2006
Author:tstarling
Status:old
Tags:
Comment:
Added revision list filter
Modified paths:
  • /trunk/mwdumper/Makefile (modified) (history)
  • /trunk/mwdumper/README (modified) (history)
  • /trunk/mwdumper/build.xml (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/dumper/Dumper.java (modified) (history)
  • /trunk/mwdumper/src/org/mediawiki/importer/RevisionListFilter.java (added) (history)

Diff [purge]

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
195 + native
Added: svn:keywords
296 + Author Date Id Revision
Index: trunk/mwdumper/src/org/mediawiki/dumper/Dumper.java
@@ -253,6 +253,8 @@
254254 return new ListFilter(sink, param);
255255 else if (filter.equals("exactlist"))
256256 return new ExactListFilter(sink, param);
 257+ else if (filter.equals("revlist"))
 258+ return new RevisionListFilter(sink, param);
257259 else
258260 throw new IllegalArgumentException("Filter unknown: " + filter);
259261 }
Index: trunk/mwdumper/Makefile
@@ -28,6 +28,7 @@
2929 src/org/mediawiki/importer/ExactListFilter.java \
3030 src/org/mediawiki/importer/LatestFilter.java \
3131 src/org/mediawiki/importer/ListFilter.java \
 32+ src/org/mediawiki/importer/RevisionListFilter.java \
3233 src/org/mediawiki/importer/MultiWriter.java \
3334 src/org/mediawiki/importer/NamespaceFilter.java \
3435 src/org/mediawiki/importer/NamespaceSet.java \
Index: trunk/mwdumper/README
@@ -96,6 +96,8 @@
9797 ignored. Talk and subject pages of given titles are both matched.
9898 --filter=exactlist:<list-filename>
9999 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.
100102 --filter=namespace:[!]<NS_KEY,NS_OTHERKEY,100,...>
101103 Includes only pages in (or not in, with "!") the given namespaces.
102104 You can use the NS_* constant names or the raw numeric keys.
Index: trunk/mwdumper/build.xml
@@ -27,6 +27,7 @@
2828 </target>
2929
3030 <target name="jar" depends="compile">
 31+ <mkdir dir="build" />
3132 <jar jarfile="build/mwdumper.jar" compress="true">
3233 <manifest>
3334 <attribute name="Main-Class" value="org.mediawiki.dumper.Dumper" />

Status & tagging log