mediawiki-gateway 0.1.6 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.2.1
@@ -7,6 +7,7 @@ require 'uri'
7
7
  module MediaWiki
8
8
 
9
9
  class Gateway
10
+ API_MAX_LIMIT = 500
10
11
 
11
12
  # Set up a MediaWiki::Gateway for a given MediaWiki installation
12
13
  #
@@ -40,7 +41,7 @@ module MediaWiki
40
41
  #
41
42
  # [page_title] Page title to fetch
42
43
  #
43
- # Returns nil if the page does not exist
44
+ # Returns content of page as string, nil if the page does not exist
44
45
  def get(page_title)
45
46
  form_data = {'action' => 'query', 'prop' => 'revisions', 'rvprop' => 'content', 'titles' => page_title}
46
47
  page = make_api_request(form_data).elements["query/pages/page"]
@@ -61,7 +62,7 @@ module MediaWiki
61
62
  # * [noeditsections] strips all edit-links if set to +true+
62
63
  # * [noimages] strips all +img+ tags from the rendered text if set to +true+
63
64
  #
64
- # Returns nil if the page does not exist
65
+ # Returns rendered page as string, or nil if the page does not exist
65
66
  def render(page_title, options = {})
66
67
  form_data = {'action' => 'parse', 'page' => page_title}
67
68
 
@@ -116,7 +117,7 @@ module MediaWiki
116
117
  #
117
118
  # [title] Title of page to undelete
118
119
  #
119
- # Returns number of revisions undeleted.
120
+ # Returns number of revisions undeleted, or zero if nothing to undelete
120
121
  def undelete(title)
121
122
  token = get_undelete_token(title)
122
123
  if token
@@ -144,7 +145,7 @@ module MediaWiki
144
145
  'list' => 'allpages',
145
146
  'apfrom' => apfrom,
146
147
  'apprefix' => key,
147
- 'aplimit' => 500, # max allowed by API
148
+ 'aplimit' => API_MAX_LIMIT,
148
149
  'apnamespace' => namespace}
149
150
  res = make_api_request(form_data)
150
151
  apfrom = res.elements['query-continue'] ? res.elements['query-continue/allpages'].attributes['apfrom'] : nil
@@ -153,6 +154,30 @@ module MediaWiki
153
154
  titles
154
155
  end
155
156
 
157
+ # Get a list of pages that link to a target page
158
+ #
159
+ # [title] Link target page
160
+ # [filter] "all" links (default), "redirects" only, or "nonredirects" (plain links only)
161
+ #
162
+ # Returns array of page titles (empty if no matches)
163
+ def backlinks(title, filter = "all")
164
+ titles = []
165
+ blcontinue = nil
166
+ begin
167
+ form_data =
168
+ {'action' => 'query',
169
+ 'list' => 'backlinks',
170
+ 'bltitle' => title,
171
+ 'blfilterredir' => filter,
172
+ 'bllimit' => API_MAX_LIMIT }
173
+ form_data['blcontinue'] = blcontinue if blcontinue
174
+ res = make_api_request(form_data)
175
+ blcontinue = res.elements['query-continue'] ? res.elements['query-continue/backlinks'].attributes['blcontinue'] : nil
176
+ titles += REXML::XPath.match(res, "//bl").map { |x| x.attributes["title"] }
177
+ end while blcontinue
178
+ titles
179
+ end
180
+
156
181
  # Get a list of pages with matching content in given namespaces
157
182
  #
158
183
  # [key] Search key
@@ -441,6 +466,5 @@ module MediaWiki
441
466
  end
442
467
  doc
443
468
  end
444
-
445
469
  end
446
470
  end
@@ -4,7 +4,7 @@ module MediaWiki
4
4
 
5
5
  # TODO sync this automatically with Gem version
6
6
  def version
7
- "0.1.6"
7
+ "0.2.1"
8
8
  end
9
9
 
10
10
  # Convert a Wiki page name ("getting there & away") to URI-safe format ("getting_there_%26_away"),
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mediawiki-gateway}
8
- s.version = "0.1.6"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jani Patokallio"]
12
- s.date = %q{2010-11-26}
12
+ s.date = %q{2010-11-29}
13
13
  s.description = %q{}
14
14
  s.email = %q{jpatokal@iki.fi}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mediawiki-gateway
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 1
9
- - 6
10
- version: 0.1.6
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jani Patokallio
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-26 00:00:00 +11:00
18
+ date: 2010-11-29 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency