mediawiki-gateway 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/media_wiki.rb +1 -1
- data/lib/media_wiki/gateway.rb +5 -4
- data/mediawiki-gateway.gemspec +4 -28
- data/script/README +14 -0
- data/script/download_batch.rb +15 -0
- metadata +6 -30
- data/doc/classes/MediaWiki.html +0 -381
- data/doc/classes/MediaWiki/APIError.html +0 -186
- data/doc/classes/MediaWiki/Config.html +0 -269
- data/doc/classes/MediaWiki/Exception.html +0 -122
- data/doc/classes/MediaWiki/Gateway.html +0 -1737
- data/doc/classes/MediaWiki/Unauthorized.html +0 -120
- data/doc/created.rid +0 -1
- data/doc/files/README.html +0 -164
- data/doc/files/lib/media_wiki/config_rb.html +0 -109
- data/doc/files/lib/media_wiki/exception_rb.html +0 -101
- data/doc/files/lib/media_wiki/gateway_rb.html +0 -113
- data/doc/files/lib/media_wiki/utils_rb.html +0 -101
- data/doc/files/script/create_page_rb.html +0 -114
- data/doc/files/script/delete_batch_rb.html +0 -108
- data/doc/files/script/export_xml_rb.html +0 -114
- data/doc/files/script/get_page_rb.html +0 -114
- data/doc/files/script/import_xml_rb.html +0 -114
- data/doc/files/script/run_fake_media_wiki_rb.html +0 -117
- data/doc/files/script/search_content_rb.html +0 -114
- data/doc/files/script/upload_commons_rb.html +0 -114
- data/doc/files/script/upload_file_rb.html +0 -114
- data/doc/fr_class_index.html +0 -32
- data/doc/fr_file_index.html +0 -40
- data/doc/fr_method_index.html +0 -68
- data/doc/index.html +0 -24
- data/doc/rdoc-style.css +0 -208
data/lib/media_wiki.rb
CHANGED
data/lib/media_wiki/gateway.rb
CHANGED
@@ -187,21 +187,22 @@ module MediaWiki
|
|
187
187
|
# Get a list of matching page titles in a namespace
|
188
188
|
#
|
189
189
|
# [key] Search key, matched as a prefix (^key.*). May contain or equal a namespace, defaults to main (namespace 0) if none given.
|
190
|
+
# [options] Optional hash of additional options, eg. { 'apfilterredir' => 'nonredirects' }. See http://www.mediawiki.org/wiki/API:Allpages
|
190
191
|
#
|
191
192
|
# Returns array of page titles (empty if no matches)
|
192
|
-
def list(key)
|
193
|
+
def list(key, options = {})
|
193
194
|
titles = []
|
194
195
|
apfrom = nil
|
195
196
|
key, namespace = key.split(":", 2).reverse
|
196
197
|
namespace = namespaces_by_prefix[namespace] || 0
|
197
198
|
begin
|
198
|
-
form_data =
|
199
|
+
form_data = options.merge(
|
199
200
|
{'action' => 'query',
|
200
201
|
'list' => 'allpages',
|
201
202
|
'apfrom' => apfrom,
|
202
203
|
'apprefix' => key,
|
203
204
|
'aplimit' => @options[:limit],
|
204
|
-
'apnamespace' => namespace}
|
205
|
+
'apnamespace' => namespace})
|
205
206
|
res, apfrom = make_api_request(form_data, '//query-continue/allpages/@apfrom')
|
206
207
|
titles += REXML::XPath.match(res, "//p").map { |x| x.attributes["title"] }
|
207
208
|
end while apfrom
|
@@ -396,7 +397,7 @@ module MediaWiki
|
|
396
397
|
end
|
397
398
|
end
|
398
399
|
|
399
|
-
# Download _file_name_. Returns file contents. All options are passed to
|
400
|
+
# Download _file_name_ (without "File:" or "Image:" prefix). Returns file contents. All options are passed to
|
400
401
|
# #image_info however options['iiprop'] is forced to url. You can still
|
401
402
|
# set other options to control what file you want to download.
|
402
403
|
def download(file_name, options={})
|
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.4.
|
8
|
+
s.version = "0.4.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{2011-
|
12
|
+
s.date = %q{2011-08-23}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{jpatokal@iki.fi}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,40 +19,16 @@ Gem::Specification.new do |s|
|
|
19
19
|
"README",
|
20
20
|
"Rakefile",
|
21
21
|
"config/hosts.yml",
|
22
|
-
"doc/classes/MediaWiki.html",
|
23
|
-
"doc/classes/MediaWiki/APIError.html",
|
24
|
-
"doc/classes/MediaWiki/Config.html",
|
25
|
-
"doc/classes/MediaWiki/Exception.html",
|
26
|
-
"doc/classes/MediaWiki/Gateway.html",
|
27
|
-
"doc/classes/MediaWiki/Unauthorized.html",
|
28
|
-
"doc/created.rid",
|
29
|
-
"doc/files/README.html",
|
30
|
-
"doc/files/lib/media_wiki/config_rb.html",
|
31
|
-
"doc/files/lib/media_wiki/exception_rb.html",
|
32
|
-
"doc/files/lib/media_wiki/gateway_rb.html",
|
33
|
-
"doc/files/lib/media_wiki/utils_rb.html",
|
34
|
-
"doc/files/script/create_page_rb.html",
|
35
|
-
"doc/files/script/delete_batch_rb.html",
|
36
|
-
"doc/files/script/export_xml_rb.html",
|
37
|
-
"doc/files/script/get_page_rb.html",
|
38
|
-
"doc/files/script/import_xml_rb.html",
|
39
|
-
"doc/files/script/run_fake_media_wiki_rb.html",
|
40
|
-
"doc/files/script/search_content_rb.html",
|
41
|
-
"doc/files/script/upload_commons_rb.html",
|
42
|
-
"doc/files/script/upload_file_rb.html",
|
43
|
-
"doc/fr_class_index.html",
|
44
|
-
"doc/fr_file_index.html",
|
45
|
-
"doc/fr_method_index.html",
|
46
|
-
"doc/index.html",
|
47
|
-
"doc/rdoc-style.css",
|
48
22
|
"lib/media_wiki.rb",
|
49
23
|
"lib/media_wiki/config.rb",
|
50
24
|
"lib/media_wiki/exception.rb",
|
51
25
|
"lib/media_wiki/gateway.rb",
|
52
26
|
"lib/media_wiki/utils.rb",
|
53
27
|
"mediawiki-gateway.gemspec",
|
28
|
+
"script/README",
|
54
29
|
"script/create_page.rb",
|
55
30
|
"script/delete_batch.rb",
|
31
|
+
"script/download_batch.rb",
|
56
32
|
"script/export_xml.rb",
|
57
33
|
"script/get_page.rb",
|
58
34
|
"script/import_xml.rb",
|
data/script/README
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Sample scripts using MediaWiki::Gateway. These expect to be run from the MediaWiki::Gateway root directory with ./config/hosts.yml accessible and configured with real usernames, passwords etc. Remove Logger::DEBUG from scripts for less verbose output.
|
2
|
+
|
3
|
+
Examples:
|
4
|
+
|
5
|
+
Check syntax for create page script
|
6
|
+
|
7
|
+
ruby script/create_page.rb
|
8
|
+
|
9
|
+
Pipe the content of "content.txt" into the page 'Sandbox:MediaWikiGatewayTest' on the English Wikipedia
|
10
|
+
|
11
|
+
ruby script/create_page.rb -h en-wp -a Sandbox:MediaWikiGatewayTest <content.txt
|
12
|
+
*or*
|
13
|
+
ruby script/create_page.rb --host en-wp --article Sandbox:MediaWikiGatewayTest <content.txt
|
14
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'lib/media_wiki'
|
2
|
+
|
3
|
+
config = MediaWiki::Config.new ARGV
|
4
|
+
|
5
|
+
mw = MediaWiki::Gateway.new(config.url, { :loglevel => Logger::DEBUG } )
|
6
|
+
mw.login(config.user, config.pw)
|
7
|
+
ARGF.readlines.each do |image|
|
8
|
+
image.strip!
|
9
|
+
unless File.exist? image
|
10
|
+
File.open(image, 'w') do |file|
|
11
|
+
file.write(mw.download(image))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
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: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.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: 2011-
|
18
|
+
date: 2011-08-23 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -102,40 +102,16 @@ files:
|
|
102
102
|
- README
|
103
103
|
- Rakefile
|
104
104
|
- config/hosts.yml
|
105
|
-
- doc/classes/MediaWiki.html
|
106
|
-
- doc/classes/MediaWiki/APIError.html
|
107
|
-
- doc/classes/MediaWiki/Config.html
|
108
|
-
- doc/classes/MediaWiki/Exception.html
|
109
|
-
- doc/classes/MediaWiki/Gateway.html
|
110
|
-
- doc/classes/MediaWiki/Unauthorized.html
|
111
|
-
- doc/created.rid
|
112
|
-
- doc/files/README.html
|
113
|
-
- doc/files/lib/media_wiki/config_rb.html
|
114
|
-
- doc/files/lib/media_wiki/exception_rb.html
|
115
|
-
- doc/files/lib/media_wiki/gateway_rb.html
|
116
|
-
- doc/files/lib/media_wiki/utils_rb.html
|
117
|
-
- doc/files/script/create_page_rb.html
|
118
|
-
- doc/files/script/delete_batch_rb.html
|
119
|
-
- doc/files/script/export_xml_rb.html
|
120
|
-
- doc/files/script/get_page_rb.html
|
121
|
-
- doc/files/script/import_xml_rb.html
|
122
|
-
- doc/files/script/run_fake_media_wiki_rb.html
|
123
|
-
- doc/files/script/search_content_rb.html
|
124
|
-
- doc/files/script/upload_commons_rb.html
|
125
|
-
- doc/files/script/upload_file_rb.html
|
126
|
-
- doc/fr_class_index.html
|
127
|
-
- doc/fr_file_index.html
|
128
|
-
- doc/fr_method_index.html
|
129
|
-
- doc/index.html
|
130
|
-
- doc/rdoc-style.css
|
131
105
|
- lib/media_wiki.rb
|
132
106
|
- lib/media_wiki/config.rb
|
133
107
|
- lib/media_wiki/exception.rb
|
134
108
|
- lib/media_wiki/gateway.rb
|
135
109
|
- lib/media_wiki/utils.rb
|
136
110
|
- mediawiki-gateway.gemspec
|
111
|
+
- script/README
|
137
112
|
- script/create_page.rb
|
138
113
|
- script/delete_batch.rb
|
114
|
+
- script/download_batch.rb
|
139
115
|
- script/export_xml.rb
|
140
116
|
- script/get_page.rb
|
141
117
|
- script/import_xml.rb
|
data/doc/classes/MediaWiki.html
DELETED
@@ -1,381 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
-
<head>
|
8
|
-
<title>Module: MediaWiki</title>
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
-
<script type="text/javascript">
|
13
|
-
// <![CDATA[
|
14
|
-
|
15
|
-
function popupCode( url ) {
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
-
}
|
18
|
-
|
19
|
-
function toggleCode( id ) {
|
20
|
-
if ( document.getElementById )
|
21
|
-
elem = document.getElementById( id );
|
22
|
-
else if ( document.all )
|
23
|
-
elem = eval( "document.all." + id );
|
24
|
-
else
|
25
|
-
return false;
|
26
|
-
|
27
|
-
elemStyle = elem.style;
|
28
|
-
|
29
|
-
if ( elemStyle.display != "block" ) {
|
30
|
-
elemStyle.display = "block"
|
31
|
-
} else {
|
32
|
-
elemStyle.display = "none"
|
33
|
-
}
|
34
|
-
|
35
|
-
return true;
|
36
|
-
}
|
37
|
-
|
38
|
-
// Make codeblocks hidden by default
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
-
|
41
|
-
// ]]>
|
42
|
-
</script>
|
43
|
-
|
44
|
-
</head>
|
45
|
-
<body>
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
<div id="classHeader">
|
50
|
-
<table class="header-table">
|
51
|
-
<tr class="top-aligned-row">
|
52
|
-
<td><strong>Module</strong></td>
|
53
|
-
<td class="class-name-in-header">MediaWiki</td>
|
54
|
-
</tr>
|
55
|
-
<tr class="top-aligned-row">
|
56
|
-
<td><strong>In:</strong></td>
|
57
|
-
<td>
|
58
|
-
<a href="../files/lib/media_wiki/config_rb.html">
|
59
|
-
lib/media_wiki/config.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
|
-
<a href="../files/lib/media_wiki/exception_rb.html">
|
63
|
-
lib/media_wiki/exception.rb
|
64
|
-
</a>
|
65
|
-
<br />
|
66
|
-
<a href="../files/lib/media_wiki/utils_rb.html">
|
67
|
-
lib/media_wiki/utils.rb
|
68
|
-
</a>
|
69
|
-
<br />
|
70
|
-
<a href="../files/lib/media_wiki/gateway_rb.html">
|
71
|
-
lib/media_wiki/gateway.rb
|
72
|
-
</a>
|
73
|
-
<br />
|
74
|
-
</td>
|
75
|
-
</tr>
|
76
|
-
|
77
|
-
</table>
|
78
|
-
</div>
|
79
|
-
<!-- banner header -->
|
80
|
-
|
81
|
-
<div id="bodyContent">
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
<div id="contextContent">
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
</div>
|
90
|
-
|
91
|
-
<div id="method-list">
|
92
|
-
<h3 class="section-bar">Methods</h3>
|
93
|
-
|
94
|
-
<div class="name-list">
|
95
|
-
<a href="#M000001">get_base_name</a>
|
96
|
-
<a href="#M000002">get_path_to_subpage</a>
|
97
|
-
<a href="#M000003">get_subpage</a>
|
98
|
-
<a href="#M000007">upcase_first_char</a>
|
99
|
-
<a href="#M000004">uri_to_wiki</a>
|
100
|
-
<a href="#M000006">version</a>
|
101
|
-
<a href="#M000005">wiki_to_uri</a>
|
102
|
-
</div>
|
103
|
-
</div>
|
104
|
-
|
105
|
-
</div>
|
106
|
-
|
107
|
-
|
108
|
-
<!-- if includes -->
|
109
|
-
|
110
|
-
<div id="section">
|
111
|
-
|
112
|
-
<div id="class-list">
|
113
|
-
<h3 class="section-bar">Classes and Modules</h3>
|
114
|
-
|
115
|
-
Class <a href="MediaWiki/APIError.html" class="link">MediaWiki::APIError</a><br />
|
116
|
-
Class <a href="MediaWiki/Config.html" class="link">MediaWiki::Config</a><br />
|
117
|
-
Class <a href="MediaWiki/Exception.html" class="link">MediaWiki::Exception</a><br />
|
118
|
-
Class <a href="MediaWiki/Gateway.html" class="link">MediaWiki::Gateway</a><br />
|
119
|
-
Class <a href="MediaWiki/Unauthorized.html" class="link">MediaWiki::Unauthorized</a><br />
|
120
|
-
|
121
|
-
</div>
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
<!-- if method_list -->
|
130
|
-
<div id="methods">
|
131
|
-
<h3 class="section-bar">Public Class methods</h3>
|
132
|
-
|
133
|
-
<div id="method-M000001" class="method-detail">
|
134
|
-
<a name="M000001"></a>
|
135
|
-
|
136
|
-
<div class="method-heading">
|
137
|
-
<a href="#M000001" class="method-signature">
|
138
|
-
<span class="method-name">get_base_name</span><span class="method-args">(title)</span>
|
139
|
-
</a>
|
140
|
-
</div>
|
141
|
-
|
142
|
-
<div class="method-description">
|
143
|
-
<p>
|
144
|
-
Extract base name. If there are no subpages, return page name.
|
145
|
-
</p>
|
146
|
-
<p>
|
147
|
-
Examples: <a
|
148
|
-
href="MediaWiki.html#M000001">get_base_name</a>("Namespace:Foo/Bar/Baz")
|
149
|
-
-> "Namespace:Foo" <a
|
150
|
-
href="MediaWiki.html#M000001">get_base_name</a>("Namespace:Foo")
|
151
|
-
-> "Namespace:Foo"
|
152
|
-
</p>
|
153
|
-
<dl>
|
154
|
-
<dt>title</dt><dd>Page name string in Wiki format
|
155
|
-
|
156
|
-
</dd>
|
157
|
-
</dl>
|
158
|
-
<p><a class="source-toggle" href="#"
|
159
|
-
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
160
|
-
<div class="method-source-code" id="M000001-source">
|
161
|
-
<pre>
|
162
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 11</span>
|
163
|
-
11: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_base_name</span>(<span class="ruby-identifier">title</span>)
|
164
|
-
12: <span class="ruby-identifier">title</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'/'</span>).<span class="ruby-identifier">first</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">title</span>
|
165
|
-
13: <span class="ruby-keyword kw">end</span>
|
166
|
-
</pre>
|
167
|
-
</div>
|
168
|
-
</div>
|
169
|
-
</div>
|
170
|
-
|
171
|
-
<div id="method-M000002" class="method-detail">
|
172
|
-
<a name="M000002"></a>
|
173
|
-
|
174
|
-
<div class="method-heading">
|
175
|
-
<a href="#M000002" class="method-signature">
|
176
|
-
<span class="method-name">get_path_to_subpage</span><span class="method-args">(title)</span>
|
177
|
-
</a>
|
178
|
-
</div>
|
179
|
-
|
180
|
-
<div class="method-description">
|
181
|
-
<p>
|
182
|
-
Extract path leading up to subpage. If title does not contain a subpage,
|
183
|
-
returns nil.
|
184
|
-
</p>
|
185
|
-
<p>
|
186
|
-
Examples: <a
|
187
|
-
href="MediaWiki.html#M000002">get_path_to_subpage</a>("Namespace:Foo/Bar/Baz")
|
188
|
-
-> "Namespace:Foo/Bar" <a
|
189
|
-
href="MediaWiki.html#M000002">get_path_to_subpage</a>("Namespace:Foo")
|
190
|
-
-> nil
|
191
|
-
</p>
|
192
|
-
<dl>
|
193
|
-
<dt>title</dt><dd>Page name string in Wiki format
|
194
|
-
|
195
|
-
</dd>
|
196
|
-
</dl>
|
197
|
-
<p><a class="source-toggle" href="#"
|
198
|
-
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
199
|
-
<div class="method-source-code" id="M000002-source">
|
200
|
-
<pre>
|
201
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 22</span>
|
202
|
-
22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_path_to_subpage</span>(<span class="ruby-identifier">title</span>)
|
203
|
-
23: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">title</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">title</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value str">'/'</span>
|
204
|
-
24: <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">title</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">/\/([^\/]*)$/</span>).<span class="ruby-identifier">first</span>
|
205
|
-
25: <span class="ruby-keyword kw">end</span>
|
206
|
-
</pre>
|
207
|
-
</div>
|
208
|
-
</div>
|
209
|
-
</div>
|
210
|
-
|
211
|
-
<div id="method-M000003" class="method-detail">
|
212
|
-
<a name="M000003"></a>
|
213
|
-
|
214
|
-
<div class="method-heading">
|
215
|
-
<a href="#M000003" class="method-signature">
|
216
|
-
<span class="method-name">get_subpage</span><span class="method-args">(title)</span>
|
217
|
-
</a>
|
218
|
-
</div>
|
219
|
-
|
220
|
-
<div class="method-description">
|
221
|
-
<p>
|
222
|
-
Extract subpage name. If there is no hierarchy above, return page name.
|
223
|
-
</p>
|
224
|
-
<p>
|
225
|
-
Examples: <a
|
226
|
-
href="MediaWiki.html#M000003">get_subpage</a>("Namespace:Foo/Bar/Baz")
|
227
|
-
-> "Baz" <a
|
228
|
-
href="MediaWiki.html#M000003">get_subpage</a>("Namespace:Foo")
|
229
|
-
-> "Namespace:Foo"
|
230
|
-
</p>
|
231
|
-
<dl>
|
232
|
-
<dt>title</dt><dd>Page name string in Wiki format
|
233
|
-
|
234
|
-
</dd>
|
235
|
-
</dl>
|
236
|
-
<p><a class="source-toggle" href="#"
|
237
|
-
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
238
|
-
<div class="method-source-code" id="M000003-source">
|
239
|
-
<pre>
|
240
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 34</span>
|
241
|
-
34: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_subpage</span>(<span class="ruby-identifier">title</span>)
|
242
|
-
35: <span class="ruby-identifier">title</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'/'</span>).<span class="ruby-identifier">last</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">title</span>
|
243
|
-
36: <span class="ruby-keyword kw">end</span>
|
244
|
-
</pre>
|
245
|
-
</div>
|
246
|
-
</div>
|
247
|
-
</div>
|
248
|
-
|
249
|
-
<div id="method-M000004" class="method-detail">
|
250
|
-
<a name="M000004"></a>
|
251
|
-
|
252
|
-
<div class="method-heading">
|
253
|
-
<a href="#M000004" class="method-signature">
|
254
|
-
<span class="method-name">uri_to_wiki</span><span class="method-args">(uri)</span>
|
255
|
-
</a>
|
256
|
-
</div>
|
257
|
-
|
258
|
-
<div class="method-description">
|
259
|
-
<p>
|
260
|
-
Convert URL-ized page name ("getting_there_%26_away") into Wiki
|
261
|
-
display format page name ("Getting there & away"). Also
|
262
|
-
capitalizes first letter, replaces underscores with spaces and strips out
|
263
|
-
any illegal characters (#<>[]|{}, cf. <a
|
264
|
-
href="http://meta.wikimedia.org/wiki/Help:Page_name#Restrictions">meta.wikimedia.org/wiki/Help:Page_name#Restrictions</a>).
|
265
|
-
</p>
|
266
|
-
<dl>
|
267
|
-
<dt>wiki</dt><dd>Page name string in URL
|
268
|
-
|
269
|
-
</dd>
|
270
|
-
</dl>
|
271
|
-
<p><a class="source-toggle" href="#"
|
272
|
-
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
273
|
-
<div class="method-source-code" id="M000004-source">
|
274
|
-
<pre>
|
275
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 42</span>
|
276
|
-
42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uri_to_wiki</span>(<span class="ruby-identifier">uri</span>)
|
277
|
-
43: <span class="ruby-identifier">upcase_first_char</span>(<span class="ruby-constant">CGI</span>.<span class="ruby-identifier">unescape</span>(<span class="ruby-identifier">uri</span>).<span class="ruby-identifier">tr</span>(<span class="ruby-value str">'_'</span>, <span class="ruby-value str">' '</span>).<span class="ruby-identifier">tr</span>(<span class="ruby-value str">'#<>[]|{}'</span>, <span class="ruby-value str">''</span>)) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span>
|
278
|
-
44: <span class="ruby-keyword kw">end</span>
|
279
|
-
</pre>
|
280
|
-
</div>
|
281
|
-
</div>
|
282
|
-
</div>
|
283
|
-
|
284
|
-
<div id="method-M000006" class="method-detail">
|
285
|
-
<a name="M000006"></a>
|
286
|
-
|
287
|
-
<div class="method-heading">
|
288
|
-
<a href="#M000006" class="method-signature">
|
289
|
-
<span class="method-name">version</span><span class="method-args">()</span>
|
290
|
-
</a>
|
291
|
-
</div>
|
292
|
-
|
293
|
-
<div class="method-description">
|
294
|
-
<p>
|
295
|
-
Return current <a href="MediaWiki.html#M000006">version</a> of <a
|
296
|
-
href="MediaWiki/Gateway.html">MediaWiki::Gateway</a>
|
297
|
-
</p>
|
298
|
-
<p><a class="source-toggle" href="#"
|
299
|
-
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
300
|
-
<div class="method-source-code" id="M000006-source">
|
301
|
-
<pre>
|
302
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 54</span>
|
303
|
-
54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">version</span>
|
304
|
-
55: <span class="ruby-constant">MediaWiki</span><span class="ruby-operator">::</span><span class="ruby-constant">VERSION</span>
|
305
|
-
56: <span class="ruby-keyword kw">end</span>
|
306
|
-
</pre>
|
307
|
-
</div>
|
308
|
-
</div>
|
309
|
-
</div>
|
310
|
-
|
311
|
-
<div id="method-M000005" class="method-detail">
|
312
|
-
<a name="M000005"></a>
|
313
|
-
|
314
|
-
<div class="method-heading">
|
315
|
-
<a href="#M000005" class="method-signature">
|
316
|
-
<span class="method-name">wiki_to_uri</span><span class="method-args">(wiki)</span>
|
317
|
-
</a>
|
318
|
-
</div>
|
319
|
-
|
320
|
-
<div class="method-description">
|
321
|
-
<p>
|
322
|
-
Convert a Wiki page name ("Getting there & away") to URI-safe
|
323
|
-
format ("Getting_there_%26_away"), taking care not to mangle
|
324
|
-
slashes or colons
|
325
|
-
</p>
|
326
|
-
<dl>
|
327
|
-
<dt>wiki</dt><dd>Page name string in Wiki format
|
328
|
-
|
329
|
-
</dd>
|
330
|
-
</dl>
|
331
|
-
<p><a class="source-toggle" href="#"
|
332
|
-
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
333
|
-
<div class="method-source-code" id="M000005-source">
|
334
|
-
<pre>
|
335
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 49</span>
|
336
|
-
49: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wiki_to_uri</span>(<span class="ruby-identifier">wiki</span>)
|
337
|
-
50: <span class="ruby-identifier">wiki</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'/'</span>).<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">chunk</span><span class="ruby-operator">|</span> <span class="ruby-constant">CGI</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">chunk</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-value str">' '</span>, <span class="ruby-value str">'_'</span>)) }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'/'</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'%3A'</span>, <span class="ruby-value str">':'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">wiki</span>
|
338
|
-
51: <span class="ruby-keyword kw">end</span>
|
339
|
-
</pre>
|
340
|
-
</div>
|
341
|
-
</div>
|
342
|
-
</div>
|
343
|
-
|
344
|
-
<h3 class="section-bar">Private Class methods</h3>
|
345
|
-
|
346
|
-
<div id="method-M000007" class="method-detail">
|
347
|
-
<a name="M000007"></a>
|
348
|
-
|
349
|
-
<div class="method-heading">
|
350
|
-
<a href="#M000007" class="method-signature">
|
351
|
-
<span class="method-name">upcase_first_char</span><span class="method-args">(str)</span>
|
352
|
-
</a>
|
353
|
-
</div>
|
354
|
-
|
355
|
-
<div class="method-description">
|
356
|
-
<p><a class="source-toggle" href="#"
|
357
|
-
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
358
|
-
<div class="method-source-code" id="M000007-source">
|
359
|
-
<pre>
|
360
|
-
<span class="ruby-comment cmt"># File lib/media_wiki/utils.rb, line 60</span>
|
361
|
-
60: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">upcase_first_char</span>(<span class="ruby-identifier">str</span>)
|
362
|
-
61: [ <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Multibyte</span><span class="ruby-operator">::</span><span class="ruby-constant">Chars</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">str</span>.<span class="ruby-identifier">mb_chars</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-value">0</span>,<span class="ruby-value">1</span>)).<span class="ruby-identifier">upcase</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">str</span>.<span class="ruby-identifier">mb_chars</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>) ].<span class="ruby-identifier">join</span>
|
363
|
-
62: <span class="ruby-keyword kw">end</span>
|
364
|
-
</pre>
|
365
|
-
</div>
|
366
|
-
</div>
|
367
|
-
</div>
|
368
|
-
|
369
|
-
|
370
|
-
</div>
|
371
|
-
|
372
|
-
|
373
|
-
</div>
|
374
|
-
|
375
|
-
|
376
|
-
<div id="validator-badges">
|
377
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
378
|
-
</div>
|
379
|
-
|
380
|
-
</body>
|
381
|
-
</html>
|