Examples of WPCConfiguration


Examples of org.wikipediacleaner.api.constants.WPCConfiguration

   * @param search String to search.
   */
  protected void addSearchEnginesISSN(
      PageAnalysis analysis, CheckErrorResult errorResult,
      String search) {
    WPCConfiguration config = analysis.getWPCConfiguration();
    List<String[]> searchEngines = config.getStringArrayList(
        WPCConfigurationStringList.ISSN_SEARCH_ENGINES);
    if ((searchEngines != null) &&
        (!searchEngines.isEmpty())) {
      List<Actionnable> actions = new ArrayList<Actionnable>();
      for (String[] searchEngine : searchEngines) {
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

      PageAnalysis analysis, CheckErrorResult errorResult,
      PageElementTemplate template) {
    if (template == null) {
      return;
    }
    WPCConfiguration config = analysis.getWPCConfiguration();
    List<String[]> searchEngines = config.getStringArrayList(
        WPCConfigurationStringList.ISBN_SEARCH_ENGINES_TEMPLATES);
    if (searchEngines == null) {
      return;
    }
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

    if ((templates == null) ||
        (wikipedia == null) ||
        (wikipedia.getConfiguration().getWiktionaryMatchesCount() == 0)){
      return false;
    }
    WPCConfiguration configuration = wikipedia.getConfiguration();
    for (Page template : templates) {
      for (int i = 0; i < configuration.getWiktionaryMatchesCount(); i++) {
        TemplateMatch match = configuration.getWiktionaryMatch(i);
        if (areSameTitle(match.getName(), template.getTitle())) {
          return true;
        }
      }
    }
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

   * @return Links to the wiktionary.
   */
  public List<String> getWiktionaryLinks() {
    List<String> wiktionary = null;
    if ((contents != null) && (wikipedia != null)) {
      WPCConfiguration configuration = wikipedia.getConfiguration();
      for (int i = 0; i < configuration.getWiktionaryMatchesCount(); i++) {
        TemplateMatch template = configuration.getWiktionaryMatch(i);
        Pattern pattern = PageUtilities.createPatternForTemplate(template);
        Matcher matcher = pattern.matcher(contents);
        while (matcher.find()) {
          List<TemplateParameter> parameters = PageUtilities.analyzeTemplateParameters(template, matcher, this);
          for (TemplateParameter param : parameters) {
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

    // Check current page
    boolean article = (page.isArticle());
    boolean redirect = article && page.isRedirect();

    // Check configuration
    WPCConfiguration wpcConfig = page.getWikipedia().getConfiguration();
    List<String> texts = wpcConfig.getStringList(
        WPCConfigurationStringList.INSERT_TEXTS);
    List<String> redirectCategories = null;
    List<String> redirectTemplates = null;
    if (redirect) {
      redirectCategories = wpcConfig.getStringList(
          WPCConfigurationStringList.REDIRECT_CATEGORIES);
      redirectTemplates = wpcConfig.getStringList(
          WPCConfigurationStringList.REDIRECT_TEMPLATES);
    }
    if (((texts == null) || (texts.isEmpty())) &&
        ((redirectCategories == null) || (redirectCategories.isEmpty())) &&
        ((redirectTemplates == null) || (redirectTemplates.isEmpty()))) {
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

    for (String pageName : elementNames) {
      Page page = DataManager.getPage(getWikipedia(), pageName, null, null, null);
      api.retrieveCategoryMembers(getWikipedia(), page, 0, true);
      List<Page> tmpPages = page.getRelatedPages(Page.RelatedPages.CATEGORY_MEMBERS);
      if (tmpPages != null) {
        WPCConfiguration configuration = getWikipedia().getConfiguration();
        for (Page tmpPage : tmpPages) {
          if (!tmpPage.isArticle()) {
            String title = tmpPage.getArticlePageName();
            String todoSubpage = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
            if ((todoSubpage != null) &&
                (todoSubpage.trim().length() > 0) &&
                (title.endsWith("/" + todoSubpage))) {
              title = title.substring(0, title.length() - 1 - todoSubpage.length());
            }
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

      }

      // Configuration depending on the type of page
      boolean isArticle = (getPage() != null) && (getPage().isArticle());
      if (isArticle) {
        WPCConfiguration wpcConfig = getConfiguration();
        boolean isbnErrors = Page.areSameTitle(
            getPage().getTitle(),
            wpcConfig.getString(WPCConfigurationString.ISBN_ERRORS_PAGE));
        Integer namespace = getPage().getNamespace();
        Configuration config = Configuration.getConfiguration();
        if (getPage().isInMainNamespace()) {
          chkUpdateDabWarning.setSelected(config.getBoolean(
              null,
              ConfigurationValueBoolean.UPDATE_DAB_WARNING));
          chkCreateDabWarning.setSelected(!isbnErrors && config.getBoolean(
              null,
              ConfigurationValueBoolean.CREATE_DAB_WARNING));
        } else if ((namespace != null) &&
                   (wpcConfig.isEncyclopedicNamespace(namespace))) {
          chkUpdateDabWarning.setSelected(config.getBoolean(
              null,
              ConfigurationValueBoolean.UPDATE_DAB_WARNING_ENCY));
          chkCreateDabWarning.setSelected(!isbnErrors && config.getBoolean(
              null,
              ConfigurationValueBoolean.CREATE_DAB_WARNING_ENCY));
        } else {
          chkUpdateDabWarning.setSelected(config.getBoolean(
              null,
              ConfigurationValueBoolean.UPDATE_DAB_WARNING_ALL));
          chkCreateDabWarning.setSelected(!isbnErrors && config.getBoolean(
              null,
              ConfigurationValueBoolean.CREATE_DAB_WARNING_ALL));
        }
      }
    }
    updateComponentState();

    // Edit warning if needed
    boolean automaticFix = true;
    WPCConfiguration wpcConfig = getWikipedia().getConfiguration();
    List<String[]> warningTemplates = wpcConfig.getStringArrayList(
        WPCConfigurationStringList.EDIT_WARNING_TEMPLATES);
    if ((warningTemplates != null) && (!warningTemplates.isEmpty())) {
      StringBuilder tmp = new StringBuilder(GT._(
          "\"{0}\" has been tagged with the following templates, be careful when editing:",
          getPage().getTitle()));
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

   */
  @Override
  protected String getAutomaticComment(PageAnalysis analysis) {

    // Comment for translation
    WPCConfiguration configuration = getConfiguration();
    if (translated) {
      String text = configuration.getString(WPCConfigurationString.TRANSLATION_COMMENT);
      if ((text != null) && (text.trim().length() > 0)) {
        return text;
      }
      return GT._("Translation");
    }

    contributions = new Contributions(getWikipedia());
    contributions.increasePages(1);

    // Comment for fixed links to disambiguation pages
    List<String> dabLinks = new ArrayList<String>();
    StringBuilder comment = new StringBuilder();
    if ((mapLinksTotalCount != null) && (mapLinksTotalCount.size() > 0)) {
      List<String> fixed = new ArrayList<String>();
      List<String> helpRequested = new ArrayList<String>();
      for (Entry<String, Integer> p : mapLinksTotalCount.entrySet()) {
        if ((p != null) && (p.getKey() != null) && (p.getValue() != null)) {
          Integer currentCount = null;
          Integer currentHelpCount = null;
          Page page = getPage();
          if ((page != null) && (page.getLinks() != null)) {
            for (Page link : page.getLinks()) {
              if (Page.areSameTitle(p.getKey(), link.getTitle())) {
                InternalLinkCount count = analysis.getLinkCount(link);
                if (count != null) {
                  currentCount = Integer.valueOf(count.getTotalLinkCount());
                  currentHelpCount = Integer.valueOf(count.getHelpNeededCount());
                }
              }
            }
          }
          if ((currentCount == null) || (currentCount < p.getValue().intValue())) {
            fixed.add(p.getKey());
          } else {
            Integer helpCount = mapLinksHelpNeededCount.get(p.getKey());
            if ((helpCount != null) &&
                ((currentHelpCount == null) || (currentHelpCount > helpCount.intValue()))) {
              helpRequested.add(p.getKey());
            }
          }
        }
      }

      // Compute list of disambiguation links that still need to be fixed
      List<Page> links = analysis.getPage().getLinks();
      if (links != null) {
        analysis.countLinks(links);
        for (Page link : links) {
          if (Boolean.TRUE.equals(link.isDisambiguationPage())) {
            InternalLinkCount linkCount = analysis.getLinkCount(link);
            if (linkCount != null) {
              if ((linkCount.getInternalLinkCount() > 0) ||
                  (linkCount.getIncorrectTemplateCount() > 0) ||
                  (linkCount.getHelpNeededCount() > 0)) {
                dabLinks.add(link.getTitle());
              }
            }
          }
        }
      }

      // Add comment
      boolean showDabLinks = false;
      if (fixed.size() > 0) {
        Collections.sort(fixed);
        contributions.increaseDabLinks(fixed.size());
        comment.append(configuration.getDisambiguationComment(
            fixed.size(), fixed));
        showDabLinks = true;
      } else if (helpRequested.size() > 0) {
        Collections.sort(helpRequested);
        comment.append(configuration.getDisambiguationCommentHelp(
            helpRequested.size(), helpRequested));
        showDabLinks = true;
      }
      if (showDabLinks) {
        if (dabLinks.size() > 0) {
          Collections.sort(dabLinks);
          comment.append(configuration.getDisambiguationCommentTodo(
              dabLinks.size(), dabLinks));
          dabLinks.clear();
        }
      }
    }

    // Comment for fixed Check Wiki errors
    if ((getInitialErrors() != null) && (getInitialErrors().size() > 0)) {
      List<CheckErrorAlgorithm> errorsFixed = computeErrorsFixed();
      if ((errorsFixed != null) && (errorsFixed.size() > 0)) {
        if (comment.length() > 0) {
          comment.append(" / ");
        }
        comment.append(getWikipedia().getCWConfiguration().getComment(errorsFixed));
        for (CheckErrorAlgorithm errorFixed : errorsFixed) {
          contributions.increaseCheckWikiError(errorFixed.getErrorNumber(), 1);
        }
      }
    }

    // Comments for added categories / templates
    boolean isCategoryAdded = false;
    if (addedCategories != null) {
      for (PageElementCategory category : analysis.getCategories()) {
        for (String category2 : addedCategories) {
          if (Page.areSameTitle(category.getName(), category2)) {
            isCategoryAdded = true;
          }
        }
      }
    }
    boolean isTemplateAdded = false;
    if (addedTemplates != null) {
      for (PageElementTemplate template : analysis.getTemplates()) {
        for (String template2 : addedTemplates) {
          if (Page.areSameTitle(template.getTemplateName(), template2)) {
            isTemplateAdded = true;
          }
        }
      }
    }
    String strCategoryAdded = configuration.getString(WPCConfigurationString.REDIRECT_CATEGORIES_COMMENT);
    String strTemplateAdded = configuration.getString(WPCConfigurationString.REDIRECT_TEMPLATES_COMMENT);
    if (strTemplateAdded == null) {
      strTemplateAdded = strCategoryAdded;
    }
    if ((isCategoryAdded && (strCategoryAdded != null)) ||
        (isTemplateAdded && (strTemplateAdded != null))) {
      if (comment.length() > 0) {
        comment.append(" / ");
      }
      if (isCategoryAdded && (strCategoryAdded != null)) {
        comment.append(strCategoryAdded);
        if (isTemplateAdded && !strCategoryAdded.equals(strTemplateAdded)) {
          comment.append(" - ");
          comment.append(strCategoryAdded);
        }
      } else {
        comment.append(strTemplateAdded);
      }
    }

    // Comment for disambiguation links
    if ((dabLinks.size() > 0) && (comment.length() > 0)) {
      String newComment = configuration.getDisambiguationWarningComment(dabLinks);
      if ((newComment != null) && (newComment.length() > 0)) {
        comment.append(" / ");
        Collections.sort(dabLinks);
        comment.append(newComment);
        dabLinks.clear();
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

   */
  @Override
  public Object construct() {
    long startTime = System.currentTimeMillis();
    EnumWikipedia wiki = getWikipedia();
    WPCConfiguration configuration = wiki.getConfiguration();

    setText(GT._("Retrieving MediaWiki API"));
    API api = APIFactory.getAPI();
    int lastCount = 0;
    WikiConfiguration wikiConfiguration = wiki.getWikiConfiguration();

    Stats stats = new Stats();
    Map<String, List<String>> errors = null;
    try {
      if (!useList) {
        warningPages.clear();

        // Retrieve talk pages including a warning
        String warningTemplateName = configuration.getString(WPCConfigurationString.ISBN_WARNING_TEMPLATE);
        if (warningTemplateName != null) {
          setText(GT._("Retrieving talk pages including {0}", "{{" + warningTemplateName + "}}"));
          String templateTitle = wikiConfiguration.getPageTitle(
              Namespace.TEMPLATE,
              warningTemplateName);
          Page warningTemplate = DataManager.getPage(
              wiki, templateTitle, null, null, null);
          api.retrieveEmbeddedIn(
              wiki, warningTemplate,
              configuration.getEncyclopedicTalkNamespaces(),
              false);
          warningPages.addAll(warningTemplate.getRelatedPages(Page.RelatedPages.EMBEDDED_IN));
        }

        // Retrieve articles in categories for ISBN errors
        List<String> categories = configuration.getStringList(WPCConfigurationStringList.ISBN_ERRORS_CATEGORIES);
        if (categories != null) {
          for (String category : categories) {
            String categoryTitle = wikiConfiguration.getPageTitle(Namespace.CATEGORY, category);
            Page categoryPage = DataManager.getPage(wiki, categoryTitle, null, null, null);
            api.retrieveCategoryMembers(wiki, categoryPage, 0, false);
            List<Page> categoryMembers = categoryPage.getRelatedPages(
                Page.RelatedPages.CATEGORY_MEMBERS);
            if (categoryMembers != null) {
              warningPages.addAll(categoryMembers);
            }
          }
        }

        // Retrieve articles listed for ISBN errors in Check Wiki
        retrieveCheckWikiPages(70, warningPages); // Incorrect length
        retrieveCheckWikiPages(71, warningPages); // Incorrect X
        retrieveCheckWikiPages(72, warningPages); // Incorrect ISBN-10
        retrieveCheckWikiPages(73, warningPages); // Incorrect ISBN-13

        // Construct list of articles with warning
        setText(GT._("Constructing list of articles with warning"));
        HashSet<Page> tmpWarningPages = new HashSet<Page>();
        List<Integer> encyclopedicNamespaces = configuration.getEncyclopedicNamespaces();
        for (Page warningPage : warningPages) {

          // Get article page for talks pages and to do sub-pages
          String title = warningPage.getTitle();
          if (!warningPage.isArticle()) {
            String todoSubpage = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
            if (title.endsWith("/" + todoSubpage)) {
              title = title.substring(0, title.length() - 1 - todoSubpage.length());
            }
            Integer namespace = warningPage.getNamespace();
            if (namespace != null) {
View Full Code Here

Examples of org.wikipediacleaner.api.constants.WPCConfiguration

        }
        buffer.append("\n");
      }

      // Update synthesis on dedicated page
      WPCConfiguration config = wiki.getConfiguration();
      String pageName = config.getString(WPCConfigurationString.ISBN_ERRORS_PAGE);
      boolean saved = false;
      if ((pageName != null) && (pageName.trim().length() > 0)) {
        boolean updatePage = false;
        if (simulation && (getWindow() != null)) {
          int answer = Utilities.displayYesNoWarning(
              getWindow().getParentComponent(),
              GT._("Do you want to update {0}?", pageName));
          if (answer == JOptionPane.YES_OPTION) {
            updatePage = true;
          }
        } else {
          updatePage = true;
        }

        if (updatePage) {
          try {
            Page page = DataManager.getPage(wiki, pageName, null, null, null);
            API api = APIFactory.getAPI();
            api.retrieveContents(wiki, Collections.singletonList(page), false, false);
            String contents = page.getContents();
            if (contents != null) {
              int begin = -1;
              int end = -1;
              for (PageElementComment comment : page.getAnalysis(contents, true).getComments()) {
                String value = comment.getComment().trim();
                if ("BOT BEGIN".equals(value)) {
                  if (begin < 0) {
                    begin = comment.getEndIndex();
                  }
                } else if ("BOT END".equals(value)) {
                  end = comment.getBeginIndex();
                }
              }
              if ((begin >= 0) && (end > begin)) {
                StringBuilder newText = new StringBuilder();
                newText.append(contents.substring(0, begin));
                newText.append("\n");
                newText.append(buffer.toString());
                newText.append(contents.substring(end));
                api.updatePage(
                    wiki, page, newText.toString(),
                    wiki.formatComment(
                        config.getString(WPCConfigurationString.ISBN_ERRORS_PAGE_COMMENT),
                        true),
                    false);
                saved = true;
              }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.