use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.
the class DisambiguationWindow method afterFinishedReloadWorker.
/**
* Callback called at the end of the Reload Worker.
*/
@Override
protected void afterFinishedReloadWorker() {
super.afterFinishedReloadWorker();
Configuration config = Configuration.getConfiguration();
Page page = getPage();
backlinksProperties = config.getSubProperties(getWikipedia(), Configuration.PROPERTIES_BACKLINKS, page.getTitle());
listCellRenderer.setPageProperties(backlinksProperties);
popupListenerLinks.setPage(page);
popupListenerLinks.setBackLinksProperties(backlinksProperties);
List<Page> links = page.getAllLinksToPage();
if (config.getBoolean(null, ConfigurationValueBoolean.IGNORE_DAB_USER_NS)) {
links = new ArrayList<>(links);
for (int i = links.size(); i > 0; i--) {
if (links.get(i - 1).isInUserNamespace()) {
links.remove(i - 1);
}
}
}
modelLinks.setElements(links);
Integer countMain = page.getBacklinksCountInMainNamespace();
Integer countTotal = page.getBacklinksCount();
linkCount.setText(((countMain != null) ? countMain.toString() : "?") + " / " + ((countTotal != null) ? countTotal.toString() : "?"));
// Construct list of known pages
knownPages.clear();
if (getPage() != null) {
knownPages = new ArrayList<>(1);
knownPages.add(getPage());
for (Page backLink : getPage().getAllLinksToPage()) {
PageRedirect redirects = backLink.getRedirects();
if ((redirects != null) && (redirects.isRedirect()) && (Page.areSameTitle(getPage().getTitle(), redirects.getTitle()))) {
knownPages.add(backLink);
}
}
}
// Select next links
actionSelectNextLinks();
}
use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.
the class CheckWikiWindow method actionLoadPages.
/**
* Action called when requesting to load selected pages.
*/
public void actionLoadPages() {
final List<CheckErrorPage> selection = listPages.getSelectedValuesList();
final List<Page> pages = new ArrayList<>();
if (selection != null) {
for (CheckErrorPage errorPage : selection) {
pages.add(errorPage.getPage());
}
}
if (pages.size() > 0) {
RetrieveContentWorker contentWorker = new RetrieveContentWorker(getWikipedia(), this, pages);
contentWorker.setListener(new DefaultBasicWorkerListener() {
/* (non-Javadoc)
* @see org.wikipediacleaner.gui.swing.basic.DefaultBasicWorkerListener#beforeFinished(org.wikipediacleaner.gui.swing.basic.BasicWorker)
*/
@Override
public void beforeFinished(BasicWorker worker) {
super.beforeFinished(worker);
final List<CheckWikiContentPanel> contentPanels = new ArrayList<>();
for (Page page : pages) {
while (page != null) {
Object errorSelected = modelAllErrors.getSelectedItem();
final CheckWikiContentPanel contentPanel = createContentsComponents(contentPane, page, (errorSelected instanceof AlgorithmError) ? Collections.singletonList((AlgorithmError) errorSelected) : getErrorsForPage(page.getTitle()));
contentPane.add(contentPanel);
contentPane.setSelectedComponent(contentPanel);
contentPanels.add(contentPanel);
PageRedirect redirects = page.getRedirects();
if (redirects.isRedirect()) {
List<Page> listRedirects = redirects.getPageList();
if ((listRedirects != null) && (listRedirects.size() > 0)) {
page = listRedirects.get(0);
} else {
page = null;
}
} else {
page = null;
}
}
}
yesAll = false;
noAll = false;
List<String> messages = new ArrayList<>();
for (CheckWikiContentPanel contentPanel : contentPanels) {
contentPanel.actionPageSelected(messages);
}
if (!messages.isEmpty()) {
StringBuilder message = new StringBuilder();
for (String line : messages) {
if (message.length() > 0) {
message.append('\n');
}
message.append(line);
}
displayWarning(message.toString());
}
}
});
contentWorker.start();
} else {
updateComponentState();
}
}
use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.
the class MediaWikiAPI method initializeDisambiguationStatus.
/**
* Initialize the disambiguation flags of a list of <code>pages</code>.
* (<code>action=query</code>, <code>prop=categories</code>) or
* (<code>action=query</code>, <code>prop=templates</code>).
*
* @param wiki Wiki.
* @param pages List of pages.
* @param forceApiCall True if API call should be forced even if the list of disambiguation pages is loaded.
* @throws APIException Exception thrown by the API.
* @see <a href="http://www.mediawiki.org/wiki/API:Properties#categories_.2F_cl">API:Properties#categories</a>
* @see <a href="http://www.mediawiki.org/wiki/API:Properties#templates_.2F_tl">API:Properties#templates</a>
*/
@Override
public void initializeDisambiguationStatus(EnumWikipedia wiki, List<Page> pages, boolean forceApiCall) throws APIException {
if ((pages == null) || (pages.isEmpty())) {
return;
}
if (wiki.isDisambiguationPagesLoaded() && !forceApiCall) {
for (Page page : pages) {
page.setDisambiguationPage(wiki.isDisambiguationPage(page));
PageRedirect redirects = page.getRedirects();
if (redirects.isRedirect() && (redirects.getPageList() != null)) {
for (Page page2 : redirects.getPageList()) {
page2.setDisambiguationPage(wiki.isDisambiguationPage(page2));
}
}
}
} else {
// Use __DISAMBIG__ magic word if possible
WPCConfiguration config = wiki.getConfiguration();
boolean useDisambig = config.getBoolean(WPCConfigurationBoolean.DAB_USE_DISAMBIG_MAGIC_WORD);
if (useDisambig) {
ApiPagePropsResult result = new ApiXmlPagePropsResult(wiki, httpClient);
ApiPagePropsRequest request = new ApiPagePropsRequest(wiki, result);
request.setDisambiguationStatus(pages);
return;
}
// Use categories if possible
List<Page> dabCategories = wiki.getConfiguration().getDisambiguationCategories();
if ((dabCategories != null) && (dabCategories.size() > 0)) {
ApiCategoriesResult result = new ApiXmlCategoriesResult(wiki, httpClient);
ApiCategoriesRequest request = new ApiCategoriesRequest(wiki, result);
request.setDisambiguationStatus(pages);
return;
}
// Use templates otherwise
ApiTemplatesResult result = new ApiXmlTemplatesResult(wiki, httpClient);
ApiTemplatesRequest request = new ApiTemplatesRequest(wiki, result);
request.setDisambiguationStatus(pages);
}
}
use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.
the class CheckErrorAlgorithm513 method isInList.
/**
* @param link Link to be checked.
* @param list List of page names (and potential URL restrictions).
* @param analysis Page analysis to check through redirects.
* @param externalLink External link.
* @return True if the link points to a page in the list.
*/
private boolean isInList(PageElementInternalLink link, Map<String, List<String>> list, PageAnalysis analysis, PageElementExternalLink externalLink) {
if ((link == null) || (list == null)) {
return false;
}
String pageName = link.getLink();
List<String> listUrl = null;
boolean listFound = false;
if (list.containsKey(pageName)) {
listUrl = list.get(pageName);
listFound = true;
} else {
if ((analysis != null) && (analysis.getPage() != null) && (analysis.getPage().getLinks() != null)) {
List<Page> links = analysis.getPage().getLinks();
for (Page tmp : links) {
if (Page.areSameTitle(pageName, tmp.getTitle())) {
PageRedirect redirect = tmp.getRedirects();
if ((redirect != null) && (redirect.getLastPage() != null) && list.containsKey(redirect.getLastPage().getTitle())) {
listUrl = list.get(redirect.getLastPage().getTitle());
listFound = true;
}
}
}
}
}
if (!listFound) {
return false;
}
if ((listUrl == null) || listUrl.isEmpty()) {
return true;
}
if (externalLink == null) {
return false;
}
return listUrl.contains(externalLink.getLink());
}
use of org.wikipediacleaner.api.data.PageRedirect in project wpcleaner by WPCleaner.
the class ContentsCallable method call.
/* (non-Javadoc)
* @see java.util.concurrent.Callable#call()
*/
@Override
public Page call() throws APIException {
setText(GT._T("Retrieving contents") + " - " + page.getTitle());
if (section == null) {
api.retrieveContents(getWikipedia(), Collections.singletonList(page), usePageId, withRedirects);
PageRedirect redirects = page.getRedirects();
if (withRedirects && redirects.isRedirect() && (redirects.getPageList() != null) && (!redirects.getPageList().isEmpty())) {
api.retrieveContents(getWikipedia(), redirects.getPageList(), false, false);
}
} else {
api.retrieveSectionContents(getWikipedia(), page, section.intValue());
}
if (doAnalysis) {
PageAnalysis analysis = page.getAnalysis(page.getContents(), true);
analysis.performFullPageAnalysis(null);
}
return returnPage;
}
Aggregations