Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Page


    if ((analysis == null) || (analysis.getPage() == null)) {
      return false;
    }

    // Preliminary setup
    Page page = analysis.getPage();
    String pageTitle = page.getTitle();
    String contents = analysis.getContents();
    List<Page> linkedPages = page.getLinks();
    if ((pageTitle == null) || (contents == null) || (linkedPages == null)) {
      return false;
    }
    List<PageElementInternalLink> links = analysis.getInternalLinks();
    if (links == null) {
      return false;
    }

    // Test every internal link
    boolean result = false;
    for (PageElementInternalLink link : links) {

      // Find page matching the link
      Page linkedPage = null;
      for (Page tmpPage : linkedPages) {
        if (Page.areSameTitle(tmpPage.getTitle(), link.getFullLink())) {
          linkedPage = tmpPage;
        }
      }

      // Check if the link is circular
      if ((linkedPage != null) &&
          linkedPage.isRedirect() &&
          Page.areSameTitle(pageTitle, linkedPage.getRedirectTitle())) {
        if (errors == null) {
          return true;
        }
        result = true;
        PageElementTag tagImagemap = analysis.getSurroundingTag(
View Full Code Here


    if (!dabInformationAvailable) {
      if (!wiki.isDisambiguationPagesLoaded()) {
        List<Page> tmpPages = new ArrayList<Page>();
        for (Page page : pages) {
          for (int numLink = 0; numLink < page.getLinks().size(); numLink++) {
            Page link = page.getLinks().get(numLink);
            if (dabPages.containsKey(link.getTitle())) {
              page.getLinks().set(numLink, dabPages.get(link.getTitle()));
              hasDisambiguationLink = true;
            } else if (nonDabPages.containsKey(link.getTitle())) {
              page.getLinks().set(numLink, nonDabPages.get(link.getTitle()));
            } else {
              tmpPages.add(link);
            }
          }
        }
        if (!tmpPages.isEmpty()) {
          mw.retrieveDisambiguationInformation(wiki, tmpPages, null, false, false, true);
        }
        for (Page page : tmpPages) {
          if (Boolean.TRUE.equals(page.isDisambiguationPage())) {
            dabPages.put(page.getTitle(), page);
            hasDisambiguationLink = true;
          } else {
            nonDabPages.put(page.getTitle(), page);
          }
        }
      } else {
        for (Page page : pages) {
          List<Page> links = page.getLinksWithRedirect();
          for (int numLink = 0; numLink < links.size(); numLink++) {
            Page link = links.get(numLink);
            if (Boolean.TRUE.equals(wiki.isDisambiguationPage(link))) {
              link.setDisambiguationPage(Boolean.TRUE);
              hasDisambiguationLink = true;
            } else {
              link.setDisambiguationPage(Boolean.FALSE);
            }
          }
        }
      }
      if (shouldStop()) {
        return false;
      }
    }

    // Retrieving page contents
    if (hasDisambiguationLink && !getContentsAvailable()) {
      List<Page> tmpPages = new ArrayList<Page>();
      for (Page page : pages) {
        boolean toAdd = false;
        for (Page link : page.getLinks()) {
          if (Boolean.TRUE.equals(link.isDisambiguationPage())) {
            toAdd = true;
          }
        }
        if (toAdd) {
          tmpPages.add(page);
View Full Code Here

    Boolean disambiguation = null;
    Boolean exist = null;
    boolean redirect = false;
    InternalLinkCount count = null;
    if (value instanceof Page) {
      Page pageElement = (Page) value;
      pageName = pageElement.getTitle();
      text = pageName;
      disambiguation = pageElement.isDisambiguationPage();
      exist = pageElement.isExisting();
      count = (analysis != null) ? analysis.getLinkCount(pageElement) : null;
      if (showCountOccurrence &&
          (count != null) &&
          (count.getTotalLinkCount() > 0)) {
        text += " → " + count.getTotalLinkCount();
      }
      redirect = pageElement.isRedirect();
      if (redirect && showRedirectBacklinks) {
        Integer backlinks = pageElement.getBacklinksCountInMainNamespace();
        if ((backlinks != null) && (backlinks.intValue() > 0)) {
          text += " ← " + backlinks;
        }
      }
    }
View Full Code Here

        progressPanel.setText(GT._("Analyzing links for disambiguation pages"));
      }
      api.initializeDisambiguationStatus(wikipedia, pages, false);
      Iterator<Page> iter = page.getRedirectIteratorWithPage();
      while (iter.hasNext()) {
        Page tmp = iter.next();
        if (progressPanel != null) {
          progressPanel.setText(GT._(
              "Retrieving possible disambiguations for {0}",
              new Object[] { tmp.getTitle() } ));
        }
        api.retrieveLinks(wikipedia, Collections.singletonList(tmp));
      }
    } catch (APIException ex) {
      //
View Full Code Here

    }
    Object object = list.getModel().getElementAt(position);
    if (!(object instanceof Page)) {
      return;
    }
    Page page = (Page) object;
    ArrayList<Page> knownPages = null;
    if ((pageWindow != null) && (pageWindow.getPage() != null)) {
      Page basePage = pageWindow.getPage();
      knownPages = new ArrayList<Page>(1);
      knownPages.add(basePage);
      for (Page backLink : basePage.getBackLinksWithRedirects()) {
        if ((backLink != null) &&
            (backLink.isRedirect()) &&
            (Page.areSameTitle(basePage.getTitle(), backLink.getRedirectDestination()))) {
          knownPages.add(backLink);
        }
      }
    }
    OnePageAnalysisWindow.createAnalysisWindow(page.getTitle(), knownPages, wikipedia);
View Full Code Here

      return pageListProvider.getPages();
    }

    // Manage a single page
    if (pageProvider != null) {
      Page page = pageProvider.getPage();
      if (page != null) {
        return Collections.singletonList(page);
      }
    }
View Full Code Here

    }
    Object object = tmpList.getModel().getElementAt(position);
    if (!(object instanceof Page)) {
      return;
    }
    Page link = (Page) object;
    showPopup(tmpList, link, e.getX(), e.getY());
  }
View Full Code Here

    }
    Object object = tmpList.getModel().getElementAt(position);
    if (!(object instanceof Page)) {
      return;
    }
    Page link = (Page) object;
    Rectangle rect = tmpList.getCellBounds(position, position);
    showPopup(tmpList, link, (int) rect.getMinX(), (int) rect.getMaxY());
  }
View Full Code Here

        }
      }
      for (Page page : splitPages) {
        Iterator<Page> itPage = page.getRedirectIteratorWithPage();
        while (itPage.hasNext()) {
          Page tmpPage = itPage.next();
          if (tmpPage.isDisambiguationPage() == null) {
            tmpPage.setDisambiguationPage(Boolean.FALSE);
          }
        }
      }
    }
  }
View Full Code Here

    while (hasRemainingTask() && !shouldStop()) {
      Object result = getNextResult();
      if ((result != null) && (result instanceof Page)) {
        boolean changed = false;
        List<String> replacementsDone = new ArrayList<String>();
        Page page = (Page) result;
        String oldContents = page.getContents();
        if (oldContents != null) {
          String newContents = oldContents;
          details.setLength(0);
          for (Entry<String, List<AutomaticFixing>> replacement : replacements.entrySet()) {
            replacementsDone.clear();
            String tmpContents = AutomaticFixing.apply(replacement.getValue(), newContents, replacementsDone);
            if (!newContents.equals(tmpContents)) {
              newContents = tmpContents;

              // Update description
              if (description != null) {
                if (!changed) {
                  String title =
                    "<a href=\"" + wiki.getSettings().getURL(page.getTitle(), false, secured) + "\">" +
                    page.getTitle() + "</a>";
                  description.append(GT._("Page {0}:", title));
                  description.append("\n");
                  description.append("<ul>\n");
                  changed = true;
                }
                for (String replacementDone : replacementsDone) {
                  description.append("<li>");
                  description.append(replacementDone);
                  description.append("</li>\n");
                }
              }

              // Memorize replacement
              if ((replacement.getKey() != null) && (replacement.getKey().length() > 0)) {
                if (details.length() > 0) {
                  details.append(", ");
                }
                details.append(replacement.getKey());
              }
            }
          }

          // Page contents has been modified
          if (!oldContents.equals(newContents)) {
            // Initialize comment
            StringBuilder fullComment = new StringBuilder();
            fullComment.append(wiki.createUpdatePageComment(comment, details.toString(), false));

            // Apply automatic Check Wiki fixing
            if (automaticCW) {
              List<CheckErrorAlgorithm> algorithms = CheckErrorAlgorithms.getAlgorithms(wiki);
              List<CheckErrorAlgorithm> usedAlgorithms = new ArrayList<CheckErrorAlgorithm>();
              newContents = AutomaticFormatter.tidyArticle(
                  page, newContents, algorithms, false, usedAlgorithms);
              if (!usedAlgorithms.isEmpty()) {
                fullComment.append(" / ");
                fullComment.append(wiki.getCWConfiguration().getComment(usedAlgorithms));
                if (description != null) {
                  for (CheckErrorAlgorithm algorithm : usedAlgorithms) {
                    description.append("<li>");
                    description.append(algorithm.getShortDescriptionReplaced());
                    description.append("</li>\n");
                  }
                }
              }
            }
            if ((description != null) && (changed)) {
              description.append("</ul>\n");
            }

            // Save page
            setText(GT._("Updating page {0}", page.getTitle()));
            count++;
            if (save) {
              api.updatePage(wiki, page, newContents, fullComment.toString(), false);
              if (updateDabWarning) {
                dabWarnings.updateWarning(
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.