Module: MediaWiki::Query::Lists::Backlinks

Included in:
MediaWiki::Query::Lists
Defined in:
lib/mediawiki/query/lists/backlinks.rb

Instance Method Summary collapse

Instance Method Details

Gets image backlinks, or the pages that use a given image.

Parameters:

  • list_redirects (Nil/Boolean) (defaults to: nil)

    Set to nil to list redirects and non-redirects. Set to true to only list redirects. Set to false to only list non-redirects.

  • thru_redir (Boolean) (defaults to: false)

    Whether to list pages that link to a redirect of the image.

  • title (String)

    The page to get the backlinks of.

  • limit (Fixnum) (defaults to: @query_limit_default)

    The maximum number of pages to get. Defaults to query_limit_default attribute. Cannot be greater than 500 for users or 5000 for bots.

Returns:

  • (Array<String>)

    All page titles that fit the requirements.

See Also:

Since:

  • 0.10.0



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/mediawiki/query/lists/backlinks.rb', line 66

def get_image_backlinks(title, list_redirects = nil, thru_redir = false, limit = @query_limit_default)
  params = {
    list: 'imageusage',
    iutitle: title,
    iulimit: get_limited(limit)
  }
  params[:iufilterredir] = list_redirects.nil? ? 'all' : list_redirects
  params[:iuredirect] = '1' if thru_redir

  query_ary(params, 'imageusage', 'title')
end

Gets interwiki backlinks by the prefix and title.

Parameters:

  • prefix (String) (defaults to: nil)

    The wiki prefix, e.g., “mcw”.

  • title (String) (defaults to: nil)

    The title of the page on that wiki.

  • limit (Fixnum) (defaults to: @query_limit_default)

Returns:

  • (Array<String>)

    All interwiki backlinking page titles.

See Also:

Since:

  • 0.10.0



29
30
31
32
33
34
35
36
37
38
# File 'lib/mediawiki/query/lists/backlinks.rb', line 29

def get_interwiki_backlinks(prefix = nil, title = nil, limit = @query_limit_default)
  params = {
    list: 'iwbacklinks',
    iwbllimit: get_limited(limit)
  }
  params[:iwblprefix] = prefix unless prefix.nil?
  params[:iwbltitle] = title unless title.nil?

  query_ary(params, 'iwbacklinks', 'title')
end

Gets language backlinks by the language and title.

Parameters:

  • language (String) (defaults to: nil)

    The language code

  • title (String) (defaults to: nil)

    The page to get the backlinks of.

  • limit (Fixnum) (defaults to: @query_limit_default)

    The maximum number of pages to get. Defaults to query_limit_default attribute. Cannot be greater than 500 for users or 5000 for bots.

Returns:

  • (Array<String>)

    All pages that link to the language links.

See Also:

Since:

  • 0.10.0



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mediawiki/query/lists/backlinks.rb', line 46

def get_language_backlinks(language = nil, title = nil, limit = @query_limit_default)
  language.downcase! if language.match(/[^A-Z]*/)[0].empty?
  params = {
    list: 'langbacklinks',
    lbltitle: get_limited(limit)
  }
  params[:lbllang] = language unless language.nil?
  params[:lbltitle] = title unless title.nil?

  query_ary(params, 'langbacklinks', 'title')
end

Gets all external link page titles.

Parameters:

  • url (String) (defaults to: nil)

    The URL to get backlinks for.

  • limit (Fixnum) (defaults to: @query_limit_default)

Returns:

  • (Array<String>)

    All pages that link to the given URL.

  • (Array<Hash<Symbol, String>>)

    All pages that link to any external links. There are 2 keys in each hash, url and title.

See Also:

Since:

  • 0.10.0



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/mediawiki/query/lists/backlinks.rb', line 86

def get_url_backlinks(url = nil, limit = @query_limit_default)
  params = {
    list: 'exturlusage',
    eulimit: get_limited(limit)
  }
  params[:euquery] = url if url

  query(params) do |return_val, query|
   query['exturlusage'].each { |bl| return_val << url ? bl['title'] : { url: bl['url'], title: bl['title'] } }
  end
end

Gets an array of backlinks to a given title, like Special:WhatLinksHere.

Parameters:

  • title (String)

    The page to get the backlinks of.

  • limit (Fixnum) (defaults to: @query_limit_default)

    The maximum number of pages to get. Defaults to query_limit_default attribute. Cannot be greater than 500 for users or 5000 for bots.

Returns:

  • (Array<String>)

    All backlinks until the limit

See Also:

Since:

  • 0.1.0



12
13
14
15
16
17
18
19
20
# File 'lib/mediawiki/query/lists/backlinks.rb', line 12

def what_links_here(title, limit = @query_limit_default)
  params = {
    list: 'backlinks',
    bltitle: title,
    bllimit: get_limited(limit)
  }

  query_ary(params, 'backlinks', 'title')
end