Package org.wikipediacleaner.gui.swing.worker.UpdateWarningTools

Examples of org.wikipediacleaner.gui.swing.worker.UpdateWarningTools.Stats


    }

    // Update disambiguation warnings
    if (!pages.isEmpty()) {
      try {
        Stats stats = new Stats();
        createDabWarning.updateWarning(
            pages, creators, modifiers, stats);
        List<Page> updatedPages = stats.getUpdatedPages();
        if (updatedPages != null) {
          for (Page page : updatedPages) {
            monitoredPages.put(page.getTitle(), Long.valueOf(currentTime.getTime()));
          }
        }
View Full Code Here


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

    Stats stats = new Stats();
    try {
      if (!useList) {
        // Retrieve talk pages including a warning
        String warningTemplateName = configuration.getString(WPCConfigurationString.DAB_WARNING_TEMPLATE);
        setText(GT._("Retrieving talk pages including {0}", "{{" + warningTemplateName + "}}"));
        String templateTitle = wikiConfiguration.getPageTitle(
            Namespace.TEMPLATE,
            warningTemplateName);
        Page warningTemplate = DataManager.getPage(
            wikipedia, templateTitle, null, null, null);
        api.retrieveEmbeddedIn(
            wikipedia, warningTemplate,
            configuration.getEncyclopedicTalkNamespaces(),
            false);
        List<Page> warningTalkPages = warningTemplate.getRelatedPages(Page.RelatedPages.EMBEDDED_IN);
 
        // Construct list of articles with warning
        setText(GT._("Constructing list of articles with warning"));
        HashSet<Page> tmpWarningPages = new HashSet<Page>();
        for (Page warningPage : warningTalkPages) {
          String title = warningPage.getTitle();
          String todoSubpage = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
          if (title.endsWith("/" + todoSubpage)) {
            title = title.substring(0, title.length() - 1 - todoSubpage.length());
          }
          int colonIndex = title.indexOf(':');
          if (colonIndex >= 0) {
            for (Integer namespace : configuration.getEncyclopedicTalkNamespaces()) {
              Namespace namespaceTalk = wikiConfiguration.getNamespace(namespace);
              if ((namespaceTalk != null) &&
                  (namespaceTalk.isPossibleName(title.substring(0, colonIndex)))) {
                String tmpTitle = title.substring(colonIndex + 1);
                if (namespace != Namespace.MAIN_TALK) {
                  tmpTitle = wikiConfiguration.getPageTitle(namespace - 1, tmpTitle);
                }
                if ((start.length() == 0) || (start.compareTo(tmpTitle) < 0)) {
                  Page page = DataManager.getPage(wikipedia, tmpTitle, null, null, null);
                  if (!tmpWarningPages.contains(page)) {
                    tmpWarningPages.add(page);
                  }
                }
              }
            }
          }
        }
        if (getWindow() != null) {
          int answer = getWindow().displayYesNoWarning(GT._(
              "Analysis found {0} articles with disambiguation warning {1}.\n" +
              "Do you want to update the disambiguation warnings ?",
              new Object[] { Integer.valueOf(tmpWarningPages.size()), "{{" + warningTemplateName + "}}" }));
          if (answer != JOptionPane.YES_OPTION) {
            return Integer.valueOf(0);
          }
        }

        // Sort the list of articles
        warningPages.addAll(tmpWarningPages);
        tmpWarningPages.clear();
        Collections.sort(warningPages, PageComparator.getTitleFirstComparator());
        if (warningPages.isEmpty()) {
          return Integer.valueOf(0);
        }
      }

      // Working with sublists
      UpdateDabWarningTools tools = new UpdateDabWarningTools(wikipedia, this, true, automaticEdit);
      tools.setContentsAvailable(contentsAvailable);
      tools.setLinksAvailable(linksAvailable);
      tools.setDabInformationAvailable(dabInformationAvailable);
      if (!useList) {
        setText(GT._("Retrieving disambiguation pages"));
        tools.preloadDabPages();
      }
      String lastTitle = null;
      int countUnsaved = 0;
      while (!warningPages.isEmpty()) {
        // Creating sublist
        int size = Math.min(10, warningPages.size());
        List<Page> sublist = new ArrayList<Page>(size);
        while ((sublist.size() < size) && (warningPages.size() > 0)) {
          Page page = warningPages.remove(0);
          if ((start.length() == 0) || (start.compareTo(page.getTitle()) < 0)) {
            sublist.add(page);
          }
        }
        if (sublist.isEmpty()) {
          displayResult(stats, startTime);
          return Integer.valueOf(stats.getUpdatedPagesCount());
        }
        countUnsaved += sublist.size();

        // Update warning
        boolean finish = false;
        while (!finish) {
          finish = true;
          try {
            tools.updateWarning(sublist, null, null, stats);
            lastTitle = sublist.get(sublist.size() - 1).getTitle();
          } catch (APIException e) {
            if (getWindow() != null) {
              int answer = getWindow().displayYesNoWarning(GT._(
                  "An error occurred when updating disambiguation warnings. Do you want to continue ?\n\n" +
                  "Error: {0}", e.getMessage()));
              if (answer != JOptionPane.YES_OPTION) {
                return e;
              }
              finish = false;
            }
          }
          if (shouldStop() || (countUnsaved > 1000)) {
            Configuration config = Configuration.getConfiguration();
            config.setString(null, ConfigurationValueString.LAST_DAB_WARNING, lastTitle);
            countUnsaved = 0;
          }
          if (shouldStop()) {
            displayResult(stats, startTime);
            return Integer.valueOf(stats.getUpdatedPagesCount());
          }
        }

        if (stats.getUpdatedPagesCount() > lastCount) {
          lastCount = stats.getUpdatedPagesCount();
          /*if (getWindow() != null) {
            int answer = getWindow().displayYesNoWarning(
                "This feature is currently under development, please check the modification.\n" +
                "Do you want to continue ?");
            if (answer != JOptionPane.YES_OPTION) {
              return Integer.valueOf(lastCount);
            }
          } else {
            return Integer.valueOf(lastCount);
          }*/
        }
      }
      if (warningPages.isEmpty()) {
        Configuration config = Configuration.getConfiguration();
        config.setString(null, ConfigurationValueString.LAST_DAB_WARNING, (String) null);
      }
    } catch (APIException e) {
      return e;
    }

    displayResult(stats, startTime);
    return Integer.valueOf(stats.getUpdatedPagesCount());
  }
View Full Code Here

    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) {
              Namespace namespaceTalk = wikiConfiguration.getNamespace(namespace.intValue());
              if (namespaceTalk != null) {
                int colonIndex = title.indexOf(':');
                if (colonIndex >= 0) {
                  title = title.substring(colonIndex + 1);
                }
                if (namespace != Namespace.MAIN_TALK) {
                  title = wikiConfiguration.getPageTitle(namespace - 1, title);
                }
              }
            }
          }

          // Add article to the list
          Page page = DataManager.getPage(wiki, title, null, null, null);
          if (encyclopedicNamespaces.contains(page.getNamespace()) &&
              !tmpWarningPages.contains(page)) {
            tmpWarningPages.add(page);
          }
        }

        if (getWindow() != null) {
          int answer = getWindow().displayYesNoWarning(GT._(
              "Analysis found {0} articles to check for ISBN errors.\n" +
              "Do you want to update the warnings ?",
              Integer.valueOf(tmpWarningPages.size()).toString() ));
          if (answer != JOptionPane.YES_OPTION) {
            return Integer.valueOf(0);
          }
        }

        // Sort the list of articles
        warningPages.clear();
        warningPages.addAll(tmpWarningPages);
        tmpWarningPages.clear();
        Collections.sort(warningPages, PageComparator.getTitleFirstComparator());
        if (warningPages.isEmpty()) {
          return Integer.valueOf(0);
        }
      }

      // Working with sublists
      UpdateISBNWarningTools tools = new UpdateISBNWarningTools(wiki, this, true, automaticEdit);
      tools.setContentsAvailable(contentsAvailable);
      tools.prepareErrorsMap();
      if (simulation) {
        tools.setSimulation(true);
      }
      String lastTitle = null;
      while (!warningPages.isEmpty()) {
        // Creating sublist
        int size = Math.min(10, warningPages.size());
        List<Page> sublist = new ArrayList<Page>(size);
        while ((sublist.size() < size) && (warningPages.size() > 0)) {
          Page page = warningPages.remove(0);
          sublist.add(page);
        }
        if (sublist.isEmpty()) {
          errors = tools.getErrorsMap();
          displayResult(stats, startTime, errors);
          return Integer.valueOf(stats.getUpdatedPagesCount());
        }

        // Update warning
        boolean finish = false;
        while (!finish) {
          finish = true;
          try {
            tools.updateWarning(sublist, null, null, stats);
            lastTitle = sublist.get(sublist.size() - 1).getTitle();
          } catch (APIException e) {
            if (getWindow() != null) {
              int answer = getWindow().displayYesNoWarning(GT._(
                  "An error occurred when updating disambiguation warnings. Do you want to continue ?\n\n" +
                  "Error: {0}", e.getMessage()));
              if (answer != JOptionPane.YES_OPTION) {
                return e;
              }
              finish = false;
            }
          }
          if (shouldStop()) {
            Configuration config = Configuration.getConfiguration();
            config.setString(null, ConfigurationValueString.LAST_ISBN_WARNING, lastTitle);
            displayResult(stats, startTime, null);
            return Integer.valueOf(stats.getUpdatedPagesCount());
          }
        }

        if (stats.getUpdatedPagesCount() > lastCount) {
          lastCount = stats.getUpdatedPagesCount();
          /*if (getWindow() != null) {
            int answer = getWindow().displayYesNoWarning(
                "This feature is currently under development, please check the modification.\n" +
                "Do you want to continue ?");
            if (answer != JOptionPane.YES_OPTION) {
              return Integer.valueOf(lastCount);
            }
          } else {
            return Integer.valueOf(lastCount);
          }*/
        }
      }
      errors = tools.getErrorsMap();
      if (warningPages.isEmpty()) {
        Configuration config = Configuration.getConfiguration();
        config.setString(null, ConfigurationValueString.LAST_ISBN_WARNING, (String) null);
      }
    } catch (APIException e) {
      return e;
    }

    displayResult(stats, startTime, errors);
    return Integer.valueOf(stats.getUpdatedPagesCount());
  }
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.gui.swing.worker.UpdateWarningTools.Stats

Copyright © 2018 www.massapicom. 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.