Skip to content

Commit dbeb7f5

Browse files
authored
Merge pull request #36 from yarl/dev
version 17.05
2 parents 0e526b6 + a067fac commit dbeb7f5

File tree

15 files changed

+421
-183
lines changed

15 files changed

+421
-183
lines changed

src/org/wikipedia/Wiki.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,11 @@ public String getDomain()
574574
{
575575
return domain;
576576
}
577+
578+
public String getProtocol()
579+
{
580+
return protocol;
581+
}
577582

578583
/**
579584
* Gets the editing throttle.

src/pattypan/Main.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package pattypan;
2525

26+
import java.util.logging.Level;
27+
import java.util.logging.Logger;
2628
import javafx.application.Application;
2729
import javafx.scene.Scene;
2830
import javafx.scene.image.Image;
@@ -33,6 +35,8 @@
3335

3436
public class Main extends Application {
3537

38+
private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
39+
3640
@Override
3741
public void start(Stage stage) {
3842
Settings.readProperties();
@@ -56,10 +60,27 @@ public void start(Stage stage) {
5660
* @param args the command line arguments
5761
*/
5862
public static void main(String[] args) {
59-
if (args.length > 0) {
60-
Session.WIKI = new Wiki(args[0].equals("-test") ? "test.wikipedia.org" : args[0]);
63+
String wiki = "commons.wikimedia.org";
64+
String protocol = "https://";
65+
String scriptPath = "/w";
66+
67+
for (String arg : args) {
68+
String[] pair = arg.split("=");
69+
if (pair[0].contains("wiki")) {
70+
wiki = pair[1];
71+
} else if (pair[0].contains("protocol")) {
72+
protocol = pair[1];
73+
} else if (pair[0].contains("scriptPath")) {
74+
scriptPath = pair[1];
75+
}
6176
}
77+
78+
LOGGER.log(Level.INFO,
79+
"Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}",
80+
new String[]{wiki, protocol, scriptPath}
81+
);
82+
83+
Session.WIKI = new Wiki(wiki, scriptPath, protocol);
6284
launch(args);
6385
}
64-
6586
}

src/pattypan/Settings.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class Settings {
4141
private Settings() {};
4242

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

4747
public static final Map<String, String> SETTINGS = new HashMap<>();
@@ -181,6 +181,8 @@ public final class Settings {
181181
new TemplateField("linkback", "Linkback"),
182182
new TemplateField("wikidata", "Wikidata"),
183183
new TemplateField("license", "License"),
184+
new TemplateField("partnership", "Partnership"),
185+
new TemplateField("license", "License"),
184186
new TemplateField("partnership", "Partnership")
185187
}, "=={{int:filedesc}}==\n"
186188
+ "{{Book\n"
@@ -225,7 +227,53 @@ public final class Settings {
225227
+ "</#if>"
226228
)
227229
);
228-
230+
TEMPLATES.put("Musical work",
231+
new Template("Musical work",
232+
new TemplateField[]{
233+
new TemplateField("composer", "Composer"),
234+
new TemplateField("lyrics_writer", "Lyrics writer"),
235+
new TemplateField("performer", "Performer"),
236+
new TemplateField("title", "Title"),
237+
new TemplateField("description", "Description"),
238+
new TemplateField("composition_date", "Composition date"),
239+
new TemplateField("performance_date", "Performance date"),
240+
new TemplateField("notes", "Notes"),
241+
new TemplateField("record_id", "Record ID"),
242+
new TemplateField("image", "Image"),
243+
new TemplateField("references", "References"),
244+
new TemplateField("source", "Source"),
245+
new TemplateField("permission", "Permission"),
246+
new TemplateField("other_versions", "Other versions"),
247+
new TemplateField("license", "License"),
248+
new TemplateField("partnership", "Partnership")
249+
}, "=={{int:filedesc}}==\n"
250+
+ "{{Musical work\n"
251+
+ " |composer = ${composer}\n"
252+
+ " |lyrics_writer = ${lyrics_writer}\n"
253+
+ " |performer = ${performer}\n"
254+
+ " |title = ${title}\n"
255+
+ " |description = ${description}\n"
256+
+ " |composition_date = ${composition_date}\n"
257+
+ " |performance_date = ${performance_date}\n"
258+
+ " |notes = ${notes}\n"
259+
+ " |record_ID = ${record_id}\n"
260+
+ " |image = ${image}\n"
261+
+ " |references = ${references}\n"
262+
+ " |source = ${source}\n"
263+
+ " |permission = ${permission}\n"
264+
+ " |other_versions = ${other_versions}\n"
265+
+ "}}\n\n"
266+
+ "=={{int:license-header}}==\n"
267+
+ "${license}${partnership}"
268+
+ "\n\n"
269+
+ "<#if categories ? has_content>\n"
270+
+ "<#list categories ? split(\";\") as category>\n"
271+
+ "[[Category:${category?trim}]]\n"
272+
+ "</#list>\n"
273+
+ "<#else>{{subst:unc}}\n"
274+
+ "</#if>"
275+
)
276+
);
229277
TEMPLATES.put("Photograph",
230278
new Template("Photograph",
231279
new TemplateField[]{

src/pattypan/TemplateField.java

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class TemplateField {
4242
public String name;
4343
public String label;
4444
public boolean isSelected;
45+
public String selection;
4546
public String value;
4647

4748
CheckBox cb;
@@ -57,36 +58,17 @@ public TemplateField(String name, String label, boolean isSelected, String const
5758
this.name = name;
5859
this.label = label;
5960
this.isSelected = isSelected;
61+
this.selection = "YES";
6062
this.value = constant;
61-
63+
6264
labelElement = new WikiLabel(label).setWidth(200, 500).setHeight(35);
6365
buttonYes.setSelected(true);
6466

6567
group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle tOld, Toggle tNew) -> {
6668
RadioButton btn = (RadioButton) tNew.getToggleGroup().getSelectedToggle();
67-
String id = btn.getId();
68-
switch (id) {
69-
case "YES":
70-
valueText.setVisible(true);
71-
labelElement.setDisable(false);
72-
this.isSelected = true;
73-
break;
74-
case "CONST":
75-
valueText.setVisible(true);
76-
labelElement.setDisable(true);
77-
this.isSelected = false;
78-
break;
79-
case "NO":
80-
valueText.setVisible(false);
81-
valueText.setText("");
82-
labelElement.setDisable(true);
83-
this.isSelected = false;
84-
break;
85-
default:
86-
break;
87-
}
69+
setSelection(btn.getId());
8870
});
89-
71+
9072
valueText.setOnKeyReleased((KeyEvent event) -> {
9173
this.value = valueText.getText();
9274
});
@@ -103,31 +85,63 @@ public VBox getRow() {
10385
VBox vb = new VBox(5);
10486
HBox hb = new HBox(10);
10587
HBox hbCheckbox = new HBox(10);
106-
88+
89+
valueText.setText(Settings.getSetting("var-" + name + "-value"));
90+
value = Settings.getSetting("var-" + name + "-value");
91+
setSelection(Settings.getSetting("var-" + name + "-selection"));
92+
10793
hb.getChildren().addAll(labelElement,
10894
buttonYes, buttonConst, buttonNo,
10995
spacer, valueText, new Region());
11096
vb.getChildren().add(hb);
111-
112-
if(name.equals("date")) {
97+
98+
if (name.equals("date")) {
11399
Region r = new Region();
114100
r.setMaxWidth(622);
115101
r.setPrefWidth(622);
116102
r.setMinWidth(420);
117103
r.setMinHeight(30);
118-
104+
119105
CheckBox checkbox = new CheckBox("Preload date from Exif");
120106
checkbox.setMaxWidth(500);
121107
checkbox.setPrefWidth(500);
122108
checkbox.setMinWidth(305);
109+
checkbox.setSelected(Settings.getSetting("exifDate").equals("true"));
123110
checkbox.setOnAction((ActionEvent e) -> {
124111
Settings.setSetting("exifDate", checkbox.isSelected() ? "true" : "");
125112
});
126113

127114
hbCheckbox.getChildren().addAll(r, checkbox);
128115
vb.getChildren().add(hbCheckbox);
129116
}
130-
117+
131118
return vb;
132119
}
120+
121+
public void setSelection(String id) {
122+
this.selection = id;
123+
switch (id) {
124+
case "YES":
125+
valueText.setVisible(true);
126+
labelElement.setDisable(false);
127+
buttonYes.setSelected(true);
128+
this.isSelected = true;
129+
break;
130+
case "CONST":
131+
valueText.setVisible(true);
132+
labelElement.setDisable(true);
133+
buttonConst.setSelected(true);
134+
this.isSelected = false;
135+
break;
136+
case "NO":
137+
valueText.setVisible(false);
138+
valueText.setText("");
139+
labelElement.setDisable(true);
140+
buttonNo.setSelected(true);
141+
this.isSelected = false;
142+
break;
143+
default:
144+
break;
145+
}
146+
}
133147
}

src/pattypan/Util.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ public static ColumnConstraints newColumn(int value, String unit, HPos position)
123123
}
124124

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

129132
public static String getNameFromFilename(String filename) {
130133
int pos = filename.lastIndexOf(".");

src/pattypan/elements/WikiButton.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.lang.reflect.Constructor;
2727
import java.lang.reflect.InvocationTargetException;
2828
import java.lang.reflect.Method;
29+
import java.util.HashMap;
2930
import java.util.logging.Level;
3031
import java.util.logging.Logger;
3132
import javafx.event.ActionEvent;
@@ -87,7 +88,17 @@ public WikiButton linkTo(String paneName, Stage stage) {
8788
});
8889
return this;
8990
}
90-
91+
92+
public WikiButton linkTo(String paneName, Stage stage, boolean clearScenes) {
93+
this.setOnAction((ActionEvent event) -> {
94+
if(clearScenes) {
95+
Session.SCENES = new HashMap<>();
96+
}
97+
goTo(paneName, stage);
98+
});
99+
return this;
100+
}
101+
91102
public void goTo(String paneName, Stage stage) {
92103
Scene scene = Session.SCENES.containsKey(paneName)
93104
? Session.SCENES.get(paneName)

src/pattypan/elements/WikiPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class WikiPane extends BorderPane {
4545
public VBox centerContainer = new VBox(15);
4646
public HBox bottomContainer = new HBox();
4747

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

5151
private final String[] progressBarLabels = {
5252
Util.text("choose-directory-name"),

src/pattypan/panes/CheckPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void setDetails(UploadElement ue, Hyperlink label) {
145145

146146
preview.setOnAction(event -> {
147147
try {
148-
Util.openUrl("https://commons.wikimedia.org/wiki/Special:ExpandTemplates"
148+
Util.openUrl(Session.WIKI.getProtocol() + Session.WIKI.getDomain() + "/wiki/Special:ExpandTemplates"
149149
+ "?wpRemoveComments=true"
150150
+ "&wpInput=" + URLEncoder.encode(ue.getWikicode(), "UTF-8")
151151
+ "&wpContextTitle=" + URLEncoder.encode(ue.getData("name"), "UTF-8"));

src/pattypan/panes/ChooseColumnsPane.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class ChooseColumnsPane extends WikiPane {
5151
VBox rightContainer = new VBox(4);
5252
Hyperlink wikicodeLink;
5353

54+
Hyperlink prevLabel = null;
55+
5456
VBox wikicodePane = new VBox(10);
5557
TextArea wikicodeText = new TextArea("");
5658

@@ -71,6 +73,10 @@ public WikiPane getContent() {
7173
}
7274

7375
private WikiPane setActions() {
76+
if (!Settings.getSetting("template").isEmpty()) {
77+
Session.TEMPLATE = Settings.getSetting("template");
78+
}
79+
7480
wikicodeLink.setOnAction(event -> {
7581
templateDescContainer.getChildren().clear();
7682
templateDescContainer.getChildren().add(wikicodePane);
@@ -89,11 +95,16 @@ private WikiPane setActions() {
8995
Template template = Settings.TEMPLATES.get(Session.TEMPLATE);
9096
Session.VARIABLES = template.getComputedVariables();
9197
Session.WIKICODE = template.getComputedWikicode();
98+
99+
for (TemplateField tf : template.variables) {
100+
Settings.setSetting("var-" + tf.name + "-value", tf.value);
101+
Settings.setSetting("var-" + tf.name + "-selection", tf.selection);
102+
}
92103
}
93104

94105
nextButton.goTo("CreateFilePane", stage);
95106
});
96-
showTemplateFieldsChoose(Session.TEMPLATE);
107+
showTemplateFields(Session.TEMPLATE);
97108
return this;
98109
}
99110

@@ -105,9 +116,24 @@ private WikiPane setContent() {
105116
Settings.TEMPLATES.forEach((key, value) -> {
106117
Hyperlink label = new Hyperlink(key);
107118
label.setOnAction(event -> {
119+
120+
Template template = Settings.TEMPLATES.get(Session.TEMPLATE);
121+
for (TemplateField tf : template.variables) {
122+
Settings.setSetting("var-" + tf.name + "-value", tf.value);
123+
Settings.setSetting("var-" + tf.name + "-selection", tf.selection);
124+
}
125+
108126
Session.METHOD = "template";
109127
Session.TEMPLATE = key;
110-
showTemplateFieldsChoose(Session.TEMPLATE);
128+
Settings.setSetting("template", Session.TEMPLATE);
129+
130+
if (prevLabel != null) {
131+
prevLabel.getStyleClass().remove("bold");
132+
}
133+
prevLabel = label;
134+
prevLabel.getStyleClass().add("bold");
135+
136+
showTemplateFields(Session.TEMPLATE);
111137
});
112138
rightContainer.getChildren().add(label);
113139
});
@@ -151,7 +177,7 @@ private WikiPane setContent() {
151177
* @param templateName name of wikitemplate
152178
* @return true, if template exists
153179
*/
154-
private boolean showTemplateFieldsChoose(String templateName) {
180+
private boolean showTemplateFields(String templateName) {
155181
Template template = Settings.TEMPLATES.get(templateName);
156182

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

0 commit comments

Comments
 (0)