/** * Attempts to transfer an enwp file to Commons * * @return True on success. */ protected boolean doTransfer() { try { root = ParsedItem.parse(enwp, wpFN); imgInfoL = enwp.getImageInfo(wpFN); uploader = imgInfoL.get(imgInfoL.size() - 1).user; procText(); String t = gen(); 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) { e.printStackTrace(); } return false; }
/** * Filters nonsense {{Information}} parameters and fills in missing default values. * * @param info The information template * @return A new Template with filtered keys and default values where applicable */ private Template filterFillInfo(Template info) { Template t = new Template("Information"); t.put("Description", info.has("Description") ? info.get("Description") : ""); 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") : "See below"); t.put("Permission", info.has("Permission") ? info.get("Permission") : ""); t.put("other versions", info.has("other versions") ? info.get("other versions") : ""); return t; }