Search in sources :

Example 1 with AlgorithmError

use of org.wikipediacleaner.api.algorithm.AlgorithmError in project wpcleaner by WPCleaner.

the class UpdateWarningWorker method retrieveCheckWikiPages.

/**
 * Retrieve pages for a given error number.
 *
 * @param errorNumber Error number.
 * @param pages Map of (title,page) to complete.
 * @param tools Update warning tools if the pages should be added as articles.
 */
protected void retrieveCheckWikiPages(int errorNumber, Map<String, Page> pages, UpdateWarningTools tools) {
    CheckWiki cw = APIFactory.getCheckWiki();
    EnumWikipedia wiki = getWikipedia();
    CheckErrorAlgorithm algorithm = CheckErrorAlgorithms.getAlgorithm(wiki, errorNumber);
    List<AlgorithmError> errors = new ArrayList<>();
    try {
        cw.retrievePages(algorithm, 100000, wiki, errors);
        for (AlgorithmError error : errors) {
            for (int pageNum = 0; pageNum < error.getPageCount(); pageNum++) {
                Page page = error.getPage(pageNum);
                addPage(page, pages);
                if (tools != null) {
                    tools.addArticle(page.getTitle());
                }
            }
        }
    } catch (APIException e) {
    // Nothing
    }
}
Also used : APIException(org.wikipediacleaner.api.APIException) CheckErrorAlgorithm(org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm) ArrayList(java.util.ArrayList) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) Page(org.wikipediacleaner.api.data.Page) AlgorithmError(org.wikipediacleaner.api.algorithm.AlgorithmError) CheckWiki(org.wikipediacleaner.api.check.CheckWiki)

Example 2 with AlgorithmError

use of org.wikipediacleaner.api.algorithm.AlgorithmError in project wpcleaner by WPCleaner.

the class CheckWikiContentPanel method actionMarkAsFixed.

/**
 * Mark a page as fixed.
 */
private void actionMarkAsFixed() {
    // Unique algorithm
    CheckErrorAlgorithm algorithm = null;
    AlgorithmError error = null;
    if ((errors != null) && (errors.size() == 1)) {
        error = errors.get(0);
        algorithm = error.getAlgorithm();
    }
    if ((error == null) || (algorithm == null)) {
        return;
    }
    // Ask for confirmation
    if (window.displayYesNoWarning(GT._T("Do you want to mark {0} as fixed for error n°{1}?", new Object[] { page.getTitle(), algorithm.getErrorNumberString() })) != JOptionPane.YES_OPTION) {
        return;
    }
    // Check if error is still present
    PageAnalysis pageAnalysis = page.getAnalysis(textPage.getText(), true);
    CheckErrorPage errorPage = AlgorithmError.analyzeError(algorithm, pageAnalysis);
    if ((errorPage.getResults() != null) && (!errorPage.getResults().isEmpty())) {
        String message = GT.__("The error n°{0} is still found {1} time on the page.", "The error n°{0} is still found {1} times on the page.", errorPage.getResults().size(), new Object[] { algorithm.getErrorNumberString(), errorPage.getResults().size() }) + "\n" + GT._T("Are you really sure that you want to mark it as fixed ?");
        if (window.displayYesNoWarning(message) != JOptionPane.YES_OPTION) {
            return;
        }
    } else if (errorPage.getErrorFound()) {
        if (window.displayYesNoWarning(GT._T("The error n°{0} is still found on the page.\n" + "Are you really sure that you want to mark it as fixed ?", algorithm.getErrorNumberString())) != JOptionPane.YES_OPTION) {
            return;
        }
    } else {
        // Check if error was initially present
        for (int i = 0; i < modelErrors.size(); i++) {
            if (modelErrors.elementAt(i) != null) {
                CheckErrorPage tmp = modelErrors.elementAt(i);
                if (tmp.getAlgorithm() == algorithm) {
                    window.displayWarning(GT._T("You have already fixed this error by modifying the page.\n" + "You should send your modifications, the page will be marked as fixed."));
                    return;
                }
            }
        }
    }
    // Mark as fixed
    error.remove(page);
    if (!textPage.isModified()) {
        pane.remove(this);
    }
    if (error.getPageCount() == 0) {
        Configuration configuration = Configuration.getConfiguration();
        if (!configuration.getBoolean(null, ConfigurationValueBoolean.CHECK_SHOW_0_ERRORS)) {
            window.listAllErrors.removeItem(error);
        }
    }
    window.actionSelectErrorType();
    OnePageWindow.markPageAsFixed(error.getAlgorithm().getErrorNumberString(), page);
}
Also used : Configuration(org.wikipediacleaner.utils.Configuration) CheckErrorAlgorithm(org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm) PageAnalysis(org.wikipediacleaner.api.data.analysis.PageAnalysis) AlgorithmError(org.wikipediacleaner.api.algorithm.AlgorithmError) CheckErrorPage(org.wikipediacleaner.api.check.CheckErrorPage) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString)

Example 3 with AlgorithmError

use of org.wikipediacleaner.api.algorithm.AlgorithmError in project wpcleaner by WPCleaner.

the class CheckWikiWindow method actionReloadError.

/**
 * Action called when Reload Error button is pressed.
 */
public void actionReloadError() {
    Object selected = listAllErrors.getSelectedItem();
    if (selected instanceof AlgorithmError) {
        AlgorithmError error = (AlgorithmError) selected;
        List<CheckErrorAlgorithm> algorithms = Collections.singletonList(error.getAlgorithm());
        CheckWikiProjectWorker reloadWorker = new CheckWikiProjectWorker(getWikipedia(), this, errors, algorithms, true, modelMaxErrors.getNumber().intValue());
        setupReloadWorker(reloadWorker);
        reloadWorker.start();
    }
}
Also used : CheckErrorAlgorithm(org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm) AlgorithmError(org.wikipediacleaner.api.algorithm.AlgorithmError) CheckWikiProjectWorker(org.wikipediacleaner.gui.swing.worker.CheckWikiProjectWorker)

Example 4 with AlgorithmError

use of org.wikipediacleaner.api.algorithm.AlgorithmError in project wpcleaner by WPCleaner.

the class CheckWikiWindow method pageFixed.

/**
 * @param page Page.
 * @param errorNumber Error number.
 * @see org.wikipediacleaner.api.check.CheckWikiListener#pageFixed(org.wikipediacleaner.api.data.Page, int)
 */
@Override
public void pageFixed(Page page, int errorNumber) {
    if ((errors == null) || (errors.isEmpty())) {
        return;
    }
    Iterator<AlgorithmError> itError = errors.iterator();
    while (itError.hasNext()) {
        AlgorithmError error = itError.next();
        if (error.getErrorNumber() == errorNumber) {
            error.remove(page);
        }
    }
    requestUpdate();
}
Also used : AlgorithmError(org.wikipediacleaner.api.algorithm.AlgorithmError)

Example 5 with AlgorithmError

use of org.wikipediacleaner.api.algorithm.AlgorithmError 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)

Aggregations

AlgorithmError (org.wikipediacleaner.api.algorithm.AlgorithmError)17 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)8 ArrayList (java.util.ArrayList)7 CheckErrorPage (org.wikipediacleaner.api.check.CheckErrorPage)7 CheckErrorAlgorithm (org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm)7 Page (org.wikipediacleaner.api.data.Page)6 Configuration (org.wikipediacleaner.utils.Configuration)5 CheckWiki (org.wikipediacleaner.api.check.CheckWiki)4 EnumWikipedia (org.wikipediacleaner.api.constants.EnumWikipedia)3 DecimalFormat (java.text.DecimalFormat)2 PageAnalysis (org.wikipediacleaner.api.data.analysis.PageAnalysis)2 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)2 HashSet (java.util.HashSet)1 List (java.util.List)1 JList (javax.swing.JList)1 APIException (org.wikipediacleaner.api.APIException)1 CheckWikiDetection (org.wikipediacleaner.api.check.CheckWikiDetection)1 PageRedirect (org.wikipediacleaner.api.data.PageRedirect)1 BasicWorker (org.wikipediacleaner.gui.swing.basic.BasicWorker)1 DefaultBasicWorkerListener (org.wikipediacleaner.gui.swing.basic.DefaultBasicWorkerListener)1