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