Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Page


   * @throws APIException
   */
  private void constructCategoryMembersArticles(List<Page> pages) throws APIException {
    final API api = APIFactory.getAPI();
    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();
View Full Code Here


   */
  private void constructInternalLinks(
      List<Page> pages,
      boolean convertTalkPages) throws APIException {
    for (String dabList : elementNames) {
      Page page = DataManager.getPage(getWikipedia(), dabList, null, null, null);
      MediaWiki mw = MediaWiki.getMediaWikiAccess(this);
      mw.retrieveAllLinks(getWikipedia(), page, null, null, true, true);
      Iterator<Page> iter = page.getLinks().iterator();
      while (iter.hasNext()) {
        Page link = iter.next();
        if (link != null) {
          if (convertTalkPages && !link.isArticle()) {
            link = link.getArticlePage();
          }
          if ((link.isInMainNamespace()) &&
              (!pages.contains(link))) {
            pages.add(link);
          }
        }
      }
View Full Code Here

   */
  private void constructSearchTitles(List<Page> pages) throws APIException {
    if (elementNames != null) {
      final API api = APIFactory.getAPI();
      for (String pageName : elementNames) {
        Page page = DataManager.getPage(getWikipedia(), pageName, null, null, null);
        api.retrieveSimilarPages(getWikipedia(), page, true);
        pages.addAll(page.getRelatedPages(Page.RelatedPages.SIMILAR_PAGES));
      }
    }
  }
View Full Code Here

  public void actionAdd() {
    String value = askForValue(
        GT._("Enter the page title you want to add to your local watchlist"),
        "", null);
    if (value != null) {
      Page page = DataManager.getPage(getWikipedia(), value, null, null, null);
      Configuration config = Configuration.getConfiguration();
      List<String> watchedPages = config.getStringList(
          getWikipedia(), Configuration.ARRAY_WATCH_PAGES);
      if (!watchedPages.contains(page.getTitle())) {
        watchedPages.add(page.getTitle());
        Collections.sort(watchedPages);
        config.setStringList(getWikipedia(), Configuration.ARRAY_WATCH_PAGES, watchedPages);
        tablePages.addPage(page);
      }
    }
View Full Code Here

    // Clean up
    listLinks.clearSelection();
    listErrors.clearSelection();

    // Update links information
    Page page = getPage();
    PageAnalysis analysis = page.getAnalysis(page.getContents(), true);
    mapLinksTotalCount = new HashMap<String, Integer>();
    mapLinksHelpNeededCount = new HashMap<String, Integer>();
    if (page.getLinks() != null) {
      List<Page> links = page.getLinks();
      modelLinks.setElements(links);
      countOccurrences(analysis, true);
      for (Page p : links) {
        if ((p != null) &&
            (Boolean.TRUE.equals(p.isDisambiguationPage()))) {
          InternalLinkCount count = analysis.getLinkCount(p);
          if ((count != null) && (count.getTotalLinkCount() > 0)) {
            mapLinksTotalCount.put(p.getTitle(), Integer.valueOf(count.getTotalLinkCount()));
            mapLinksHelpNeededCount.put(p.getTitle(), Integer.valueOf(count.getHelpNeededCount()));
          }
        }
      }
    }
    selectLinks(0);
    modelLinks.updateLinkCount();

    // Update fix redirects menu
    createFixRedirectsMenu();

    // Check Wiki
    modelErrors.clear();
    initializeInitialErrors(allAlgorithms);
    if (getInitialErrors() != null) {
      for (CheckErrorPage error : getInitialErrors()) {
        modelErrors.addElement(error);
      }
    }
    listErrors.clearSelection();

    if (firstReload) {
      firstReload = false;

      // Check page contents
      Page pageLoaded = getPage();
      if ((pageLoaded != null) &&
          (Boolean.FALSE.equals(pageLoaded.isExisting()))) {
        List<Page> similarPages = pageLoaded.getRelatedPages(Page.RelatedPages.SIMILAR_PAGES);
        if ((similarPages != null) && (similarPages.size() > 0)) {
          String answer = Utilities.askForValue(
              getParentComponent(),
              GT._(
                  "Page {0} doesn''t exist, do you want to load a similar page ?",
                  pageLoaded.getTitle()),
              similarPages.toArray(), true,
              similarPages.get(0).toString(), null);
          if ((answer != null) && (answer.trim().length() > 0)) {
            Controller.runFullAnalysis(answer, null, getWikipedia());
          }
          dispose();
          return;
        }
        int answer = Utilities.displayYesNoWarning(
            getParentComponent(),
            GT._(
                "Page {0} doesn''t exist, do you still want to analyze it ?",
                pageLoaded.getTitle()));
        if (answer != JOptionPane.YES_OPTION) {
          dispose();
          return;
        }
      }
View Full Code Here

   *
   * @param analysis Page analysis.
   * @param forceDisambiguation Flag indicating if disambiguation should be counted.
   */
  void countOccurrences(PageAnalysis analysis, boolean forceDisambiguation) {
    Page page = getPage();
    if ((page != null) && (page.getLinks() != null)) {
      List<Page> links = new ArrayList<Page>();
      for (Page link : page.getLinks()) {
        if (link != null) {
          boolean count = false;
          if (Boolean.TRUE.equals(link.isDisambiguationPage())) {
            if (forceDisambiguation || modelLinks.getCountDisambiguation()) {
              count = true;
View Full Code Here

      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());
View Full Code Here

        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);
View Full Code Here

          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();
                  }
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.api.data.Page

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.