|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Peachy MediaWiki Bot API |
|
5
|
|
|
* |
|
6
|
|
|
* Peachy is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License |
|
17
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
class RPED { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Wiki class |
|
24
|
|
|
* |
|
25
|
|
|
* @var Wiki |
|
26
|
|
|
* @access private |
|
27
|
|
|
*/ |
|
28
|
|
|
private $wiki; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* maxURLLength |
|
32
|
|
|
* Default maximum length of the URL to be posted |
|
33
|
|
|
* |
|
34
|
|
|
* @var int |
|
35
|
|
|
* @access private |
|
36
|
|
|
*/ |
|
37
|
|
|
private $defaultMaxURLLength; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Construction method for the RPED class |
|
41
|
|
|
* |
|
42
|
|
|
* @access public |
|
43
|
|
|
* @param Wiki &$wikiClass The Wiki class object |
|
44
|
|
|
*/ |
|
45
|
|
|
function __construct( Wiki &$wikiClass ) { |
|
|
|
|
|
|
46
|
|
|
$this->wiki = $wikiClass; |
|
47
|
|
|
$defaultMaxURLLength = 2000; |
|
|
|
|
|
|
48
|
|
|
return; |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Insert a page title into the rped_page table |
|
53
|
|
|
* |
|
54
|
|
|
* @static |
|
55
|
|
|
* @access public |
|
56
|
|
|
* @param string $page |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
public function insert( $page ) { |
|
60
|
|
|
$this->wiki->apiQuery( |
|
61
|
|
|
array( |
|
62
|
|
|
'action' => 'rped', |
|
63
|
|
|
'insert' => $page, |
|
64
|
|
|
), true |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Delete a page title from the rped_page table |
|
70
|
|
|
* |
|
71
|
|
|
* @static |
|
72
|
|
|
* @access public |
|
73
|
|
|
* @param string $page |
|
74
|
|
|
* @return void |
|
75
|
|
|
*/ |
|
76
|
|
|
public function delete( $page ) { |
|
77
|
|
|
$this->wiki->apiQuery( |
|
78
|
|
|
array( |
|
79
|
|
|
'action' => 'rped', |
|
80
|
|
|
'delete' => $page, |
|
81
|
|
|
), true |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Insert/delete an array of page titles into/from the rped_page table |
|
87
|
|
|
* |
|
88
|
|
|
* @static |
|
89
|
|
|
* @access public |
|
90
|
|
|
* @param string $command Either 'insert' or 'delete' |
|
91
|
|
|
* @param array $pageArray The array of page title to insert |
|
92
|
|
|
* @param int $maxURLLength The maximum length of the url to be POSTed |
|
93
|
|
|
* @return void |
|
94
|
|
|
*/ |
|
95
|
|
|
public function insertOrDeleteArray( $command, $pageArray, $maxURLLength = 0 ) { |
|
96
|
|
|
if( $command != 'insert' && $command != 'delete' ) { |
|
97
|
|
|
die( 'Something tried to call insertOrDeleteArray without' |
|
|
|
|
|
|
98
|
|
|
. 'specifying an insert or delete command.' ); |
|
99
|
|
|
} |
|
100
|
|
|
if( $maxURLLength == 0 ) { |
|
101
|
|
|
$maxURLLength = $this->defaultMaxURLLength; |
|
102
|
|
|
} |
|
103
|
|
|
$line = ''; |
|
104
|
|
|
foreach( $pageArray as $page ){ |
|
105
|
|
|
if( $line != '' ) { |
|
106
|
|
|
$line .= '|'; |
|
107
|
|
|
} |
|
108
|
|
|
if( strlen( $line ) + strlen( $page ) > $maxURLLength ) { |
|
109
|
|
|
if( $command == 'delete' ) { |
|
110
|
|
|
$this->delete( $line ); |
|
111
|
|
|
} else { |
|
112
|
|
|
$this->insert( $line ); |
|
113
|
|
|
} |
|
114
|
|
|
$line = ''; |
|
115
|
|
|
} |
|
116
|
|
|
$line .= $page; |
|
117
|
|
|
} |
|
118
|
|
|
if( $command == 'delete' ) { |
|
119
|
|
|
$this->delete( $line ); |
|
120
|
|
|
} else { |
|
121
|
|
|
$this->insert( $line ); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Insert an array of page titles into/from the rped_page table |
|
127
|
|
|
* |
|
128
|
|
|
* @static |
|
129
|
|
|
* @access public |
|
130
|
|
|
* @param array $pageArray The array of page title to insert |
|
131
|
|
|
* @param int $maxURLLength The maximum length of the url to be POSTed |
|
132
|
|
|
* @return void |
|
133
|
|
|
*/ |
|
134
|
|
|
public function insertArray( $pageArray, $maxURLLength = 0 ) { |
|
135
|
|
|
$this->insertOrDeleteArray( 'insert', $pageArray, $maxURLLength ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Delete an array of page titles from the rped_page table |
|
140
|
|
|
* |
|
141
|
|
|
* @static |
|
142
|
|
|
* @access public |
|
143
|
|
|
* @param array $pageArray The array of page title to insert |
|
144
|
|
|
* @param int $maxURLLength The maximum length of the url to be POSTed |
|
145
|
|
|
* @return void |
|
146
|
|
|
*/ |
|
147
|
|
|
public function deleteArray( $pageArray, $maxURLLength = 0 ) { |
|
148
|
|
|
$this->insertOrDeleteArray( 'delete', $pageArray, $maxURLLength ); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.