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
}
}
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);
}
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();
}
}
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();
}
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();
}
}
Aggregations