Search in sources :

Example 1 with API

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) UpdateDabWarningTools(org.wikipediacleaner.gui.swing.worker.UpdateDabWarningTools) JTable(javax.swing.JTable) API(org.wikipediacleaner.api.API)

Example 2 with API

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();
}
Also used : API(org.wikipediacleaner.api.API)

Example 3 with API

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;
    }
}
Also used : PageListWorker(org.wikipediacleaner.gui.swing.pagelist.PageListWorker) APIException(org.wikipediacleaner.api.APIException) ArrayList(java.util.ArrayList) API(org.wikipediacleaner.api.API) EnumQueryPage(org.wikipediacleaner.api.constants.EnumQueryPage) Page(org.wikipediacleaner.api.data.Page) ConfigurationValueString(org.wikipediacleaner.utils.ConfigurationValueString)

Example 4 with API

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);
                }
            }
        }
    }
}
Also used : API(org.wikipediacleaner.api.API) EnumQueryPage(org.wikipediacleaner.api.constants.EnumQueryPage) Page(org.wikipediacleaner.api.data.Page) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString)

Example 5 with API

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);
            }
        }
    }
}
Also used : WikiConfiguration(org.wikipediacleaner.api.configuration.WikiConfiguration) EnumWikipedia(org.wikipediacleaner.api.constants.EnumWikipedia) API(org.wikipediacleaner.api.API) Page(org.wikipediacleaner.api.data.Page) WPCConfigurationString(org.wikipediacleaner.api.configuration.WPCConfigurationString) WPCConfiguration(org.wikipediacleaner.api.configuration.WPCConfiguration) Namespace(org.wikipediacleaner.api.data.Namespace)

Aggregations

API (org.wikipediacleaner.api.API)64 Page (org.wikipediacleaner.api.data.Page)47 APIException (org.wikipediacleaner.api.APIException)42 ArrayList (java.util.ArrayList)21 EnumWikipedia (org.wikipediacleaner.api.constants.EnumWikipedia)16 WPCConfigurationString (org.wikipediacleaner.api.configuration.WPCConfigurationString)13 EnumQueryPage (org.wikipediacleaner.api.constants.EnumQueryPage)12 WPCConfiguration (org.wikipediacleaner.api.configuration.WPCConfiguration)10 PageAnalysis (org.wikipediacleaner.api.data.analysis.PageAnalysis)7 BadLocationException (javax.swing.text.BadLocationException)5 ConfigurationValueString (org.wikipediacleaner.utils.ConfigurationValueString)5 MediaWiki (org.wikipediacleaner.api.MediaWiki)4 CheckErrorAlgorithm (org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithm)4 Configuration (org.wikipediacleaner.utils.Configuration)4 WikiConfiguration (org.wikipediacleaner.api.configuration.WikiConfiguration)3 PageElementFunction (org.wikipediacleaner.api.data.PageElementFunction)3 HashMap (java.util.HashMap)2 AlgorithmError (org.wikipediacleaner.api.algorithm.AlgorithmError)2 CheckErrorPage (org.wikipediacleaner.api.check.CheckErrorPage)2 CheckWiki (org.wikipediacleaner.api.check.CheckWiki)2