Search in sources :

Example 1 with PageRedirect

use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.

the class DisambiguationWindow method afterFinishedReloadWorker.

/**
 * Callback called at the end of the Reload Worker.
 */
@Override
protected void afterFinishedReloadWorker() {
    super.afterFinishedReloadWorker();
    Configuration config = Configuration.getConfiguration();
    Page page = getPage();
    backlinksProperties = config.getSubProperties(getWikipedia(), Configuration.PROPERTIES_BACKLINKS, page.getTitle());
    listCellRenderer.setPageProperties(backlinksProperties);
    popupListenerLinks.setPage(page);
    popupListenerLinks.setBackLinksProperties(backlinksProperties);
    List<Page> links = page.getAllLinksToPage();
    if (config.getBoolean(null, ConfigurationValueBoolean.IGNORE_DAB_USER_NS)) {
        links = new ArrayList<>(links);
        for (int i = links.size(); i > 0; i--) {
            if (links.get(i - 1).isInUserNamespace()) {
                links.remove(i - 1);
            }
        }
    }
    modelLinks.setElements(links);
    Integer countMain = page.getBacklinksCountInMainNamespace();
    Integer countTotal = page.getBacklinksCount();
    linkCount.setText(((countMain != null) ? countMain.toString() : "?") + " / " + ((countTotal != null) ? countTotal.toString() : "?"));
    // Construct list of known pages
    knownPages.clear();
    if (getPage() != null) {
        knownPages = new ArrayList<>(1);
        knownPages.add(getPage());
        for (Page backLink : getPage().getAllLinksToPage()) {
            PageRedirect redirects = backLink.getRedirects();
            if ((redirects != null) && (redirects.isRedirect()) && (Page.areSameTitle(getPage().getTitle(), redirects.getTitle()))) {
                knownPages.add(backLink);
            }
        }
    }
    // Select next links
    actionSelectNextLinks();
}
Also used : ConfigurationValueInteger(org.wikipediacleaner.utils.ConfigurationValueInteger) Configuration(org.wikipediacleaner.utils.Configuration) PageRedirect(org.wikipediacleaner.api.data.PageRedirect) Page(org.wikipediacleaner.api.data.Page) ActionWatchPage(org.wikipediacleaner.gui.swing.action.ActionWatchPage)

Example 2 with PageRedirect

use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.

the class CheckWikiWindow method actionLoadPages.

/**
 * Action called when requesting to load selected pages.
 */
public void actionLoadPages() {
    final List<CheckErrorPage> selection = listPages.getSelectedValuesList();
    final List<Page> pages = new ArrayList<>();
    if (selection != null) {
        for (CheckErrorPage errorPage : selection) {
            pages.add(errorPage.getPage());
        }
    }
    if (pages.size() > 0) {
        RetrieveContentWorker contentWorker = new RetrieveContentWorker(getWikipedia(), this, pages);
        contentWorker.setListener(new DefaultBasicWorkerListener() {

            /* (non-Javadoc)
         * @see org.wikipediacleaner.gui.swing.basic.DefaultBasicWorkerListener#beforeFinished(org.wikipediacleaner.gui.swing.basic.BasicWorker)
         */
            @Override
            public void beforeFinished(BasicWorker worker) {
                super.beforeFinished(worker);
                final List<CheckWikiContentPanel> contentPanels = new ArrayList<>();
                for (Page page : pages) {
                    while (page != null) {
                        Object errorSelected = modelAllErrors.getSelectedItem();
                        final CheckWikiContentPanel contentPanel = createContentsComponents(contentPane, page, (errorSelected instanceof AlgorithmError) ? Collections.singletonList((AlgorithmError) errorSelected) : getErrorsForPage(page.getTitle()));
                        contentPane.add(contentPanel);
                        contentPane.setSelectedComponent(contentPanel);
                        contentPanels.add(contentPanel);
                        PageRedirect redirects = page.getRedirects();
                        if (redirects.isRedirect()) {
                            List<Page> listRedirects = redirects.getPageList();
                            if ((listRedirects != null) && (listRedirects.size() > 0)) {
                                page = listRedirects.get(0);
                            } else {
                                page = null;
                            }
                        } else {
                            page = null;
                        }
                    }
                }
                yesAll = false;
                noAll = false;
                List<String> messages = new ArrayList<>();
                for (CheckWikiContentPanel contentPanel : contentPanels) {
                    contentPanel.actionPageSelected(messages);
                }
                if (!messages.isEmpty()) {
                    StringBuilder message = new StringBuilder();
                    for (String line : messages) {
                        if (message.length() > 0) {
                            message.append('\n');
                        }
                        message.append(line);
                    }
                    displayWarning(message.toString());
                }
            }
        });
        contentWorker.start();
    } else {
        updateComponentState();
    }
}
Also used : PageRedirect(org.wikipediacleaner.api.data.PageRedirect) ArrayList(java.util.ArrayList) Page(org.wikipediacleaner.api.data.Page) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage) AlgorithmError(org.wikipediacleaner.api.algorithm.AlgorithmError) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString) RetrieveContentWorker(org.wikipediacleaner.gui.swing.worker.RetrieveContentWorker) DefaultBasicWorkerListener(org.wikipediacleaner.gui.swing.basic.DefaultBasicWorkerListener) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage) BasicWorker(org.wikipediacleaner.gui.swing.basic.BasicWorker)

Example 3 with PageRedirect

use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.

the class MediaWikiAPI method initializeDisambiguationStatus.

/**
 * Initialize the disambiguation flags of a list of <code>pages</code>.
 * (<code>action=query</code>, <code>prop=categories</code>) or
 * (<code>action=query</code>, <code>prop=templates</code>).
 *
 * @param wiki Wiki.
 * @param pages List of pages.
 * @param forceApiCall True if API call should be forced even if the list of disambiguation pages is loaded.
 * @throws APIException Exception thrown by the API.
 * @see <a href="http://www.mediawiki.org/wiki/API:Properties#categories_.2F_cl">API:Properties#categories</a>
 * @see <a href="http://www.mediawiki.org/wiki/API:Properties#templates_.2F_tl">API:Properties#templates</a>
 */
@Override
public void initializeDisambiguationStatus(EnumWikipedia wiki, List<Page> pages, boolean forceApiCall) throws APIException {
    if ((pages == null) || (pages.isEmpty())) {
        return;
    }
    if (wiki.isDisambiguationPagesLoaded() && !forceApiCall) {
        for (Page page : pages) {
            page.setDisambiguationPage(wiki.isDisambiguationPage(page));
            PageRedirect redirects = page.getRedirects();
            if (redirects.isRedirect() && (redirects.getPageList() != null)) {
                for (Page page2 : redirects.getPageList()) {
                    page2.setDisambiguationPage(wiki.isDisambiguationPage(page2));
                }
            }
        }
    } else {
        // Use __DISAMBIG__ magic word if possible
        WPCConfiguration config = wiki.getConfiguration();
        boolean useDisambig = config.getBoolean(WPCConfigurationBoolean.DAB_USE_DISAMBIG_MAGIC_WORD);
        if (useDisambig) {
            ApiPagePropsResult result = new ApiXmlPagePropsResult(wiki, httpClient);
            ApiPagePropsRequest request = new ApiPagePropsRequest(wiki, result);
            request.setDisambiguationStatus(pages);
            return;
        }
        // Use categories if possible
        List<Page> dabCategories = wiki.getConfiguration().getDisambiguationCategories();
        if ((dabCategories != null) && (dabCategories.size() > 0)) {
            ApiCategoriesResult result = new ApiXmlCategoriesResult(wiki, httpClient);
            ApiCategoriesRequest request = new ApiCategoriesRequest(wiki, result);
            request.setDisambiguationStatus(pages);
            return;
        }
        // Use templates otherwise
        ApiTemplatesResult result = new ApiXmlTemplatesResult(wiki, httpClient);
        ApiTemplatesRequest request = new ApiTemplatesRequest(wiki, result);
        request.setDisambiguationStatus(pages);
    }
}
Also used : PageRedirect(org.wikipediacleaner.api.data.PageRedirect) ApiTemplatesResult(org.wikipediacleaner.api.request.query.prop.ApiTemplatesResult) Page(org.wikipediacleaner.api.data.Page) EnumQueryPage(org.wikipediacleaner.api.constants.EnumQueryPage) ApiXmlTemplatesResult(org.wikipediacleaner.api.request.query.prop.ApiXmlTemplatesResult) ApiXmlPagePropsResult(org.wikipediacleaner.api.request.query.prop.ApiXmlPagePropsResult) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration) ApiXmlCategoriesResult(org.wikipediacleaner.api.request.query.prop.ApiXmlCategoriesResult) ApiTemplatesRequest(org.wikipediacleaner.api.request.query.prop.ApiTemplatesRequest) ApiCategoriesResult(org.wikipediacleaner.api.request.query.prop.ApiCategoriesResult) ApiPagePropsRequest(org.wikipediacleaner.api.request.query.prop.ApiPagePropsRequest) ApiPagePropsResult(org.wikipediacleaner.api.request.query.prop.ApiPagePropsResult) ApiCategoriesRequest(org.wikipediacleaner.api.request.query.prop.ApiCategoriesRequest)

Example 4 with PageRedirect

use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.

the class CheckErrorAlgorithm513 method isInList.

/**
 * @param link Link to be checked.
 * @param list List of page names (and potential URL restrictions).
 * @param analysis Page analysis to check through redirects.
 * @param externalLink External link.
 * @return True if the link points to a page in the list.
 */
private boolean isInList(PageElementInternalLink link, Map<String, List<String>> list, PageAnalysis analysis, PageElementExternalLink externalLink) {
    if ((link == null) || (list == null)) {
        return false;
    }
    String pageName = link.getLink();
    List<String> listUrl = null;
    boolean listFound = false;
    if (list.containsKey(pageName)) {
        listUrl = list.get(pageName);
        listFound = true;
    } else {
        if ((analysis != null) && (analysis.getPage() != null) && (analysis.getPage().getLinks() != null)) {
            List<Page> links = analysis.getPage().getLinks();
            for (Page tmp : links) {
                if (Page.areSameTitle(pageName, tmp.getTitle())) {
                    PageRedirect redirect = tmp.getRedirects();
                    if ((redirect != null) && (redirect.getLastPage() != null) && list.containsKey(redirect.getLastPage().getTitle())) {
                        listUrl = list.get(redirect.getLastPage().getTitle());
                        listFound = true;
                    }
                }
            }
        }
    }
    if (!listFound) {
        return false;
    }
    if ((listUrl == null) || listUrl.isEmpty()) {
        return true;
    }
    if (externalLink == null) {
        return false;
    }
    return listUrl.contains(externalLink.getLink());
}
Also used : PageRedirect(org.wikipediacleaner.api.data.PageRedirect) Page(org.wikipediacleaner.api.data.Page)

Example 5 with PageRedirect

use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.

the class ContentsCallable method call.

/* (non-Javadoc)
   * @see java.util.concurrent.Callable#call()
   */
@Override
public Page call() throws APIException {
    setText(GT._T("Retrieving contents") + " - " + page.getTitle());
    if (section == null) {
        api.retrieveContents(getWikipedia(), Collections.singletonList(page), usePageId, withRedirects);
        PageRedirect redirects = page.getRedirects();
        if (withRedirects && redirects.isRedirect() && (redirects.getPageList() != null) && (!redirects.getPageList().isEmpty())) {
            api.retrieveContents(getWikipedia(), redirects.getPageList(), false, false);
        }
    } else {
        api.retrieveSectionContents(getWikipedia(), page, section.intValue());
    }
    if (doAnalysis) {
        PageAnalysis analysis = page.getAnalysis(page.getContents(), true);
        analysis.performFullPageAnalysis(null);
    }
    return returnPage;
}
Also used : PageRedirect(org.wikipediacleaner.api.data.PageRedirect) PageAnalysis(org.wikipediacleaner.api.data.analysis.PageAnalysis)

Aggregations

PageRedirect (org.wikipediacleaner.api.data.PageRedirect)7 Page (org.wikipediacleaner.api.data.Page)6 JList (javax.swing.JList)2 CheckErrorPage (org.wikipediacleaner.api.check.CheckErrorPage)2 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JMenuItem (javax.swing.JMenuItem)1 AlgorithmError (org.wikipediacleaner.api.algorithm.AlgorithmError)1 WPCConfiguration (org.wikipediacleaner.api.configuration.WPCConfiguration)1 EnumQueryPage (org.wikipediacleaner.api.constants.EnumQueryPage)1 PageAnalysis (org.wikipediacleaner.api.data.analysis.PageAnalysis)1 ApiCategoriesRequest (org.wikipediacleaner.api.request.query.prop.ApiCategoriesRequest)1 ApiCategoriesResult (org.wikipediacleaner.api.request.query.prop.ApiCategoriesResult)1 ApiPagePropsRequest (org.wikipediacleaner.api.request.query.prop.ApiPagePropsRequest)1 ApiPagePropsResult (org.wikipediacleaner.api.request.query.prop.ApiPagePropsResult)1 ApiTemplatesRequest (org.wikipediacleaner.api.request.query.prop.ApiTemplatesRequest)1 ApiTemplatesResult (org.wikipediacleaner.api.request.query.prop.ApiTemplatesResult)1 ApiXmlCategoriesResult (org.wikipediacleaner.api.request.query.prop.ApiXmlCategoriesResult)1 ApiXmlPagePropsResult (org.wikipediacleaner.api.request.query.prop.ApiXmlPagePropsResult)1