Module: MediaWiki::Purge

Included in:
Butt
Defined in:
lib/mediawiki/purge.rb

Instance Method Summary collapse

Instance Method Details

#purge(*titles) ⇒ Hash<String, Boolean>

Note:

This creates a warning for every invalid purge with the reason it is invalid, as provided by the MediaWiki API, as well as the title of the invalid page.

Purges the provided pages, without updating link tables. This will warn for every invalid purge with the reason it is invalid, as provided by the MediaWiki API.

Parameters:

  • titles (Array<String>)

    A list of the pages to purge.

Returns:

  • (Hash<String, Boolean>)

    The key is the page title, and the value is whether it was a successful purge.

See Also:



10
11
12
# File 'lib/mediawiki/purge.rb', line 10

def purge(*titles)
  purge_request({}, titles)
end
Note:

This creates a warning for every invalid purge with the reason it is invalid, as provided by the MediaWiki API, as well as the title of the invalid page.

Purges the provided pages and updates their link tables.

Parameters:

  • titles (Array<String>)

    A list of the pages to purge.

Returns:

  • (Hash<String, Boolean>)

    The key is the page title, and the value is whether it was a successful purge.

See Also:



19
20
21
# File 'lib/mediawiki/purge.rb', line 19

def purge_link_update(*titles)
  purge_request({ forcelinkupdate: 1 }, titles)
end
Note:

This creates a warning for every invalid purge with the reason it is invalid, as provided by the MediaWiki API, as well as the title of the invalid page.

Purges the provided pages and recursively updates the link tables.

Parameters:

  • titles (Array<String>)

    A list of the pages to purge.

Returns:

  • (Hash<String, Boolean>)

    The key is the page title, and the value is whether it was a successful purge.

See Also:



28
29
30
# File 'lib/mediawiki/purge.rb', line 28

def purge_recursive_link_update(*titles)
  purge_request({ forcerecursivelinkupdate: 1 }, titles)
end

#purge_request(params, *titles) ⇒ Hash<String, Boolean> (private)

Note:

This creates a warning for every invalid purge with the reason it is invalid, as provided by the MediaWiki API, as well as the title of the invalid page.

Sends a purge API request, and handles the return value and warnings.

Parameters:

  • params (Hash<Object, Object>)

    The parameter hash to begin with. Cannot include the titles or action keys.

  • titles (Array<String>)

    A list of the pages to purge.

Returns:

  • (Hash<String, Boolean>)

    The key is the page title, and the value is whether it was a successful purge.

See Also:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mediawiki/purge.rb', line 40

def purge_request(params, *titles)
  params[:action] = 'purge'
  params[:titles] = titles.join('|')

  post(params)['purge'].inject({}) do |result, hash|
    title = hash['title']
    result[title] = hash.key?('purged') && !hash.key?('missing')
    warn "Invalid purge (#{title}) #{hash['invalidreason']}" if hash.key?('invalid')
    result
  end
end