Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions wikitools/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,39 @@ def getLinks(self, force=False):
self.links.extend(self.__extractToList(data, 'links'))
return self.links

def getLinksHere(self, namespace='all', lhshow='all', force=False):
"""Gets a list of all the internal links elsewhere on Wikipedia pointing *to* the page
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily Wikipedia. This should probably read "on the wiki" or similar.


namespace - pipe-separated list of namespaces to collect, default is "all"
lhshow - include redirects with 'redirect', exclude with '!redirect', default is "all"
force - load the list even if we already loaded it before

"""
if self.links and not force:
return self.links
if self.pageid == 0 and not self.title:
self.setPageInfo()
if not self.exists:
raise NoPage
params = {
'action': 'query',
'prop': 'linkshere',
'lhlimit': self.site.limit,
}
if namespace != 'all':
params['lhnamespace'] = namespace
if namespace != 'all':
params['lhshow'] = lhshow
if self.pageid > 0:
params['pageids'] = self.pageid
else:
params['titles'] = self.title
req = api.APIRequest(self.site, params)
self.links = []
for data in req.queryGen():
self.links.extend(self.__extractToList(data, 'linkshere'))
return self.links

def getProtection(self, force=False):
"""Returns the current protection status of the page"""
if self.protection and not force:
Expand Down