Module: MediaWiki::Query::Properties::Contributors
- Included in:
- MediaWiki::Query::Properties
- Defined in:
- lib/mediawiki/query/properties/contributors.rb
Instance Method Summary collapse
-
#get_anonymous_contributors_count(title, limit = @query_limit_default) ⇒ Fixnum, Nil
private
Gets the total number of anonymous contributors for the given page.
-
#get_contributors_response(title, limit = @query_limit_default) ⇒ Hash
private
Gets the parsed response for the contributors property.
-
#get_logged_in_contributors(title, limit = @query_limit_default) ⇒ Array<String>
Gets the non-anonymous contributors for the given page.
-
#get_total_contributors(title, limit = @query_limit_default) ⇒ Fixnum, Nil
Gets the total amount of contributors for the given page.
Instance Method Details
#get_anonymous_contributors_count(title, limit = @query_limit_default) ⇒ Fixnum, Nil (private)
Gets the total number of anonymous contributors for the given page.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mediawiki/query/properties/contributors.rb', line 61 def get_anonymous_contributors_count(title, limit = @query_limit_default) ret = 0 get_contributors_response(title, limit) do |_, query| pageid = query['pages'].keys.find(MediaWiki::Constants::MISSING_PAGEID_PROC) { |id| id != '-1' } return if query['pages'][pageid].key?('missing') ret += query['pages'][pageid]['anoncontributors'].to_i end ret end |
#get_contributors_response(title, limit = @query_limit_default) ⇒ Hash (private)
Gets the parsed response for the contributors property.
45 46 47 48 49 50 51 52 53 |
# File 'lib/mediawiki/query/properties/contributors.rb', line 45 def get_contributors_response(title, limit = @query_limit_default) params = { prop: 'contributors', titles: title, pclimit: get_limited(limit) } query(params) { |return_val, query| yield(return_val, query) } end |
#get_logged_in_contributors(title, limit = @query_limit_default) ⇒ Array<String>
Gets the non-anonymous contributors for the given page.
30 31 32 33 34 35 36 |
# File 'lib/mediawiki/query/properties/contributors.rb', line 30 def get_logged_in_contributors(title, limit = @query_limit_default) get_contributors_response(title, limit) do |return_val, query| pageid = query['pages'].keys.find(MediaWiki::Constants::MISSING_PAGEID_PROC) { |id| id != '-1' } return if query['pages'][pageid].key?('missing') query['pages'][pageid]['contributors'].each { |c| return_val << c['name'] } end end |
#get_total_contributors(title, limit = @query_limit_default) ⇒ Fixnum, Nil
Gets the total amount of contributors for the given page. unless the user is a bot. If the user is a bot, the limit cannot be greater than 5000.
17 18 19 20 21 22 23 |
# File 'lib/mediawiki/query/properties/contributors.rb', line 17 def get_total_contributors(title, limit = @query_limit_default) anon_users = get_anonymous_contributors_count(title, limit) users = get_logged_in_contributors(title, limit) return if users.nil? users.size + anon_users end |