mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Add Campaign & CampaignContribution classes
Change-Id: Ib300e32b0d8146321b661ab5feb20ba9714bfd52
This commit is contained in:
parent
3465dc044c
commit
0be6e87d5e
3 changed files with 110 additions and 3 deletions
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.wikimedia.commons.campaigns;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Campaign {
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
private String autoAddWikitext;
|
||||||
|
private ArrayList<String> autoAddCategories;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String ownWorkLicenseDefault;
|
||||||
|
|
||||||
|
private String defaultDescription;
|
||||||
|
|
||||||
|
private JSONObject config;
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAutoAddWikitext() {
|
||||||
|
return autoAddWikitext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getAutoAddCategories() {
|
||||||
|
return autoAddCategories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwnWorkLicenseDefault() {
|
||||||
|
return ownWorkLicenseDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultDescription() {
|
||||||
|
return defaultDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Campaign(String name, JSONObject config) {
|
||||||
|
this.config = config;
|
||||||
|
this.name = name;
|
||||||
|
if(config.has("autoAdd")) {
|
||||||
|
this.autoAddWikitext = config.optJSONObject("autoAdd").optString("wikitext", null);
|
||||||
|
if(config.optJSONObject("autoAdd").has("categories")) {
|
||||||
|
this.autoAddCategories = new ArrayList<String>();
|
||||||
|
JSONArray catsArray = config.optJSONObject("autoAdd").optJSONArray("categories");
|
||||||
|
for(int i=0; i < catsArray.length(); i++) {
|
||||||
|
autoAddCategories.add(catsArray.optString(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.wikimedia.commons.campaigns;
|
||||||
|
|
||||||
|
import org.wikimedia.commons.contributions.Contribution;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class CampaignContribution extends Contribution {
|
||||||
|
private Campaign campaign;
|
||||||
|
|
||||||
|
private ArrayList<String> fieldValues;
|
||||||
|
|
||||||
|
public Campaign getCampaign() {
|
||||||
|
return campaign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCampaign(Campaign campaign) {
|
||||||
|
this.campaign = campaign;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTrackingTemplates() {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
if(campaign.getAutoAddWikitext() != null) {
|
||||||
|
buffer.append(campaign.getAutoAddWikitext()).append("\n");
|
||||||
|
}
|
||||||
|
if(campaign.getAutoAddCategories() != null && campaign.getAutoAddCategories().size() != 0) {
|
||||||
|
for(String cat : campaign.getAutoAddCategories()) {
|
||||||
|
buffer.append("[[Category:").append(cat).append("]]").append("\n");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer.append("{{subst:unc}}\n");
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return super.getDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -117,13 +117,17 @@ public class Contribution extends Media {
|
||||||
this.dateUploaded = date;
|
this.dateUploaded = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTrackingTemplates() {
|
||||||
|
return "{{subst:unc}}"; // Remove when we have categorization
|
||||||
|
}
|
||||||
|
|
||||||
public String getPageContents() {
|
public String getPageContents() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
buffer
|
buffer
|
||||||
.append("== {{int:filedesc}} ==\n")
|
.append("== {{int:filedesc}} ==\n")
|
||||||
.append("{{Information\n")
|
.append("{{Information\n")
|
||||||
.append("|description=").append(description).append("\n")
|
.append("|description=").append(getDescription()).append("\n")
|
||||||
.append("|source=").append("{{own}}\n")
|
.append("|source=").append("{{own}}\n")
|
||||||
.append("|author=[[User:").append(creator).append("]]\n");
|
.append("|author=[[User:").append(creator).append("]]\n");
|
||||||
if(dateCreated != null) {
|
if(dateCreated != null) {
|
||||||
|
|
@ -133,9 +137,9 @@ public class Contribution extends Media {
|
||||||
buffer
|
buffer
|
||||||
.append("}}").append("\n")
|
.append("}}").append("\n")
|
||||||
.append("== {{int:license-header}} ==\n")
|
.append("== {{int:license-header}} ==\n")
|
||||||
.append(Utils.licenseTemplateFor(license)).append("\n\n")
|
.append(Utils.licenseTemplateFor(getLicense())).append("\n\n")
|
||||||
.append("{{Uploaded from Mobile|platform=Android|version=").append(CommonsApplication.APPLICATION_VERSION).append("}}\n")
|
.append("{{Uploaded from Mobile|platform=Android|version=").append(CommonsApplication.APPLICATION_VERSION).append("}}\n")
|
||||||
.append("{{subst:unc}}"); // Remove when we have categorization
|
.append(getTrackingTemplates());
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue