-
Notifications
You must be signed in to change notification settings - Fork 15
/
mediawiki.el
2390 lines (2112 loc) · 88.2 KB
/
mediawiki.el
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
;;; mediawiki.el --- mediawiki frontend
;; Copyright (C) 2008, 2009, 2010, 2011, 2015 Mark A. Hershberger
;; Original Authors: Jerry <[email protected]>,
;; Chong Yidong <cyd at stupidchicken com> for wikipedia.el,
;; Uwe Brauer <oub at mat.ucm.es> for wikimedia.el
;; Author: Mark A. Hershberger <[email protected]>
;; Created: Sep 17 2004
;; Keywords: mediawiki wikipedia network wiki
;; URL: https://github.com/hexmode/mediawiki-el
;; Last Modified: <2020-07-11 22:45:06 mah>
(defconst mediawiki-version "2.3.1"
"Current version of mediawiki.el.")
;; This file is NOT (yet) part of GNU Emacs.
;; 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.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This version of mediawiki.el represents a merging of
;; wikipedia-mode.el (maintained by Uwe Brauer <oub at mat.ucm.es>)
;; from https://www.emacswiki.org/emacs/wikipedia-mode.el for its
;; font-lock code, menu, draft mode, replying and convenience
;; functions to produce mediawiki.el 2.0.
;;; Installation
;; If you use ELPA, you can install via the M-x package-list-packages
;; interface. This is preferrable as you will have access to updates
;; automatically.
;; Otherwise, just make sure this file is in your load-path (usually
;; ~/.emacs.d is included) and put (require 'mediawiki.el) in your
;; ~/.emacs or ~/.emacs.d/init.el file.
;;; Howto:
;; M-x customize-group RET mediawiki RET
;; *dink* *dink*
;; M-x mediawiki-site RET Wikipedia RET
;;
;; Open a wiki file: M-x mediawiki-open
;; Save a wiki buffer: C-x C-s
;; Save a wiki buffer with a different name: C-x C-w
;;; TODO
;; * Optionally use org-mode formatting for editing and translate
;; that to mw
;; * Move url-* methods to url-http
;; * Use the MW API to support searching, etc.
;; * Clean up and thoroughly test imported wikimedia.el code
;; * Improve language support. Currently there is a toggle for
;; English or German. This should probably just be replaced with
;; customizable words given MediaWiki's wide language support.
;;; Changes
;; 2.2.7:
;; * Add the ability to accept the domain
;; * Fix false failures when site isn't found.
;; 2.2.6:
;; * Moved to github
;; * Code cleanup, flycheck
;; Since 2.2.4.2
;; * Move to github
;; * Added Readme.mediawiki to with information about security.
;; Since 2.2.4.1:
;; * Add the forgotten customizable mediawiki-debug.
;; Since 2.2.4:
;; * Made it clearer where debugging information is found when
;; mediawiki-debug is non-nil by adding messages to the message
;; buffer when debug buffers are killed.
;;; History
;; From the News section of wikipedia.el comes this bit, kept here for
;; reference later.
;; (4) "Draft", "send" and "reply" (for discussion pages)
;; abilities `based' on ideas of John Wigleys remember.el: see
;; the functions wikipedia-draft-*
;; RATIONALE: This comes handy in 2 situations
;; 1. You are editing articles which various authors (this I
;; think is the usual case), you then want not to submit
;; your edit immediately but want to copy it somewhere and
;; to continue later. You can use the following functions
;; for doing that:
;; wikipedia-draft-buffer \C-c\C-b
;; wikipedia-draft-region \C-c\C-r
;; then the buffer/region will be appended to the
;; wikipedia-draft-data-file (default is
;; "~/Wiki/discussions/draft.wiki", which you can visit via
;; wikipedia-draft-view-draft) and it will be
;; surrounded by the ^L marks in order to set a page.
;; moreover on top on that a section header == will be
;; inserted, which consists of the Word Draft, a subject
;; you are asked for and a date stamp.
;;
;; Another possibility consists in using the function
;; wikipedia-draft, bound to \C-c \C-m then a new buffer
;; will opened already in wikipedia mode. You edit and then
;; either can send the content of the buffer to the
;; wikipedia-draft-data-file in the same manner as
;; described above using the function
;; wikipedia-draft-buffer (bound to \C-c\C-k)
;;
;; BACK: In order to copy/send the content of temporary
;; buffer or of a page in the wikipedia-draft-data-file
;; back in to your wikipedia file, use the function
;; wikipedia-send-draft-to-mozex bound to "\C-c\C-c". You
;; will be asked to which buffer to copy your text!
;;
;;
;; 2. You want to reply in a discussion page to a specific
;; contribution, you can use either the function
;;
;; \\[wikipedia-reply-at-point-simple] bound to [(meta shift r)]
;; which inserts a newline, a hline, and the signature of
;; the author. Or can use
;; \\[wikipedia-draft-reply] bound [(meta r)]
;; which does the same as wikipedia-reply-at-point-simple
;; but in a temporary draft buffer.
;;
;; BACK: In order to copy/send the content of that buffer
;; back in to your wikipedia file, use the function
;; \\[wikipedia-send-draft-to-mozex] bound to "\C-c\C-c". You
;; will be asked to which buffer to copy your text! If
;; you want a copy to be send to your draft file, use
;; the variable wikipedia-draft-send-archive
;;
;;; Code:
(require 'url-http)
(require 'mml)
(require 'mm-url)
(require 'ring)
(require 'subr-x)
(eval-when-compile
(require 'cl)
(require 'mml)
;; Below copied from url-http to avoid compilation warnings
(defvar url-http-extra-headers)
(defvar url-http-target-url)
(defvar url-http-proxy)
(defvar url-http-connection-opened)
;; This should only be used in xemacs, anyway
(setq byte-compile-not-obsolete-funcs (list 'assoc-ignore-case)))
;; As of 2010-06-22, these functions are in Emacs
(unless (fboundp 'url-bit-for-url)
(defun url-bit-for-url (method lookfor url)
(when (fboundp 'auth-source-user-or-password)
(let* ((urlobj (url-generic-parse-url url))
(bit (funcall method urlobj))
(methods (list 'url-recreate-url
'url-host)))
(if (and (not bit) (> (length methods) 0))
(auth-source-user-or-password
lookfor (funcall (pop methods) urlobj) (url-type urlobj))
bit)))))
(unless (fboundp 'url-user-for-url)
(defun url-user-for-url (url)
"Attempt to use .authinfo to find a user for this URL."
(url-bit-for-url 'url-user "login" url)))
(unless (fboundp 'url-password-for-url)
(defun url-password-for-url (url)
"Attempt to use .authinfo to find a password for this URL."
(url-bit-for-url 'url-password "password" url)))
(when (fboundp 'url-http-create-request)
(if (string= "GET / HTTP/1.0\r\nMIME-Version: 1.0\r\nConnection: close\r\nHost: example.com\r\nAccept: */*\r\nUser-Agent: URL/Emacs\r\nContent-length: 4\r\n\r\ntest"
(let ((url-http-target-url (url-generic-parse-url "http://example.com/"))
(url-http-data "test") (url-http-version "1.0") (url-http-referer "test")
url-http-method url-http-attempt-keepalives url-extensions-header
url-http-extra-headers url-http-proxy url-mime-charset-string)
(url-http-create-request)))
(defun url-http-create-request (&optional ref-url)
"Create an HTTP request for `url-http-target-url', referred to by REF-URL."
(declare (special proxy-info
url-http-method url-http-data
url-http-extra-headers))
(let* ((extra-headers)
(request nil)
(no-cache (cdr-safe (assoc "Pragma" url-http-extra-headers)))
(using-proxy url-http-proxy)
(proxy-auth (if (or (cdr-safe (assoc "Proxy-Authorization"
url-http-extra-headers))
(not using-proxy))
nil
(let ((url-basic-auth-storage
'url-http-proxy-basic-auth-storage))
(url-get-authentication url-http-target-url nil 'any nil))))
(real-fname (concat (url-filename url-http-target-url)
(with-no-warnings
(url-recreate-url-attributes url-http-target-url))))
(host (url-host url-http-target-url))
(auth (if (cdr-safe (assoc "Authorization" url-http-extra-headers))
nil
(url-get-authentication (or
(and (boundp 'proxy-info)
proxy-info)
url-http-target-url) nil 'any nil))))
(if (equal "" real-fname)
(setq real-fname "/"))
(setq no-cache (and no-cache (string-match "no-cache" no-cache)))
(if auth
(setq auth (concat "Authorization: " auth "\r\n")))
(if proxy-auth
(setq proxy-auth (concat "Proxy-Authorization: " proxy-auth "\r\n")))
;; Protection against stupid values in the referer
(if (and ref-url (stringp ref-url) (or (string= ref-url "file:nil")
(string= ref-url "")))
(setq ref-url nil))
;; We do not want to expose the referer if the user is paranoid.
(if (or (memq url-privacy-level '(low high paranoid))
(and (listp url-privacy-level)
(memq 'lastloc url-privacy-level)))
(setq ref-url nil))
;; url-http-extra-headers contains an assoc-list of
;; header/value pairs that we need to put into the request.
(setq extra-headers (mapconcat
(lambda (x)
(concat (car x) ": " (cdr x)))
url-http-extra-headers "\r\n"))
(if (not (equal extra-headers ""))
(setq extra-headers (concat extra-headers "\r\n")))
;; This was done with a call to `format'. Concatting parts has
;; the advantage of keeping the parts of each header together and
;; allows us to elide null lines directly, at the cost of making
;; the layout less clear.
(setq request
;; We used to concat directly, but if one of the strings happens
;; to being multibyte (even if it only contains pure ASCII) then
;; every string gets converted with `string-MAKE-multibyte' which
;; turns the 127-255 codes into things like latin-1 accented chars
;; (it would work right if it used `string-TO-multibyte' instead).
;; So to avoid the problem we force every string to be unibyte.
(mapconcat
;; FIXME: Instead of `string-AS-unibyte' we'd want
;; `string-to-unibyte', so as to properly signal an error if one
;; of the strings contains a multibyte char.
'string-as-unibyte
(delq nil
(list
;; The request
(or url-http-method "GET") " "
(if using-proxy (url-recreate-url url-http-target-url) real-fname)
" HTTP/" url-http-version "\r\n"
;; Version of MIME we speak
"MIME-Version: 1.0\r\n"
;; (maybe) Try to keep the connection open
"Connection: " (if (or using-proxy
(not url-http-attempt-keepalives))
"close" "keep-alive") "\r\n"
;; HTTP extensions we support
(if url-extensions-header
(format
"Extension: %s\r\n" url-extensions-header))
;; Who we want to talk to
(if (/= (url-port url-http-target-url)
(url-scheme-get-property
(url-type url-http-target-url) 'default-port))
(format
"Host: %s:%d\r\n" host (url-port url-http-target-url))
(format "Host: %s\r\n" host))
;; Who its from
(if url-personal-mail-address
(concat
"From: " url-personal-mail-address "\r\n"))
;; Encodings we understand
(if url-mime-encoding-string
(concat
"Accept-encoding: " url-mime-encoding-string "\r\n"))
(if url-mime-charset-string
(concat
"Accept-charset: " url-mime-charset-string "\r\n"))
;; Languages we understand
(if url-mime-language-string
(concat
"Accept-language: " url-mime-language-string "\r\n"))
;; Types we understand
"Accept: " (or url-mime-accept-string "*/*") "\r\n"
;; User agent
(url-http-user-agent-string)
;; Proxy Authorization
proxy-auth
;; Authorization
auth
;; Cookies
(url-cookie-generate-header-lines host real-fname
(equal "https" (url-type url-http-target-url)))
;; If-modified-since
(if (and (not no-cache)
(member url-http-method '("GET" nil)))
(let ((tm (url-is-cached url-http-target-url)))
(if tm
(concat "If-modified-since: "
(url-get-normalized-date tm) "\r\n"))))
;; Whence we came
(if ref-url (concat
"Referer: " ref-url "\r\n"))
extra-headers
;; Length of data
(if url-http-data
(concat
"Content-length: " (number-to-string
(length url-http-data))
"\r\n"))
;; End request
"\r\n"
;; Any data
url-http-data "\r\n"))
""))
(url-http-debug "Request is: \n%s" request)
request))))
;; There are some versions of emacs that don't have
;; mm-url-encode-multipart-form-data.
;; See https://lists.gnu.org/archive/html/emacs-diffs/2014-11/msg00167.html
(unless (fboundp 'mm-url-encode-multipart-form-data)
(defun mm-url-encode-multipart-form-data (pairs &optional boundary)
"Return PAIRS encoded in multipart/form-data."
;; RFC1867
;; Get a good boundary
(unless boundary
(setq boundary (mml-compute-boundary '())))
(concat
;; Start with the boundary
"--" boundary "\r\n"
;; Create name value pairs
(mapconcat
'identity
;; Delete any returned items that are empty
(delq nil
(mapcar (lambda (data)
(cond
((consp (car data))
(let ((fieldname (cadar data))
(filename (caadar data))
(mimetype (car (caadar data)))
(content (caar (caadar data))))
(concat
;; Encode the name
"Content-Disposition: form-data; name=\"" fieldname "\"\r\n"
"Content-Type: " mimetype "\r\n"
"Content-Transfer-Encoding: binary\r\n\r\n"
content
"\r\n")))
((stringp (car data))
;; For each pair
(concat
;; Encode the name
"Content-Disposition: form-data; name=\""
(car data) "\"\r\n"
"Content-Type: text/plain; charset=utf-8\r\n"
"Content-Transfer-Encoding: binary\r\n\r\n"
(cond ((stringp (cdr data))
(cdr data))
((integerp (cdr data))
(int-to-string (cdr data))))
"\r\n"))
(t (error "I don't handle this"))))
pairs))
;; use the boundary as a separator
(concat "--" boundary "\r\n"))
;; put a boundary at the end.
"--" boundary "--\r\n")))
;; Not defined in my Xemacs
(unless (fboundp 'assoc-string)
(defun assoc-string (key list &optional case-fold)
(if case-fold
(assoc-ignore-case key list)
(assoc key list))))
(defun url-compat-retrieve (url post-process buffer callback cbargs)
"Function to compatibly retrieve a URL.
Some provision is made for different versions of Emacs version.
POST-PROCESS is the function to call for post-processing.
BUFFER is the buffer to store the result in. CALLBACK will be
called in BUFFER with CBARGS, if given."
(let ((url-user-agent (concat
(if (not (eq url-user-agent 'default))
(string-trim (if (functionp url-user-agent)
(funcall url-user-agent)
url-user-agent))
"")
" mediawiki.el " mediawiki-version "\r\n")))
(cond ((boundp 'url-be-asynchronous) ; Sniff w3 lib capability
(if callback
(setq url-be-asynchronous t)
(setq url-be-asynchronous nil))
(url-retrieve url t)
(when (not url-be-asynchronous)
(let ((result (funcall post-process buffer)))
result)))
(t (if callback
(url-retrieve url post-process
(list buffer callback cbargs))
(with-current-buffer (url-retrieve-synchronously url)
(funcall post-process buffer)))))))
(defvar url-http-get-post-process 'url-http-response-post-process)
(defun url-http-get (url &optional headers buffer callback cbargs)
"Convenience method to use method 'GET' to retrieve URL.
HEADERS is the optional headers to send. BUFFER is where the
result will be stored. CALLBACK will be called in BUFFER with
CBARGS, if given."
(let* ((url-request-extra-headers (if headers headers
(if url-request-extra-headers
url-request-extra-headers
(cons nil nil))))
(url-request-method "GET"))
(when (url-basic-auth url)
(add-to-list 'url-request-extra-headers
(cons "Authorization" (url-basic-auth url))))
(url-compat-retrieve url url-http-get-post-process
buffer callback cbargs)))
(defvar url-http-post-post-process 'url-http-response-post-process)
(defun url-http-post (url parameters &optional multipart headers buffer
callback cbargs)
"Convenience method to use method 'POST' to retrieve URL.
PARAMETERS are the parameters to put the the body. If MULTIPART
is t, then multipart/form-data will be used. Otherwise,
applicaton/x-www-form-urlencoded is used. HEADERS is the
optional headers to send. BUFFER is where the result will be
stored. CALLBACK will be called in BUFFER with CBARGS, if
given."
(let* ((url-request-extra-headers
(if headers headers
(when url-request-extra-headers url-request-extra-headers)))
(boundary (int-to-string (random)))
(cs 'utf-8)
(content-type
(if multipart
(concat "multipart/form-data, boundary=" boundary)
(format "application/x-www-form-urlencoded; charset=%s" cs)))
(url-request-method "POST")
(url-request-coding-system cs)
(url-request-data
(if multipart
(mm-url-encode-multipart-form-data
parameters boundary)
(mm-url-encode-www-form-urlencoded (delq nil parameters)))))
(mapc
(lambda (pair)
(let ((key (car pair))
(val (cdr pair)))
(if (assoc key url-request-extra-headers)
(setcdr (assoc key url-request-extra-headers) val)
(add-to-list 'url-request-extra-headers
(cons key val)))))
(list
(cons "Connection" "close")
(cons "Content-Type" content-type)))
(url-compat-retrieve url url-http-post-post-process
buffer callback cbargs)))
(defun url-http-response-post-process (status &optional buffer
callback cbargs)
"Default post-processor for an HTTP POST request response.
STATUS is the HTTP status code. BUFFER, CALLBACK, and CBARGS are
passed as well from the original POST request."
(declare (special url-http-end-of-headers))
(let ((kill-this-buffer (current-buffer)))
(when (and (integerp status) (not (< status 300)))
(mediawiki-debug kill-this-buffer "url-http-response-post-process:1")
(error "Oops! Invalid status: %d" status))
(when (or (not (boundp 'url-http-end-of-headers))
(not url-http-end-of-headers))
(mediawiki-debug kill-this-buffer "url-http-response-post-process:2")
(error "Oops! Don't see end of headers!"))
;; FIXME: need to limit redirects
(if (and (listp status)
(eq (car status) :redirect))
(progn
(message (concat "Redirecting to " (cadr status)))
(url-http-get (cadr status) nil buffer callback cbargs))
(goto-char url-http-end-of-headers)
(forward-line)
(let ((str (decode-coding-string
(buffer-substring-no-properties (point) (point-max))
'utf-8)))
(mediawiki-debug (current-buffer) "url-http-response-post-process:3")
(when buffer
(set-buffer buffer)
(insert str)
(goto-char (point-min))
(set-buffer-modified-p nil))
(when callback
(apply callback (list str cbargs)))
(when (not (or callback buffer))
str)))))
(defgroup mediawiki nil
"A mode for editting pages on MediaWiki sites."
:tag "MediaWiki"
:group 'applications)
(defcustom mediawiki-site-default "Wikipedia"
"The default mediawiki site to point to.
Set here for the default and use `mediawiki-site' to set it
per-session later."
:type 'string
:tag "MediaWiki Site Default"
:group 'mediawiki)
(defcustom mediawiki-debug nil
"Turn on debugging (non-nil)."
:type 'boolean
:tag "MediaWiki Debugging"
:group 'mediawiki)
(defcustom mediawiki-site-alist '(("Wikipedia"
"https://en.wikipedia.org/w/"
"username"
"password"
nil
"Main Page"))
"A list of MediaWiki websites."
:tag "MediaWiki sites"
:group 'mediawiki
:type '(alist :tag "Site Name"
:key-type (string :tag "Site Name")
:value-type (list :tag "Parameters"
(string :tag "URL")
(string :tag "Username")
(string :tag "Password")
(choice :tag "Provide LDAP Domain?"
(string)
(other :tag "No" nil))
(string :tag "First Page"
:description "First page to open when `mediawiki-site' is called for this site"))))
(defcustom mediawiki-pop-buffer-hook '()
"List of functions to execute after popping to a buffer.
Can be used to to open the whole buffer."
:options '(delete-other-windows)
:type 'hook
:group 'mediawiki)
(defvar mediawiki-page-history '()
"Assoc list of visited pages on this MW site.")
(defvar mediawiki-enumerate-with-terminate-paragraph nil
"*Before insert enumerate/itemize do \\[mediawiki-terminate-paragraph].")
(defvar mediawiki-english-or-german t
"*Variable in order to set the english (t) or german (nil) environment.")
(defcustom mediawiki-user-simplify-signature t
"Simplify other user's signatures."
:type 'boolean
:group 'mediawiki)
(defgroup mediawiki-draft nil
"A mode to mediawiki-draft information."
:group 'mediawiki)
;;; User Variables:
(defcustom mediawiki-debug nil
"Keep buffers around for debugging purposes."
:type 'boolean
:group 'mediawiki)
(defcustom mediawiki-draft-mode-hook nil
"*Functions run upon entering mediawiki-draft-mode."
:type 'hook
:group 'mediawiki-draft)
(defcustom mediawiki-draft-register ?R
"The register in which the window configuration is stored."
:type 'character
:group 'mediawiki-draft)
(defcustom mediawiki-draft-filter-functions nil
"*Functions run to filter mediawiki-draft data.
All functions are run in the mediawiki-draft buffer."
:type 'hook
:group 'mediawiki-draft)
(defcustom mediawiki-draft-handler-functions '(mediawiki-draft-append-to-file)
"*Functions run to process mediawiki-draft data.
Each function is called with the current buffer narrowed to what the
user wants mediawiki-drafted.
If any function returns non-nil, the data is assumed to have been
recorded somewhere by that function."
:type 'hook
:group 'mediawiki-draft)
(defcustom mediawiki-draft-data-file "~/Wiki/discussions/draft.wiki"
"*The file in which to store the wikipedia drafts."
:type 'file
:group 'mediawiki-draft)
(defcustom mediawiki-draft-reply-register ?M
"The register in which the window configuration is stored."
:type 'character
:group 'mediawiki-draft)
(defcustom mediawiki-draft-page ?S ;Version:1.37
"The register in which the a page of the wiki draft file is stored."
:type 'character
:group 'mediawiki-draft)
(defcustom mediawiki-draft-leader-text "== "
"*The text used to begin each mediawiki-draft item."
:type 'string
:group 'mediawiki-draft)
(defvar mediawiki-reply-with-hline nil
"*Whether to use a hline as a header seperator in the reply.")
(defvar mediawiki-reply-with-quote nil
"*Whether to use a quotation tempalate or not.")
(defvar mediawiki-imenu-generic-expression
(list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1))
"Imenu expression for `mediawiki-mode'. See `imenu-generic-expression'.")
(defvar mediawiki-login-success "pt-logout"
"String to look for in HTML response.
This will be used to verify a successful login.")
(defvar mediawiki-permission-denied
"[^;]The action you have requested is limited"
"String that indicates permission has been denied.
Note that it should not match the mediawiki.el file itself since
it is sometimes put on MediaWiki sites.")
(defvar mediawiki-view-source
"ca-viewsource"
"String that indicates you cannot edit this page.")
(defvar mediawiki-site nil
"The current mediawiki site from `mediawiki-site-alist'.
If not set, defaults to `mediawiki-site-default'.")
(defvar mediawiki-site-info nil
"Holds the site information fetched in this session.")
(defvar mediawiki-argument-pattern "?title=%s&action=%s"
"Format of the string to append to URLs.
Two string arguments are expected: first is a title and then an
action.")
(defvar mediawiki-URI-pattern
"https?://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?/"
"Pattern match for a URI.
Expected to match something like this:
https://mediawiki.sf.net/index.php
Passwords in the URL are not supported yet")
(defvar mediawiki-page-uri nil
"The URI of the page corresponding to the current buffer.
This is used to determine the base URI of the wiki engine as well
as group and page name.")
(defvar mediawiki-page-title nil
"The title of the page corresponding to the current buffer.")
(defvar mediawiki-edittoken nil
"The edit token for this page.")
(defvar mediawiki-starttimestamp nil
"The starttimestamp for this page.")
(defvar mediawiki-basetimestamp nil
"The base timestamp for this page.")
(defvar mediawiki-page-ring nil
"Ring that holds names of buffers we navigate through.")
(defvar mediawiki-page-ring-index 0)
(defvar font-mediawiki-sedate-face 'font-mediawiki-sedate-face
"Face to use for mediawiki minor keywords.")
(defvar font-mediawiki-italic-face 'font-mediawiki-italic-face
"Face to use for mediawiki italics.")
(defvar font-mediawiki-bold-face 'font-mediawiki-bold-face
"Face to use for mediawiki bolds.")
(defvar font-mediawiki-math-face 'font-mediawiki-math-face
"Face to use for mediawiki math environments.")
(defvar font-mediawiki-string-face 'font-mediawiki-string-face
"Face to use for strings.")
(defvar font-mediawiki-verbatim-face 'font-mediawiki-verbatim-face
"Face to use for text in verbatim macros or environments.")
(defface font-mediawiki-bold-face
`((((class grayscale) (background light))
:foreground "DimGray"
:weight bold)
(((class grayscale) (background dark))
:foreground "LightGray"
:weight bold)
(((class color) (background light))
:foreground "DarkOliveGreen"
:weight bold)
(((class color) (background dark))
:foreground "OliveDrab"
:weight bold)
(t
:weight bold))
"Face used to highlight text to be typeset in bold."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-italic-face
`((((class grayscale) (background light))
:foreground "DimGray"
:slant italic)
(((class grayscale) (background dark))
:foreground "LightGray"
:slant italic)
(((class color) (background light))
:foreground "DarkOliveGreen"
:slant italic)
(((class color) (background dark))
:foreground "OliveDrab"
:slant italic)
(t
:slant italic))
"Face used to highlight text to be typeset in italic."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-math-face
`((((class grayscale) (background light))
:foreground "DimGray"
:underline t)
(((class grayscale) (background dark))
:foreground "LightGray"
:underline t)
(((class color) (background light))
:foreground "SaddleBrown"
:underline t)
(((class color) (background dark))
:foreground "burlywood"
:underline t)
(t
:underline t))
"Face used to highlight math."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-sedate-face
'((((class grayscale) (background light))
:foreground "DimGray")
(((class grayscale) (background dark))
:foreground "LightGray")
(((class color) (background light))
:foreground "DimGray")
(((class color) (background dark))
:foreground "LightGray"))
"Face used to highlight sedate stuff."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-string-face
`((((type tty) (class color))
:foreground "green"
:slant italic)
(((class grayscale) (background light))
:foreground "DimGray"
:slant italic)
(((class grayscale) (background dark))
:foreground "LightGray"
:slant italic)
(((class color) (background light))
:foreground "RosyBrown"
:slant italic)
(((class color) (background dark))
:foreground "LightSalmon"
:slant italic)
(t
:slant italic))
"Face used to highlight strings."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-warning-face
`((((class grayscale)(background light))
:foreground "DimGray"
:weight bold)
(((class grayscale)(background dark))
:foreground "LightGray"
:weight bold)
(((class color)(background light))
:foreground "red"
:weight bold)
(((class color)(background dark))
:foreground "red"
:weight bold)
(t
:weight bold))
"Face for important keywords."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-verbatim-face
`((((class grayscale) (background light))
:foreground "DimGray"
:inherit fixed-pitch)
(((class grayscale) (background dark))
:foreground "LightGray"
:inherit fixed-pitch)
(((class color) (background light))
:foreground "SaddleBrown"
:inherit fixed-pitch)
(((class color) (background dark))
:foreground "burlywood"
:inherit fixed-pitch)
(t
:inherit fixed-pitch))
"Face used to highlight TeX verbatim environments."
:group 'font-mediawiki-highlighting-faces)
(defvar mediawiki-simple-tags
'("b" "big" "blockquote" "br" "caption" "code" "center" "cite" "del"
"dfn" "dl" "em" "i" "ins" "kbd" "math" "nowiki" "ol" "pre" "samp"
"small" "strike" "strong" "sub" "sup" "tt" "u" "ul" "var")
"Tags that do not accept arguments.")
(defvar mediawiki-complex-tags
'("a" "div" "font" "table" "td" "th" "tr")
"Tags that accept arguments.")
(defvar mediawiki-url-protocols
'("ftp" "gopher" "http" "https" "mailto" "news")
"Valid protocols for URLs in Wikipedia articles.")
(defvar mediawiki-draft-buffer "*MW-Draft*"
"The name of the wikipedia-draft (temporary) data entry buffer.")
(defvar mediawiki-edit-form-vars nil)
(defvar mediawiki-font-lock-keywords
(list
;; Apostrophe-style text markup
(cons "''''\\([^']\\|[^']'\\)*?\\(''''\\|\n\n\\)"
'font-lock-builtin-face)
(cons "'''\\([^']\\|[^']'\\)*?\\('''\\|\n\n\\)"
;'font-lock-builtin-face)
'font-mediawiki-bold-face)
(cons "''\\([^']\\|[^']'\\)*?\\(''\\|\n\n\\)"
'font-mediawiki-italic-face)
;; Headers and dividers
(list "^\\(==+\\)\\(.*\\)\\(\\1\\)"
'(1 font-lock-builtin-face)
;'(2 mediawiki-header-face)
'(2 font-mediawiki-sedate-face)
'(3 font-lock-builtin-face))
(cons "^-----*" 'font-lock-builtin-face)
;; Bare URLs and ISBNs
(cons (concat "\\(^\\| \\)" (regexp-opt mediawiki-url-protocols t)
"://[-A-Za-z0-9._\/~%+&#?!=()@]+")
'font-lock-variable-name-face)
(cons "\\(^\\| \\)ISBN [-0-9A-Z]+" 'font-lock-variable-name-face)
;; Colon indentation, lists, definitions, and tables
(cons "^\\(:+\\|[*#]+\\||[}-]?\\|{|\\)" 'font-lock-builtin-face)
(list "^\\(;\\)\\([^:\n]*\\)\\(:?\\)"
'(1 font-lock-builtin-face)
'(2 font-lock-keyword-face)
'(3 font-lock-builtin-face))
;; Tags and comments
(list (concat "\\(</?\\)"
(regexp-opt mediawiki-simple-tags t) "\\(>\\)")
'(1 font-lock-builtin-face t t)
'(2 font-lock-function-name-face t t)
'(3 font-lock-builtin-face t t))
(list (concat "\\(</?\\)"
(regexp-opt mediawiki-complex-tags t)
"\\(\\(?: \\(?:[^\"'/><]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?\\)\\(>\\)")
'(1 font-lock-builtin-face t t)
'(2 font-lock-function-name-face t t)
'(3 font-lock-keyword-face t t)
'(4 font-lock-builtin-face t t))
(cons (concat "<!-- \\([^->]\\|>\\|-\\([^-]\\|-[^>]\\)\\)*-->")
'(0 font-lock-comment-face t t))
;; External Links
(list (concat "\\(\\[\\)\\(\\(?:"
(regexp-opt mediawiki-url-protocols)
"\\)://[-A-Za-z0-9._\/~%-+&#?!=()@]+\\)\\(\\(?: [^]\n]*\\)?\\)\\(\\]\\)")
'(1 font-lock-builtin-face t t)
'(2 font-lock-variable-name-face t t)
'(3 font-lock-keyword-face t t)
'(4 font-lock-builtin-face t t))
;; Wiki links
'("\\(\\[\\[\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)"
(1 font-lock-builtin-face t t)
(2 font-lock-variable-name-face t t)
(3 font-lock-builtin-face t t)
(4 font-lock-keyword-face t t)
(5 font-lock-builtin-face t t))
;; Semantic relations
'("\\(\\[\\[\\)\\([^]\n|]*\\)\\(::\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)"
(1 font-lock-builtin-face t t)
(2 font-lock-variable-name-face t t)
(3 font-lock-builtin-face t t)
(4 font-lock-constant-face t t)
(5 font-lock-builtin-face t t)
(6 font-lock-keyword-face t t)
(7 font-lock-builtin-face t t))
;; Wiki variables
'("\\({{\\)\\(.+?\\)\\(}}\\)"
(1 font-lock-builtin-face t t)
(2 font-lock-variable-name-face t t)
(3 font-lock-builtin-face t t))
;; Semantic variables
'("\\({{{\\)\\(.+?\\)\\(}}}\\)"
(1 font-lock-builtin-face t t)
(2 font-lock-variable-name-face t t)
(3 font-lock-builtin-face t t))
;; Character entity references
(cons "&#?[a-zA-Z0-9]+;" '(0 font-lock-type-face t t))
;; Preformatted text
(cons "^ .*$" '(0 font-lock-constant-face t t))
;; Math environment (uniform highlight only, no TeX markup)
(list "<math>\\(\\(\n?.\\)*?\\)</math>"
'(1 font-lock-keyword-face t t))))
(defvar mediawiki-draft-send-archive t
"*Archive the reply.")
(defvar mediawiki-draft-mode-map ())
(defvar mediawiki-debug-buffer " *MediaWiki Debug*")
(defun mediawiki-debug-line (line)
"Log a LINE to BUFFER."
(when mediawiki-debug
(with-current-buffer (get-buffer-create mediawiki-debug-buffer)
(goto-char (point-max))
(insert "\n")
(insert line))))
(defun mediawiki-debug (buffer function)
"The debug handler.
When debugging is turned on, log the name of the BUFFER with the
FUNCTION that called the debugging function, so it can be
examined. If debugging is off, just kill the buffer. This
allows you to see what is being sent to and from the server."
(when mediawiki-debug
(mediawiki-debug-line
(concat
"\n\n=-=-=-=-=-=-=-=\n"
function "\n\n"
(with-current-buffer buffer
(buffer-string)))))
(kill-buffer buffer))