Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.PageAnalysis$Result


    setText(prefix + " - " + GT._("Analyzing page {0}", page.getTitle()));

    // Retrieve page content
    API api = APIFactory.getAPI();
    api.retrieveContents(getWikipedia(), Collections.singletonList(page), true, false);
    PageAnalysis analysis = page.getAnalysis(page.getContents(), true);

    // Check that robots are authorized to change this page
    if (saveModifications) {
      WPCConfiguration config = getWikipedia().getConfiguration();
      List<String[]> nobotTemplates = config.getStringArrayList(
          WPCConfigurationStringList.NOBOT_TEMPLATES);
      if ((nobotTemplates != null) && (!nobotTemplates.isEmpty())) {
        for (String[] nobotTemplate : nobotTemplates) {
          String templateName = nobotTemplate[0];
          List<PageElementTemplate> templates = analysis.getTemplates(templateName);
          if ((templates != null) && (!templates.isEmpty())) {
            if (analyzeNonFixed) {
              Controller.runFullAnalysis(page.getTitle(), null, getWikipedia());
            }
            return;
View Full Code Here


    List<PageElementImage> images = analysis.getImages();
    for (PageElementImage image : images) {
      String description = image.getDescription();
      if (description != null) {
        description = description.trim();
        PageAnalysis descAnalysis = analysis.getPage().getAnalysis(description, false);
        List<PageElementTag> smallTags = descAnalysis.getTags(PageElementTag.TAG_HTML_SMALL);
        if ((smallTags != null) && (!smallTags.isEmpty())) {
          int lastTest = 0;
          int currentDepth = 0;
          boolean onlySmall = true;
          StringBuilder innerText = new StringBuilder();
View Full Code Here

      return;
    }

    // Update warning
    for (Page page : pages) {
      PageAnalysis pageAnalysis = page.getAnalysis(page.getContents(), true);
      boolean updated = updateWarning(
          pageAnalysis, page.getRevisionId(),
          mapTalkPages.get(page),
          mapTodoSubpages.get(page),
          (creators != null) ? creators.get(page.getTitle()) : null,
View Full Code Here

    // Search warning in the "To do" sub-page
    String contents = todoSubpage.getContents();
    if (contents == null) {
      contents = "";
    }
    PageAnalysis analysis = todoSubpage.getAnalysis(contents, true);
    PageElementTemplate templateWarning = getFirstWarningTemplate(analysis);

    // If warning is missing, add it
    if (templateWarning == null) {
      if (!createWarning) {
View Full Code Here

    // Search "To do" template in the talk page
    String contents = talkPage.getContents();
    if (contents == null) {
      contents = "";
    }
    PageAnalysis talkAnalysis = talkPage.getAnalysis(contents, true);
    PageElementTemplate templateTodo = null;
    List<String> todoTemplates = configuration.getStringList(WPCConfigurationStringList.TODO_TEMPLATES);
    if ((todoTemplates == null) ||
        (todoTemplates.isEmpty())) {
      return false;
    }
    for (String todoTemplate : todoTemplates) {
      List<PageElementTemplate> templates = talkAnalysis.getTemplates(todoTemplate);
      PageElementTemplate templateTmp = (templates != null) && (templates.size() > 0) ?
          templates.get(0) : null;
      if (templateTmp != null) {
        if ((templateTodo == null) || (templateTmp.getBeginIndex() < templateTodo.getBeginIndex())) {
          templateTodo = templateTmp;
        }
      }
    }

    // If "To do" template is missing, add it
    if (templateTodo == null) {
      if (!createWarning) {
        return false;
      }

      // Search where to add "To do" template
      PageElementTemplate templatePrevious = null;
      List<String> warningAfterTemplates = configuration.getStringList(
          WPCConfigurationStringList.WARNING_AFTER_TEMPLATES);
      if (warningAfterTemplates != null) {
        for (String previousTemplate : warningAfterTemplates) {
          Collection<PageElementTemplate> templates = talkAnalysis.getTemplates(previousTemplate);
          for (PageElementTemplate templateTmp : templates) {
            if ((templatePrevious == null) ||
                (templateTmp.getEndIndex() > templatePrevious.getEndIndex())) {
              templatePrevious = templateTmp;
            }
          }
        }
      }
      int indexStart = (templatePrevious != null) ? templatePrevious.getEndIndex() : 0;
      if ((indexStart == 0) && (talkPage.isRedirect())) {
        indexStart = contents.length();
      }

      // Add warning
      setText(getMessageUpdateWarning(talkPage.getTitle()));
      StringBuilder tmp = new StringBuilder();
      if (indexStart > 0) {
        tmp.append(contents.substring(0, indexStart));
        if (tmp.charAt(tmp.length() - 1) != '\n') {
          tmp.append("\n");
        }
      }
      tmp.append("{{");
      tmp.append(todoTemplates.get(0));
      tmp.append("|* ");
      addWarning(tmp, pageRevId, elements);
      tmp.append("}}");
      if (indexStart < contents.length()) {
        if (contents.charAt(indexStart) != '\n') {
          tmp.append("\n");
        }
        tmp.append(contents.substring(indexStart));
      }
      String comment = wiki.formatComment(
          getWarningComment(elements),
          automaticEdit);
      updateTalkPage(talkPage, tmp.toString(), comment);

      // Inform creator and modifiers of the page
      informContributors(analysis, elements, creator, modifiers);

      return true;
    }

    // Search warning in the "To do" parameter
    String parameter = templateTodo.getParameterValue("1");
    PageAnalysis parameterAnalysis = talkPage.getAnalysis(parameter, false);
    PageElementTemplate templateWarning = getFirstWarningTemplate(parameterAnalysis);
    if (templateWarning == null) {
      StringBuilder tmp = new StringBuilder();
      int indexStart = templateTodo.getBeginIndex();
      if (indexStart > 0) {
View Full Code Here

    }
    String contents = todoSubpage.getContents();
    if ((contents == null) || (contents.trim().equals(""))) {
      return false;
    }
    PageAnalysis analysis = todoSubpage.getAnalysis(contents, true);

    // Search warning in the "To do" sub-page
    PageElementTemplate template = getFirstWarningTemplate(analysis);
    if (template == null) {
      return false;
View Full Code Here

    String contents = talkPage.getContents();
    if (contents == null) {
      return false;
    }
    PageAnalysis analysis = talkPage.getAnalysis(contents, true);

    // Search "To do" in the talk page
    PageElementTemplate templateTodo = null;
    for (String templateName : todoTemplates) {
      List<PageElementTemplate> templates = analysis.getTemplates(templateName);
      if ((templates != null) && (templates.size() > 0)) {
        templateTodo = templates.get(0);
      }
    }

    // If template is missing, verify that a link to the "To do" sub-page exists
    if (templateTodo == null) {

      // If link exists, nothing more to do
      PageElementTemplate templateTodoLink = getExistingTemplateTodoLink(talkPage, contents);
      if (templateTodoLink != null) {
        return false;
      }

      // Search where to add "To do" template
      PageElementTemplate templatePrevious = null;
      List<String> warningAfterTemplates = configuration.getStringList(
          WPCConfigurationStringList.WARNING_AFTER_TEMPLATES);
      if (warningAfterTemplates != null) {
        for (String previousTemplate : warningAfterTemplates) {
          Collection<PageElementTemplate> templates = analysis.getTemplates(previousTemplate);
          for (PageElementTemplate templateTmp : templates) {
            if ((templatePrevious == null) ||
                (templateTmp.getEndIndex() > templatePrevious.getEndIndex())) {
              templatePrevious = templateTmp;
            }
          }
        }
      }

      // Add warning
      setText(getMessageUpdateWarning(talkPage.getTitle()));
      StringBuilder tmp = new StringBuilder();
      int indexStart = (templatePrevious != null) ? templatePrevious.getEndIndex() : 0;
      if (indexStart > 0) {
        tmp.append(contents.substring(0, indexStart));
        if (tmp.charAt(tmp.length() - 1) != '\n') {
          tmp.append("\n");
        }
      }
      tmp.append("{{");
      tmp.append(todoTemplates.get(0));
      tmp.append("}}");
      if (indexStart < contents.length()) {
        if (contents.charAt(indexStart) != '\n') {
          tmp.append("\n");
        }
        tmp.append(contents.substring(indexStart));
      }
      String comment = wiki.formatComment(
          getWarningComment(elements),
          automaticEdit);
      updateTalkPage(talkPage, tmp.toString(), comment);
      return true;
    }
    if (templateTodo.getParameterValue("1") == null) {
      return false;
    }

    // Search warning in the "To do" parameter
    String parameter = templateTodo.getParameterValue("1");
    PageAnalysis parameterAnalysis = talkPage.getAnalysis(parameter, false);
    PageElementTemplate templateWarning = getFirstWarningTemplate(parameterAnalysis);
    if (templateWarning != null) {
      setText(getMessageRemoveWarning(talkPage.getTitle()));
      StringBuilder tmp = new StringBuilder();
      if (templateTodo.getBeginIndex() > 0) {
View Full Code Here

    }
    String contents = talkPage.getContents();
    if (contents == null) {
      return false;
    }
    PageAnalysis analysis = talkPage.getAnalysis(contents, true);

    // Search "To do" in the talk page
    PageElementTemplate templateTodo = null;
    List<String> todoTemplates = configuration.getStringList(WPCConfigurationStringList.TODO_TEMPLATES);
    if (todoTemplates != null) {
      for (String templateName : todoTemplates) {
        List<PageElementTemplate> templates = analysis.getTemplates(templateName);
        if ((templates != null) && (templates.size() > 0)) {
          templateTodo = templates.get(0);
        }
      }
    }
View Full Code Here

    // Updating disambiguation warning
    if (updateDabWarning) {
      try {
        UpdateDabWarningTools dabWarningTools = new UpdateDabWarningTools(
            getWikipedia(), this, createDabWarning, false);
        PageAnalysis pageAnalysis = page.getAnalysis(text, true);
        dabWarningTools.updateWarning(
            pageAnalysis, queryResult.getPageNewRevId(),
            null, null, null, null, null);
      } catch (APIException e) {
        return e;
      }
    }

    // Updating ISBN warning
    if (updateISBNWarning) {
      try {
        UpdateISBNWarningTools isbnWarningTools = new UpdateISBNWarningTools(
            getWikipedia(), this, createISBNWarning, false);
        PageAnalysis pageAnalysis = page.getAnalysis(text, true);
        isbnWarningTools.updateWarning(
            pageAnalysis, queryResult.getPageNewRevId(),
            null, null, null, null, null);
      } catch (APIException e) {
        return e;
View Full Code Here

      mw.block(true);
      if (Boolean.FALSE.equals(page.isExisting())) {
        mw.retrieveSimilarPages(wiki, page);
      }
      setText("Analyzing data");
      PageAnalysis analysis = page.getAnalysis(page.getContents(), true);
      CheckError.analyzeErrors(algorithms, analysis, false);
    } catch (APIException e) {
      return e;
    }
    return null;
View Full Code Here

TOP

Related Classes of org.wikipediacleaner.api.data.PageAnalysis$Result

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.