use of org.wikipediacleaner.api.API in project wpcleaner by WPCleaner.
the class MonitorRCWindow method createComponents.
/**
* @return Window components.
*/
@Override
protected Component createComponents() {
JPanel panel = new JPanel(new GridBagLayout());
// Initialize constraints
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = new Insets(0, 0, 0, 0);
constraints.ipadx = 0;
constraints.ipady = 0;
constraints.weightx = 0;
constraints.weighty = 0;
// Recent changes table
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1;
constraints.weighty = 1;
modelRC = new RecentChangesTableModel(null);
tableRC = new JTable(modelRC);
modelRC.configureColumnModel(tableRC.getColumnModel());
JScrollPane scrollRC = new JScrollPane(tableRC);
scrollRC.setMinimumSize(new Dimension(300, 200));
scrollRC.setPreferredSize(new Dimension(800, 300));
scrollRC.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel.add(scrollRC, constraints);
constraints.gridy++;
// Interesting recent changes table
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1;
constraints.weighty = 1;
modelRCInteresting = new RecentChangesTableModel(null);
tableRCInteresting = new JTable(modelRCInteresting);
modelRCInteresting.configureColumnModel(tableRCInteresting.getColumnModel());
JScrollPane scrollRCInteresting = new JScrollPane(tableRCInteresting);
scrollRCInteresting.setMinimumSize(new Dimension(300, 200));
scrollRCInteresting.setPreferredSize(new Dimension(800, 300));
scrollRCInteresting.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel.add(scrollRCInteresting, constraints);
constraints.gridy++;
// Buttons
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton buttonClose = ActionDispose.createButton(getParentComponent(), true, false);
buttonPanel.add(buttonClose);
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.gridx = 0;
constraints.weightx = 1;
constraints.weighty = 0;
panel.add(buttonPanel, constraints);
constraints.gridy++;
updateComponentState();
monitoredPages = new HashMap<>();
createDabWarning = new UpdateDabWarningTools(getWikipedia(), this, true);
updateDabWarning = new UpdateDabWarningTools(getWikipedia(), this, false);
API api = APIFactory.getAPI();
api.addRecentChangesListener(getWikipedia(), this);
return panel;
}
use of org.wikipediacleaner.api.API in project wpcleaner by WPCleaner.
the class MainWindow method actionLogout.
/**
* Action called when Logout button is pressed.
*/
public void actionLogout() {
API api = APIFactory.getAPI();
api.logout(getWikipedia());
logged = false;
userLogged = false;
updateComponentState();
}
use of org.wikipediacleaner.api.API 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;
}
}
use of org.wikipediacleaner.api.API 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.API 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