Package org.wikipediacleaner.api.data

Examples of org.wikipediacleaner.api.data.Page


      XPath xpaPages = XPath.newInstance("/api/query/pages/page");
      List listLinks = xpaPages.selectNodes(root);
      Iterator itLinks = listLinks.iterator();
      while (itLinks.hasNext()) {
        Element linkNode = (Element) itLinks.next();
        Page link = getPage(getWiki(), linkNode, knownPages, useDisambig);
        if ((redirects != null) && (link.isRedirect())) {
          redirects.add(link);
        }
        links.add(link);
      }
View Full Code Here


    // 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);
        }
      }
    }
    CheckErrorAlgorithms.initializeAlgorithms(wiki);
View Full Code Here

      XPath xpa = XPath.newInstance("/api/query/querypage/results/page");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        Page page = DataManager.getPage(
            getWiki(), currentNode.getAttributeValue("title"), null, null, null);
        page.setNamespace(currentNode.getAttributeValue("ns"));
        list.add(page);
      }

      // Retrieve continue
      return shouldContinue(
View Full Code Here

    }

    // Check if an update has been made on a monitored page
    for (RecentChange rc : filteredNewRC) {
      if (monitoredPages.containsKey(rc.getTitle())) {
        Page page = DataManager.getPage(getWikipedia(), rc.getTitle(), null, null, null);
        try {
          updateDabWarning.updateWarning(
              Collections.singletonList(page), null, null, null);
        } catch (APIException e) {
          // Nothing to do
        }
        monitoredPages.put(rc.getTitle(), Long.valueOf(currentTime.getTime()));
      }
    }

    // Check monitored pages for expired delay
    Iterator<Entry<String, Long>> itPages = monitoredPages.entrySet().iterator();
    while (itPages.hasNext()) {
      Entry<String, Long> entry = itPages.next();
      if (currentTime.getTime() > entry.getValue().longValue() + delayMonitoring) {
        itPages.remove();
      }
    }

    // Update list of interesting recent changes
    for (RecentChange rc : filteredNewRC) {
      if (isInterestingNamespace(rc)) {
        if (RecentChange.TYPE_NEW.equals(rc.getType())) {
          if (rc.isNew()) {
            modelRCInteresting.addRecentChange(rc);
          }
        } else if (RecentChange.TYPE_EDIT.equals(rc.getType())) {
          if (modelRCInteresting.containsRecentChange(rc.getTitle())) {
            modelRCInteresting.addRecentChange(rc);
          }
        } else if (RecentChange.TYPE_LOG.equals(rc.getType())) {
          if (RecentChange.LOG_TYPE_DELETE.equals(rc.getLogType()) &&
              RecentChange.LOG_ACTION_DELETE_DELETE.equals(rc.getLogAction())) {
            modelRCInteresting.removeRecentChanges(rc.getTitle());
          }
        }
      }
    }

    // Check if interesting recent changes are old enough
    List<RecentChange> interestingRC = modelRCInteresting.getRecentChanges();
    List<Page> pages = new ArrayList<Page>();
    Map<String, String> creators = new HashMap<String, String>();
    Map<String, List<String>> modifiers = new HashMap<String, List<String>>();
    while (!interestingRC.isEmpty()) {

      // Retrieve synthetic information about recent changes for one title
      List<RecentChange> listRC = extractRecentChanges(interestingRC);
      String title = listRC.get(0).getTitle();
      String creator = null;
      List<String> pageModifiers = new ArrayList<String>();
      boolean oldEnough = true;
      boolean redirect = false;
      for (int rcNum = listRC.size(); rcNum > 0; rcNum--) {
        RecentChange rc = listRC.get(rcNum - 1);
        if (currentTime.getTime() <= rc.getTimestamp().getTime() + delayForNew) {
          oldEnough = false;
        }
        String user = rc.getUser();
        redirect = rc.isRedirect();
        if (rc.isNew()) {
          creator = user;
        } else {
          if (!rc.isBot()) {
            if ((creator == null) || (!creator.equals(user))) {
              if (!pageModifiers.contains(user)) {
                pageModifiers.add(user);
              }
            }
          }
        }
      }

      if (oldEnough) {
        modelRCInteresting.removeRecentChanges(title);
        if (!redirect) {
          Page page = DataManager.getPage(getWikipedia(), title, null, null, null);
          pages.add(page);
          creators.put(title, creator);
          modifiers.put(title, pageModifiers);
        }
      }
    }

    // Update disambiguation warnings
    if (!pages.isEmpty()) {
      try {
        Stats stats = new Stats();
        createDabWarning.updateWarning(
            pages, creators, modifiers, stats);
        List<Page> updatedPages = stats.getUpdatedPages();
        if (updatedPages != null) {
          for (Page page : updatedPages) {
            monitoredPages.put(page.getTitle(), Long.valueOf(currentTime.getTime()));
          }
        }
      } catch (APIException e) {
        // Nothing to do
      }
View Full Code Here

    if (analysis.isInNamespace(Namespace.TEMPLATE)) {
      return false;
    }

    // Check every position
    Page page = analysis.getPage();
    String contents = analysis.getContents();
    int maxLen = contents.length();
    boolean result = false;
    int currentIndex = 0;
    while (currentIndex < maxLen) {
      int nextIndex = currentIndex;
      if (contents.startsWith("{{", currentIndex)) {
        boolean done = false;

        // Check for templates beginning with '{{{' instead of '{{'
        if (!done &&
            contents.startsWith("{{{", currentIndex)) {
          PageElementTemplate currentTemplate = analysis.isInTemplate(currentIndex);
          PageElementTemplate nextTemplate = analysis.isInTemplate(currentIndex + 1);
          if ((nextTemplate != null) &&
              (currentIndex + 1 == nextTemplate.getBeginIndex()) &&
              ((currentTemplate == null) ||
               (currentTemplate.getBeginIndex() < currentIndex - 1))) {
            result = true;
            done = true;
            if (errors == null) {
              return true;
            }
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis, currentIndex, currentIndex + 3);
            errorResult.addReplacement("{{");
            errors.add(errorResult);
            nextIndex = currentIndex + 3;
          }
        }

        // Check for parameters
        if (!done) {
          PageElementParameter parameter = analysis.isInParameter(currentIndex);
          if ((parameter != null) &&
              (parameter.getBeginIndex() == currentIndex)) {
            result = true;
            done = true;
            if (errors == null) {
              return true;
            }
            CheckErrorResult errorResult = createCheckErrorResult(
                analysis, parameter.getBeginIndex(), parameter.getEndIndex());
            if (parameter.getParameterCount() == 1) {
              String value = parameter.getParameterValue(0);
              if (value != null) {
                errorResult.addReplacement(value);
              }
            }
            errors.add(errorResult);
            nextIndex = parameter.getEndIndex();
          }
        }

        // Check for functions
        if (!done) {
          PageElementFunction function = analysis.isInFunction(currentIndex);
          if ((function != null) &&
              (function.getBeginIndex() == currentIndex)) {
            MagicWord magicWord = function.getMagicWord();
            String magicWordName = magicWord.getName();
            boolean isOk = false;
            if (MagicWord.DEFAULT_SORT.equals(magicWordName) ||
                MagicWord.FORMAT_NUM.equals(magicWordName) ||
                MagicWord.DISPLAY_TITLE.equals(magicWordName)) {
              isOk = true;
            }
            if (!isOk &&
                MagicWord.TAG.equals(magicWordName) &&
                (function.getParameterCount() > 0) &&
                (PageElementTag.TAG_WIKI_REF.equals(function.getParameterValue(0)))) {
              isOk = true;
            }
            if (!isOk) {
              result = true;
              done = true;
              if (errors == null) {
                return true;
              }
              CheckErrorResult errorResult = createCheckErrorResult(
                  analysis, function.getBeginIndex(), function.getEndIndex());
              if (MagicWord.PAGE_NAME.equals(magicWordName)) {
                errorResult.addReplacement(page.getTitle());
              }
              if (MagicWord.IF_EXPR.equals(magicWordName)) {
                for (int param = 1; param < function.getParameterCount(); param++) {
                  errorResult.addReplacement(function.getParameterValue(param));
                }
View Full Code Here

      } catch (NumberFormatException e) {
        //
      }
    }
    String revisionId = pageNode.getAttributeValue("lastrevid");
    Page page = DataManager.getPage(wiki, title, pageId, revisionId, knownPages);
    page.setNamespace(pageNode.getAttributeValue("ns"));
    if (pageNode.getAttribute("missing") != null) {
      page.setExisting(Boolean.FALSE);
    } else if (pageId != null) {
      page.setExisting(Boolean.TRUE);
    }
    if (pageNode.getAttribute("redirect") != null) {
      page.isRedirect(true);
    }
    if (useDisambig) {
      Element pageProps = pageNode.getChild("pageprops");
      boolean dabPage = (pageProps != null) && (pageProps.getAttribute("disambiguation") != null);
      page.setDisambiguationPage(Boolean.valueOf(dabPage));
    }
    return page;
  }
View Full Code Here

    int maxSize = getMaxSize(limit, ConfigurationValueInteger.MAX_CATEGORY_MEMBERS);
    while (!categories.isEmpty()) {

      // Find which category to analyze
      Entry<Page, Integer> entry = categories.entrySet().iterator().next();
      Page currentCategory = entry.getKey();
      categories.remove(currentCategory);
      int currentDepth = entry.getValue().intValue();
      String categoryName = currentCategory.getTitle();
      int colonIndex = categoryName.indexOf(':');
      if (colonIndex < 0) {
        categoryName = getWiki().getWikiConfiguration().getPageTitle(
            Namespace.CATEGORY, categoryName);
      } else {
        Namespace namespaceCategory = getWiki().getWikiConfiguration().getNamespace(Namespace.CATEGORY);
        if (!namespaceCategory.isPossibleName(categoryName.substring(0, colonIndex))) {
          categoryName = getWiki().getWikiConfiguration().getPageTitle(Namespace.CATEGORY, categoryName);
        }
      }
      boolean shouldAnalyze = true;
      if (currentDepth > depth) {
        shouldAnalyze = false;
      }
      if (categoriesAnalyzed.contains(categoryName)) {
        shouldAnalyze = false;
      }

      // Analyze the category
      if (shouldAnalyze) {
        categoriesAnalyzed.add(categoryName);
        Map<String, String> properties = getProperties(ACTION_QUERY, result.getFormat());
        properties.put(
            PROPERTY_LIST,
            PROPERTY_LIST_CATEGORYMEMBERS);
        properties.put(PROPERTY_LIMIT, LIMIT_MAX);
        properties.put(PROPERTY_TITLE, categoryName);
        List<Page> list = new ArrayList<Page>();
        while (result.executeCategoryMembers(
            properties, list, categories, currentDepth) &&
            (list.size() < maxSize)) {
          //
        }
        Collections.sort(list);
        currentCategory.setRelatedPages(Page.RelatedPages.CATEGORY_MEMBERS, list);
      }
    }
  }
View Full Code Here

    listPages.clearSelection();
    listPages.setSelectionInterval(0, modelPages.getSize() - 1);

    // Fill list of automatic fixing
    Configuration config = Configuration.getConfiguration();
    Page page = getPage();
    if (page != null) {
      Object[] automaticFixing = config.getPojoArray(
          page.getWikipedia(), Configuration.POJO_AUTOMATIC_FIXING,
          page.getTitle(), AutomaticFixing.class);
      if (automaticFixing != null) {
        List<AutomaticFixing> data = new ArrayList<AutomaticFixing>(automaticFixing.length);
        for (int i = 0; i < automaticFixing.length; i++) {
          if (automaticFixing[i] instanceof AutomaticFixing) {
            data.add((AutomaticFixing) automaticFixing[i]);
View Full Code Here

            endIndex++;
          }
          CheckErrorResult errorResult = createCheckErrorResult(
              analysis, beginIndex, endIndex);
          if (link.hasSecondSquare() && (link.getLink().indexOf('?') < 0)) {
            Page articlePage = DataManager.getPage(analysis.getWikipedia(), article, null, null, null);
            boolean needColon = false;
            if (articlePage.getNamespace() != null) {
              int ns = articlePage.getNamespace().intValue();
              if (ns % 2 == 0) {
                if ((ns != Namespace.MAIN) &&
                    (ns != Namespace.USER) &&
                    (ns != Namespace.HELP) &&
                    (ns != Namespace.MEDIAWIKI) &&
View Full Code Here

      displayErrorDescription();

      // Pages
      int nbPages = error.getPageCount();
      for (int numPage = 0; numPage < nbPages; numPage++) {
        Page page = error.getPage(numPage);
        CheckErrorPage errorPage = new CheckErrorPage(page, error.getAlgorithm());
        if ((errorPage.isInWhiteList()) && (page.getPageId() != null)) {
          markPageAsFixed(error.getAlgorithm().getErrorNumberString(), page);
        } else {
          modelPages.addElement(errorPage);
        }
      }
      setPageLoaded(false);
      actionSelectPages();
      updateComponentState();
    } else {
      buttonReloadError.setEnabled(false);
      buttonErrorDetail.setEnabled(false);
      buttonErrorList.setEnabled(false);
      buttonWhiteList.setEnabled(false);
      displayErrorDescription();

      if (selection instanceof String) {
        List<String> listTmp = new ArrayList<String>();
        for (CheckError error : errors) {
          int nbPages = error.getPageCount();
          for (int numPage = 0; numPage < nbPages; numPage++) {
            Page page = error.getPage(numPage);
            listTmp.add(page.getTitle());
          }
        }
        Collections.sort(listTmp);
        List<String> listErrorPages = new ArrayList<String>();
        for (int listPosition = 1; listPosition < listTmp.size(); listPosition++) {
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.