forked from huggle/huggle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPage.vb
247 lines (202 loc) · 7.32 KB
/
Page.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
'This is a source code or part of Huggle project
'Copyright (C) 2011 Huggle team
'This program is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 3 of the License, or
'(at your option) any later version.
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
<DebuggerDisplay("{Name}")> <DebuggerStepThrough()> _
Class Page
'Represents a MediaWiki page
Private _Name As String
Private _Space As Space
Private _Exists As Boolean
Private Shared All As New Dictionary(Of String, Page)
Public FirstEdit As Edit 'First edit
Public LastEdit As Edit 'Current edit
Public Level As PageLevel
Public Deletes As List(Of Delete)
Public DeletesCurrent As Boolean
Public Protections As List(Of Protection)
Public ProtectionsCurrent As Boolean
Public HistoryOffset As String
Public Patrolled As Boolean
Public Rcid As String
Public SpeedyCriterion As SpeedyCriterion
Public Text As String
Public EditLevel As String
Public Pending As Boolean = False
Public MoveLevel As String
Private Sub New(ByVal Name As String)
_Name = Name
_Space = Space.GetSpace(_Name)
All.Add(_Name, Me)
End Sub
Public ReadOnly Property BaseName() As String
Get
If Space Is Space.Article OrElse Name.Length <= Space.Name.Length + 1 Then Return Name _
Else Return Name.Substring(Space.Name.Length + 1)
End Get
End Property
Public ReadOnly Property Creator() As User
Get
If FirstEdit Is Nothing Then Return Nothing
Return FirstEdit.User
End Get
End Property
Public ReadOnly Property Edits() As List(Of Edit)
Get
Dim Break As Integer = 0
Dim PageEdits As New List(Of Edit)
Dim Edit As Edit = LastEdit
While Edit IsNot Nothing AndAlso Edit IsNot NullEdit And Break < Misc.GlExcess
Break = Break + 1
PageEdits.Add(Edit)
Edit = Edit.Prev
End While
If Break >= Misc.GlExcess Then Log("Debug interrupted Page.Edits")
Return PageEdits
End Get
End Property
Public Property Exists() As Boolean
Get
Return _Exists
End Get
Set(ByVal value As Boolean)
_Exists = value
End Set
End Property
Public ReadOnly Property IsArticle() As Boolean
Get
Return (Space Is Space.Article)
End Get
End Property
Public ReadOnly Property IsArticleTalkPage() As Boolean
Get
Return (Space Is Space.Talk)
End Get
End Property
Public ReadOnly Property IsEditable() As Boolean
Get
Return Not ((EditLevel = "sysop" OrElse Space.Locked) AndAlso Not Config.Rights.Contains("protect"))
End Get
End Property
Public ReadOnly Property IsMovable() As Boolean
Get
Return Not (Space.Unmovable OrElse ((MoveLevel = "sysop" OrElse Space.Locked) _
AndAlso Not Config.Rights.Contains("protect")))
End Get
End Property
Public ReadOnly Property IsSubjectPage() As Boolean
Get
Return Space.IsSubjectSpace
End Get
End Property
Public ReadOnly Property IsSubpage() As Boolean
Get
Return (Space.Subpages AndAlso Name.Contains("/"))
End Get
End Property
Public ReadOnly Property IsTalkPage() As Boolean
Get
Return Space.IsTalkSpace
End Get
End Property
Public ReadOnly Property Name() As String
Get
Return _Name
End Get
End Property
Public ReadOnly Property Owner() As User
Get
If (Space Is Space.User OrElse Space Is Space.UserTalk) AndAlso Name.Contains(":") Then
Dim Username As String = Name.Substring(Name.IndexOf(":"))
If Username.Contains("/") Then Username = Username.Substring(0, Username.IndexOf("/"))
Return GetUser(Username)
Else
Return Nothing
End If
End Get
End Property
Public ReadOnly Property Space() As Space
Get
Return _Space
End Get
End Property
Public ReadOnly Property SubjectPage() As Page
Get
Return GetPage(SubjectPageName)
End Get
End Property
Public ReadOnly Property SubjectPageName() As String
Get
If Space Is Space.Article Then Return BaseName _
Else If Space.IsSubjectSpace Then Return Name _
Else Return Space.SubjectSpace.Name & ":" & BaseName
End Get
End Property
Public ReadOnly Property TalkPage() As Page
Get
Return GetPage(TalkPageName)
End Get
End Property
Public ReadOnly Property TalkPageName() As String
Get
Return Space.TalkSpace.Name & ":" & BaseName
End Get
End Property
Public Overrides Function ToString() As String
Return _Name
End Function
Public Sub MovedTo(ByVal NewName As String)
'Handle a page move
If All.ContainsKey(NewName) Then All.Remove(NewName)
All.Remove(_Name)
_Name = NewName
All.Add(NewName, Me)
End Sub
Public Shared Sub ClearAll()
All.Clear()
End Sub
Public Shared Function GetPage(ByVal Name As String) As Page
Name = SanitizeTitle(Name)
If Name Is Nothing Then Return Nothing
If All.ContainsKey(Name) Then Return All(Name) Else Return New Page(Name)
End Function
Public Shared Function SanitizeTitle(ByVal Name As String) As String
'Remove illegal characters
If Name.Contains("#") Then Name = Name.Substring(0, Name.IndexOf("#"))
Name = Name.Replace("[", "").Replace("]", "").Replace("{", "").Replace("}", "").Replace("|", "") _
.Replace("<", "").Replace(">", "").Replace("#", "").Replace(Tab, "").Replace(LF, "") _
.Replace("_", " ").Trim(" "c)
While Name.StartsWith(":")
Name = Name.Substring(1)
End While
If Name Is Nothing OrElse Name.Length = 0 Then Return Nothing
'Capitalize
If Name.Length > 1 Then Name = Name.Substring(0, 1).ToUpper & Name.Substring(1) Else Name = Name.ToUpper
'Handle special namespaces
Name = Name.Replace("Special:Mypage", Space.User.Name & ":" & Config.Username)
Name = Name.Replace("Special:Mytalk", Space.UserTalk.Name & ":" & Config.Username)
For Each Item As String In Space.Special
If Name.StartsWith(Item & ":") Then Return Nothing
Next Item
'Handle namespace aliases
For Each Item As KeyValuePair(Of String, Integer) In Space.Aliases
If Name.StartsWith(Item.Key & ":") Then
Name = Space.GetSpace(Item.Value).Name & Name.Substring(Name.IndexOf(":"))
Exit For
End If
Next Item
Return Name
End Function
End Class
Public Enum PageLevel As Integer
None = 0
Ignore = -1
Watch = 1
Bad = 2
End Enum