Search in sources :

Example 6 with Page

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

the class DisambiguationWindow method actionMarkBacklink.

/**
 * Action called when Mark back link button is pressed.
 */
private void actionMarkBacklink(String mark) {
    for (Page selection : listLinks.getSelectedValuesList()) {
        if (selection != null) {
            backlinksProperties.put(selection.getTitle(), mark);
        }
    }
    Configuration configuration = Configuration.getConfiguration();
    configuration.setSubProperties(getWikipedia(), Configuration.PROPERTIES_BACKLINKS, getPageName(), backlinksProperties);
    listLinks.repaint();
}
Also used : Configuration(org.wikipediacleaner.utils.Configuration) Page(org.wikipediacleaner.api.data.Page) ActionWatchPage(org.wikipediacleaner.gui.swing.action.ActionWatchPage)

Example 7 with Page

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

the class AutomaticFixingWindow method runAutomaticFixing.

/**
 * Action called when Run Automatic Fixing button is pressed.
 *
 * @param save True if modifications should be saved.
 */
private void runAutomaticFixing(boolean save) {
    // Check that information is set
    List<Page> values = listPages.getSelectedValuesList();
    if ((values == null) || (values.size() == 0)) {
        Utilities.displayWarning(getParentComponent(), GT._T("You must select the pages on which running automatic fixing."));
        return;
    }
    String comment = getComment();
    if ((comment != null) && (comment.trim().length() == 0)) {
        if (save) {
            Utilities.displayWarning(getParentComponent(), GT._T("A comment is required for automatic fixing."));
            return;
        }
        comment = "Test";
    }
    List<AutomaticFixing> fixing = modelAutomaticFixing.getData();
    if ((fixing == null) || (fixing.isEmpty())) {
        if (automaticCWAlgorithms.isEmpty() || forceCWAlgorithms.isEmpty()) {
            Utilities.displayWarning(getParentComponent(), GT._T("You must input the initial and destination texts."));
            return;
        }
    }
    boolean pauseAfterEachEdit = chkWaitAfterEdit.isSelected();
    boolean botFix = chkBotFix.isSelected();
    // Warn the user about what this function does
    if (save) {
        int answer = Utilities.displayYesNoWarning(getParentComponent(), GT._T("!!! WARNING !!!") + "\n" + GT._T("This function will carry out all replacements on all selected pages.") + "\n" + GT._T("It may modify a lot of pages in a short period of time.") + "\n" + GT._T("On some Wikipedia projects, you may need the bot status for doing this.") + "\n" + GT._T("Please, check if you need the bot status by reading the rules of Wikipedia.") + "\n" + GT._T("Also, verify again the texts you have inputted before running this function.") + "\n" + GT._T("You can also test the modifications before actually doing them.") + "\n" + GT._T("Do you want to proceed with the modifications ?"));
        if (answer != JOptionPane.YES_OPTION) {
            return;
        }
    }
    // Prepare the replacements
    Page[] tmpPages = new Page[values.size()];
    for (int i = 0; i < values.size(); i++) {
        tmpPages[i] = values.get(i);
    }
    Map<String, List<AutomaticFixing>> replacements = new HashMap<>();
    if (getPage() != null) {
        replacements.put("[[" + getPage().getTitle() + "]]", fixing);
    } else {
        replacements.put(null, fixing);
    }
    // Do the replacements
    AutomaticFixingWorker automaticWorker = new AutomaticFixingWorker(getWiki(), this, tmpPages, replacements, comment, true, automaticCWAlgorithms, forceCWAlgorithms, save, pauseAfterEachEdit, botFix, this.getParentComponent());
    automaticWorker.setListener(new DefaultBasicWorkerListener() {

        @Override
        public void afterFinished(BasicWorker worker, @SuppressWarnings("unused") boolean ok) {
            if (!worker.shouldContinue()) {
                return;
            }
            if (worker.get() instanceof Integer) {
                Integer count = (Integer) worker.get();
                if (count.intValue() == 0) {
                    return;
                }
            }
            actionReload();
        }
    });
    automaticWorker.start();
}
Also used : AutomaticFixingWorker(org.wikipediacleaner.gui.swing.worker.AutomaticFixingWorker) HashMap(java.util.HashMap) Page(org.wikipediacleaner.api.data.Page) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString) DefaultBasicWorkerListener(org.wikipediacleaner.gui.swing.basic.DefaultBasicWorkerListener) AutomaticFixingList(org.wikipediacleaner.api.data.AutomaticFixingList) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) AutomaticFixing(org.wikipediacleaner.api.data.AutomaticFixing) BasicWorker(org.wikipediacleaner.gui.swing.basic.BasicWorker)

Example 8 with Page

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

the class MainWindow method actionHelpRequestedOn.

/**
 * Action called when Help Requested On is pressed.
 */
public void actionHelpRequestedOn() {
    EnumWikipedia wikipedia = getWikipedia();
    if (wikipedia == null) {
        return;
    }
    WPCConfiguration configuration = wikipedia.getConfiguration();
    List<Page> templates = configuration.getTemplatesForHelpRequested();
    if ((templates == null) || (templates.isEmpty())) {
        Utilities.displayMessageForMissingConfiguration(getParentComponent(), WPCConfigurationStringList.TEMPLATES_FOR_HELP_REQUESTED.getAttributeName());
        return;
    }
    List<String> pageNames = new ArrayList<>();
    for (Page template : templates) {
        pageNames.add(template.getTitle());
    }
    new PageListWorker(wikipedia, this, null, pageNames, PageListWorker.Mode.EMBEDDED_IN, false, GT._T("Help requested on...")).start();
}
Also used : PageListWorker(org.wikipediacleaner.gui.swing.pagelist.PageListWorker) ArrayList(java.util.ArrayList) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) EnumQueryPage(org.wikipediacleaner.api.constants.EnumQueryPage) Page(org.wikipediacleaner.api.data.Page) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration)

Example 9 with Page

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

the class MonitorRCWindow method recentChanges.

/**
 * Callback to be notified about recent changes.
 *
 * @param newRC List of recent changes.
 * @param currentTime Current time.
 * @see org.wikipediacleaner.api.RecentChangesListener#recentChanges(java.util.List, java.util.Date)
 */
@Override
public void recentChanges(List<RecentChange> newRC, Date currentTime) {
    // Retrieve configuration
    WPCConfiguration config = getWikipedia().getConfiguration();
    long delayForNew = config.getLong(WPCConfigurationLong.RC_NEW_ARTICLE_WITH_DAB_DELAY) * 60 * 1000;
    long delayMonitoring = config.getLong(WPCConfigurationLong.RC_KEEP_MONITORING_DELAY) * 60 * 1000;
    // Add new recent changes to the list
    modelRC.addRecentChanges(newRC);
    // Remove old changes
    List<RecentChange> filteredNewRC = new ArrayList<>();
    for (RecentChange rc : newRC) {
        if (currentTime.getTime() < rc.getTimestamp().getTime() + delayForNew) {
            filteredNewRC.add(rc);
        }
    }
    // Check if an update has been made on a monitored page
    for (RecentChange rc : filteredNewRC) {
        if (monitoredPages.containsKey(rc.getTitle())) {
            Page page = DataManager.createSimplePage(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<>();
    Map<String, String> creators = new HashMap<>();
    Map<String, List<String>> modifiers = new HashMap<>();
    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<>();
        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.createSimplePage(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
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Page(org.wikipediacleaner.api.data.Page) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration) Entry(java.util.Map.Entry) RecentChange(org.wikipediacleaner.api.data.RecentChange) APIException(org.wikipediacleaner.api.APIException) WPCConfigurationLong(org.wikipediacleaner.api.configuration.WPCConfigurationLong) Stats(org.wikipediacleaner.gui.swing.worker.UpdateWarningTools.Stats) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with Page

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

the class MainWindow method actionRandomArticles.

/**
 * @param redirects True if redirects are requested.
 */
private void actionRandomArticles(boolean redirects) {
    final int maxPages = 50;
    int count = 0;
    while ((count < 1) || (count > maxPages)) {
        String answer = askForValue(GT._T("How many pages do you want?"), "20", null);
        if (answer == null) {
            return;
        }
        try {
            count = Integer.parseInt(answer);
        } catch (NumberFormatException e) {
            return;
        }
        if ((count < 1) || (count > maxPages)) {
            displayWarning(GT._T("The number of pages must be between {0} and {1}", new Object[] { Integer.valueOf(0), Integer.valueOf(maxPages) }));
        }
    }
    API api = APIFactory.getAPI();
    try {
        List<String> pageNames = new ArrayList<>(count);
        while (pageNames.size() < count) {
            List<Page> pages = api.getRandomPages(getWikipedia(), count - pageNames.size(), redirects);
            for (int i = 0; i < pages.size(); i++) {
                pageNames.add(pages.get(i).getTitle());
            }
        }
        Collections.sort(pageNames);
        new PageListWorker(getWikipedia(), this, null, pageNames, PageListWorker.Mode.DIRECT, false, GT._T("Random pages")).start();
    } catch (APIException e) {
        displayError(e);
        return;
    }
}
Also used : PageListWorker(org.wikipediacleaner.gui.swing.pagelist.PageListWorker) APIException(org.wikipediacleaner.api.APIException) ArrayList(java.util.ArrayList) API(org.wikipediacleaner.api.API) EnumQueryPage(org.wikipediacleaner.api.constants.EnumQueryPage) Page(org.wikipediacleaner.api.data.Page) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString)

Aggregations

Page (org.wikipediacleaner.api.data.Page)205 APIException (org.wikipediacleaner.api.APIException)71 ArrayList (java.util.ArrayList)66 API (org.wikipediacleaner.api.API)47 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)39 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)32 WPCConfiguration (org.wikipediacleaner.api.configuration.WPCConfiguration)30 EnumQueryPage (org.wikipediacleaner.api.constants.EnumQueryPage)29 EnumWikipedia (org.wikipediacleaner.api.constants.EnumWikipedia)29 Configuration (org.wikipediacleaner.utils.Configuration)26 Element (org.jdom2.Element)25 JDOMException (org.jdom2.JDOMException)21 HashMap (java.util.HashMap)15 CheckErrorPage (org.wikipediacleaner.api.check.CheckErrorPage)15 PageAnalysis (org.wikipediacleaner.api.data.analysis.PageAnalysis)13 List (java.util.List)12 MediaWiki (org.wikipediacleaner.api.MediaWiki)12 JMenu (javax.swing.JMenu)10 PageElementTemplate (org.wikipediacleaner.api.data.PageElementTemplate)10 ActionWatchPage (org.wikipediacleaner.gui.swing.action.ActionWatchPage)10