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