Skip to content
This repository has been archived by the owner on Mar 20, 2020. It is now read-only.

Commit

Permalink
Bug fixes and usability updates for MTC
Browse files Browse the repository at this point in the history
  • Loading branch information
Fastily committed Nov 2, 2016
1 parent 1a6bf26 commit 9516cef
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 106 deletions.
11 changes: 0 additions & 11 deletions MTCui.bat

This file was deleted.

27 changes: 15 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,38 @@ apply plugin: 'maven'

description="ctools build script"
version="1.0.0"
//group="fastily"

sourceSets {
main {
resources {
srcDirs = ['.']
includes=['*.md']
}
}
}

compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}


repositories {
mavenCentral()
jcenter()
}

dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'commons-cli:commons-cli:1.3.1'

compile project(":jwiki-extras")
}

task wrapper(type: Wrapper) {
gradleVersion = '3.1'
}

jar {
archiveName = "MTC-0.1.1.jar"

from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
}

manifest {
attributes 'Main-Class': 'mtc.MTCui'
}

exclude "**/test/**", "enwp/**", "up/**", "**/README.md", "**/ToDo.md"
}
27 changes: 0 additions & 27 deletions mtcBuild.xml

This file was deleted.

42 changes: 0 additions & 42 deletions src/main/java/enwp/analysis/FindPossibleNSD.java

This file was deleted.

1 change: 1 addition & 0 deletions src/main/java/mtc/CMTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void main(String[] args) throws Throwable
Wiki wiki = Toolbox.getFastilyClone();
// Do initial logins, and generate MTC regexes
mtc = new MTC(wiki);
mtc.useTrackingCat = false;
mtc.dryRun = l.hasOption('d');

if (l.hasOption('f'))
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/mtc/MTC.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fastily.jwiki.core.Wiki;
import fastily.jwiki.util.FError;
import fastily.jwiki.util.FL;
import fastily.jwikix.core.TParse;
import fastily.jwikix.tplate.Template;
import util.Toolbox;

Expand All @@ -38,6 +39,11 @@ public final class MTC
*/
protected final Wiki enwp, com;

/**
* Regex matching Copy to Commons templates.
*/
protected final String mtcRegex;

/**
* Flag indicating whether this is a debug-mode/dry run (do not perform transfers)
*/
Expand All @@ -48,6 +54,11 @@ public final class MTC
*/
protected boolean ignoreFilter = false;

/**
* Flag indicating whether the Commons category tracking transfers should be used.
*/
protected boolean useTrackingCat = true;

/**
* Contains data for license tags
*/
Expand All @@ -72,6 +83,8 @@ else if (!Files.isDirectory(Config.fdPath))
com = wiki.getWiki("commons.wikimedia.org");
enwp = wiki.getWiki("en.wikipedia.org");

mtcRegex = TParse.makeTemplateRegex(enwp, "Template:Copy to Wikimedia Commons");

// Process template data
for (Map.Entry<String, String> e : Toolbox.fetchPairedConfig(enwp, Config.fullname + "/Regexes").entrySet())
{
Expand Down
46 changes: 32 additions & 14 deletions src/main/java/mtc/TransferFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.regex.Pattern;

import fastily.jwiki.core.MQuery;
import fastily.jwiki.core.NS;
import fastily.jwiki.core.Wiki;
import fastily.jwiki.dwrap.ImageInfo;
import fastily.jwiki.util.FL;
Expand Down Expand Up @@ -106,22 +107,29 @@ protected TransferFile(String wpFN, String comFN, MTC mtc)
*/
protected boolean doTransfer()
{
root = ParsedItem.parse(enwp, wpFN);
try
{
root = ParsedItem.parse(enwp, wpFN);

imgInfoL = enwp.getImageInfo(wpFN);
uploader = imgInfoL.get(imgInfoL.size() - 1).user;
imgInfoL = enwp.getImageInfo(wpFN);
uploader = imgInfoL.get(imgInfoL.size() - 1).user;

procText();
String t = gen();
procText();
String t = gen();

if (mtc.dryRun)
if (mtc.dryRun)
{
System.out.println(t);
return true;
}
else if (t != null && Toolbox.downloadFile(imgInfoL.get(0).url, localFN)
&& com.upload(Paths.get(localFN), comFN, t, String.format(Config.tFrom, wpFN)))
return enwp.edit(wpFN, String.format("{{subst:ncd|%s|reviewer=%s}}%n", comFN, enwp.whoami()) + enwp.getPageText(wpFN).replaceAll(mtc.mtcRegex, ""), Config.tTo);
}
catch (Throwable e)
{
System.out.println(t);
return true;
e.printStackTrace();
}
else if (t != null && Toolbox.downloadFile(imgInfoL.get(0).url, localFN)
&& com.upload(Paths.get(localFN), comFN, t, String.format(Config.tFrom, wpFN)))
return enwp.addText(wpFN, String.format("{{subst:ncd|%s}}%n", comFN), Config.tTo, true);

return false;
}
Expand All @@ -135,8 +143,11 @@ private void procText()

// Normalize license and special template titles
for (Template t : masterTPL)
if (mtc.tpMap.containsKey(t.title))
t.title = mtc.tpMap.get(t.title);
{
String tp = enwp.whichNS(t.title).equals(NS.TEMPLATE) ? enwp.nss(t.title): t.title;
if (mtc.tpMap.containsKey(tp))
t.title = mtc.tpMap.get(tp);
}

ArrayList<Template> tpl = new ArrayList<>(masterTPL);

Expand Down Expand Up @@ -168,6 +179,10 @@ private void procText()
t.title = "GFDL-user-en-with-disclaimers";
t.put("1", uploader);
break;
case "GFDL-self":
t.title = "GFDL-self-en";
t.put("author", String.format("{{User at project|%s|w|en}}", uploader));
break;
case "Copy to Wikimedia Commons":
tpl.remove(t.drop());
break;
Expand Down Expand Up @@ -215,7 +230,7 @@ private Template filterFillInfo(Template info)
t.put("Date", info.has("Date") ? info.get("Date") : "");
t.put("Source", info.has("Source") ? info.get("Source")
: String.format("{{Transferred from|en.wikipedia|%s|%s}}", enwp.whoami(), Config.mtcComLink));
t.put("Author", info.has("Author") ? info.get("Author") : String.format("{{Original uploader|%s|w}}", uploader));
t.put("Author", info.has("Author") ? info.get("Author") : "See below");
t.put("Permission", info.has("Permission") ? info.get("Permission") : "");
t.put("other versions", info.has("other versions") ? info.get("other versions") : "");

Expand Down Expand Up @@ -245,6 +260,9 @@ private String gen()
ii.user, ii.user, ii.summary.replace("\n", " "));
t += "|}\n\n{{Subst:Unc}}";

if(mtc.useTrackingCat)
t += "\n[[Category:Uploaded with MTC!]]";

return t;
}
}
File renamed without changes.

0 comments on commit 9516cef

Please sign in to comment.