-
Notifications
You must be signed in to change notification settings - Fork 20
/
Variables.cs
1103 lines (936 loc) · 36.8 KB
/
Variables.cs
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2007 Martin Richards, 2008 Stephen Kennedy
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 2 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using WikiFunctions.Lists.Providers;
using WikiFunctions.Plugin;
using WikiFunctions.Background;
using System.Net;
using System.Threading;
namespace WikiFunctions
{
public enum ProjectEnum
{
wikipedia,
wiktionary,
wikisource,
wikiquote,
wikiversity,
wikivoyage,
wikibooks,
wikinews,
species,
commons,
meta,
mediawiki,
incubator,
wikia,
fandom,
custom
}
/// <summary>
/// Holds static variables, to allow functionality on different wikis.
/// </summary>
public static partial class Variables
{
static Variables()
{
CanonicalNamespaces[-2] = "Media:";
CanonicalNamespaces[-1] = "Special:";
CanonicalNamespaces[1] = "Talk:";
CanonicalNamespaces[2] = "User:";
CanonicalNamespaces[3] = "User talk:";
CanonicalNamespaces[4] = "Project:";
CanonicalNamespaces[5] = "Project talk:";
CanonicalNamespaces[6] = "File:";
CanonicalNamespaces[7] = "File talk:";
CanonicalNamespaces[8] = "MediaWiki:";
CanonicalNamespaces[9] = "MediaWiki talk:";
CanonicalNamespaces[10] = "Template:";
CanonicalNamespaces[11] = "Template talk:";
CanonicalNamespaces[12] = "Help:";
CanonicalNamespaces[13] = "Help talk:";
CanonicalNamespaces[14] = "Category:";
CanonicalNamespaces[15] = "Category talk:";
CanonicalNamespaceAliases = PrepareAliases(CanonicalNamespaces);
CanonicalNamespaceAliases[6].Add("Image:");
CanonicalNamespaceAliases[7].Add("Image talk:");
if (!Globals.UnitTestMode)
SetProject("en", ProjectEnum.wikipedia); //Shouldn't have to load en defaults...
else
{
SetToEnglish();
RegenerateRegexes();
}
CapitalizeFirstLetter = true;
IndexPHP = "index.php";
ApiPHP = "api.php";
TypoSummaryTag = "typos fixed: ";
AWBDefaultSummaryTag();
mSummaryTag = "using ";
Protocol = "http://";
NotificationsEnabled = true;
UnicodeCategoryCollation = false;
}
/// <summary>
/// Gets the SVN revision of the current build and the date it was committed
/// </summary>
public static string Revision
{
get // see SvnInfo.template.cs for details
{
return !m_Revision.Contains("$") ? m_Revision.Replace("/", "-") : "?";
}
}
/// <summary>
/// Gets the SVN revision number of the current build
/// </summary>
public static int RevisionNumber
{
get
{
return !m_Revision.Contains("$")
? int.Parse(m_Revision.Substring(0, m_Revision.IndexOf(' ')))
: 0;
}
}
/// <summary>
/// Page of RegexTypoFix rules page e.g. Project:AutoWikiBrowser/Typos.
/// Can be full URL if specified as such on <!--Typos--> check page comment
/// </summary>
public static string RetfPath;
/// <summary>
///
/// </summary>
public static IAutoWikiBrowser MainForm { get; set; }
/// <summary>
/// Performance profiler
/// </summary>
public static Profiler Profiler = new Profiler();
#region project and language settings
/// <summary>
/// Provides access to the en namespace keys e.g. Category:
/// </summary>
public static readonly Dictionary<int, string> CanonicalNamespaces = new Dictionary<int, string>(20);
/// <summary>
/// Canonical namespace aliases
/// </summary>
public static readonly Dictionary<int, List<string>> CanonicalNamespaceAliases;
/// <summary>
/// Provides access to the namespace keys e.g. Category:
/// </summary>
public static Dictionary<int, string> Namespaces = new Dictionary<int, string>(40);
/// <summary>
/// Aliases for current namespaces
/// </summary>
public static Dictionary<int, List<string>> NamespaceAliases;
/// <summary>
/// Provides access to the namespace keys in a form so the first letter is case insensitive e.g. [Ww]ikipedia:
/// </summary>
public static readonly Dictionary<int, string> NamespacesCaseInsensitive = new Dictionary<int, string>(24);
/// <summary>
///
/// </summary>
public static Dictionary<string, List<string>> MagicWords = new Dictionary<string, List<string>>();
/// <summary>
/// Gets a URL of the site, e.g. "https://en.wikipedia.org/w/"
/// </summary>
public static string URLLong
{
get { return URL + URLEnd; }
}
/// <summary>
/// Gets a Index URL of the site, e.g. "https://en.wikipedia.org/w/index.php"
/// </summary>
public static string URLIndex
{
get { return URLLong + IndexPHP; }
}
/// <summary>
/// Gets a Index URL of the site, e.g. "https://en.wikipedia.org/w/api.php"
/// </summary>
public static string URLApi
{
get { return URLLong + ApiPHP; }
}
public static string HttpAuthUsername { get; set; }
public static string HttpAuthPassword { get; set; }
/// <summary>
/// true if current wiki uses right-to-left writing system
/// </summary>
public static bool RTL { get; set; }
/// <summary>
/// Whether user notifications (from MediaWiki Echo extension) are available on the wiki
/// </summary>
public static bool NotificationsEnabled { get; set; }
/// <summary>
/// Whether the wiki capitalizes first letter of page names (usually yes, e.g. English Wikipedia) or not (e.g. Wiktionary)
///
/// This is based on the value of $wgCapitalLinks
/// </summary>
public static bool CapitalizeFirstLetter { get; set; }
/// <summary>
/// Whether the wiki uses Unicode (uca-) sorting for category sort keys, i.e. the wgCategoryCollation value is a uca-type
/// </summary>
public static bool UnicodeCategoryCollation { get; set; }
/// <summary>
/// localized names of months
/// </summary>
public static string[] MonthNames;
public static readonly string[] ENLangMonthNames =
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
private static string URLEnd = "/w/";
/// <summary>
/// Gets a URL of the site, e.g. "https://en.wikipedia.org".
/// </summary>
public static string URL = "https://en.wikipedia.org";
public static string Host
{
get { return new Uri(URL).Host; }
}
/// <summary>
/// Returns the script path of the site, e.g. /w
/// </summary>
public static string ScriptPath
{
get { return URLEnd.Substring(0, URLEnd.LastIndexOf('/')); }
}
/// <summary>
/// Gets a name of the project, e.g. "wikipedia".
/// </summary>
public static ProjectEnum Project { get; private set; }
/// <summary>
/// Gets the language code, e.g. "en".
/// </summary>
public static string LangCode { get; internal set; }
/// <summary>
/// Returns true if we are currently editing a WMF wiki
/// </summary>
public static bool IsWikimediaProject
{
get { return Project <= ProjectEnum.commons; }
}
/// <summary>
/// Returns true if we are currently editing the English Wikipedia
/// </summary>
public static bool IsWikipediaEN
{
get { return Project == ProjectEnum.wikipedia && LangCode.Equals("en"); }
}
/// <summary>
/// Returns true if we are currently editing Commons
/// </summary>
public static bool IsCommons
{
get { return Project == ProjectEnum.commons; }
}
/// <summary>
/// Returns true if we are currently a monolingual Wikimedia project
/// </summary>
public static bool IsWikimediaMonolingualProject
{
get { return Project >= ProjectEnum.species && Project < ProjectEnum.wikia; }
}
/// <summary>
/// Returns true if we are currently editing a "custom" wiki
/// </summary>
public static bool IsCustomProject
{
get { return Project == ProjectEnum.custom; }
}
/// <summary>
/// Returns true if we are currently editing a Wikia/Fandom site
/// </summary>
public static bool IsWikia
{
get { return Project == ProjectEnum.wikia || Project == ProjectEnum.fandom; }
}
/// <summary>
/// Gets script path of a custom project or empty string if standard project
/// </summary>
public static string CustomProject { get; private set; }
/// <summary>
/// Login domain if needed
/// </summary>
public static string LoginDomain { get; set; }
/// <summary>
/// Protocol, HTTP or HTTPS?
/// </summary>
public static string Protocol { get; private set; }
/// <summary>
/// index.php appended with "5" if appropriate for the wiki
/// </summary>
public static string IndexPHP { get; private set; }
/// <summary>
/// api.php appended with "5" if appropriate for the wiki
/// </summary>
public static string ApiPHP { get; private set; }
/// <summary>
/// Typos wording e.g. "typos fixed: "
/// Should not start with spaces or commas. Must end with a space
/// </summary>
public static string TypoSummaryTag { get; private set; }
/// <summary>
/// Localized version of " using " for edit summary tag
/// Does not need spaces at start or end
/// </summary>
private static string mSummaryTag;
/// <summary>
/// Gets the tag to add to the edit summary, e.g. " using [[Project:AWB]]".
/// </summary>
public static string SummaryTag
{
get
{
if (TagEdits)
{
// If we're applying an Edit Tag, don't append "using AWB" to the Edit Summary
return "";
}
string text = " " + mSummaryTag + " " + WPAWB;
#if DEBUG
text += " (" + RevisionNumber + ")";
#endif
return text;
}
}
public static string WPAWB { get; private set; }
internal static Dictionary<int, List<string>> PrepareAliases(Dictionary<int, string> namespaces)
{
Dictionary<int, List<string>> ret = new Dictionary<int, List<string>>(namespaces.Count);
// fill aliases with empty lists, to avoid KeyNotFoundException
foreach (int n in namespaces.Keys)
{
ret[n] = new List<string>();
}
return ret;
}
/// <summary>
/// Sets the AWB default summary tag.
/// </summary>
private static void AWBDefaultSummaryTag()
{
mSummaryTag = "using ";
WPAWB = "[[Project:AWB|AWB]]";
}
/// <summary>
/// Whether edits should be tagged with AWB (not edit summary)
/// </summary>
public static bool TagEdits;
#region Delayed load stuff
/// <summary>
/// Contains list of pages with underscores in titles, from [[Category:Articles with underscores in the title]] for en wiki
/// </summary>
public static readonly List<string> UnderscoredTitles = new List<string>();
private static readonly List<BackgroundRequest> DelayedRequests = new List<BackgroundRequest>();
/// <summary>
/// For unit tests only, method to add entries to UnderscoredTitles
/// </summary>
/// <param name="titles"></param>
public static void AddUnderscoredTitles(List<string> titles)
{
if (Globals.UnitTestMode)
UnderscoredTitles.AddRange(titles);
}
private static void CancelBackgroundRequests()
{
lock (DelayedRequests)
{
foreach (BackgroundRequest b in DelayedRequests) b.Abort();
DelayedRequests.Clear();
}
}
/// <summary>
/// Waits for all background stuff to be loaded
/// </summary>
public static void WaitForDelayedRequests()
{
do
{
lock (DelayedRequests)
{
if (DelayedRequests.Count == 0)
return;
}
Thread.Sleep(100);
} while (true);
}
internal static void LoadUnderscores(params string[] cats)
{
BackgroundRequest r = new BackgroundRequest(UnderscoresLoaded) {HasUI = false};
lock (DelayedRequests)
{
DelayedRequests.Add(r);
}
r.GetList(new CategoryListProvider(), cats);
}
private static void UnderscoresLoaded(BackgroundRequest req)
{
lock (DelayedRequests)
{
DelayedRequests.Remove(req);
UnderscoredTitles.Clear();
foreach (Article a in (List<Article>) req.Result)
{
UnderscoredTitles.Add(a.Name);
}
}
}
#endregion
#region Proxy support
private static IWebProxy SystemProxy;
/// <summary>
/// Creates an HTTP web request. Timeout set to 15 seconds
/// </summary>
/// <param name="url"></param>
/// <param name="userAgent"></param>
/// <returns></returns>
public static HttpWebRequest PrepareWebRequest(string url, string userAgent)
{
ServicePointManager.Expect100Continue = false;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(url);
req.KeepAlive = true;
req.ServicePoint.Expect100Continue = false;
req.Expect = "";
if (SystemProxy != null) req.Proxy = SystemProxy;
req.UserAgent = string.IsNullOrEmpty(userAgent) ? Tools.DefaultUserAgentString : userAgent;
req.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
req.Proxy.Credentials = CredentialCache.DefaultCredentials;
req.UseDefaultCredentials = true;
req.Timeout = 15000; // override default timeout of 300,000 (= 5 minutes) down to 15 seconds
return req;
}
/// <summary>
/// Creates an HTTP web request. Timeout set to 15 seconds
/// </summary>
/// <returns>
/// The web request.
/// </returns>
/// <param name='url'>
/// URL.
/// </param>
public static HttpWebRequest PrepareWebRequest(string url)
{
return PrepareWebRequest(url, "");
}
/// <summary>
/// Refreshs the system proxy.
/// </summary>
public static void RefreshProxy()
{
// no Internet Explorer available on Linux, so GetSystemWebProxy doesn't work, so disable to avoid 60-second timeouts when offline (unit tests etc.)
if(Globals.UsingLinux)
return;
SystemProxy = WebRequest.GetSystemWebProxy();
if (SystemProxy.IsBypassed(new Uri(URL)))
{
SystemProxy = null;
}
}
#endregion
// for logging, these will probably need internationalising
public static string AWBVersionString(string version)
{
return "*" + WPAWB + " version " + version + Environment.NewLine;
}
public static string Stub;
public static string SectStub;
public static Regex SectStubRegex;
/// <summary>
/// Sets different language variables, such as namespaces. Default is english Wikipedia
/// </summary>
/// <param name="langCode">The language code, default is en</param>
/// <param name="projectName">The project name default is Wikipedia</param>
public static void SetProject(string langCode, ProjectEnum projectName)
{
SetProject(langCode, projectName, "", "https://");
}
#if DEBUG || UNITTEST
/// <summary>
/// Sets the language code of the current project
/// </summary>
/// <param name="langCode">The new language code to use</param>
/// <remarks>Do not use this outside unit tests</remarks>
public static void SetProjectLangCode(string langCode)
{
SetLanguageSpecificValues(langCode, ProjectEnum.wikipedia);
LangCode = langCode;
RTL = langCode.Equals("ar");
}
/// <summary>
/// Sets different language variables, such as namespaces. Default is English Wikipedia
/// </summary>
/// <param name="langCode">The language code, default is en</param>
/// <param name="projectName">The project name default is Wikipedia</param>
/// <remarks>Do not use this outside unit tests</remarks>
public static void SetProjectSimple(string langCode, ProjectEnum projectName)
{
Project = projectName;
SetProjectLangCode(langCode);
}
#endif
public static bool TryLoadingAgainAfterLogin { get; private set; }
public static ProjectHoldArea ReloadProjectSettings;
public class ProjectHoldArea
{
public ProjectEnum projectName;
public string langCode;
public string customProject;
public string protocol;
}
/// <summary>
/// Sets different language variables, such as namespaces. Default is english Wikipedia
/// </summary>
/// <param name="langCode">The language code, default is en</param>
/// <param name="projectName">The project name default is Wikipedia</param>
/// <param name="customProject">Script path of a custom project or ""</param>
/// <param name="protocol"></param>
public static void SetProject(string langCode, ProjectEnum projectName, string customProject, string protocol)
{
TryLoadingAgainAfterLogin = false;
Namespaces.Clear();
CancelBackgroundRequests();
UnderscoredTitles.Clear();
WikiRegexes.TemplateRedirects.Clear();
bool typoReloadNeeded = (LangCode != langCode || Project != projectName || customProject != CustomProject);
Project = projectName;
LangCode = langCode;
CustomProject = customProject;
Protocol = protocol;
RefreshProxy();
URLEnd = "/w/";
Stub = "[^{}|]*?[Ss]tub";
MonthNames = ENLangMonthNames;
SectStub = @"\{\{[Ss]ect";
SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
TypoSummaryTag = "typos fixed: ";
AWBDefaultSummaryTag();
mSummaryTag = "using";
NotificationsEnabled = true;
if (IsCustomProject)
{
LangCode = "en";
var uri = new Uri(Protocol + customProject);
URLEnd = uri.AbsolutePath;
URL = protocol + uri.Host;
if (!uri.IsDefaultPort)
{
URL += ":" + uri.Port;
}
CustomProject = customProject;
}
else
{
URL = "https://" + LangCode + "." + Project + ".org";
}
// HACK:
switch (projectName)
{
case ProjectEnum.wikipedia:
case ProjectEnum.wikinews:
case ProjectEnum.wikisource:
case ProjectEnum.wikibooks:
case ProjectEnum.wikiquote:
case ProjectEnum.wiktionary:
case ProjectEnum.wikiversity:
//If not set the following will be used:
//mSummaryTag="using";
//WPAWB = "[[Project:Wikipedia:AutoWikiBrowser|AWB]]";
SetLanguageSpecificValues(langCode, projectName);
break;
case ProjectEnum.commons:
URL = "https://commons.wikimedia.org";
LangCode = "en";
break;
case ProjectEnum.meta:
URL = "https://meta.wikimedia.org";
LangCode = "en";
break;
case ProjectEnum.mediawiki:
URL = "https://www.mediawiki.org";
LangCode = "en";
break;
case ProjectEnum.incubator:
URL = "https://incubator.wikimedia.org";
LangCode = "en";
break;
case ProjectEnum.species:
URL = "https://species.wikimedia.org";
LangCode = "en";
break;
case ProjectEnum.wikia:
URL = "https://" + customProject + ".wikia.com";
URLEnd = "/";
break;
case ProjectEnum.fandom:
URL = "https://" + customProject + ".fandom.com";
URLEnd = "/";
break;
case ProjectEnum.custom:
break;
}
//refresh once more in case project settings were reset due to error with loading
RefreshProxy();
//HACK:HACK:HACK:HACK:HACK:
if (MainForm != null && MainForm.TheSession != null)
{
try
{
if (!MainForm.TheSession.UpdateProject(false))
{
LangCode = "en";
Project = ProjectEnum.wikipedia;
SetToEnglish();
}
}
catch (ReadApiDeniedException)
{
TryLoadingAgainAfterLogin = true;
ReloadProjectSettings = new ProjectHoldArea
{
projectName = projectName,
customProject = customProject,
langCode = langCode,
protocol = Protocol
};
return;
}
}
RegenerateRegexes();
RetfPath = Namespaces[Namespace.Project] + "AutoWikiBrowser/Typos";
if (typoReloadNeeded && MainForm != null)
MainForm.LoadTypos(true);
foreach (string s in Namespaces.Values)
{
System.Diagnostics.Trace.Assert(s.EndsWith(":"), "Internal error: namespace does not end with ':'.",
"Please contact a developer.");
}
System.Diagnostics.Trace.Assert(!Namespaces.ContainsKey(0), "Internal error: key exists for namespace 0.",
"Please contact a developer.");
}
/// <summary>
///
/// </summary>
private static void RegenerateRegexes()
{
NamespacesCaseInsensitive.Clear();
foreach (int ns in Namespaces.Keys)
{
NamespacesCaseInsensitive.Add(ns, "(?i:"
+ WikiRegexes.GenerateNamespaceRegex(ns) + @")\s*:");
}
WikiRegexes.MakeLangSpecificRegexes();
}
/// <summary>
///
/// </summary>
private static void SetToEnglish()
{
foreach (var i in CanonicalNamespaces.Keys)
Namespaces[i] = CanonicalNamespaces[i];
Namespaces[4] = "Wikipedia:";
Namespaces[5] = "Wikipedia talk:";
Namespaces[100] = "Portal:";
Namespaces[101] = "Portal talk:";
Namespaces[108] = "Book:";
Namespaces[109] = "Book talk:";
Namespaces[118] = "Draft:";
Namespaces[119] = "Draft talk:";
Namespaces[446] = "Education Program:";
Namespaces[447] = "Education Program talk:";
Namespaces[710] = "TimedText:";
Namespaces[711] = "TimedText talk:";
Namespaces[828] = "Module:";
Namespaces[829] = "Module talk:";
mSummaryTag = "using";
WPAWB = "[[Project:AWB|AWB]]";
NamespaceAliases = CanonicalNamespaceAliases;
MonthNames = ENLangMonthNames;
SectStub = @"\{\{[Ss]ect";
SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
Stub = "[^{}|]*?[Ss]tub";
LangCode = "en";
RTL = false;
CapitalizeFirstLetter = true;
}
/// <summary>
/// Sets the language specific values: summary tag, stub regex, AWB project link
/// </summary>
/// <param name='langCode'>
/// Language code of wiki.
/// </param>
/// <param name='projectName'>
/// Project name of wiki.
/// </param>
private static void SetLanguageSpecificValues(string langCode, ProjectEnum projectName)
{
switch (langCode)
{
case "en":
if (projectName == ProjectEnum.wikipedia)
{
SetToEnglish();
WPAWB = "[[WP:AWB|AWB]]";
}
TypoSummaryTag = @"[[WP:AWB/T|typo(s) fixed]]: ";
break;
case "ar":
mSummaryTag = "";
WPAWB = "باستخدام [[Project:أوب|أوب]]";
Stub = @"[^{}|]*?(?:[Ss]tub|بذرة|بذور)[^{}]*?";
TypoSummaryTag = "الأخطاء المصححة: ";
break;
case "arz":
mSummaryTag = "";
WPAWB = "عن طريق [[Project:AWB|اوب]]";
Stub = @"[^{}|]*?(?:[Ss]tub|تقاوى|بذرة)[^{}]*?";
TypoSummaryTag = "الأخطاء المصححة: ";
break;
case "be":
mSummaryTag = "з дапамогай";
break;
case "bg":
mSummaryTag = "редактирано с";
WPAWB = "AWB";
break;
case "bn":
mSummaryTag = "";
WPAWB = "[[Project:অউব্রা|অউব্রা]] ব্যবহার করে";
TypoSummaryTag = "বানান সংশোধন: ";
break;
case "ca":
mSummaryTag = "";
WPAWB = "[[Viquipèdia:AutoWikiBrowser|AWB]]";
break;
case "cs":
mSummaryTag = "za použití";
WPAWB = "[[Wikipedie:AutoWikiBrowser|AWB]]";
Stub = @"[^{}|]*?([Pp]ahýl)";
break;
case "cy":
Stub = @"[^{}|]*?([Ss]tub|[Εe]ginyn[^{}]*?)";
break;
case "da":
mSummaryTag = "ved brug af";
WPAWB = "[[en:WP:AWB|AWB]]";
break;
case "de":
mSummaryTag = "mit";
TypoSummaryTag = "Schreibweise: ";
break;
case "el":
mSummaryTag = "με τη χρήση";
Stub = @"[^{}|]*?([Ss]tub|[Εε]πέκταση)";
SectStub = @"\{\{θέματος";
SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
break;
case "eo":
mSummaryTag = "per";
WPAWB = "[[Vikipedio:AutoWikiBrowser|AWB]]";
TypoSummaryTag = "Skribmaniero: ";
break;
case "es":
mSummaryTag = "(Usando";
WPAWB = "[[:w:WP:AWB|AWB]])";
break;
case "fa":
mSummaryTag = "";
WPAWB = "با استفاده از [[Project:AutoWikiBrowser|AWB]]";
break;
case "fr":
mSummaryTag = "avec";
WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
break;
case "he":
mSummaryTag = "באמצעות";
WPAWB = "[[ויקיפדיה:AutoWikiBrowser|AWB]]";
break;
case "hi":
mSummaryTag = "";
WPAWB = "[[विकिपीडिया:ऑटोविकिब्राउज़र|AWB]] के साथ";
break;
case "hu":
mSummaryTag = "";
WPAWB = "[[Wikipédia:AutoWikiBrowser|AWB]]";
break;
case "hy":
mSummaryTag = "oգտվելով";
WPAWB = "[[Վիքիպեդիա:ԱվտոՎիքիԲրաուզեր|ԱՎԲ]]";
Stub = @"[^{}|]*?([Ss]tub|Անավարտ|Զարգացնել[^{}]*?)";
break;
case "it":
mSummaryTag = "";
Stub = @"(DUMMYTEMPLATE)";
break;
case "ku":
mSummaryTag = "";
WPAWB = "[[Wîkîpediya:AutoWikiBrowser|AWB]]";
break;
case "ms":
mSummaryTag = "menggunakan";
break;
case "ne":
mSummaryTag = "";
WPAWB = "स्वतःविकी ब्राउजर प्रयोग गर्दै";
break;
case "nl":
mSummaryTag = "met";
break;
case "pa":
mSummaryTag = "ਦੀ ਵਰਤੋਂ ਨਾਲ";
break;
case "pl":
mSummaryTag = "przy użyciu";
SectStub = @"\{\{[Ss]ek";
SectStubRegex = new Regex(SectStub, RegexOptions.Compiled);
break;
case "pt":
mSummaryTag = "utilizando";
break;
case "ru":
mSummaryTag = "с помощью";
Stub = "[^{}]*?(?:[Ss]tub|[Зз]аготовка)";
break;
case "sco":
Stub = "(Stub/[^{}|]+|[^{}|]*?[Ss]tub)";
break;
case "sk":
mSummaryTag = "";
break;
case "sl":
mSummaryTag = "";
Stub = "(?:[^{}]*?[Ss]tub|[Šš]krbina[^{}]*?)";
break;
case "sq":
mSummaryTag = "duke përdorur";
TypoSummaryTag = @"[[WP:AWB/T|përmirësime tipografike]]: ";
Stub = "(?:[^{}]*?[Cc]ung[^{}]*?)";
break;
case "sr":
mSummaryTag = "користећи";
WPAWB = "[[Project:AWB|AWB]]";
break;
case "sv":
mSummaryTag = "med";
TypoSummaryTag = "rättar stavfel: ";
Stub = @"(?:[^{}]*?[Ss]tub|[^{}]+?stub(?:[ \-][^{}]+)?)(?<![Ss]tubbmall|[Ss]ubstub|[Ss]tubavsnitt|[Uu]ncategorized stub)";
break;
case "tr":
mSummaryTag = "";
WPAWB = "[[Vikipedi:AWB|AWB]] ile ";
TypoSummaryTag = "yazış şekli: ";
break;