Module: MediaWiki::Query::Properties::Files
- Included in:
- MediaWiki::Query::Properties
- Defined in:
- lib/mediawiki/query/properties/files.rb
Instance Method Summary collapse
-
#get_all_duplicated_files(limit = @query_limit_default) ⇒ Array<String>
Gets all duplicated files on the wiki.
-
#get_duplicated_files_of(title, limit = @query_limit_default) ⇒ Array<String>
Gets the duplicated files of the title.
-
#get_image_bytes(image) ⇒ Fixnum, Nil
Gets the size of an image in bytes.
-
#get_image_dimensions(image) ⇒ Array<Fixnum>, Nil
Gets the dimensions of an image as width, height.
-
#get_image_sizes(image) ⇒ Hash<String, Fixnum>, Nil
private
Gets the imageinfo property ‘size’ for the image.
Instance Method Details
#get_all_duplicated_files(limit = @query_limit_default) ⇒ Array<String>
Gets all duplicated files on the wiki.
34 35 36 37 38 39 40 41 42 |
# File 'lib/mediawiki/query/properties/files.rb', line 34 def get_all_duplicated_files(limit = @query_limit_default) params = { generator: 'allimages', prop: 'duplicatedfiles', dflimit: get_limited(limit) } query_ary_irrelevant_keys(params, 'pages', 'title') end |
#get_duplicated_files_of(title, limit = @query_limit_default) ⇒ Array<String>
Gets the duplicated files of the title.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mediawiki/query/properties/files.rb', line 14 def get_duplicated_files_of(title, limit = @query_limit_default) params = { prop: 'duplicatefiles', titles: title, dflimit: get_limited(limit) } query(params) do |return_val, query| query['pages'].each do |_, c| next unless c['duplicatefies'] c['duplicatefiles'].each { |f| return_val << f['name'] } end end end |
#get_image_bytes(image) ⇒ Fixnum, Nil
Gets the size of an image in bytes.
50 51 52 53 54 |
# File 'lib/mediawiki/query/properties/files.rb', line 50 def get_image_bytes(image) response = get_image_sizes(image) return nil if response.nil? response['size'] end |
#get_image_dimensions(image) ⇒ Array<Fixnum>, Nil
TODO:
Use data_types library to store the pair of width, height.
Gets the dimensions of an image as width, height.
63 64 65 66 67 |
# File 'lib/mediawiki/query/properties/files.rb', line 63 def get_image_dimensions(image) response = get_image_sizes(image) return nil if response.nil? [response['width'], response['height']] end |
#get_image_sizes(image) ⇒ Hash<String, Fixnum>, Nil (private)
Gets the imageinfo property ‘size’ for the image.
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mediawiki/query/properties/files.rb', line 77 def get_image_sizes(image) params = { action: 'query', prop: 'imageinfo', iiprop: 'size', titles: image } response = post(params) pageid = response['query']['pages'].keys.find(MediaWiki::Constants::MISSING_PAGEID_PROC) { |id| id != '-1'} return nil if pageid == '-1' response['query']['pages'][pageid]['imageinfo'].reduce({}, :merge) end |