예제 #1
0
  /**
   * 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;
  }
예제 #2
0
  /** Processes parsed text and templates from the API */
  private void procText() {
    ArrayList<Template> masterTPL = root.getTemplateR();

    // Normalize license and special template titles
    for (Template t : masterTPL) {
      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);

    // Filter Templates which are not on Commons
    HashSet<String> ncomT =
        FL.toSet(
            MQuery.exists(com, false, FL.toAL(tpl.stream().map(t -> "Template:" + t.title)))
                .stream()
                .map(com::nss));
    for (Template t : new ArrayList<>(tpl)) if (ncomT.contains(t.title)) tpl.remove(t.drop());

    // Process special Templates
    Template info = null;
    for (Template t : new ArrayList<>(tpl))
      switch (t.title) {
        case "Information":
          info = t;
          tpl.remove(t.drop());
          break;
        case "Self":
          if (!t.has("author"))
            t.put("author", String.format("{{User at project|%s|w|en}}", uploader));
          break;
        case "PD-self":
          t.title = "PD-user-en";
          t.put("1", uploader);
          break;
        case "GFDL-self-with-disclaimers":
          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;
        default:
          break;
      }

    // Add any Commons-compatible top-level templates to License section.
    tpl.retainAll(root.tplates);
    for (Template t : tpl) licSection += String.format("%s%n", t);

    // Create and fill in missing {{Information}} fields with default values.
    info = filterFillInfo(info == null ? new Template("Information") : info);

    // Append any additional Strings to the description.
    if (!root.contents.isEmpty())
      info.append("Description", "\n" + String.join("\n", root.contents));

    // Convert {{Information}} to String and save result.
    sumSection += info.toString(true) + "\n";

    // Extract the first caption table and move it to the end of the sumSection
    String x = "";
    Matcher m = captionRegex.matcher(sumSection);
    if (m.find()) {
      x = m.group().trim();
      sumSection = m.reset().replaceAll("");
      sumSection += x + "\n";
    }
  }