コード例 #1
0
  /**
   * Create a default popup menu for a category.
   * 
   * @param textPane Text pane.
   * @param position Position in the text.
   * @param pageAnalysis Page analysis.
   * @param category Category.
   * @return Popup menu.
   */
  protected JPopupMenu createDefaultPopupCategory(
      MWPane textPane, int position,
      PageAnalysis pageAnalysis,
      PageElementCategory category) {
    if (category == null) {
      return null;
    }

    // Initialization
    String fullName = wikipedia.getWikiConfiguration().getPageTitle(
        Namespace.CATEGORY,
        category.getName());
    Page page = DataManager.getPage(wikipedia, fullName, null, null, null);

    // Menu creation
    BasicMenuCreator menu = new BasicMenuCreator();
    JPopupMenu popup = menu.createPopupMenu(GT._(
        "Category: {0}",
        limitTextLength(category.getName(), 50)));
    menu.addCurrentChapter(popup, position, pageAnalysis);
    menu.addSeparator(popup);
    menu.addView(wikipedia, popup, page, false);
    menu.addAnalyze(wikipedia, popup, page);

    return popup;
  }
コード例 #2
0
  /**
   * Execute abuse log request.
   *
   * @param properties Properties defining request.
   * @param list List to be filled with abuse logs.
   * @return True if request should be continued.
   * @throws APIException
   */
  @Override
  public boolean executeAbuseLog(Map<String, String> properties, List<Page> list)
      throws APIException {
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Retrieve category members
      XPathExpression<Element> xpa =
          XPathFactory.instance().compile("/api/query/abuselog/item", Filters.element());
      List<Element> results = xpa.evaluate(root);
      Iterator<Element> iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = iter.next();
        String title = currentNode.getAttributeValue("title");
        Page page = DataManager.getPage(getWiki(), title, null, null, null);
        list.add(page);
      }

      // Retrieve continue
      return false; // Not continuing
      /*return shouldContinue(
      root, "/api/query-continue/abuselog",
      properties);*/
    } catch (JDOMException e) {
      log.error("Error loading abuse filters list", e);
      throw new APIException("Error parsing XML", e);
    }
  }
コード例 #3
0
  /**
   * Create a default popup menu for a language link.
   * 
   * @param textPane Text pane.
   * @param position Position in the text.
   * @param pageAnalysis Page analysis.
   * @param link Language link.
   * @return Popup menu.
   */
  protected JPopupMenu createDefaultPopupLanguageLink(
      MWPane textPane, int position,
      PageAnalysis pageAnalysis,
      PageElementLanguageLink link) {
    if (link == null) {
      return null;
    }

    // Initialization
    EnumWikipedia otherWikipedia = EnumWikipedia.getWikipedia(link.getLanguage());
    Page otherPage = null;
    if (otherWikipedia != null) {
      otherPage = DataManager.getPage(otherWikipedia, link.getLink(), null, null, null);
    }

    // Menu creation
    BasicMenuCreator menu = new BasicMenuCreator();
    JPopupMenu popup = menu.createPopupMenu(
        link.getLanguage() + ":" +
        limitTextLength(link.getLink(), 50));
    menu.addCurrentChapter(popup, position, pageAnalysis);
    if (otherWikipedia != null) {
      menu.addSeparator(popup);
      menu.addView(otherWikipedia, popup, otherPage, false);
    }

    return popup;
  }
コード例 #4
0
  /**
   * Create a default popup menu for an internal link.
   * 
   * @param textPane Text pane.
   * @param position Position in the text.
   * @param pageAnalysis Page analysis.
   * @param link Internal link.
   * @return Popup menu.
   */
  protected JPopupMenu createDefaultPopupInternalLink(
      MWPane textPane, int position,
      PageAnalysis pageAnalysis,
      PageElementInternalLink link) {
    if (link == null) {
      return null;
    }

    // Initialization
    Page page = DataManager.getPage(wikipedia, link.getLink(), null, null, null);

    // Menu creation
    BasicMenuCreator menu = new BasicMenuCreator();
    JPopupMenu popup = menu.createPopupMenu(GT._(
        "Page: {0}",
        limitTextLength(page.getTitle(), 50)));
    menu.addCurrentChapter(popup, position, pageAnalysis);
    menu.addSeparator(popup);
    menu.addView(wikipedia, popup, page, false);
    menu.addAnalyze(wikipedia, popup, page);
    menu.addDisambiguation(wikipedia, popup, page);
    menu.addSeparator(popup);
    menu.addItemRemoveLink(
        popup, link.getDisplayedText(),
        textPane, link.getBeginIndex(), link.getEndIndex());

    return popup;
  }
コード例 #5
0
 /**
  * Retrieve the list of pages in error.
  * 
  * @param wiki Wiki.
  * @param limit Maximum number of pages to retrieve.
  * @return List of pages in error.
  */
 @Override
 public List<Page> getSpecialList(EnumWikipedia wiki, int limit) {
   List<Page> result = null;
   String categoryName = getTrackingCategory();
   if (categoryName != null) {
     API api = APIFactory.getAPI();
     String title = wiki.getWikiConfiguration().getPageTitle(Namespace.CATEGORY, categoryName);
     Page category = DataManager.getPage(wiki, title, null, null, null);
     try {
       api.retrieveCategoryMembers(wiki, category, 0, false, limit);
       result = category.getRelatedPages(RelatedPages.CATEGORY_MEMBERS);
     } catch (APIException e) {
       //
     }
   }
   return result;
 }
コード例 #6
0
  /**
   * Create a default popup menu for a template.
   * 
   * @param pageAnalysis Page analysis.
   * @param position Position in the text.
   * @param template Template.
   * @return Popup menu.
   */
  protected JPopupMenu createDefaultPopupTemplate(
      PageAnalysis pageAnalysis, int position,
      PageElementTemplate template) {
    if (template == null) {
      return null;
    }

    // Initialization
    String fullName = wikipedia.getWikiConfiguration().getPageTitle(
        Namespace.TEMPLATE,
        template.getTemplateName());
    Page page = DataManager.getPage(wikipedia, fullName, null, null, null);

    // Menu creation
    BasicMenuCreator menu = new BasicMenuCreator();
    JPopupMenu popup = menu.createPopupMenu(GT._(
        "Template: {0}",
        limitTextLength(template.getTemplateName(), 50)));
    menu.addCurrentChapter(popup, position, pageAnalysis);

    // Search engines
    Map<String, List<SearchEngine>> searchEngines = SearchEngine.getSearchEngines(
        wikipedia, template, null);
    if ((searchEngines != null) && !searchEngines.isEmpty()) {
      menu.addSeparator(popup);
      List<String> parameterNames = new ArrayList<>(searchEngines.keySet());
      Collections.sort(parameterNames);
      for (String parameterName : parameterNames) {
        JMenu submenu = new JMenu(GT._("Search using {0}", parameterName));
        for (SearchEngine searchEngine : searchEngines.get(parameterName)) {
          menu.addItemView(null, submenu, searchEngine.getUrl(), searchEngine.getName());
        }
        menu.addSubmenu(popup, submenu, 0, 0);
      }
    }

    // General items
    menu.addSeparator(popup);
    menu.addCheckTemplate(wikipedia, window.getParentComponent(), popup, template);
    menu.addView(wikipedia, popup, page, false);
    menu.addAnalyze(wikipedia, popup, page);

    return popup;
  }
コード例 #7
0
  /**
   * Update redirect and missing information of a list of pages.
   *
   * @param root Root element.
   * @param pages List of pages.
   * @throws JDOMException
   */
  public void updateRedirect(Element root, Collection<Page> pages) throws JDOMException {

    // Retrieving redirects
    XPath xpaRedirects = XPath.newInstance("/api/query/redirects/r");
    List listRedirects = xpaRedirects.selectNodes(root);
    XPath xpaFrom = XPath.newInstance("./@from");
    XPath xpaTo = XPath.newInstance("./@to");

    // Retrieving pages
    XPath xpaPages = XPath.newInstance("/api/query/pages");
    Element listPages = (Element) xpaPages.selectSingleNode(root);
    XPath xpaPageId = XPath.newInstance("./@pageid");
    XPath xpaNamespace = XPath.newInstance("./@ns");
    XPath xpaTitle = XPath.newInstance("./@title");

    // Retrieving normalization information
    Map<String, String> normalization = new HashMap<String, String>();
    retrieveNormalization(root, normalization);

    // Analyzing redirects
    Iterator itRedirect = listRedirects.iterator();
    while (itRedirect.hasNext()) {
      Element currentRedirect = (Element) itRedirect.next();
      String fromPage = xpaFrom.valueOf(currentRedirect);
      String toPage = xpaTo.valueOf(currentRedirect);
      for (Page p : pages) {

        // Find if the redirect is already taken into account
        boolean exists = false;
        Iterator<Page> itPage = p.getRedirectIteratorWithPage();
        while (itPage.hasNext()) {
          Page tmp = itPage.next();
          String title = getNormalizedTitle(tmp.getTitle(), normalization);
          if (Page.areSameTitle(title, toPage)) {
            exists = true;
          }
        }

        // Add the redirect if needed
        itPage = p.getRedirectIteratorWithPage();
        while (itPage.hasNext()) {
          Page tmp = itPage.next();
          String title = getNormalizedTitle(tmp.getTitle(), normalization);
          if (!exists && Page.areSameTitle(title, fromPage)) {
            XPath xpaPage = createXPath("page", "title", toPage);
            List listTo = xpaPage.selectNodes(listPages);
            if (!listTo.isEmpty()) {
              Element to = (Element) listTo.get(0);
              Page pageTo =
                  DataManager.getPage(p.getWikipedia(), xpaTitle.valueOf(to), null, null, null);
              pageTo.setNamespace(xpaNamespace.valueOf(to));
              pageTo.setPageId(xpaPageId.valueOf(to));
              p.addRedirect(pageTo);
            }
          }
        }
      }
    }

    // Analyzing missing pages
    for (Page p : pages) {
      Iterator<Page> itPage = p.getRedirectIteratorWithPage();
      while (itPage.hasNext()) {
        Page tmp = itPage.next();
        String title = getNormalizedTitle(tmp.getTitle(), normalization);
        XPath xpaPage = createXPath("page", "title", title);
        Element page = (Element) xpaPage.selectSingleNode(listPages);
        if (page != null) {
          List pageId = xpaPageId.selectNodes(page);
          if ((pageId != null) && (!pageId.isEmpty())) {
            tmp.setExisting(Boolean.TRUE);
          } else {
            Attribute attrMissing = page.getAttribute("missing");
            if (attrMissing != null) {
              tmp.setExisting(Boolean.FALSE);
            }
          }
        }
      }
    }
  }