mediawiki-gateway 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/doc/classes/MediaWiki.html +106 -26
- data/doc/classes/MediaWiki/Config.html +12 -12
- data/doc/classes/MediaWiki/Gateway.html +553 -430
- data/doc/created.rid +1 -1
- data/doc/files/lib/media_wiki/gateway_rb.html +1 -1
- data/doc/files/lib/media_wiki/utils_rb.html +1 -1
- data/doc/fr_method_index.html +29 -25
- data/lib/media_wiki.rb +4 -0
- data/lib/media_wiki/gateway.rb +20 -3
- data/lib/media_wiki/utils.rb +30 -9
- data/mediawiki-gateway.gemspec +2 -3
- data/spec/utils_spec.rb +30 -2
- metadata +4 -5
- data/VERSION +0 -1
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon, 13 Dec 2010 14:34:22 +1100
|
data/doc/fr_method_index.html
CHANGED
@@ -20,32 +20,36 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
|
-
<a href="classes/MediaWiki/Config.html#
|
24
|
-
<a href="classes/MediaWiki/Gateway.html#
|
25
|
-
<a href="classes/MediaWiki/Gateway.html#
|
26
|
-
<a href="classes/MediaWiki/Gateway.html#
|
27
|
-
<a href="classes/MediaWiki/Gateway.html#
|
28
|
-
<a href="classes/MediaWiki/Gateway.html#
|
29
|
-
<a href="classes/MediaWiki/Gateway.html#
|
30
|
-
<a href="classes/MediaWiki/Gateway.html#
|
31
|
-
<a href="classes/MediaWiki
|
32
|
-
<a href="classes/MediaWiki/Gateway.html#
|
33
|
-
<a href="classes/MediaWiki
|
34
|
-
<a href="classes/MediaWiki/Gateway.html#
|
35
|
-
<a href="classes/MediaWiki/Gateway.html#
|
36
|
-
<a href="classes/MediaWiki/Gateway.html#
|
37
|
-
<a href="classes/MediaWiki/Gateway.html#
|
38
|
-
<a href="classes/MediaWiki/Gateway.html#
|
39
|
-
<a href="classes/MediaWiki/
|
40
|
-
<a href="classes/MediaWiki/Gateway.html#
|
41
|
-
<a href="classes/MediaWiki/Gateway.html#
|
42
|
-
<a href="classes/MediaWiki/Gateway.html#
|
43
|
-
<a href="classes/MediaWiki/
|
44
|
-
<a href="classes/MediaWiki/Gateway.html#
|
45
|
-
<a href="classes/MediaWiki/Gateway.html#
|
23
|
+
<a href="classes/MediaWiki/Config.html#M000030">abort (MediaWiki::Config)</a><br />
|
24
|
+
<a href="classes/MediaWiki/Gateway.html#M000015">backlinks (MediaWiki::Gateway)</a><br />
|
25
|
+
<a href="classes/MediaWiki/Gateway.html#M000010">create (MediaWiki::Gateway)</a><br />
|
26
|
+
<a href="classes/MediaWiki/Gateway.html#M000012">delete (MediaWiki::Gateway)</a><br />
|
27
|
+
<a href="classes/MediaWiki/Gateway.html#M000019">download (MediaWiki::Gateway)</a><br />
|
28
|
+
<a href="classes/MediaWiki/Gateway.html#M000021">export (MediaWiki::Gateway)</a><br />
|
29
|
+
<a href="classes/MediaWiki/Gateway.html#M000023">extensions (MediaWiki::Gateway)</a><br />
|
30
|
+
<a href="classes/MediaWiki/Gateway.html#M000008">get (MediaWiki::Gateway)</a><br />
|
31
|
+
<a href="classes/MediaWiki.html#M000001">get_path_to_subpage (MediaWiki)</a><br />
|
32
|
+
<a href="classes/MediaWiki/Gateway.html#M000028">get_response (MediaWiki::Gateway)</a><br />
|
33
|
+
<a href="classes/MediaWiki.html#M000002">get_subpage (MediaWiki)</a><br />
|
34
|
+
<a href="classes/MediaWiki/Gateway.html#M000025">get_token (MediaWiki::Gateway)</a><br />
|
35
|
+
<a href="classes/MediaWiki/Gateway.html#M000026">get_undelete_token (MediaWiki::Gateway)</a><br />
|
36
|
+
<a href="classes/MediaWiki/Gateway.html#M000018">image_info (MediaWiki::Gateway)</a><br />
|
37
|
+
<a href="classes/MediaWiki/Gateway.html#M000020">import (MediaWiki::Gateway)</a><br />
|
38
|
+
<a href="classes/MediaWiki/Gateway.html#M000014">list (MediaWiki::Gateway)</a><br />
|
39
|
+
<a href="classes/MediaWiki/Gateway.html#M000007">login (MediaWiki::Gateway)</a><br />
|
40
|
+
<a href="classes/MediaWiki/Gateway.html#M000027">make_api_request (MediaWiki::Gateway)</a><br />
|
41
|
+
<a href="classes/MediaWiki/Gateway.html#M000011">move (MediaWiki::Gateway)</a><br />
|
42
|
+
<a href="classes/MediaWiki/Gateway.html#M000022">namespaces_by_prefix (MediaWiki::Gateway)</a><br />
|
43
|
+
<a href="classes/MediaWiki/Config.html#M000029">new (MediaWiki::Config)</a><br />
|
44
|
+
<a href="classes/MediaWiki/Gateway.html#M000006">new (MediaWiki::Gateway)</a><br />
|
45
|
+
<a href="classes/MediaWiki/Gateway.html#M000009">render (MediaWiki::Gateway)</a><br />
|
46
|
+
<a href="classes/MediaWiki/Gateway.html#M000016">search (MediaWiki::Gateway)</a><br />
|
47
|
+
<a href="classes/MediaWiki/Gateway.html#M000024">semantic_query (MediaWiki::Gateway)</a><br />
|
48
|
+
<a href="classes/MediaWiki/Gateway.html#M000013">undelete (MediaWiki::Gateway)</a><br />
|
49
|
+
<a href="classes/MediaWiki/Gateway.html#M000017">upload (MediaWiki::Gateway)</a><br />
|
46
50
|
<a href="classes/MediaWiki.html#M000003">uri_to_wiki (MediaWiki)</a><br />
|
47
|
-
<a href="classes/MediaWiki.html#
|
48
|
-
<a href="classes/MediaWiki.html#
|
51
|
+
<a href="classes/MediaWiki.html#M000005">version (MediaWiki)</a><br />
|
52
|
+
<a href="classes/MediaWiki.html#M000004">wiki_to_uri (MediaWiki)</a><br />
|
49
53
|
</div>
|
50
54
|
</div>
|
51
55
|
</body>
|
data/lib/media_wiki.rb
CHANGED
data/lib/media_wiki/gateway.rb
CHANGED
@@ -105,6 +105,23 @@ module MediaWiki
|
|
105
105
|
make_api_request(form_data)
|
106
106
|
end
|
107
107
|
|
108
|
+
# Move a page to a new title
|
109
|
+
#
|
110
|
+
# [from] Old page name
|
111
|
+
# [to] New page name
|
112
|
+
# [options] Hash of additional options
|
113
|
+
#
|
114
|
+
# Options:
|
115
|
+
# * [movesubpages] Move associated subpages
|
116
|
+
# * [movetalk] Move associated talkpages
|
117
|
+
def move(from, to, options={})
|
118
|
+
valid_options = %w(movesubpages movetalk)
|
119
|
+
options.keys.each{|opt| raise ArgumentError.new("Unknown option '#{opt}'") unless valid_options.include?(opt.to_s)}
|
120
|
+
|
121
|
+
form_data = options.merge({'action' => 'move', 'from' => from, 'to' => to, 'token' => get_token('move', from)})
|
122
|
+
make_api_request(form_data)
|
123
|
+
end
|
124
|
+
|
108
125
|
# Delete one page. (MediaWiki API does not support deleting multiple pages at a time.)
|
109
126
|
#
|
110
127
|
# [title] Title of page to delete
|
@@ -129,9 +146,9 @@ module MediaWiki
|
|
129
146
|
end
|
130
147
|
end
|
131
148
|
|
132
|
-
# Get a list of matching page titles
|
149
|
+
# Get a list of matching page titles in a namespace
|
133
150
|
#
|
134
|
-
# [key] Search key, matched as a prefix (^key.*). May contain or equal a namespace.
|
151
|
+
# [key] Search key, matched as a prefix (^key.*). May contain or equal a namespace, defaults to main (namespace 0) if none given.
|
135
152
|
#
|
136
153
|
# Returns array of page titles (empty if no matches)
|
137
154
|
def list(key)
|
@@ -401,7 +418,7 @@ module MediaWiki
|
|
401
418
|
|
402
419
|
private
|
403
420
|
|
404
|
-
# Fetch token (type 'delete', 'edit', 'import')
|
421
|
+
# Fetch token (type 'delete', 'edit', 'import', 'move')
|
405
422
|
def get_token(type, page_titles)
|
406
423
|
form_data = {'action' => 'query', 'prop' => 'info', 'intoken' => type, 'titles' => page_titles}
|
407
424
|
res = make_api_request(form_data)
|
data/lib/media_wiki/utils.rb
CHANGED
@@ -1,10 +1,33 @@
|
|
1
1
|
module MediaWiki
|
2
|
-
|
3
2
|
class << self
|
4
3
|
|
5
|
-
#
|
6
|
-
|
7
|
-
|
4
|
+
# Extract path leading up to subpage. If title does not contain a subpage, returns nil.
|
5
|
+
#
|
6
|
+
# Examples:
|
7
|
+
# get_path_to_subpage("Namespace:Foo/Bar/Baz") -> "Namespace:Foo/Bar"
|
8
|
+
# get_path_to_subpage("Namespace:Foo") -> nil
|
9
|
+
#
|
10
|
+
# [title] Page name string in Wiki format
|
11
|
+
def get_path_to_subpage(title)
|
12
|
+
return nil unless title and title.include? '/'
|
13
|
+
parts = title.split(/\/([^\/]*)$/).first
|
14
|
+
end
|
15
|
+
|
16
|
+
# Extract subpage name. If there is no hierarchy above, return page name.
|
17
|
+
#
|
18
|
+
# Examples:
|
19
|
+
# get_subpage("Namespace:Foo/Bar/Baz") -> "Baz"
|
20
|
+
# get_subpage("Namespace:Foo") -> "Namespace:Foo"
|
21
|
+
#
|
22
|
+
# [title] Page name string in Wiki format
|
23
|
+
def get_subpage(title)
|
24
|
+
title.split('/').last if title
|
25
|
+
end
|
26
|
+
|
27
|
+
# Convert URL-ized page name ("getting_there_%26_away") into Wiki display format page name ("getting there & away")
|
28
|
+
# [wiki] Page name string in URL
|
29
|
+
def uri_to_wiki(uri)
|
30
|
+
CGI.unescape(uri).tr('_', ' ') if uri
|
8
31
|
end
|
9
32
|
|
10
33
|
# Convert a Wiki page name ("getting there & away") to URI-safe format ("getting_there_%26_away"),
|
@@ -14,12 +37,10 @@ module MediaWiki
|
|
14
37
|
wiki.to_s.split('/').map {|chunk| CGI.escape(chunk.tr(' ', '_')) }.join('/') if wiki
|
15
38
|
end
|
16
39
|
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
CGI.unescape(uri).tr('_', ' ') if uri
|
40
|
+
# Return current version of MediaWiki::Gateway
|
41
|
+
def version
|
42
|
+
MediaWiki::VERSION
|
21
43
|
end
|
22
|
-
|
23
44
|
end
|
24
45
|
|
25
46
|
end
|
data/mediawiki-gateway.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mediawiki-gateway}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
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-
|
12
|
+
s.date = %q{2010-12-13}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{jpatokal@iki.fi}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = [
|
19
19
|
"README",
|
20
20
|
"Rakefile",
|
21
|
-
"VERSION",
|
22
21
|
"config/hosts.yml",
|
23
22
|
"doc/classes/MediaWiki.html",
|
24
23
|
"doc/classes/MediaWiki/Config.html",
|
data/spec/utils_spec.rb
CHANGED
@@ -2,6 +2,34 @@ require 'media_wiki'
|
|
2
2
|
|
3
3
|
describe MediaWiki do
|
4
4
|
|
5
|
+
describe '.get_path_to_subpage' do
|
6
|
+
it "should return the everything before the subpage if there are subpages" do
|
7
|
+
MediaWiki.get_path_to_subpage('namespace:base/base/subpage').should == 'namespace:base/base'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return nil if there is no subpage" do
|
11
|
+
MediaWiki.get_path_to_subpage('namespace:subpage').should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should pass through nil" do
|
15
|
+
MediaWiki.get_path_to_subpage(nil).should be_nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.get_subpage' do
|
20
|
+
it "should return subpage name if there are subpages" do
|
21
|
+
MediaWiki.get_subpage('namespace:base/base/subpage').should == 'subpage'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return entire name if there are no subpages" do
|
25
|
+
MediaWiki.get_subpage('namespace:subpage').should == 'namespace:subpage'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should pass through nil" do
|
29
|
+
MediaWiki.get_subpage(nil).should be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
5
33
|
describe '.wiki_to_uri' do
|
6
34
|
|
7
35
|
it "should underscore spaces" do
|
@@ -21,7 +49,7 @@ describe MediaWiki do
|
|
21
49
|
end
|
22
50
|
|
23
51
|
it "should pass through nil" do
|
24
|
-
MediaWiki.wiki_to_uri(nil).should
|
52
|
+
MediaWiki.wiki_to_uri(nil).should be_nil
|
25
53
|
end
|
26
54
|
|
27
55
|
end
|
@@ -41,7 +69,7 @@ describe MediaWiki do
|
|
41
69
|
end
|
42
70
|
|
43
71
|
it "should pass through nil" do
|
44
|
-
MediaWiki.uri_to_wiki(nil).should
|
72
|
+
MediaWiki.uri_to_wiki(nil).should be_nil
|
45
73
|
end
|
46
74
|
|
47
75
|
end
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
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-
|
18
|
+
date: 2010-12-13 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -85,7 +85,6 @@ extra_rdoc_files:
|
|
85
85
|
files:
|
86
86
|
- README
|
87
87
|
- Rakefile
|
88
|
-
- VERSION
|
89
88
|
- config/hosts.yml
|
90
89
|
- doc/classes/MediaWiki.html
|
91
90
|
- doc/classes/MediaWiki/Config.html
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.1
|