use of org.wikipediacleaner.api.data.Page in project wpcleaner by WPCleaner.
the class PageListWindow method actionRemove.
/**
* Action called when Remove button is pressed.
*/
public void actionRemove() {
if (displayYesNoWarning(GT._T("You are about to remove the pages from your local watchlist.\n" + "Are you sure?")) != JOptionPane.YES_OPTION) {
return;
}
List<Page> selectedPages = tablePages.getSelectedPages();
if ((selectedPages == null) || (selectedPages.isEmpty())) {
return;
}
Configuration config = Configuration.getConfiguration();
List<String> watchedPages = config.getStringList(getWikipedia(), Configuration.ARRAY_WATCH_PAGES);
for (Page page : selectedPages) {
watchedPages.remove(page.getTitle());
}
config.setStringList(getWikipedia(), Configuration.ARRAY_WATCH_PAGES, watchedPages);
tablePages.removePages(selectedPages);
}
use of org.wikipediacleaner.api.data.Page in project wpcleaner by WPCleaner.
the class PageListWorker method constructBackLinks.
/**
* Construct list of backlinks.
*
* @param pages List of backlinks.
* @throws APIException
*/
private void constructBackLinks(List<Page> pages) throws APIException {
final API api = APIFactory.getAPI();
for (String pageName : elementNames) {
Page page = DataManager.getPage(getWikipedia(), pageName, null, null, null);
api.retrieveLinksHere(getWikipedia(), page, true);
List<Page> tmpPages = page.getRelatedPages(Page.RelatedPages.LINKS_HERE);
if (tmpPages != null) {
for (Page tmpPage : tmpPages) {
if (!pages.contains(tmpPage)) {
pages.add(tmpPage);
}
}
}
}
}
use of org.wikipediacleaner.api.data.Page in project wpcleaner by WPCleaner.
the class PageListWorker method finished.
/* (non-Javadoc)
* @see org.wikipediacleaner.gui.swing.utils.SwingWorker#finished()
*/
@Override
public void finished() {
super.finished();
Object result = get();
if (!(result instanceof Throwable)) {
if (mode == Mode.ALL_DAB_PAGES) {
Set<String> set = new HashSet<>(pageList.size());
for (Page page : pageList) {
set.add(page.getTitle());
}
getWikipedia().setDisambiguationPages(set);
int answer = Utilities.displayYesNoWarning((getWindow() != null) ? getWindow().getParentComponent() : null, GT._T("You have loaded the list of all disambiguation pages to speed up page analysis.\n" + "Do you want to display the list of all disambiguation pages ?"));
if (answer != JOptionPane.YES_OPTION) {
return;
}
}
PageListWindow.createPageListWindow(message, referencePage, pageList, getWikipedia(), watchList);
}
}
use of org.wikipediacleaner.api.data.Page in project wpcleaner by WPCleaner.
the class UpdateWarningTools method updateWarning.
// ==========================================================================
// Warning management
// ==========================================================================
/**
* Update warning for a list of pages.
*
* @param pages List of pages.
* @param creators For each page title, user who has created the page.
* @param modifiers For each page title, users who have modified the page.
* @param stats Statistics.
* @throws APIException Exception thrown by the API.
*/
public void updateWarning(List<Page> pages, Map<String, String> creators, Map<String, List<String>> modifiers, Stats stats) throws APIException {
if ((pages == null) || (pages.isEmpty())) {
return;
}
// Retrieve information in the pages
if (!retrievePageInformation(pages)) {
return;
}
// Deal with non encyclopedic pages
manageNonEncyclopedicPages(pages);
// Load talk pages and "To do" sub pages
Map<Page, Page> mapTalkPages = new HashMap<>();
Map<Page, Page> mapTodoSubpages = new HashMap<>();
for (Page page : pages) {
Page talkPage = page.getTalkPage();
mapTalkPages.put(page, talkPage);
String todoSubpageAttr = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
if (todoSubpageAttr != null) {
Page todoSubpage = talkPage.getSubPage(todoSubpageAttr);
mapTodoSubpages.put(page, todoSubpage);
}
}
if (canUpdateWarning()) {
MediaWiki mw = MediaWiki.getMediaWikiAccess(worker);
if (section0) {
mw.retrieveSectionContents(wiki, mapTalkPages.values(), 0, false);
} else {
mw.retrieveContents(wiki, mapTalkPages.values(), false, false, false, false);
}
mw.retrieveContents(wiki, mapTodoSubpages.values(), true, false, false, false);
if (mw.shouldStop()) {
return;
}
}
// Update warning
for (Page page : pages) {
PageAnalysis pageAnalysis = page.getAnalysis(page.getContents(), true);
boolean updated = updateWarning(pageAnalysis, page.getRevisionId(), mapTalkPages.get(page), mapTodoSubpages.get(page), (creators != null) ? creators.get(page.getTitle()) : null, (modifiers != null) ? modifiers.get(page.getTitle()) : null, stats);
if (updated) {
// log.debug("Page " + page.getTitle() + " has been updated.");
}
if (stats != null) {
stats.addAnalyzedPage(page);
if (updated) {
stats.addUpdatedPage(page);
}
}
}
return;
}
use of org.wikipediacleaner.api.data.Page in project wpcleaner by WPCleaner.
the class UpdateWarningWorker method retrieveArticlesWithWarning.
/**
* Retrieve pages with a warning on their talk page.
*
* @param templateNameProperty Property for the name of the warning template.
* @param pages Map of (title,page) to complete.
* @throws APIException Exception thrown by the API.
*/
protected void retrieveArticlesWithWarning(WPCConfigurationString templateNameProperty, Map<String, Page> pages) throws APIException {
EnumWikipedia wiki = getWikipedia();
WPCConfiguration configuration = wiki.getConfiguration();
WikiConfiguration wikiConfiguration = wiki.getWikiConfiguration();
API api = APIFactory.getAPI();
// Retrieve talk pages including a warning
String warningTemplateName = configuration.getString(templateNameProperty);
if (warningTemplateName != null) {
setText(GT._T("Retrieving talk pages including {0}", TemplateBuilder.from(warningTemplateName).toString()));
String templateTitle = wikiConfiguration.getPageTitle(Namespace.TEMPLATE, warningTemplateName);
Page warningTemplate = DataManager.createSimplePage(wiki, templateTitle, null, null, null);
api.retrieveEmbeddedIn(wiki, warningTemplate, configuration.getEncyclopedicTalkNamespaces(), false);
// Convert them to article pages
setText(GT._T("Constructing list of articles with warning"));
List<Page> talkPages = warningTemplate.getRelatedPages(Page.RelatedPages.EMBEDDED_IN);
if (talkPages != null) {
for (Page talkPage : talkPages) {
Page page = null;
if (talkPage.isArticle()) {
page = talkPage;
} else {
String title = talkPage.getTitle();
String todoSubpage = configuration.getString(WPCConfigurationString.TODO_SUBPAGE);
if (title.endsWith("/" + todoSubpage)) {
title = title.substring(0, title.length() - 1 - todoSubpage.length());
}
Integer namespace = talkPage.getNamespace();
if (namespace != null) {
Namespace namespaceTalk = wikiConfiguration.getNamespace(namespace.intValue());
if (namespaceTalk != null) {
int colonIndex = title.indexOf(':');
if (colonIndex >= 0) {
title = title.substring(colonIndex + 1);
}
if (namespace != Namespace.MAIN_TALK) {
title = wikiConfiguration.getPageTitle(namespace - 1, title);
}
}
}
page = DataManager.createSimplePage(wiki, title, null, null, null);
}
addPage(page, pages);
}
}
}
}
Aggregations