Search in sources :

Example 1 with EnumWikipedia

use of org.wikipediacleaner.api.constants.EnumWikipedia in project wpcleaner by WPCleaner.

the class CheckErrorAlgorithmBase method createDefaultSort.

/**
 * Create a default DEFAULTSORT.
 *
 * @param analysis Page analysis.
 * @return Default DEFAULTSORT.
 */
protected String createDefaultSort(PageAnalysis analysis) {
    // Basic check
    if ((analysis == null) || (analysis.getContents() == null)) {
        return null;
    }
    String contents = analysis.getContents();
    if ((analysis.getPage() == null) || (analysis.getPage().getTitle() == null)) {
        return contents;
    }
    // Get DEFAULTSORT name
    String defaultSort = "DEFAULTSORT:";
    MagicWord magicWord = analysis.getWikiConfiguration().getMagicWordByType(FunctionMagicWordType.DEFAULT_SORT);
    if (magicWord != null) {
        String value = analysis.getWPCConfiguration().getString(WPCConfigurationString.DEFAULTSORT);
        if ((value != null) && (value.trim().length() > 0)) {
            value = value.trim();
            if (magicWord.isPossibleAlias(value)) {
                defaultSort = value;
            }
        }
    }
    // Create DEFAULTSORT
    StringBuilder buffer = new StringBuilder();
    buffer.append("{{");
    buffer.append(defaultSort);
    // Remove special characters from title
    String title = analysis.getPage().getTitle();
    StringBuilder currentTitle = new StringBuilder();
    EnumWikipedia wiki = analysis.getWikipedia();
    for (int i = 0; i < title.length(); i++) {
        char character = title.charAt(i);
        if (!CheckErrorAlgorithms.isAlgorithmActive(wiki, 6) || SpecialCharacters.isAuthorized(character, wiki)) {
            currentTitle.append(character);
        } else {
            currentTitle.append(SpecialCharacters.proposeReplacement(character, wiki));
        }
    }
    // Manage capitals and small letters
    title = currentTitle.toString();
    currentTitle.setLength(0);
    boolean previousSpace = true;
    for (int i = 0; i < title.length(); i++) {
        char character = title.charAt(i);
        if (previousSpace) {
            if (Character.isLowerCase(character) && (i == 0)) {
                currentTitle.append(Character.toUpperCase(character));
            } else {
                currentTitle.append(character);
            }
        } else {
            currentTitle.append(character);
        }
        previousSpace = (character == ' ');
    }
    // Finish
    buffer.append(currentTitle);
    buffer.append("}}");
    return buffer.toString();
}
Also used : MagicWord(org.wikipediacleaner.api.data.contents.magicword.MagicWord) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString)

Example 2 with EnumWikipedia

use of org.wikipediacleaner.api.constants.EnumWikipedia in project wpcleaner by WPCleaner.

the class CheckWiki method markAsFixed.

/**
 * Mark a page as fixed.
 *
 * @param page Page.
 * @param errorNumber Error number.
 * @return True if it has been done.
 */
public boolean markAsFixed(Page page, String errorNumber) {
    if (!Namespace.isHandledByCW(page.getNamespace())) {
        return false;
    }
    try {
        int error = Integer.parseInt(errorNumber);
        notifyPageFixed(page, error);
        if (error > CheckErrorAlgorithm.MAX_ERROR_NUMBER_WITH_LIST) {
            return true;
        }
        EnumWikipedia wiki = page.getWikipedia();
        String code = wiki.getSettings().getCodeCheckWiki().replace("-", "_");
        Map<String, String> properties = new HashMap<>();
        properties.put("id", Integer.toString(error));
        properties.put("project", code);
        // WMF Labs
        properties.put("title", page.getTitle());
        if (!useBotList) {
            properties.put("view", "only");
            labs.sendPost(rootPath + "cgi-bin/checkwiki.cgi", properties, null);
        } else {
            properties.put("action", "mark");
            labs.sendPost(rootPath + "cgi-bin/checkwiki_bots.cgi", properties, null);
        }
    } catch (NumberFormatException e) {
        return false;
    } catch (APIException e) {
        return false;
    }
    return true;
}
Also used : APIException(org.wikipediacleaner.api.APIException) HashMap(java.util.HashMap) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString)

Example 3 with EnumWikipedia

use of org.wikipediacleaner.api.constants.EnumWikipedia in project wpcleaner by WPCleaner.

the class DisambiguationWindow method createFilterMenu.

/**
 * @return Filter namespace menu.
 */
private JMenu createFilterMenu() {
    if (menuFilter == null) {
        menuFilter = Utilities.createJMenu(GT._T("Filter namespaces"));
    } else {
        menuFilter.removeAll();
    }
    EnumWikipedia wiki = getWikipedia();
    if (wiki == null) {
        return menuFilter;
    }
    Configuration config = Configuration.getConfiguration();
    List<String> filtered = config.getStringList(wiki, Configuration.ARRAY_FILTER_NS);
    for (Namespace ns : wiki.getWikiConfiguration().getNamespaces()) {
        Integer id = ns.getId();
        if ((id != null) && (id.intValue() >= 0)) {
            boolean active = !filtered.contains(Integer.toString(ns.getId()));
            JMenuItem item = new JCheckBoxMenuItem(ns.toString(), active);
            item.setActionCommand(id.toString());
            item.addActionListener(EventHandler.create(ActionListener.class, this, active ? "actionFilterNamespaceTrue" : "actionFilterNamespaceFalse", "actionCommand"));
            menuFilter.add(item);
        }
    }
    return menuFilter;
}
Also used : ConfigurationValueInteger(org.wikipediacleaner.utils.ConfigurationValueInteger) Configuration(org.wikipediacleaner.utils.Configuration) ActionListener(java.awt.event.ActionListener) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) JMenuItem(javax.swing.JMenuItem) Namespace(org.wikipediacleaner.api.data.Namespace) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 4 with EnumWikipedia

use of org.wikipediacleaner.api.constants.EnumWikipedia in project wpcleaner by WPCleaner.

the class MainWindow method actionWatchlist.

/**
 * Action called when watch list button is pressed.
 */
public void actionWatchlist() {
    EnumWikipedia wikipedia = getWikipedia();
    if (wikipedia == null) {
        return;
    }
    new PageListWorker(wikipedia, this, null, null, PageListWorker.Mode.WATCH_LIST, true, GT._T("Watch list")).start();
}
Also used : PageListWorker(org.wikipediacleaner.gui.swing.pagelist.PageListWorker) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia)

Example 5 with EnumWikipedia

use of org.wikipediacleaner.api.constants.EnumWikipedia 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)

Aggregations

EnumWikipedia (org.wikipediacleaner.api.constants.EnumWikipedia)83 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)32 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)30 Page (org.wikipediacleaner.api.data.Page)29 WPCConfiguration (org.wikipediacleaner.api.configuration.WPCConfiguration)25 ArrayList (java.util.ArrayList)17 API (org.wikipediacleaner.api.API)16 APIException (org.wikipediacleaner.api.APIException)16 Configuration (org.wikipediacleaner.utils.Configuration)15 CheckErrorResult (org.wikipediacleaner.api.check.CheckErrorResult)10 PageListWorker (org.wikipediacleaner.gui.swing.pagelist.PageListWorker)10 EnumQueryPage (org.wikipediacleaner.api.constants.EnumQueryPage)8 StringReader (java.io.StringReader)7 Test (org.junit.Test)7 ActionExternalViewer (org.wikipediacleaner.gui.swing.action.ActionExternalViewer)6 CheckErrorAlgorithm (org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm)5 PageElementInternalLink (org.wikipediacleaner.api.data.PageElementInternalLink)5 Stats (org.wikipediacleaner.gui.swing.worker.UpdateWarningTools.Stats)5 MediaWiki (org.wikipediacleaner.api.MediaWiki)4 AlgorithmError (org.wikipediacleaner.api.algorithm.AlgorithmError)4