-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaWikiUtils.pas
3101 lines (2684 loc) · 117 KB
/
MediaWikiUtils.pas
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
{**************************************************************************************************}
{ }
{ Project JEDI }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at http://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is MediaWikiUtils.pas }
{ }
{ The Initial Developer of the Original Code is Florent Ouchet. }
{ Portions created by Florent Ouchet are Copyright Florent Ouchet. All rights reserved. }
{ }
{ Contributor(s): }
{ }
{**************************************************************************************************}
unit MediaWikiUtils;
interface
uses
SysUtils,
Classes,
Math,
JclBase,
JclSimpleXml;
type
EMediaWikiException = class(Exception)
private
FInfo: string;
public
constructor Create(const AInfo: string);
procedure AfterConstruction; override;
property Info: string read FInfo;
end;
EMediaWikiWarning = class(EMediaWikiException)
private
FQuery: string;
public
constructor Create(const AInfo, AQuery: string);
procedure AfterConstruction; override;
property Query: string read FQuery;
end;
EMediaWikiError = class(EMediaWikiException)
private
FCode: string;
public
constructor Create(const AInfo, ACode: string);
procedure AfterConstruction; override;
property Code: string read FCode;
end;
TMediaWikiID = Integer;
type
TMediaWikiXMLWarningCallback = procedure (const AInfo, AQuery: string) of object;
TMediaWikiXMLErrorCallback = procedure (const AInfo, ACode: string) of object;
procedure MediaWikiCheckXML(XML: TJclSimpleXML; WarningCallback: TMediaWikiXMLWarningCallback;
ErrorCallback: TMediaWikiXMLErrorCallback);
type
TMediaWikiOutputFormat = (mwoJSON, // JSON format
mwoPHP, // serialized PHP format
mwoWDDX, // WDDX format
mwoXML, // XML format
mwoYAML, // YAML format
mwoDebugJSON, // JSON format with the debugging elements (HTML)
mwoText, // PHP print_r() format
mwoDebug); // PHP var_export() format
TMediaWikiLoginResult = (mwlNoName, // You didn't set the lgname parameter
mwlIllegal, // You provided an illegal username
mwlNotExists, // The username you provided doesn't exist
mwlEmptyPass, // You didn't set the lgpassword parameter or you left it empty
mwlWrongPass, // The password you provided is incorrect
mwlWrongPluginPass, // Same as WrongPass, returned when an authentication plugin rather than MediaWiki itself rejected the password
mwlCreateBlocked, // The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation
mwlThrottled, // You've logged in too many times in a short time. See also throttling
mwlBlocked, // User is blocked
mwlMustBePosted, // The login module requires a POST request
mwlNeedToken, // Either you did not provide the login token or the sessionid cookie. Request again with the token and cookie given in this response
mwlSuccess); // Login success
const
MediaWikiOutputFormats: array [TMediaWikiOutputFormat] of string =
( 'json', // JSON format
'php', // serialized PHP format
'wddx', // WDDX format
'xml', // XML format
'yaml', // YAML format
'rawfm', // JSON format with the debugging elements (HTML)
'txt', // PHP print_r() format
'dbg' ); // PHP var_export() format
MediaWikiLoginResults: array [TMediaWikiLoginResult] of string =
( 'NoName', // You didn't set the lgname parameter
'Illegal', // You provided an illegal username
'NotExists', // The username you provided doesn't exist
'EmptyPass', // You didn't set the lgpassword parameter or you left it empty
'WrongPass', // The password you provided is incorrect
'WrongPluginPass', // Same as WrongPass, returned when an authentication plugin rather than MediaWiki itself rejected the password
'CreateBlocked', // The wiki tried to automatically create a new account for you, but your IP address has been blocked from account creation
'Throttled', // You've logged in too many times in a short time. See also throttling
'Blocked', // User is blocked
'mustbeposted', // The login module requires a POST request
'NeedToken', // Either you did not provide the login token or the sessionid cookie. Request again with the token and cookie given in this response
'Success' ); // Login success
function FindMediaWikiLoginResult(const AString: string): TMediaWikiLoginResult;
function StrISO8601ToDateTime(const When: string): TDateTime;
function DateTimeToStrISO8601(When: TDateTime): string;
type
TMediaWikiContinueInfo = record
ParameterName: string;
ParameterValue: string;
end;
// post stuff
procedure MediaWikiQueryAdd(Queries: TStrings; const AName: string; const AValue: string = '';
RawValue: Boolean = False; Content: TStream = nil); overload;
procedure MediaWikiQueryAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo); overload;
procedure MediaWikiQueryPost(Queries: TStrings; ASendStream: TStream; out ContentType: string);
// login stuff
procedure MediaWikiQueryLoginAdd(Queries: TStrings; const lgName, lgPassword, lgToken: string; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryLoginParseXmlResult(XML: TJclSimpleXML; out LoginResult: TMediaWikiLoginResult;
out LoginUserID: TMediaWikiID; out LoginUserName: string);
// logout stuff
procedure MediaWikiQueryLogoutAdd(Queries: TStrings; const token: string; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryLogoutParseXmlResult(XML: TJclSimpleXML);
// query, site info general
procedure MediaWikiQuerySiteInfoGeneralAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoGeneralParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info namespaces
procedure MediaWikiQuerySiteInfoNamespacesAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoNamespacesParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info, namespace aliases
procedure MediaWikiQuerySiteInfoNamespaceAliasesAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoNamespaceAliasesParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info, special page aliases
procedure MediaWikiQuerySiteInfoSpecialPageAliasesAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoSpecialPageAliasesParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info, magic words
procedure MediaWikiQuerySiteInfoMagicWordsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoMagicWordsParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info, statistics
procedure MediaWikiQuerySiteInfoStatisticsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoStatisticsParseXmlResult(XML: TJclSimpleXML; Info: TStrings);
// query, site info, inter wiki map
procedure MediaWikiQuerySiteInfoInterWikiMapAdd(Queries: TStrings; Local: Boolean; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoInterWikiMapParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info , DB replication lag
procedure MediaWikiQuerySiteInfoDBReplLagAdd(Queries: TStrings; ShowAllDB: Boolean;
OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoDBReplLagParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info, user groups
procedure MediaWikiQuerySiteInfoUserGroupsAdd(Queries: TStrings; IncludeUserCount: Boolean;
OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoUserGroupsParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, site info, extensions
type
TMediaWikiExtension = record
ExtensionType: string;
ExtensionName: string;
ExtensionDescription: string;
ExtensionDescriptionMsg: string;
ExtensionAuthor: string;
ExtensionVersion: string;
end;
TMediaWikiExtensions = array of TMediaWikiExtension;
procedure MediaWikiQuerySiteInfoExtensionsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQuerySiteInfoExtensionsParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiExtensions);
// query token stuff
type
TMediaWikiToken = (mwtCreateAccount, mwtCsrf, mwtDeleteGlobalAccount,
mwtLogin, mwtPatrol, mwtRollback, mwtSetGlobalAccountStatus,
mwtUserRights, mwtWatch);
TMediaWikiTokens = set of TMediaWikiToken;
TMediaWikiTokenValues = array [TMediaWikiToken] of string;
const
MediaWikiTokenNames: array [TMediaWikiToken] of string =
( 'createaccount', 'csrf', 'deleteglobalaccount', 'login', 'patrol',
'rollback', 'setglobalaccountstatus', 'userrights', 'watch' );
procedure MediaWikiQueryTokensAdd(Queries: TStrings; Tokens: TMediaWikiTokens; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryTokensParseXmlResult(XML: TJclSimpleXML; out TokenValues: TMediaWikiTokenValues);
// query, user info, block info
procedure MediaWikiQueryUserInfoBlockInfoAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoBlockInfoParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, user info, has msg
procedure MediaWikiQueryUserInfoHasMsgAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoHasMsgParseXmlResult(XML: TJclSimpleXML; out HasMessage: Boolean);
// query, user info, groups
procedure MediaWikiQueryUserInfoGroupsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoGroupsParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
//query, user info, rights
procedure MediaWikiQueryUserInfoRightsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoRightsParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, user info, changeable groups
procedure MediaWikiQueryUserInfoChangeableGroupsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoChangeableGroupsParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, user info, options
procedure MediaWikiQueryUserInfoOptionsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoOptionsParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, user info, edit count
procedure MediaWikiQueryUserInfoEditCountAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoEditCountParseXmlResult(XML: TJclSimpleXML; out EditCount: Integer);
// query, user info, rate limits
type
TMediaWikiRateLimit = record
RateLimitAction: string;
RateLimitGroup: string;
RateLimitHits: Integer;
RateLimitSeconds: Integer;
end;
TMediaWikiRateLimits = array of TMediaWikiRateLimit;
procedure MediaWikiQueryUserInfoRateLimitsAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryUserInfoRateLimitsParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiRateLimits);
// query, messages
procedure MediaWikiQueryMessagesAdd(Queries: TStrings; const NameFilter, ContentFilter, Lang: string;
OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryMessagesParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
// query, page info
type
TMediaWikiPageBasics = record
PageID: TMediaWikiID;
PageNamespace: Integer;
PageTitle: string;
end;
TMediaWikiPageProtection = record
PageProtectionAction: string;
PageProtectionGroup: string;
PageProtectionExpiry: string;
end;
TMediaWikiPageProtections = array of TMediaWikiPageProtection;
TMediaWikiPageFlag = (mwfPageIsNew, mwfPageIsRedirect);
TMediaWikiPageFlags = set of TMediaWikiPageFlag;
TMediaWikiPageInfo = record
PageBasics: TMediaWikiPageBasics;
PageLastTouched: TDateTime;
PageRevisionID: TMediaWikiID;
PageViews: Integer;
PageSize: Integer;
PageFlags: TMediaWikiPageFlags;
PageProtections: TMediaWikiPageProtections; // on request, use mwfIncludeProtection
PageTalkID: TMediaWikiID; // on request, use mwfIncludeTalkID
PageSubjectID: TMediaWikiID; // on request, mwfIncludeSubjectID
PageFullURL: string; // on request, mwfIncludeURL
PageEditURL: string; // on request, mwfIncludeURL
end;
TMediaWikiPageInfos = array of TMediaWikiPageInfo;
TMediaWikiPageInfoFlag = (mwfIncludeProtection, mwfIncludeTalkID, mwfIncludeSubjectID, mwfIncludeURL);
TMediaWikiPageInfoFlags = set of TMediaWikiPageInfoFlag;
procedure MediaWikiQueryPageInfoAdd(Queries: TStrings; const Titles: string; PageID: Boolean; Flags: TMediaWikiPageInfoFlags;
OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryPageInfoParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiPageInfos);
// query, page info, revision info
type
TMediaWikiPageRevisionFlag = (mwfMinorEdit);
TMediaWikiPageRevisionFlags = set of TMediaWikiPageRevisionFlag;
TMediaWikiPageRevisionInfo = record
PageRevisionInfoPageBasics: TMediaWikiPageBasics;
PageRevisionInfoID: TMediaWikiID;
PageRevisionInfoFlags: TMediaWikiPageRevisionFlags;
PageRevisionInfoDateTime: TDateTime;
PageRevisionInfoAuthor: string;
PageRevisionInfoComment: string;
PageRevisionInfoSize: Integer;
PageRevisionInfoContent: string;
// TODO RevisionTags: string;
PageRevisionInfoRollbackToken: string;
end;
TMediaWikiPageRevisionInfos = array of TMediaWikiPageRevisionInfo;
TMediaWikiPageRevisionInfoFlag = (mwfIncludeRevisionID, mwfIncludeRevisionFlags, mwfIncludeRevisionTimeStamp,
mwfIncludeRevisionAuthor, mwfIncludeRevisionComment, mwfIncludeRevisionSize, mwfIncludeRevisionContent,
mwfIncludeRevisionRollbackToken, mwfRevisionReverseOrder, mwfRevisionContentXml, mwfRevisionContentExpandTemplates,
mwfRevisionContinue);
TMediaWikiPageRevisionInfoFlags = set of TMediaWikiPageRevisionInfoFlag;
procedure MediaWikiQueryPageRevisionInfoAdd(Queries: TStrings; const Titles: string; PageID: Boolean;
Flags: TMediaWikiPageRevisionInfoFlags; const ContinueInfo: TMediaWikiContinueInfo; MaxRevisions, Section: Integer; StartRevisionID, EndRevisionID: TMediaWikiID;
const StartDateTime, EndDateTime: TDateTime; const IncludeUser, ExcludeUser: string; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryPageRevisionInfoParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiPageRevisionInfos; out ContinueInfo: TMediaWikiContinueInfo);
// query, page info, category info
type
TMediaWikiPageCategoryInfo = record
CategoryPageBasics: TMediaWikiPageBasics;
CategoryTitle: string;
CategoryNameSpace: Integer;
CategoryTimeStamp: TDateTime; // on request
CategorySortKey: string; // on request
end;
TMediaWikiPageCategoryInfos = array of TMediaWikiPageCategoryInfo;
TMediaWikiPageCategoryInfoFlag = (mwfIncludeCategorySortKey, mwfIncludeCategoryTimeStamp,
mwfCategoryHidden);
TMediaWikiPageCategoryInfoFlags = set of TMediaWikiPageCategoryInfoFlag;
procedure MediaWikiQueryPageCategoryInfoAdd(Queries: TStrings; const Titles: string; PageID: Boolean;
Flags: TMediaWikiPageCategoryInfoFlags; const ContinueInfo: TMediaWikiContinueInfo; MaxCategories: Integer;
const CategoryTitles: string; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryPageCategoryInfoParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiPageCategoryInfos; out ContinueInfo: TMediaWikiContinueInfo);
// query, page info, link info
type
TMediaWikiPageLinkInfo = record
LinkSourceBasics: TMediaWikiPageBasics;
LinkTargetTitle: string;
LinkTargetNameSpace: Integer;
end;
TMediaWikiPageLinkInfos = array of TMediaWikiPageLinkInfo;
procedure MediaWikiQueryPageLinkInfoAdd(Queries: TStrings; const Titles: string; PageID: Boolean;
const ContinueInfo: TMediaWikiContinueInfo; MaxLinks, Namespace: Integer; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryPageLinkInfoParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiPageLinkInfos; out ContinueInfo: TMediaWikiContinueInfo);
// query, page info, template info
type
TMediaWikiPageTemplateInfo = record
TemplatePageBasics: TMediaWikiPageBasics;
TemplateTitle: string;
TemplateNameSpace: Integer;
end;
TMediaWikiPageTemplateInfos = array of TMediaWikiPageTemplateInfo;
procedure MediaWikiQueryPageTemplateInfoAdd(Queries: TStrings; const Titles: string; PageID: Boolean;
const ContinueInfo: TMediaWikiContinueInfo; MaxTemplates, Namespace: Integer; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryPageTemplateInfoParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiPageTemplateInfos; out ContinueInfo: TMediaWikiContinueInfo);
// query, page info, ext links
type
TMediaWikiPageExtLinkInfo = record
ExtLinkPageBasics: TMediaWikiPageBasics;
ExtLinkTarget: string;
end;
TMediaWikiPageExtLinkInfos = array of TMediaWikiPageExtLinkInfo;
procedure MediaWikiQueryPageExtLinkInfoAdd(Queries: TStrings; const Titles: string; PageID: Boolean;
const ContinueInfo: TMediaWikiContinueInfo; MaxLinks: Integer; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryPageExtLinkInfoParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiPageExtLinkInfos; out ContinueInfo: TMediaWikiContinueInfo);
// query, list, all pages
type
TMediaWikiAllPageInfos = array of TMediaWikiPageBasics;
TMediaWikiAllPageFilterRedir = (mwfAllPageFilterAll, mwfAllPageFilterRedirect, mwfAllPageFilterNonRedirect);
TMediaWikiAllPageFilterLang = (mwfAllPageLangAll, mwfAllPageLangOnly, mwfAllPageLangNone);
TMediaWikiAllPageFilterProtection = (mwfAllPageProtectionNone, mwfAllPageProtectionEdit, mwfAllPageProtectionMove);
TMediaWikiAllPageFilterLevel = (mwfAllPageLevelNone, mwfAllPageLevelAutoConfirmed, mwfAllPageLevelSysops);
TMediaWikiAllPageDirection = (mwfAllPageAscending, mwfAllPageDescending);
procedure MediaWikiQueryAllPageAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo; const Prefix: string; MaxPage: Integer;
Namespace: Integer; RedirFilter: TMediaWikiAllPageFilterRedir;
LangFilter: TMediaWikiAllPageFilterLang; MinSize, MaxSize: Integer; ProtectionFilter: TMediaWikiAllPageFilterProtection;
LevelFilter: TMediaWikiAllPageFilterLevel; Direction: TMediaWikiAllPageDirection; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryAllPageParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiAllPageInfos; out ContinueInfo: TMediaWikiContinueInfo);
// query, list, alllinks: Returns a list of (unique) links to pages in a given namespace starting ordered by link title.
type
TMediaWikiAllLinkInfo = record
LinkTitle: string;
PageID: TMediaWikiID;
LinkNamespace: Integer;
end;
TMediaWikiAllLinkInfos = array of TMediaWikiAllLinkInfo;
TMediaWikiAllLinkInfoFlag = (mwfLinkUnique, mwfLinkIncludePageID);
TMediaWikiAllLinkInfoFlags = set of TMediaWikiAllLinkInfoFlag;
procedure MediaWikiQueryAllLinkAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo; const Prefix: string; MaxLink: Integer;
Namespace: Integer; Flags: TMediaWikiAllLinkInfoFlags;
OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryAllLinkParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiAllLinkInfos; out ContinueInfo: TMediaWikiContinueInfo);
type
TMediaWikiAllCategoryInfoFlag = (mwfCategoryDescending);
TMediaWikiAllCategoryInfoFlags = set of TMediaWikiAllCategoryInfoFlag;
procedure MediaWikiQueryAllCategoryAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo; const Prefix: string; MaxCategory: Integer;
Flags: TMediaWikiAllCategoryInfoFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryAllCategoryParseXmlResult(XML: TJclSimpleXML; Infos: TStrings; out ContinueInfo: TMediaWikiContinueInfo);
type
TMediaWikiAllUserInfo = record
UserName: string;
UserGroups: TDynStringArray;
UserEditCount: Integer;
UserRegistration: TDateTime;
end;
TMediaWikiAllUserInfos = array of TMediaWikiAllUserInfo;
TMediaWikiAllUserInfoFlag = (mwfIncludeUserEditCount, mwfIncludeUserGroups, mwfIncludeUserRegistration);
TMediaWikiAllUserInfoFlags = set of TMediaWikiAllUserInfoFlag;
procedure MediaWikiQueryAllUserAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo; const Prefix, Group: string; MaxUser: Integer;
Flags: TMediaWikiAllUserInfoFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryAllUserParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiAllUserInfos; out ContinueInfo: TMediaWikiContinueInfo);
type
TMediaWikiBackLinkFlag = (mwfBackLinkIsRedirect, // BackLinkPageID is redirected to BackLinkTitle
mwfBackLinkToRedirect); // BackLinkFromPageID links to BackLinkPageID which is redirected to BackLinkTitle
TMediaWikiBackLinkFlags = set of TMediaWikiBackLinkFlag;
TMediaWikiBackLinkInfo = record
BackLinkPageBasics: TMediaWikiPageBasics;
BackLinkFlags: TMediaWikiBackLinkFlags;
BackLinkRedirFromPageBasics: TMediaWikiPageBasics;
end;
TMediaWikiBackLinkInfos = array of TMediaWikiBackLinkInfo;
TMediaWikiBackLinkInfoFlag = (mwfExcludeBackLinkRedirect, mwfExcludeBackLinkNonRedirect, mwfIncludeBackLinksFromRedirect);
TMediaWikiBackLinkInfoFlags = set of TMediaWikiBackLinkInfoFlag;
procedure MediaWikiQueryBackLinkAdd(Queries: TStrings; const BackLinkTitle: string; const ContinueInfo: TMediaWikiContinueInfo; Namespace, MaxLink: Integer;
Flags: TMediaWikiBackLinkInfoFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryBackLinkParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiBackLinkInfos; out ContinueInfo: TMediaWikiContinueInfo);
type
TMediaWikiBlockFlag = (mwfBlockAutomatic, mwfBlockAnonymousEdits, mwfBlockNoAccountCreate, mwfBlockAutomaticBlocking, mwfBlockNoEmail, mwfBlockHidden);
TMediaWikiBlockFlags = set of TMediaWikiBlockFlag;
TMediaWikiBlockInfo = record
BlockID: TMediaWikiID;
BlockUser: string;
BlockUserID: TMediaWikiID;
BlockByUser: string;
BlockByUserID: TMediaWikiID;
BlockDateTime: TDateTime;
BlockExpirityDateTime: TDateTime;
BlockReason: string;
BlockIPRangeStart: string;
BlockIPRangeStop: string;
BlockFlags: TMediaWikiBlockFlags;
end;
TMediaWikiBlockInfos = array of TMediaWikiBlockInfo;
TMediaWikiBlockInfoFlag = (mwfBlockID, mwfBlockUser, mwfBlockByUser, mwfBlockDateTime, mwfBlockExpiry, mwfBlockReason, mwfBlockIPRange, mwfBlockFlags, mwfBlockDescending);
TMediaWikiBlockInfoFlags = set of TMediaWikiBlockInfoFlag;
procedure MediaWikiQueryBlockAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo;
const StartDateTime, StopDateTime: TDateTime;
const BlockIDs, Users, IP: string; MaxBlock: Integer;
Flags: TMediaWikiBlockInfoFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryBlockParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiBlockInfos; out ContinueInfo: TMediaWikiContinueInfo);
type
TMediaWikiCategoryMemberInfo = record
CategoryMemberPageBasics: TMediaWikiPageBasics;
CategoryMemberDateTime: TDateTime;
CategoryMemberSortKey: string;
end;
TMediaWikiCategoryMemberInfos = array of TMediaWikiCategoryMemberInfo;
TMediaWikiCategoryMemberInfoFlag = (mwfCategoryMemberPageID, mwfCategoryMemberPageTitle,
mwfCategoryMemberPageDateTime, mwfCategoryMemberPageSortKey, mwfCategoryMemberDescending);
TMediaWikiCategoryMemberInfoFlags = set of TMediaWikiCategoryMemberInfoFlag;
procedure MediaWikiQueryCategoryMemberAdd(Queries: TStrings; const CategoryTitle: string;
const ContinueInfo: TMediaWikiContinueInfo; PageNamespace: Integer;
const StartDateTime, StopDateTime: TDateTime; const StartSortKey, StopSortKey: string;
MaxCategoryMember: Integer; Flags: TMediaWikiCategoryMemberInfoFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiQueryCategoryMemberParseXmlResult(XML: TJclSimpleXML; out Infos: TMediaWikiCategoryMemberInfos; out ContinueInfo: TMediaWikiContinueInfo);
type
TMediaWikiEditFlag = (mwfEditMinor, mwfEditNotMinor, mwfEditBot, mwfEditAlwaysRecreate, mwfEditMustCreate, mwfEditMustExist,
mwfEditWatchAdd, mwfEditWatchRemove, mwfEditWatchNoChange, mwfEditUndoAfterRev);
TMediaWikiEditFlags = set of TMediaWikiEditFlag;
TMediaWikiEditInfo = record
EditSuccess: Boolean;
EditPageTitle: string;
EditPageID: TMediaWikiID;
EditOldRevID: TMediaWikiID;
EditNewRevID: TMediaWikiID;
EditCaptchaType: string;
EditCaptchaURL: string;
EditCaptchaMime: string;
EditCaptchaID: string;
EditCaptchaQuestion: string;
end;
procedure MediaWikiEditAdd(Queries: TStrings; const PageTitle, Section, Text, PrependText, AppendText, EditToken, Summary, MD5, CaptchaID, CaptchaWord: string;
const BaseDateTime, StartDateTime: TDateTime; UndoRevisionID: TMediaWikiID;
Flags: TMediaWikiEditFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiEditParseXmlResult(XML: TJclSimpleXML; out Info: TMediaWikiEditInfo);
type
TMediaWikiMoveFlag = (mwfMoveTalk, mwfMoveSubPages, mwfMoveNoRedirect, mwfMoveAddToWatch, mwfMoveNoWatch);
TMediaWikiMoveFlags = set of TMediaWikiMoveFlag;
TMediaWikiMoveInfo = record
MoveSuccess: Boolean;
MoveFromPage: string;
MoveToPage: string;
MoveReason: string;
MoveFromTalk: string;
MoveToTalk: string;
end;
procedure MediaWikiMoveAdd(Queries: TStrings; const FromPageTitle, ToPageTitle, MoveToken, Reason: string;
FromPageID: TMediaWikiID; Flags: TMediaWikiMoveFlags; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiMoveParseXmlResult(XML: TJclSimpleXML; out Info: TMediaWikiMoveInfo);
// DeleteRevision requires some modifications in the MediaWiki API running in the server
type
TMediaWikiDeleteInfo = record
DeleteSuccess: Boolean;
DeletePage: string;
DeleteReason: string;
end;
procedure MediaWikiDeleteAdd(Queries: TStrings; const PageTitle, DeleteToken, Reason: string;
PageID: TMediaWikiID; Suppress: Boolean; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiDeleteParseXmlResult(XML: TJclSimpleXML; out Info: TMediaWikiDeleteInfo);
type
TMediaWikiDeleteRevisionInfo = record
DeleteRevisionSuccess: Boolean;
DeleteRevisionPage: string;
DeleteRevisionID: TMediaWikiID;
DeleteRevisionReason: string;
end;
procedure MediaWikiDeleteRevisionAdd(Queries: TStrings; const PageTitle, DeleteToken, Reason: string;
PageID, RevisionID: TMediaWikiID; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiDeleteRevisionParseXmlResult(XML: TJclSimpleXML; out Info: TMediaWikiDeleteRevisionInfo);
type
TMediaWikiUploadFlag = (mwfUploadWatch, mwfUploadIgnoreWarnings);
TMediaWikiUploadFlags = set of TMediaWikiUploadFlag;
TMediaWikiUploadInfo = record
UploadSuccess: Boolean;
UploadFileName: string;
UploadImageDataTime: TDateTime;
UploadImageUser: string;
UploadImageSize: Int64;
UploadImageWidth: Int64;
UploadImageHeight: Int64;
UploadImageURL: string;
UploadImageDescriptionURL: string;
UploadImageComment: string;
UploadImageSHA1: string;
UploadImageMetaData: string;
UploadImageMime: string;
UploadImageBitDepth: Int64;
end;
procedure MediaWikiUploadAdd(Queries: TStrings; const FileName, Comment, Text, EditToken: string;
Flags: TMediaWikiUploadFlags; Content: TStream; const URL: string; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiUploadParseXmlResult(XML: TJclSimpleXML; out Info: TMediaWikiUploadInfo);
type
TMediaWikiUserMergeInfo = record
UserMergeSuccess: Boolean;
UserMergeOldUser: string;
UserMergeNewUser: string;
end;
procedure MediaWikiUserMergeAdd(Queries: TStrings; const OldUser, NewUser, Token: string;
DeleteUser: Boolean; OutputFormat: TMediaWikiOutputFormat);
procedure MediaWikiUserMergeParseXmlResult(XML: TJclSimpleXML; out Info: TMediaWikiUserMergeInfo);
implementation
uses
DateUtils,
OverbyteIcsUrl,
JclAnsiStrings,
JclMime,
JclStrings;
//=== { EMediaWikiException } ================================================
constructor EMediaWikiException.Create(const AInfo: string);
begin
inherited Create('');
FInfo := AInfo;
end;
procedure EMediaWikiException.AfterConstruction;
begin
Message := Format('MediaWiki exception with message: "%s"', [Info]);
end;
//=== { EMediaWikiWarning } ==================================================
constructor EMediaWikiWarning.Create(const AInfo, AQuery: string);
begin
inherited Create(AInfo);
FQuery := AQuery;
end;
procedure EMediaWikiWarning.AfterConstruction;
begin
Message := Format('MediaWiki warning during query "%s" with info "%s"', [Query, Info]);
end;
//=== { EMediaWikiError } ====================================================
constructor EMediaWikiError.Create(const AInfo, ACode: string);
begin
inherited Create(AInfo);
FCode := ACode;
end;
procedure EMediaWikiError.AfterConstruction;
begin
Message := Format('MediaWiki error code "%s" with info "%s"', [Code, Info]);
end;
procedure MediaWikiCheckXML(XML: TJclSimpleXML; WarningCallback: TMediaWikiXMLWarningCallback;
ErrorCallback: TMediaWikiXMLErrorCallback);
var
ErrorElem, WarningsElem, WarningElem: TJclSimpleXMLElem;
Info, Code: string;
Index: Integer;
begin
XML.Options := XML.Options - [sxoAutoCreate];
// check errors and warnings
ErrorElem := XML.Root.Items.ItemNamed['error'];
WarningsElem := XML.Root.Items.ItemNamed['warnings'];
if Assigned(ErrorElem) then
begin
XML.Options := XML.Options + [sxoAutoCreate];
Info := ErrorElem.Properties.ItemNamed['info'].Value;
Code := ErrorElem.Properties.ItemNamed['code'].Value;
ErrorCallback(Info, Code);
end;
if Assigned(WarningsElem) then
begin
XML.Options := XML.Options - [sxoAutoCreate];
for Index := 0 to WarningsElem.Items.Count - 1 do
begin
WarningElem := WarningsElem.Items.Item[Index];
WarningCallback(WarningElem.Value, WarningElem.Name);
end;
end;
end;
function FindMediaWikiLoginResult(const AString: string): TMediaWikiLoginResult;
begin
for Result := Low(TMediaWikiLoginResult) to High(TMediaWikiLoginResult) do
if SameText(AString, MediaWikiLoginResults[Result]) then
Exit;
raise EMediaWikiException.Create('not a valid login result');
end;
function StrISO8601ToDateTime(const When: string): TDateTime;
var
Year, Month, Day, Hour, Min, Sec: Integer;
ErrCode: Integer;
begin
Result := 0;
if (Length(When) = 20) and (When[5] = '-') and (When[8] = '-') and (When[11] = 'T') and
(When[14] = ':') and (When[17] = ':') and (When[20] = 'Z') then
begin
Val(Copy(When, 1, 4), Year, ErrCode);
if (ErrCode <> 0) or (Year < 0) then
Exit;
Val(Copy(When, 6, 2), Month, ErrCode);
if (ErrCode <> 0) or (Month < 1) or (Month > 12) then
Exit;
Val(Copy(When, 9, 2), Day, ErrCode);
if (ErrCode <> 0) or (Day < 1) or (Day > 31) then
Exit;
Val(Copy(When, 12, 2), Hour, ErrCode);
if (ErrCode <> 0) or (Hour < 0) or (Hour > 23) then
Exit;
Val(Copy(When, 15, 2), Min, ErrCode);
if (ErrCode <> 0) or (Min < 0) or (Min > 59) then
Exit;
Val(Copy(When, 18, 2), Sec, ErrCode);
if (ErrCode <> 0) or (Sec < 0) or (Sec > 59) then
Exit;
Result := DateUtils.EncodeDateTime(Year, Month, Day, Hour, Min, Sec, 0);
end
else
if When = 'infinity' then
Result := Infinity;
end;
function DateTimeToStrISO8601(When: TDateTime): string;
var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
if When = Infinity then
Result := 'infinity'
else
begin
DateUtils.DecodeDateTime(When, Year, Month, Day, Hour, Min, Sec, MSec);
Result := Format('%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ', [Year, Month, Day, Hour, Min, Sec]);
end;
end;
// post stuff
procedure MediaWikiQueryAdd(Queries: TStrings; const AName, AValue: AnsiString; RawValue: Boolean; Content: TStream);
var
NamePos: Integer;
CurrentValue: string;
Values: TStringList;
begin
NamePos := Queries.IndexOfName(string(AName));
if Assigned(Content) then
begin
if NamePos >= 0 then
Queries.Delete(NamePos);
NamePos := Queries.IndexOf(string(AName));
if NamePos >= 0 then
Queries.Delete(NamePos);
Queries.Values[AName] := AValue;
NamePos := Queries.IndexOfName(AName);
Queries.Objects[NamePos] := Content;
end
else
if (NamePos >= 0) and (AValue <> '') then
begin
// avoid duplicate values
CurrentValue := Queries.Values[AName];
if (CurrentValue <> AValue) and (Pos('|', CurrentValue) > 0) then
begin
Values := TStringList.Create;
try
StrToStrings(CurrentValue, '|', Values, True);
if Values.IndexOf(AValue) < 0 then
Queries.Values[AName] := CurrentValue + '|' + AValue;
finally
Values.Free;
end;
end
else
if CurrentValue <> AValue then
Queries.Values[AName] := CurrentValue + '|' + AValue;
if RawValue then
Queries.Objects[NamePos] := Queries;
end
else
if AValue = '' then
begin
Queries.Values[AName] := 'true';
if RawValue then
begin
NamePos := Queries.IndexOfName(AName);
Queries.Objects[NamePos] := Queries;
end;
end
else
begin
Queries.Values[AName] := AValue;
if RawValue then
begin
NamePos := Queries.IndexOfName(AName);
Queries.Objects[NamePos] := Queries;
end;
end;
end;
procedure MediaWikiQueryAdd(Queries: TStrings; const ContinueInfo: TMediaWikiContinueInfo);
begin
if ContinueInfo.ParameterName <> '' then
MediaWikiQueryAdd(Queries, ContinueInfo.ParameterName, ContinueInfo.ParameterValue, True, nil);
end;
procedure MediaWikiQueryPostAdd(ASendStream: TStream; const Data: AnsiString);
begin
if Length(Data) > 0 then
ASendStream.WriteBuffer(Data[1], Length(Data));
end;
procedure MediaWikiQueryPostWWWFormUrlEncoded(Queries: TStrings; ASendStream: TStream);
var
AName: string;
I, J: Integer;
Values: TStrings;
begin
Values := TStringList.Create;
try
for I := 0 to Queries.Count - 1 do
begin
if I > 0 then
MediaWikiQueryPostAdd(ASendStream, '&');
AName := Queries.Names[I];
if AName = '' then
MediaWikiQueryPostAdd(ASendStream, AnsiString(Queries.Strings[I]))
else
begin
if Queries.Objects[I] = nil then
begin
// call UrlEncodeToA
StrToStrings(Queries.ValueFromIndex[I], '|', Values, False);
for J := 0 to Values.Count - 1 do
Values.Strings[J] := UrlEncodeToA(Values.Strings[J]);
MediaWikiQueryPostAdd(ASendStream, AnsiString(AName) + '=' + AnsiString(StringsToStr(Values, '|', False)));
end
else
// skip UrlEncodeToA
MediaWikiQueryPostAdd(ASendStream, AnsiString(Queries.Strings[I]));
end;
end;
//MediaWikiQueryPostAdd(ASendStream, AnsiCarriageReturn);
finally
Values.Free;
end;
end;
procedure MediaWikiQueryPostFormData(Queries: TStrings; ASendStream: TStream);
var
AName: string;
Boundary: AnsiString;
Index: Integer;
Content: TStream;
begin
Boundary := Format('--%.4x%.4x%.8x', [Cardinal(Queries), Cardinal(ASendStream), DateTimeToUnix(Now)]);
for Index := 0 to Queries.Count - 1 do
begin
MediaWikiQueryPostAdd(ASendStream, Boundary + AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, 'Content-Disposition: form-data; ');
AName := Queries.Names[Index];
if Queries.Objects[Index] is TStream then
begin
Content := TStream(Queries.Objects[Index]);
MediaWikiQueryPostAdd(ASendStream, 'name="' + AnsiString(AName) + '"; filename="' + Queries.Values[AName] + '"' + AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, 'content-type: application/octet-stream' + AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, 'Content-Transfer-Encoding: base64' + AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, AnsiLineBreak);
MimeEncodeStream(Content, ASendStream);
//ASendStream.CopyFrom(Content, Content.Size);
MediaWikiQueryPostAdd(ASendStream, AnsiLineBreak);
end
else
if AName = '' then
begin
MediaWikiQueryPostAdd(ASendStream, 'name="' + AnsiString(Queries.Strings[Index]) + '"' + AnsiLineBreak);
//MediaWikiQueryPostAdd(ASendStream, 'content-type: text/plain' + AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, AnsiLineBreak);
end
else
begin
MediaWikiQueryPostAdd(ASendStream, 'name="' + AnsiString(AName) + '"' + AnsiLineBreak);
//MediaWikiQueryPostAdd(ASendStream, 'content-type: text/plain' + AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, AnsiLineBreak);
MediaWikiQueryPostAdd(ASendStream, AnsiString(Queries.Values[AName]) + AnsiLineBreak);
end;
end;
MediaWikiQueryPostAdd(ASendStream, Boundary + '--' + AnsiLineBreak);
end;
procedure MediaWikiQueryPost(Queries: TStrings; ASendStream: TStream; out ContentType: string);
var
Index: Integer;
begin
for Index := 0 to Queries.Count - 1 do
if Queries.Objects[Index] is TStream then
begin
ContentType := 'multipart/form-data';
MediaWikiQueryPostFormData(Queries, ASendStream);
Exit;
end;
ContentType := 'application/x-www-form-urlencoded';
MediaWikiQueryPostWWWFormUrlEncoded(Queries, ASendStream);
end;
// login stuff
procedure MediaWikiQueryLoginAdd(Queries: TStrings; const lgName, lgPassword, lgToken: string;
OutputFormat: TMediaWikiOutputFormat);
begin
MediaWikiQueryAdd(Queries, 'action', 'login');
MediaWikiQueryAdd(Queries, 'lgname', lgName, True);
MediaWikiQueryAdd(Queries, 'lgpassword', lgPassword);
MediaWikiQueryAdd(Queries, 'lgtoken', lgToken);
MediaWikiQueryAdd(Queries, 'format', MediaWikiOutputFormats[OutputFormat]);
end;
procedure MediaWikiQueryLoginParseXmlResult(XML: TJclSimpleXML; out LoginResult: TMediaWikiLoginResult;
out LoginUserID: TMediaWikiID; out LoginUserName: string);
var
Login: TJclSimpleXMLElem;
begin
XML.Options := XML.Options + [sxoAutoCreate];
Login := XML.Root.Items.ItemNamed['login'];
LoginResult := FindMediaWikiLoginResult(Login.Properties.ItemNamed['result'].Value);
LoginUserID := Login.Properties.ItemNamed['lguserid'].IntValue;
LoginUserName := Login.Properties.ItemNamed['lgusername'].Value;
end;
// logout stuff
procedure MediaWikiQueryLogoutAdd(Queries: TStrings; const token: string; OutputFormat: TMediaWikiOutputFormat);
begin
MediaWikiQueryAdd(Queries, 'action', 'logout');
MediaWikiQueryAdd(Queries, 'token', token);
MediaWikiQueryAdd(Queries, 'format', MediaWikiOutputFormats[OutputFormat]);
end;
procedure MediaWikiQueryLogoutParseXmlResult(XML: TJclSimpleXML);
begin
// nothing special to be done
end;
// query, site info general
procedure MediaWikiQuerySiteInfoGeneralAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
begin
MediaWikiQueryAdd(Queries, 'action', 'query');
MediaWikiQueryAdd(Queries, 'meta', 'siteinfo');
MediaWikiQueryAdd(Queries, 'siprop', 'general');
MediaWikiQueryAdd(Queries, 'format', MediaWikiOutputFormats[OutputFormat]);
end;
procedure MediaWikiQuerySiteInfoGeneralParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
var
Query, General: TJclSimpleXMLElem;
Index: Integer;
Prop: TJclSimpleXMLProp;
begin
Infos.Clear;
XML.Options := XML.Options + [sxoAutoCreate];
Query := XML.Root.Items.ItemNamed['query'];
General := Query.Items.ItemNamed['general'];
Infos.BeginUpdate;
try
for Index := 0 to General.Properties.Count - 1 do
begin
Prop := General.Properties.Item[Index];
Infos.Values[Prop.Name] := Prop.Value;
end;
finally
Infos.EndUpdate;
end;
end;
// query, site info namespaces
procedure MediaWikiQuerySiteInfoNamespacesAdd(Queries: TStrings; OutputFormat: TMediaWikiOutputFormat);
begin
MediaWikiQueryAdd(Queries, 'action', 'query');
MediaWikiQueryAdd(Queries, 'meta', 'siteinfo');
MediaWikiQueryAdd(Queries, 'siprop', 'namespaces');
MediaWikiQueryAdd(Queries, 'format', MediaWikiOutputFormats[OutputFormat]);
end;
procedure MediaWikiQuerySiteInfoNamespacesParseXmlResult(XML: TJclSimpleXML; Infos: TStrings);
var
Query, Namespaces, NameSpace: TJclSimpleXMLElem;
Index: Integer;
IDProp, CanonicalProp: TJclSimpleXMLProp;
begin
Infos.Clear;
XML.Options := XML.Options + [sxoAutoCreate];
Query := XML.Root.Items.ItemNamed['query'];
Namespaces := Query.Items.ItemNamed['namespaces'];
Infos.BeginUpdate;
try
for Index := 0 to Namespaces.Items.Count - 1 do
begin
NameSpace := Namespaces.Items.Item[Index];