mediawiki-gateway 0.3.8 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/classes/MediaWiki.html +8 -1
- data/doc/classes/MediaWiki/APIError.html +186 -0
- data/doc/classes/MediaWiki/Config.html +12 -12
- data/doc/classes/MediaWiki/Exception.html +122 -0
- data/doc/classes/MediaWiki/Gateway.html +740 -530
- data/doc/classes/MediaWiki/Unauthorized.html +120 -0
- data/doc/created.rid +1 -1
- data/doc/files/README.html +12 -3
- data/doc/files/lib/media_wiki/exception_rb.html +101 -0
- data/doc/files/lib/media_wiki/gateway_rb.html +2 -1
- data/doc/files/lib/media_wiki/utils_rb.html +1 -1
- data/doc/fr_class_index.html +3 -0
- data/doc/fr_file_index.html +1 -0
- data/doc/fr_method_index.html +32 -26
- data/lib/media_wiki.rb +2 -1
- data/lib/media_wiki/exception.rb +22 -0
- data/lib/media_wiki/gateway.rb +15 -14
- data/lib/media_wiki/utils.rb +1 -3
- data/mediawiki-gateway.gemspec +7 -2
- data/spec/gateway_spec.rb +11 -11
- data/spec/spec_helper.rb +4 -6
- data/spec/utils_spec.rb +4 -0
- metadata +10 -5
@@ -0,0 +1,120 @@
|
|
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>Class: MediaWiki::Unauthorized</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>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">MediaWiki::Unauthorized</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/media_wiki/exception_rb.html">
|
59
|
+
lib/media_wiki/exception.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
<a href="Exception.html">
|
69
|
+
MediaWiki::Exception
|
70
|
+
</a>
|
71
|
+
</td>
|
72
|
+
</tr>
|
73
|
+
</table>
|
74
|
+
</div>
|
75
|
+
<!-- banner header -->
|
76
|
+
|
77
|
+
<div id="bodyContent">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<div id="contextContent">
|
82
|
+
|
83
|
+
<div id="description">
|
84
|
+
<p>
|
85
|
+
User is not authorized to perform this operation. Also thrown if <a
|
86
|
+
href="Gateway.html#M000009">MediaWiki::Gateway#login</a> fails.
|
87
|
+
</p>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
</div>
|
93
|
+
|
94
|
+
|
95
|
+
</div>
|
96
|
+
|
97
|
+
|
98
|
+
<!-- if includes -->
|
99
|
+
|
100
|
+
<div id="section">
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
<!-- if method_list -->
|
110
|
+
|
111
|
+
|
112
|
+
</div>
|
113
|
+
|
114
|
+
|
115
|
+
<div id="validator-badges">
|
116
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
117
|
+
</div>
|
118
|
+
|
119
|
+
</body>
|
120
|
+
</html>
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Wed, 20 Apr 2011 16:25:00 +1000
|
data/doc/files/README.html
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Wed Mar 30 13:32:04 +1100 2011</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -117,9 +117,18 @@ Simple page creation script:
|
|
117
117
|
Maintained by Jani Patokallio.
|
118
118
|
</p>
|
119
119
|
<p>
|
120
|
-
Thanks to
|
121
|
-
Lonely Planet Atlas team.
|
120
|
+
Thanks to:
|
122
121
|
</p>
|
122
|
+
<ul>
|
123
|
+
<li>John Carney, Mike Williams, Daniel Heath and the rest of the Lonely Planet
|
124
|
+
Atlas team.
|
125
|
+
|
126
|
+
</li>
|
127
|
+
<li>Github users arturaz, carpodaster, muffinista and singlebrook for code
|
128
|
+
contributions
|
129
|
+
|
130
|
+
</li>
|
131
|
+
</ul>
|
123
132
|
|
124
133
|
</div>
|
125
134
|
|
@@ -0,0 +1,101 @@
|
|
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>File: exception.rb</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="fileHeader">
|
50
|
+
<h1>exception.rb</h1>
|
51
|
+
<table class="header-table">
|
52
|
+
<tr class="top-aligned-row">
|
53
|
+
<td><strong>Path:</strong></td>
|
54
|
+
<td>lib/media_wiki/exception.rb
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tr class="top-aligned-row">
|
58
|
+
<td><strong>Last Update:</strong></td>
|
59
|
+
<td>Wed Apr 20 16:18:20 +1000 2011</td>
|
60
|
+
</tr>
|
61
|
+
</table>
|
62
|
+
</div>
|
63
|
+
<!-- banner header -->
|
64
|
+
|
65
|
+
<div id="bodyContent">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<div id="contextContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
</div>
|
74
|
+
|
75
|
+
|
76
|
+
</div>
|
77
|
+
|
78
|
+
|
79
|
+
<!-- if includes -->
|
80
|
+
|
81
|
+
<div id="section">
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
<!-- if method_list -->
|
91
|
+
|
92
|
+
|
93
|
+
</div>
|
94
|
+
|
95
|
+
|
96
|
+
<div id="validator-badges">
|
97
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
98
|
+
</div>
|
99
|
+
|
100
|
+
</body>
|
101
|
+
</html>
|
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Wed Apr 20 16:16:59 +1000 2011</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -78,6 +78,7 @@
|
|
78
78
|
rest_client
|
79
79
|
rexml/document
|
80
80
|
uri
|
81
|
+
active_support
|
81
82
|
</div>
|
82
83
|
</div>
|
83
84
|
|
data/doc/fr_class_index.html
CHANGED
@@ -21,8 +21,11 @@
|
|
21
21
|
<h1 class="section-bar">Classes</h1>
|
22
22
|
<div id="index-entries">
|
23
23
|
<a href="classes/MediaWiki.html">MediaWiki</a><br />
|
24
|
+
<a href="classes/MediaWiki/APIError.html">MediaWiki::APIError</a><br />
|
24
25
|
<a href="classes/MediaWiki/Config.html">MediaWiki::Config</a><br />
|
26
|
+
<a href="classes/MediaWiki/Exception.html">MediaWiki::Exception</a><br />
|
25
27
|
<a href="classes/MediaWiki/Gateway.html">MediaWiki::Gateway</a><br />
|
28
|
+
<a href="classes/MediaWiki/Unauthorized.html">MediaWiki::Unauthorized</a><br />
|
26
29
|
</div>
|
27
30
|
</div>
|
28
31
|
</body>
|
data/doc/fr_file_index.html
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
<div id="index-entries">
|
23
23
|
<a href="files/README.html">README</a><br />
|
24
24
|
<a href="files/lib/media_wiki/config_rb.html">lib/media_wiki/config.rb</a><br />
|
25
|
+
<a href="files/lib/media_wiki/exception_rb.html">lib/media_wiki/exception.rb</a><br />
|
25
26
|
<a href="files/lib/media_wiki/gateway_rb.html">lib/media_wiki/gateway.rb</a><br />
|
26
27
|
<a href="files/lib/media_wiki/utils_rb.html">lib/media_wiki/utils.rb</a><br />
|
27
28
|
<a href="files/script/create_page_rb.html">script/create_page.rb</a><br />
|
data/doc/fr_method_index.html
CHANGED
@@ -20,41 +20,47 @@
|
|
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#
|
23
|
+
<a href="classes/MediaWiki/Config.html#M000041">abort (MediaWiki::Config)</a><br />
|
24
|
+
<a href="classes/MediaWiki/Gateway.html#M000019">backlinks (MediaWiki::Gateway)</a><br />
|
25
|
+
<a href="classes/MediaWiki/Gateway.html#M000013">create (MediaWiki::Gateway)</a><br />
|
26
|
+
<a href="classes/MediaWiki/Gateway.html#M000016">delete (MediaWiki::Gateway)</a><br />
|
27
|
+
<a href="classes/MediaWiki/Gateway.html#M000024">download (MediaWiki::Gateway)</a><br />
|
28
|
+
<a href="classes/MediaWiki/Gateway.html#M000014">edit (MediaWiki::Gateway)</a><br />
|
29
|
+
<a href="classes/MediaWiki/Gateway.html#M000026">export (MediaWiki::Gateway)</a><br />
|
30
|
+
<a href="classes/MediaWiki/Gateway.html#M000028">extensions (MediaWiki::Gateway)</a><br />
|
31
31
|
<a href="classes/MediaWiki/Gateway.html#M000010">get (MediaWiki::Gateway)</a><br />
|
32
32
|
<a href="classes/MediaWiki.html#M000001">get_base_name (MediaWiki)</a><br />
|
33
33
|
<a href="classes/MediaWiki.html#M000002">get_path_to_subpage (MediaWiki)</a><br />
|
34
|
-
<a href="classes/MediaWiki/Gateway.html#
|
34
|
+
<a href="classes/MediaWiki/Gateway.html#M000037">get_response (MediaWiki::Gateway)</a><br />
|
35
35
|
<a href="classes/MediaWiki.html#M000003">get_subpage (MediaWiki)</a><br />
|
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/Gateway.html#
|
40
|
-
<a href="classes/MediaWiki/Gateway.html#
|
36
|
+
<a href="classes/MediaWiki/Gateway.html#M000032">get_token (MediaWiki::Gateway)</a><br />
|
37
|
+
<a href="classes/MediaWiki/Gateway.html#M000033">get_undelete_token (MediaWiki::Gateway)</a><br />
|
38
|
+
<a href="classes/MediaWiki/Gateway.html#M000034">get_userrights_token (MediaWiki::Gateway)</a><br />
|
39
|
+
<a href="classes/MediaWiki/Gateway.html#M000023">image_info (MediaWiki::Gateway)</a><br />
|
40
|
+
<a href="classes/MediaWiki/Gateway.html#M000025">import (MediaWiki::Gateway)</a><br />
|
41
|
+
<a href="classes/MediaWiki/Gateway.html#M000018">list (MediaWiki::Gateway)</a><br />
|
41
42
|
<a href="classes/MediaWiki/Gateway.html#M000009">login (MediaWiki::Gateway)</a><br />
|
42
|
-
<a href="classes/MediaWiki/Gateway.html#
|
43
|
-
<a href="classes/MediaWiki/Gateway.html#
|
44
|
-
<a href="classes/MediaWiki/Gateway.html#
|
43
|
+
<a href="classes/MediaWiki/Gateway.html#M000036">make_api_request (MediaWiki::Gateway)</a><br />
|
44
|
+
<a href="classes/MediaWiki/Gateway.html#M000015">move (MediaWiki::Gateway)</a><br />
|
45
|
+
<a href="classes/MediaWiki/Gateway.html#M000027">namespaces_by_prefix (MediaWiki::Gateway)</a><br />
|
45
46
|
<a href="classes/MediaWiki/Gateway.html#M000008">new (MediaWiki::Gateway)</a><br />
|
46
|
-
<a href="classes/MediaWiki/Config.html#
|
47
|
-
<a href="classes/MediaWiki/
|
48
|
-
<a href="classes/MediaWiki/Gateway.html#
|
49
|
-
<a href="classes/MediaWiki/Gateway.html#
|
50
|
-
<a href="classes/MediaWiki/Gateway.html#
|
51
|
-
<a href="classes/MediaWiki/Gateway.html#
|
47
|
+
<a href="classes/MediaWiki/Config.html#M000040">new (MediaWiki::Config)</a><br />
|
48
|
+
<a href="classes/MediaWiki/APIError.html#M000042">new (MediaWiki::APIError)</a><br />
|
49
|
+
<a href="classes/MediaWiki/Gateway.html#M000022">redirect? (MediaWiki::Gateway)</a><br />
|
50
|
+
<a href="classes/MediaWiki/Gateway.html#M000012">render (MediaWiki::Gateway)</a><br />
|
51
|
+
<a href="classes/MediaWiki/Gateway.html#M000031">review (MediaWiki::Gateway)</a><br />
|
52
|
+
<a href="classes/MediaWiki/Gateway.html#M000011">revision (MediaWiki::Gateway)</a><br />
|
53
|
+
<a href="classes/MediaWiki/Gateway.html#M000020">search (MediaWiki::Gateway)</a><br />
|
54
|
+
<a href="classes/MediaWiki/Gateway.html#M000029">semantic_query (MediaWiki::Gateway)</a><br />
|
55
|
+
<a href="classes/MediaWiki/Gateway.html#M000030">set_groups (MediaWiki::Gateway)</a><br />
|
56
|
+
<a href="classes/MediaWiki/Gateway.html#M000017">undelete (MediaWiki::Gateway)</a><br />
|
52
57
|
<a href="classes/MediaWiki.html#M000007">upcase_first_char (MediaWiki)</a><br />
|
53
|
-
<a href="classes/MediaWiki/Gateway.html#
|
58
|
+
<a href="classes/MediaWiki/Gateway.html#M000021">upload (MediaWiki::Gateway)</a><br />
|
54
59
|
<a href="classes/MediaWiki.html#M000004">uri_to_wiki (MediaWiki)</a><br />
|
55
|
-
<a href="classes/MediaWiki/Gateway.html#
|
60
|
+
<a href="classes/MediaWiki/Gateway.html#M000035">userrights (MediaWiki::Gateway)</a><br />
|
61
|
+
<a href="classes/MediaWiki/Gateway.html#M000038">valid_page? (MediaWiki::Gateway)</a><br />
|
56
62
|
<a href="classes/MediaWiki.html#M000006">version (MediaWiki)</a><br />
|
57
|
-
<a href="classes/MediaWiki/Gateway.html#
|
63
|
+
<a href="classes/MediaWiki/Gateway.html#M000039">warning (MediaWiki::Gateway)</a><br />
|
58
64
|
<a href="classes/MediaWiki.html#M000005">wiki_to_uri (MediaWiki)</a><br />
|
59
65
|
</div>
|
60
66
|
</div>
|
data/lib/media_wiki.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/media_wiki/config'
|
2
|
+
require File.dirname(__FILE__) + '/media_wiki/exception'
|
2
3
|
require File.dirname(__FILE__) + '/media_wiki/utils'
|
3
4
|
require File.dirname(__FILE__) + '/media_wiki/gateway'
|
4
5
|
|
5
6
|
module MediaWiki
|
6
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.4.1"
|
7
8
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MediaWiki
|
2
|
+
# General exception occurred within MediaWiki::Gateway, and parent class for MediaWiki::APIError, MediaWiki::Unauthorized.
|
3
|
+
class Exception < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
# Wrapper for errors returned by MediaWiki API. Possible codes are defined in http://www.mediawiki.org/wiki/API:Errors_and_warnings.
|
7
|
+
#
|
8
|
+
# Warnings also throw errors with code 'warning', unless MediaWiki::Gateway#new was called with :ignorewarnings.
|
9
|
+
class APIError < MediaWiki::Exception
|
10
|
+
attr_reader :code, :info, :message
|
11
|
+
|
12
|
+
def initialize(code, info)
|
13
|
+
@code = code
|
14
|
+
@info = info
|
15
|
+
@message = "API error: code '#{code}', info '#{info}'"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# User is not authorized to perform this operation. Also thrown if MediaWiki::Gateway#login fails.
|
20
|
+
class Unauthorized < MediaWiki::Exception
|
21
|
+
end
|
22
|
+
end
|
data/lib/media_wiki/gateway.rb
CHANGED
@@ -3,6 +3,7 @@ require 'logger'
|
|
3
3
|
require 'rest_client'
|
4
4
|
require 'rexml/document'
|
5
5
|
require 'uri'
|
6
|
+
require 'active_support'
|
6
7
|
|
7
8
|
module MediaWiki
|
8
9
|
|
@@ -15,7 +16,7 @@ module MediaWiki
|
|
15
16
|
# [options] Hash of options
|
16
17
|
#
|
17
18
|
# Options:
|
18
|
-
# [:ignorewarnings] Log API warnings and invalid page titles, instead
|
19
|
+
# [:ignorewarnings] Log API warnings and invalid page titles, instead throwing MediaWiki::APIError
|
19
20
|
# [:limit] Maximum number of results returned per search (see http://www.mediawiki.org/wiki/API:Query_-_Lists#Limits), defaults to the MediaWiki default of 500.
|
20
21
|
# [:loglevel] Log level to use, defaults to Logger::WARN. Set to Logger::DEBUG to dump every request and response to the log.
|
21
22
|
# [:maxlag] Maximum allowed server lag (see http://www.mediawiki.org/wiki/Manual:Maxlag_parameter), defaults to 5 seconds.
|
@@ -45,7 +46,7 @@ module MediaWiki
|
|
45
46
|
# [password] Password
|
46
47
|
# [domain] Domain for authentication plugin logins (eg. LDAP), optional -- defaults to 'local' if not given
|
47
48
|
#
|
48
|
-
# Throws
|
49
|
+
# Throws MediaWiki::Unauthorized if login fails
|
49
50
|
def login(username, password, domain = 'local')
|
50
51
|
form_data = {'action' => 'login', 'lgname' => username, 'lgpassword' => password, 'lgdomain' => domain}
|
51
52
|
make_api_request(form_data)
|
@@ -489,7 +490,7 @@ module MediaWiki
|
|
489
490
|
# [flags] Hash of flags and values to set, eg. { "accuracy" => "1", "depth" => "2" }
|
490
491
|
# [comment] Comment to add to review (optional)
|
491
492
|
def review(title, flags, comment = "Reviewed by MediaWiki::Gateway")
|
492
|
-
raise "
|
493
|
+
raise APIError.new('missingtitle', "Article #{title} not found") unless revid = revision(title)
|
493
494
|
form_data = {'action' => 'review', 'revid' => revid, 'token' => get_token('edit', title), 'comment' => comment}
|
494
495
|
form_data.merge!( Hash[flags.map {|k,v| ["flag_#{k}", v]}] )
|
495
496
|
res, dummy = make_api_request(form_data)
|
@@ -503,7 +504,7 @@ module MediaWiki
|
|
503
504
|
form_data = {'action' => 'query', 'prop' => 'info', 'intoken' => type, 'titles' => page_titles}
|
504
505
|
res, dummy = make_api_request(form_data)
|
505
506
|
token = res.elements["query/pages/page"].attributes[type + "token"]
|
506
|
-
raise "User is not permitted to perform this operation: #{type}" if token.nil?
|
507
|
+
raise Unauthorized.new "User is not permitted to perform this operation: #{type}" if token.nil?
|
507
508
|
token
|
508
509
|
end
|
509
510
|
|
@@ -512,7 +513,7 @@ module MediaWiki
|
|
512
513
|
res, dummy = make_api_request(form_data)
|
513
514
|
if res.elements["query/deletedrevs/page"]
|
514
515
|
token = res.elements["query/deletedrevs/page"].attributes["token"]
|
515
|
-
raise "User is not permitted to perform this operation: #{type}" if token.nil?
|
516
|
+
raise Unauthorized.new "User is not permitted to perform this operation: #{type}" if token.nil?
|
516
517
|
token
|
517
518
|
else
|
518
519
|
nil
|
@@ -528,9 +529,9 @@ module MediaWiki
|
|
528
529
|
@log.debug("RESPONSE: #{res.to_s}")
|
529
530
|
if token.nil?
|
530
531
|
if res.elements["query/users/user"].attributes["missing"]
|
531
|
-
raise "User '#{user}' was not found (get_userrights_token)"
|
532
|
+
raise APIError.new('invaliduser', "User '#{user}' was not found (get_userrights_token)")
|
532
533
|
else
|
533
|
-
raise "User '#{@username}' is not permitted to perform this operation: get_userrights_token"
|
534
|
+
raise Unauthorized.new "User '#{@username}' is not permitted to perform this operation: get_userrights_token"
|
534
535
|
end
|
535
536
|
end
|
536
537
|
|
@@ -575,7 +576,7 @@ module MediaWiki
|
|
575
576
|
make_api_request(form_data, continue_xpath, retry_count + 1)
|
576
577
|
end
|
577
578
|
# Check response for errors and return XML
|
578
|
-
raise "
|
579
|
+
raise MediaWiki::Exception.new "Bad response: #{response}" unless response.code >= 200 and response.code < 300
|
579
580
|
doc = get_response(response.dup)
|
580
581
|
if(form_data['action'] == 'login')
|
581
582
|
login_result = doc.elements["login"].attributes['result']
|
@@ -583,7 +584,7 @@ module MediaWiki
|
|
583
584
|
case login_result
|
584
585
|
when "Success" then # do nothing
|
585
586
|
when "NeedToken" then make_api_request(form_data.merge('lgtoken' => doc.elements["login"].attributes["token"]))
|
586
|
-
else raise "Login failed: " + login_result
|
587
|
+
else raise Unauthorized.new "Login failed: " + login_result
|
587
588
|
end
|
588
589
|
end
|
589
590
|
continue = (continue_xpath and doc.elements['query-continue']) ? REXML::XPath.first(doc, continue_xpath).value : nil
|
@@ -592,20 +593,20 @@ module MediaWiki
|
|
592
593
|
end
|
593
594
|
|
594
595
|
# Get API XML response
|
595
|
-
# If there are errors or warnings, raise
|
596
|
+
# If there are errors or warnings, raise APIError
|
596
597
|
# Otherwise return XML root
|
597
598
|
def get_response(res)
|
598
599
|
begin
|
599
600
|
doc = REXML::Document.new(res).root
|
600
601
|
rescue REXML::ParseException => e
|
601
|
-
raise "Response is not XML. Are you sure you are pointing to api.php?"
|
602
|
+
raise MediaWiki::Exception.new "Response is not XML. Are you sure you are pointing to api.php?"
|
602
603
|
end
|
603
604
|
log.debug("RES: #{doc}")
|
604
|
-
raise "Response does not contain Mediawiki API XML: #{res}" unless [ "api", "mediawiki" ].include? doc.name
|
605
|
+
raise MediaWiki::Exception.new "Response does not contain Mediawiki API XML: #{res}" unless [ "api", "mediawiki" ].include? doc.name
|
605
606
|
if doc.elements["error"]
|
606
607
|
code = doc.elements["error"].attributes["code"]
|
607
608
|
info = doc.elements["error"].attributes["info"]
|
608
|
-
raise
|
609
|
+
raise APIError.new(code, info)
|
609
610
|
end
|
610
611
|
if doc.elements["warnings"]
|
611
612
|
warning("API warning: #{doc.elements["warnings"].children.map {|e| e.text}.join(", ")}")
|
@@ -628,7 +629,7 @@ module MediaWiki
|
|
628
629
|
log.warn(msg)
|
629
630
|
return false
|
630
631
|
else
|
631
|
-
raise msg
|
632
|
+
raise APIError.new('warning', msg)
|
632
633
|
end
|
633
634
|
end
|
634
635
|
end
|