Package org.wikipediacleaner.api

Examples of org.wikipediacleaner.api.API


   */
  @Override
  public Object construct() {
    try {
      setText(GT._("Retrieving MediaWiki API"));
      API api = APIFactory.getAPI();
      setText(GT._("Adding comment"));
      api.addNewSection(getWikipedia(), page, section, text, forceWatch);
    } catch (APIException e) {
      return e;
    }
    return null;
  }
View Full Code Here


    try {
      if (progressPanel != null) {
        progressPanel.start();
        progressPanel.setText(GT._("Retrieving MediaWiki API"));
      }
      API api = APIFactory.getAPI();
      if (progressPanel != null) {
        progressPanel.setText(GT._("Analyzing links for redirect pages"));
      }
      ArrayList<Page> pages = new ArrayList<Page>();
      pages.add(page);
      api.initializeRedirect(wikipedia, pages);
      if (progressPanel != null) {
        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) {
      //
    } finally {
      if (progressPanel != null) {
View Full Code Here

   */
  public Collection<String> getTexts() {
    Collection<String> result = new ArrayList<String>();
    if (image != null) {
      try {
        API api = APIFactory.getAPI();

        // Retrieve image descriptions
        Page imagePage = DataManager.getPage(
            image.getWiki(),
            image.getNamespace() + ":" + image.getImage(),
            null, null, null);
        api.retrieveContents(
            image.getWiki(),
            Collections.singletonList(imagePage), false, false);

        // Use image description on the wiki
        if (Boolean.TRUE.equals(imagePage.isExisting())) {
          PageAnalysis pageAnalysis = imagePage.getAnalysis(imagePage.getContents(), true);
          for (PageElementTemplate template : pageAnalysis.getTemplates()) {
            if (Page.areSameTitle("Information", template.getTemplateName())) {
              String description = template.getParameterValue("Description");
              if ((description != null) && (description.trim().length() > 0)) {
                result.add(description.trim());
              }
            }
          }
        }

        // Retrieve image description on Commons
        Page commonsPage = DataManager.getPage(
            EnumWikipedia.COMMONS,
            "File:" + image.getImage(),
            null, null, null);
        api.retrieveContents(
            EnumWikipedia.COMMONS,
            Collections.singletonList(commonsPage), false, false);
        if (Boolean.TRUE.equals(commonsPage.isExisting())) {
          PageAnalysis pageAnalysis = commonsPage.getAnalysis(commonsPage.getContents(), true);
          for (PageElementTemplate template : pageAnalysis.getTemplates()) {
View Full Code Here

  /**
   * Action called when Logout button is pressed.
   */
  public void actionLogout() {
    API api = APIFactory.getAPI();
    api.logout(getWikipedia());
    logged = false;
    userLogged = false;
    updateComponentState();
  }
View Full Code Here

  /**
   * Action called when Abuse Filters button is pressed.
   */
  public void actionAbuseFilters() {
    try {
      API api = APIFactory.getAPI();
      List<AbuseFilter> abuseFilters = api.retrieveAbuseFilters(getWikipedia());
      if ((abuseFilters != null) && (abuseFilters.size() > 0)) {
        Object filter = Utilities.askForValue(
            getParentComponent(),
            GT._("What abuse filter are you interested in?"),
            abuseFilters.toArray(), abuseFilters.get(0));
        if ((filter != null) && (filter instanceof AbuseFilter)) {
          List<Page> pages = api.retrieveAbuseLog(getWikipedia(), (AbuseFilter) filter);
          if ((pages != null) && (!pages.isEmpty())) {
            List<String> pageNames = new ArrayList<String>(pages.size());
            for (Page page : pages) {
              if (!pageNames.contains(page.getTitle())) {
                pageNames.add(page.getTitle());
View Full Code Here

        displayWarning(GT._(
            "The number of pages must be between {0} and {1}",
            new Object[] { Integer.valueOf(0), Integer.valueOf(maxPages) } ));
      }
    }
    API api = APIFactory.getAPI();
    try {
      List<String> pageNames = new ArrayList<String>(count);
      while (pageNames.size() < count) {
        List<Page> pages = api.getRandomPages(getWikipedia(), count - pageNames.size(), redirects);
        for (int i = 0; i < pages.size(); i++) {
          pageNames.add(pages.get(i).getTitle());
        }
      }
      Collections.sort(pageNames);
View Full Code Here

  public void retrieveConfiguration(
      EnumWikipedia wiki,
      MediaWikiListener listener) throws APIException {

    // Retrieve general configuration
    final API api = APIFactory.getAPI();
    final WPCConfiguration wpcConfiguration = wiki.getConfiguration();
    boolean useLabs = wiki.getConfiguration().getBoolean(WPCConfigurationBoolean.CW_USE_LABS);
    final CWConfiguration cwConfiguration = wiki.getCWConfiguration();
    if (!useLabs) {
      String code = wiki.getSettings().getCodeCheckWiki().replace("-", "_");
      try {
        ResponseManager manager = new ResponseManager() {
         
          public void manageResponse(InputStream stream) throws IOException, APIException {
            if (stream != null) {
              cwConfiguration.setGeneralConfiguration(
                  new InputStreamReader(stream, "UTF-8"));
            }
          }
        };
        toolServer.sendGet(
            "~sk/checkwiki/" + code + "/" + code + "_translation.txt",
            manager);
      } catch (APIException e) {
        System.err.println("Error retrieving Check Wiki configuration: " + e.getMessage());
      }
    }

    // Retrieve specific configuration
    try {
      String translationPage = wpcConfiguration.getString(WPCConfigurationString.CW_TRANSLATION_PAGE);
      if (translationPage != null) {
        Page page = DataManager.getPage(
            wiki, translationPage,
            null, null, null);
        api.retrieveContents(wiki, Collections.singleton(page), false, false);
        if (Boolean.TRUE.equals(page.isExisting())) {
          cwConfiguration.setWikiConfiguration(new StringReader(page.getContents()));
        }
      }
    } catch (APIException e) {
      System.err.println("Error retrieving Check Wiki configuration: " + e.getMessage());
    }

    // Retrieving white lists
    HashMap<String, Page> whiteListPages = new HashMap<String, Page>();
    for (int i = 0; i < CWConfiguration.MAX_ERROR_NUMBER; i++) {
      CWConfigurationError error = cwConfiguration.getErrorConfiguration(i);
      if ((error != null) && (error.getWhiteListPageName() != null)) {
        Page page = DataManager.getPage(
            wiki, error.getWhiteListPageName(), null, null, null);
        whiteListPages.put(error.getWhiteListPageName(), page);
      }
    }
    if (whiteListPages.size() > 0) {
      api.retrieveLinks(wiki, whiteListPages.values());
      for (int i = 0; i < CWConfiguration.MAX_ERROR_NUMBER; i++) {
        CWConfigurationError error = cwConfiguration.getErrorConfiguration(i);
        if ((error != null) && (error.getWhiteListPageName() != null)) {
          Page page = whiteListPages.get(error.getWhiteListPageName());
          error.setWhiteList(page);
View Full Code Here

    updateComponentState();
    monitoredPages = new HashMap<String, Long>();
    createDabWarning = new UpdateDabWarningTools(getWikipedia(), this, true);
    updateDabWarning = new UpdateDabWarningTools(getWikipedia(), this, false);
    API api = APIFactory.getAPI();
    api.addRecentChangesListener(getWikipedia(), this);
    return panel;
  }
View Full Code Here

   * @see org.wikipediacleaner.gui.swing.basic.BasicWindow#dispose()
   */
  @Override
  public void dispose() {
    API api = APIFactory.getAPI();
    api.removeRecentChangesListener(getWikipedia(), this);
    super.dispose();
  }
View Full Code Here

     */
    @Override
    public Object construct() {
      try {
        setText(GT._("Retrieving MediaWiki API"));
        API api = APIFactory.getAPI();
        setText(GT._("Retrieving templates"));
        api.retrieveTemplates(getWikipedia(), page1);
        setText(GT._("Retrieving links in templates"));
        api.retrieveLinks(getWikipedia(), page1.getTemplates());
        setText(GT._("Displaying templates found"));
        for (Page p : page1.getTemplates()) {
          boolean found = false;
          for (Page l : p.getLinks()) {
            if (link1.getTitle().equals(l.getTitle())) {
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.