Package org.wikipediacleaner.api

Examples of org.wikipediacleaner.api.API


   *
   * @param pages List of pages in the watch list.
   * @throws APIException
   */
  private void constructWatchList(List<Page> pages) throws APIException {
    final API api = APIFactory.getAPI();
    List<Page> tmpPages = api.retrieveRawWatchlist(getWikipedia());
    if (tmpPages != null) {
      pages.addAll(tmpPages);
    }
  }
View Full Code Here


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

        }

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

  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
    try {
      API api = APIFactory.getAPI();
      StringBuilder message = new StringBuilder();
      List<String> values = new ArrayList<String>();

      // Check language link
      if ((fromWiki != null) && (toWiki != null)) {
        String languageLink = api.getLanguageLink(fromWiki, toWiki, title);
        if (message.length() > 0) {
          message.append("\n");
        }
        if (languageLink != null) {
          message.append(GT._(
              "The page {0} in \"{1}\" has a language link to \"{2}\": {3}.",
              new Object[] { title, fromWiki.toString(), toWiki.toString(), languageLink } ));
          String value = PageElementInternalLink.createInternalLink(languageLink, text);
          if (!values.contains(value)) {
            values.add(value);
          }
          value = PageElementInternalLink.createInternalLink(languageLink, null);
          if (!values.contains(value)) {
            values.add(value);
          }
          value = PageElementInternalLink.createInternalLink(languageLink, title);
          if (!values.contains(value)) {
            values.add(value);
          }
        } else {
          message.append(GT._(
              "The page {0} in \"{1}\" doesn''t have a language link to \"{2}\".",
              new Object[] { title, fromWiki.toString(), toWiki.toString() } ));
        }
      }

      // Check local page
      if (toWiki != null) {
        Page page = DataManager.getPage(toWiki, title, null, null, null);
        api.retrieveInfo(toWiki, Collections.singletonList(page));
        if (message.length() > 0) {
          message.append("\n");
        }
        if (Boolean.FALSE.equals(page.isExisting())) {
          message.append(GT._(
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.api.API

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.