Search in sources :

Example 1 with WPCConfiguration

use of org.wikipediacleaner.api.configuration.WPCConfiguration in project wpcleaner by WPCleaner.

the class LanguageSelectionPanel method actionLanguage.

/**
 * Action called when the Language button is clicked.
 */
public void actionLanguage() {
    JPopupMenu menu = new JPopupMenu();
    // Common languages
    WPCConfiguration config = wiki.getConfiguration();
    List<String> commonLanguages = config.getStringList(WPCConfigurationStringList.COMMON_LANGUAGES);
    if ((commonLanguages != null) && (commonLanguages.size() > 0)) {
        for (String commonLanguage : commonLanguages) {
            LanguageRegistry.Language tmpLanguage = registry.getLanguage(commonLanguage);
            if (tmpLanguage != null) {
                JMenuItem item = new JMenuItem(tmpLanguage.toString());
                item.setActionCommand(tmpLanguage.getCode());
                item.addActionListener(EventHandler.create(ActionListener.class, this, "selectLanguage", "actionCommand"));
                menu.add(item);
            }
        }
    }
    // All languages
    List<LanguageRegistry.Language> languages = registry.getLanguages();
    char firstLetter = '\0';
    JMenu firstMenu = null;
    char secondLetter = '\0';
    JMenu secondMenu = null;
    for (LanguageRegistry.Language lang : languages) {
        String code = lang.getCode();
        if ((firstMenu == null) || (code.charAt(0) != firstLetter)) {
            firstMenu = new JMenu(code.substring(0, 1));
            menu.add(firstMenu);
            firstLetter = code.charAt(0);
            secondLetter = '\0';
        }
        if ((secondMenu == null) || (code.charAt(1) != secondLetter)) {
            secondMenu = new JMenu(code.substring(0, 2));
            firstMenu.add(secondMenu);
            secondLetter = code.charAt(1);
        }
        JMenuItem item = new JMenuItem(lang.toString());
        item.setActionCommand(lang.getCode());
        item.addActionListener(EventHandler.create(ActionListener.class, this, "selectLanguage", "actionCommand"));
        secondMenu.add(item);
    }
    menu.show(buttonLanguage, 0, buttonLanguage.getHeight());
}
Also used : ActionListener(java.awt.event.ActionListener) LanguageRegistry(org.wikipediacleaner.api.data.LanguageRegistry) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration) JMenu(javax.swing.JMenu)

Example 2 with WPCConfiguration

use of org.wikipediacleaner.api.configuration.WPCConfiguration in project wpcleaner by WPCleaner.

the class MainWindow method actionMostDabLinks.

/**
 * Action called when "Pages with most disambiguation links" is pressed.
 */
public void actionMostDabLinks() {
    EnumWikipedia wikipedia = getWikipedia();
    if (wikipedia == null) {
        return;
    }
    WPCConfiguration configuration = wikipedia.getConfiguration();
    List<String> mostDabLinks = configuration.getStringList(WPCConfigurationStringList.MOST_DAB_LINKS);
    if ((mostDabLinks == null) || (mostDabLinks.isEmpty())) {
        Utilities.displayMessageForMissingConfiguration(getParentComponent(), WPCConfigurationStringList.MOST_DAB_LINKS.getAttributeName());
        return;
    }
    new PageListWorker(wikipedia, this, null, mostDabLinks, PageListWorker.Mode.CATEGORY_MEMBERS_ARTICLES, false, GT._T("Pages with many disambiguation links")).start();
}
Also used : PageListWorker(org.wikipediacleaner.gui.swing.pagelist.PageListWorker) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration)

Example 3 with WPCConfiguration

use of org.wikipediacleaner.api.configuration.WPCConfiguration 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 4 with WPCConfiguration

use of org.wikipediacleaner.api.configuration.WPCConfiguration 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 5 with WPCConfiguration

use of org.wikipediacleaner.api.configuration.WPCConfiguration in project wpcleaner by WPCleaner.

the class ActionUpdateWarning method actionDisambiguationWarning.

/**
 * Update disambiguation warnings on talk page.
 */
public void actionDisambiguationWarning() {
    // Check selection
    if (wikiProvider == null) {
        return;
    }
    EnumWikipedia wiki = wikiProvider.getWiki();
    if (wiki == null) {
        return;
    }
    List<Page> pages = getPages();
    if ((pages == null) || (pages.isEmpty())) {
        return;
    }
    // Check configuration
    WPCConfiguration wpcConfig = wiki.getConfiguration();
    String template = wpcConfig.getString(WPCConfigurationString.DAB_WARNING_TEMPLATE);
    if ((template == null) || (template.trim().length() == 0)) {
        Utilities.displayMessageForMissingConfiguration(parent, WPCConfigurationString.DAB_WARNING_TEMPLATE.getAttributeName());
        return;
    }
    // Ask for confirmation
    int answer = Utilities.displayYesNoWarning(parent, GT._T("Do you want to update the disambiguation warning on talk page?"));
    if (answer != JOptionPane.YES_OPTION) {
        return;
    }
    // Update warning
    UpdateDabWarningWorker worker = new UpdateDabWarningWorker(wiki, window, pages, false, false, false, false);
    worker.start();
}
Also used : UpdateDabWarningWorker(org.wikipediacleaner.gui.swing.worker.UpdateDabWarningWorker) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) Page(org.wikipediacleaner.api.data.Page) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration)

Aggregations

WPCConfiguration (org.wikipediacleaner.api.configuration.WPCConfiguration)61 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)38 ArrayList (java.util.ArrayList)22 EnumWikipedia (org.wikipediacleaner.api.constants.EnumWikipedia)21 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)21 Page (org.wikipediacleaner.api.data.Page)20 API (org.wikipediacleaner.api.API)9 PageAnalysis (org.wikipediacleaner.api.data.analysis.PageAnalysis)8 APIException (org.wikipediacleaner.api.APIException)7 Actionnable (org.wikipediacleaner.api.check.Actionnable)7 CompositeAction (org.wikipediacleaner.api.check.CompositeAction)7 SimpleAction (org.wikipediacleaner.api.check.SimpleAction)7 ActionExternalViewer (org.wikipediacleaner.gui.swing.action.ActionExternalViewer)7 Configuration (org.wikipediacleaner.utils.Configuration)7 HashMap (java.util.HashMap)4 List (java.util.List)4 PageElementTemplate (org.wikipediacleaner.api.data.PageElementTemplate)4 JMenu (javax.swing.JMenu)3 CheckErrorResult (org.wikipediacleaner.api.check.CheckErrorResult)3 CheckErrorAlgorithm (org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm)3