Skip to content

Commit

Permalink
Merge pull request #36 from yarl/dev
Browse files Browse the repository at this point in the history
version 17.05
  • Loading branch information
yarl authored May 8, 2017
2 parents 0e526b6 + a067fac commit dbeb7f5
Show file tree
Hide file tree
Showing 15 changed files with 421 additions and 183 deletions.
5 changes: 5 additions & 0 deletions src/org/wikipedia/Wiki.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ public String getDomain()
{
return domain;
}

public String getProtocol()
{
return protocol;
}

/**
* Gets the editing throttle.
Expand Down
27 changes: 24 additions & 3 deletions src/pattypan/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package pattypan;

import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
Expand All @@ -33,6 +35,8 @@

public class Main extends Application {

private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

@Override
public void start(Stage stage) {
Settings.readProperties();
Expand All @@ -56,10 +60,27 @@ public void start(Stage stage) {
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length > 0) {
Session.WIKI = new Wiki(args[0].equals("-test") ? "test.wikipedia.org" : args[0]);
String wiki = "commons.wikimedia.org";
String protocol = "https://";
String scriptPath = "/w";

for (String arg : args) {
String[] pair = arg.split("=");
if (pair[0].contains("wiki")) {
wiki = pair[1];
} else if (pair[0].contains("protocol")) {
protocol = pair[1];
} else if (pair[0].contains("scriptPath")) {
scriptPath = pair[1];
}
}

LOGGER.log(Level.INFO,
"Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}",
new String[]{wiki, protocol, scriptPath}
);

Session.WIKI = new Wiki(wiki, scriptPath, protocol);
launch(args);
}

}
52 changes: 50 additions & 2 deletions src/pattypan/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class Settings {
private Settings() {};

public static final String NAME = "pattypan";
public static final String VERSION = "0.6.0";
public static final String VERSION = "17.05";
public static final String USERAGENT = NAME + "/" + VERSION + " (https://github.com/yarl/pattypan)";

public static final Map<String, String> SETTINGS = new HashMap<>();
Expand Down Expand Up @@ -181,6 +181,8 @@ public final class Settings {
new TemplateField("linkback", "Linkback"),
new TemplateField("wikidata", "Wikidata"),
new TemplateField("license", "License"),
new TemplateField("partnership", "Partnership"),
new TemplateField("license", "License"),
new TemplateField("partnership", "Partnership")
}, "=={{int:filedesc}}==\n"
+ "{{Book\n"
Expand Down Expand Up @@ -225,7 +227,53 @@ public final class Settings {
+ "</#if>"
)
);

TEMPLATES.put("Musical work",
new Template("Musical work",
new TemplateField[]{
new TemplateField("composer", "Composer"),
new TemplateField("lyrics_writer", "Lyrics writer"),
new TemplateField("performer", "Performer"),
new TemplateField("title", "Title"),
new TemplateField("description", "Description"),
new TemplateField("composition_date", "Composition date"),
new TemplateField("performance_date", "Performance date"),
new TemplateField("notes", "Notes"),
new TemplateField("record_id", "Record ID"),
new TemplateField("image", "Image"),
new TemplateField("references", "References"),
new TemplateField("source", "Source"),
new TemplateField("permission", "Permission"),
new TemplateField("other_versions", "Other versions"),
new TemplateField("license", "License"),
new TemplateField("partnership", "Partnership")
}, "=={{int:filedesc}}==\n"
+ "{{Musical work\n"
+ " |composer = ${composer}\n"
+ " |lyrics_writer = ${lyrics_writer}\n"
+ " |performer = ${performer}\n"
+ " |title = ${title}\n"
+ " |description = ${description}\n"
+ " |composition_date = ${composition_date}\n"
+ " |performance_date = ${performance_date}\n"
+ " |notes = ${notes}\n"
+ " |record_ID = ${record_id}\n"
+ " |image = ${image}\n"
+ " |references = ${references}\n"
+ " |source = ${source}\n"
+ " |permission = ${permission}\n"
+ " |other_versions = ${other_versions}\n"
+ "}}\n\n"
+ "=={{int:license-header}}==\n"
+ "${license}${partnership}"
+ "\n\n"
+ "<#if categories ? has_content>\n"
+ "<#list categories ? split(\";\") as category>\n"
+ "[[Category:${category?trim}]]\n"
+ "</#list>\n"
+ "<#else>{{subst:unc}}\n"
+ "</#if>"
)
);
TEMPLATES.put("Photograph",
new Template("Photograph",
new TemplateField[]{
Expand Down
70 changes: 42 additions & 28 deletions src/pattypan/TemplateField.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class TemplateField {
public String name;
public String label;
public boolean isSelected;
public String selection;
public String value;

CheckBox cb;
Expand All @@ -57,36 +58,17 @@ public TemplateField(String name, String label, boolean isSelected, String const
this.name = name;
this.label = label;
this.isSelected = isSelected;
this.selection = "YES";
this.value = constant;

labelElement = new WikiLabel(label).setWidth(200, 500).setHeight(35);
buttonYes.setSelected(true);

group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle tOld, Toggle tNew) -> {
RadioButton btn = (RadioButton) tNew.getToggleGroup().getSelectedToggle();
String id = btn.getId();
switch (id) {
case "YES":
valueText.setVisible(true);
labelElement.setDisable(false);
this.isSelected = true;
break;
case "CONST":
valueText.setVisible(true);
labelElement.setDisable(true);
this.isSelected = false;
break;
case "NO":
valueText.setVisible(false);
valueText.setText("");
labelElement.setDisable(true);
this.isSelected = false;
break;
default:
break;
}
setSelection(btn.getId());
});

valueText.setOnKeyReleased((KeyEvent event) -> {
this.value = valueText.getText();
});
Expand All @@ -103,31 +85,63 @@ public VBox getRow() {
VBox vb = new VBox(5);
HBox hb = new HBox(10);
HBox hbCheckbox = new HBox(10);


valueText.setText(Settings.getSetting("var-" + name + "-value"));
value = Settings.getSetting("var-" + name + "-value");
setSelection(Settings.getSetting("var-" + name + "-selection"));

hb.getChildren().addAll(labelElement,
buttonYes, buttonConst, buttonNo,
spacer, valueText, new Region());
vb.getChildren().add(hb);
if(name.equals("date")) {

if (name.equals("date")) {
Region r = new Region();
r.setMaxWidth(622);
r.setPrefWidth(622);
r.setMinWidth(420);
r.setMinHeight(30);

CheckBox checkbox = new CheckBox("Preload date from Exif");
checkbox.setMaxWidth(500);
checkbox.setPrefWidth(500);
checkbox.setMinWidth(305);
checkbox.setSelected(Settings.getSetting("exifDate").equals("true"));
checkbox.setOnAction((ActionEvent e) -> {
Settings.setSetting("exifDate", checkbox.isSelected() ? "true" : "");
});

hbCheckbox.getChildren().addAll(r, checkbox);
vb.getChildren().add(hbCheckbox);
}

return vb;
}

public void setSelection(String id) {
this.selection = id;
switch (id) {
case "YES":
valueText.setVisible(true);
labelElement.setDisable(false);
buttonYes.setSelected(true);
this.isSelected = true;
break;
case "CONST":
valueText.setVisible(true);
labelElement.setDisable(true);
buttonConst.setSelected(true);
this.isSelected = false;
break;
case "NO":
valueText.setVisible(false);
valueText.setText("");
labelElement.setDisable(true);
buttonNo.setSelected(true);
this.isSelected = false;
break;
default:
break;
}
}
}
7 changes: 5 additions & 2 deletions src/pattypan/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ public static ColumnConstraints newColumn(int value, String unit, HPos position)
}

/* file utils */
private final static ArrayList<String> allowedExtentionImage
= new ArrayList<>(Arrays.asList("png", "gif", "jpg", "jpeg", "ogg", "svg", "tiff", "tif", "wav", "xcf"));
private final static ArrayList<String> allowedExtentionImage = new ArrayList<>(
Arrays.asList("djvu", "flac", "gif", "jpg", "jpeg", "mid",
"oga", "ogg","ogv", "opus", "png", "svg", "tiff",
"tif", "wav", "webm", "webp", "xcf")
);

public static String getNameFromFilename(String filename) {
int pos = filename.lastIndexOf(".");
Expand Down
13 changes: 12 additions & 1 deletion src/pattypan/elements/WikiButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.event.ActionEvent;
Expand Down Expand Up @@ -87,7 +88,17 @@ public WikiButton linkTo(String paneName, Stage stage) {
});
return this;
}


public WikiButton linkTo(String paneName, Stage stage, boolean clearScenes) {
this.setOnAction((ActionEvent event) -> {
if(clearScenes) {
Session.SCENES = new HashMap<>();
}
goTo(paneName, stage);
});
return this;
}

public void goTo(String paneName, Stage stage) {
Scene scene = Session.SCENES.containsKey(paneName)
? Session.SCENES.get(paneName)
Expand Down
4 changes: 2 additions & 2 deletions src/pattypan/elements/WikiPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class WikiPane extends BorderPane {
public VBox centerContainer = new VBox(15);
public HBox bottomContainer = new HBox();

public WikiButton prevButton = new WikiButton("generic-back", "inversed").setWidth(150);
public WikiButton nextButton = new WikiButton("generic-next", "inversed").setWidth(150);
public WikiButton prevButton = new WikiButton("generic-back", "inversed").setWidth(250);
public WikiButton nextButton = new WikiButton("generic-next", "inversed").setWidth(250);

private final String[] progressBarLabels = {
Util.text("choose-directory-name"),
Expand Down
2 changes: 1 addition & 1 deletion src/pattypan/panes/CheckPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void setDetails(UploadElement ue, Hyperlink label) {

preview.setOnAction(event -> {
try {
Util.openUrl("https://commons.wikimedia.org/wiki/Special:ExpandTemplates"
Util.openUrl(Session.WIKI.getProtocol() + Session.WIKI.getDomain() + "/wiki/Special:ExpandTemplates"
+ "?wpRemoveComments=true"
+ "&wpInput=" + URLEncoder.encode(ue.getWikicode(), "UTF-8")
+ "&wpContextTitle=" + URLEncoder.encode(ue.getData("name"), "UTF-8"));
Expand Down
32 changes: 29 additions & 3 deletions src/pattypan/panes/ChooseColumnsPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class ChooseColumnsPane extends WikiPane {
VBox rightContainer = new VBox(4);
Hyperlink wikicodeLink;

Hyperlink prevLabel = null;

VBox wikicodePane = new VBox(10);
TextArea wikicodeText = new TextArea("");

Expand All @@ -71,6 +73,10 @@ public WikiPane getContent() {
}

private WikiPane setActions() {
if (!Settings.getSetting("template").isEmpty()) {
Session.TEMPLATE = Settings.getSetting("template");
}

wikicodeLink.setOnAction(event -> {
templateDescContainer.getChildren().clear();
templateDescContainer.getChildren().add(wikicodePane);
Expand All @@ -89,11 +95,16 @@ private WikiPane setActions() {
Template template = Settings.TEMPLATES.get(Session.TEMPLATE);
Session.VARIABLES = template.getComputedVariables();
Session.WIKICODE = template.getComputedWikicode();

for (TemplateField tf : template.variables) {
Settings.setSetting("var-" + tf.name + "-value", tf.value);
Settings.setSetting("var-" + tf.name + "-selection", tf.selection);
}
}

nextButton.goTo("CreateFilePane", stage);
});
showTemplateFieldsChoose(Session.TEMPLATE);
showTemplateFields(Session.TEMPLATE);
return this;
}

Expand All @@ -105,9 +116,24 @@ private WikiPane setContent() {
Settings.TEMPLATES.forEach((key, value) -> {
Hyperlink label = new Hyperlink(key);
label.setOnAction(event -> {

Template template = Settings.TEMPLATES.get(Session.TEMPLATE);
for (TemplateField tf : template.variables) {
Settings.setSetting("var-" + tf.name + "-value", tf.value);
Settings.setSetting("var-" + tf.name + "-selection", tf.selection);
}

Session.METHOD = "template";
Session.TEMPLATE = key;
showTemplateFieldsChoose(Session.TEMPLATE);
Settings.setSetting("template", Session.TEMPLATE);

if (prevLabel != null) {
prevLabel.getStyleClass().remove("bold");
}
prevLabel = label;
prevLabel.getStyleClass().add("bold");

showTemplateFields(Session.TEMPLATE);
});
rightContainer.getChildren().add(label);
});
Expand Down Expand Up @@ -151,7 +177,7 @@ private WikiPane setContent() {
* @param templateName name of wikitemplate
* @return true, if template exists
*/
private boolean showTemplateFieldsChoose(String templateName) {
private boolean showTemplateFields(String templateName) {
Template template = Settings.TEMPLATES.get(templateName);

Hyperlink docLink = new Hyperlink(Util.text("choose-columns-template-doc"));
Expand Down
Loading

0 comments on commit dbeb7f5

Please sign in to comment.