Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
;; 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:
;;; 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.
;;; 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)))
(concat
(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")))
(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"
"\r\n"))
(t (error "I don't handle this"))))
pairs))
;; use the boundary as a separator
(concat "--" boundary "\r\n"))
(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)))
(goto-char url-http-end-of-headers)
(forward-line)
(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)
(defcustom mediawiki-draft-register ?R
"The register in which the window configuration is stored."
:type 'character
: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)
(defvar mediawiki-imenu-generic-expression
(list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1))
"Imenu expression for `mediawiki-mode'. See `imenu-generic-expression'.")
(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-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-ring-index 0)
(defface font-mediawiki-bold-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
((assq :weight custom-face-attributes) '(:weight bold))
(t '(:bold t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "DarkOliveGreen" ,@font))
(((class color) (background dark))
(:foreground "OliveDrab" ,@font))
(t (,@font))))
"Face used to highlight text to be typeset in bold."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-italic-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
((assq :slant custom-face-attributes) '(:slant italic))
(t '(:italic t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "DarkOliveGreen" ,@font))
(((class color) (background dark))
(:foreground "OliveDrab" ,@font))
(t (,@font))))
"Face used to highlight text to be typeset in italic."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-math-face
(let ((font (cond ((assq :inherit custom-face-attributes)
'(:inherit underline))
(t '(:underline t)))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "SaddleBrown"))
(((class color) (background dark))
(:foreground "burlywood"))
(t (,@font))))
"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"))
;;;(t (:underline t))
)
"Face used to highlight sedate stuff."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-string-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit italic))
((assq :slant custom-face-attributes) '(:slant italic))
(t '(:italic t)))))
`((((type tty) (class color))
(:foreground "green"))
(((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "RosyBrown"))
(((class color) (background dark))
(:foreground "LightSalmon"))
(t (,@font))))
"Face used to highlight strings."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-warning-face
(let ((font (cond ((assq :inherit custom-face-attributes) '(:inherit bold))
((assq :weight custom-face-attributes) '(:weight bold))
(t '(:bold t)))))
`((((class grayscale)(background light))
(:foreground "DimGray" ,@font))
(((class grayscale)(background dark))
(:foreground "LightGray" ,@font))
(((class color)(background light))
(:foreground "red" ,@font))
(((class color)(background dark))
(:foreground "red" ,@font))
(t (,@font))))
"Face for important keywords."
:group 'font-mediawiki-highlighting-faces)
(defface font-mediawiki-verbatim-face
(let ((font (if (and (assq :inherit custom-face-attributes)
(if (fboundp 'find-face)
(find-face 'fixed-pitch)
(facep 'fixed-pitch)))
'(:inherit fixed-pitch)
'(:family "courier"))))
`((((class grayscale) (background light))
(:foreground "DimGray" ,@font))
(((class grayscale) (background dark))
(:foreground "LightGray" ,@font))
(((class color) (background light))
(:foreground "SaddleBrown" ,@font))
(((class color) (background dark))
(:foreground "burlywood" ,@font))
(t (,@font))))
"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-font-lock-keywords
(list
;; 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))
;; Preformatted text
(cons "^ .*$" '(0 font-lock-constant-face t t))
(defvar mediawiki-draft-send-archive t
"*Archive the reply.")
action-res)
t)))
(defun mediawiki-reload ()
"Reload the page from the server."
(interactive)
(let ((title mediawiki-page-title))
(if title
(mediawiki-open title)
(error "Error: %s is not a mediawiki document" (buffer-name)))))
(set-buffer-modified-p nil)
(setq buffer-undo-list t)
(buffer-enable-undo)
(mediawiki-pop-to-buffer (current-buffer))
(setq mediawiki-page-title pagetitle)
(goto-char (point-min))
(current-buffer))))
(setq start
(string-match
"<input \\([^>]*name=[\"']\\([^\"']+\\)['\"][^>]*\\)>"
form start)))
vars)))
(defun mediawiki-prompt-for-page ()
"Prompt for a page name and return the answer."
(let* ((prompt (concat "Page"
(when mediawiki-page-title
(format " (default %s)" mediawiki-page-title))
": "))
(answer (completing-read prompt '())))
(if (string= "" answer)
mediawiki-page-title
answer)))
(defun mediawiki-prompt-for-summary ()
"Prompt for a summary and return the answer."
(completing-read "Summary: " '()))
(defun mediawiki-prompt-for-site ()
"Prompt the user for a site."
(let* ((prompt (concat "Sitename"
(when mediawiki-site
(format " (default %s)" mediawiki-site))
": "))
(answer (completing-read prompt mediawiki-site-alist nil t)))
(if (string= "" answer)
mediawiki-site
answer)))
;;;###autoload
(defun mediawiki-site (&optional site)
"Set up mediawiki.el for a SITE.
Without an argument, use `mediawiki-site-default'.
Interactively, prompt for a SITE."
(interactive)
(when (not site)
(setq site (mediawiki-prompt-for-site)))
(when (or (eq nil mediawiki-site)
(not (string-equal site mediawiki-site)))
(setq mediawiki-site (mediawiki-do-login site)))
(mediawiki-edit site (mediawiki-site-first-page site)))
(defun mediawiki-open-page-at-point ()
"Open a new buffer with the page at point."
(interactive)
(mediawiki-open (mediawiki-page-at-point)))
(defun mediawiki-page-at-point ()
"Return the page name under point.
Typically, this means anything enclosed in [[PAGE]]."
(let ((pos (point))
(eol (point-at-eol))
(bol (point-at-bol)))
(save-excursion
(let* ((start (when (search-backward "[[" bol t)
(+ (point) 2)))
(end (when (search-forward "]]" eol t)
(- (point) 2)))
(middle (progn
(goto-char start)
(when (search-forward "|" end t)
(1- (point)))))
(pagename (when (and
(not (eq nil start))
(not (eq nil end))
(<= pos end)
(>= pos start))
(buffer-substring-no-properties
start (or middle end)))))
(if (string= "/"
(substring pagename 0 1))
(concat mediawiki-page-title pagename)
pagename)))))
(defun mediawiki-next-header ()
"Move point to the end of the next section header."
(interactive)
(let ((oldpoint (point)))
(end-of-line)
(if (re-search-forward "\\(^==+\\).*\\1" (point-max) t)
(beginning-of-line)
(goto-char oldpoint)
(message "No section headers after point."))))
(defun mediawiki-prev-header ()
"Move point to the start of the previous section header."
(interactive)
(unless (re-search-backward "\\(^==+\\).*\\1" (point-min) t)
(message "No section headers before point.")))
(defun mediawiki-terminate-paragraph-and-indent ()
"In a list, start a new list item.
In a paragraph, start a new paragraph but *,# will be ignored; if
the current paragraph is colon indented, the new paragraph will
be indented in the same way."
(interactive)
(let (indent-chars)
(save-excursion
(beginning-of-line)
(while (cond ((looking-at "^$") nil)
((looking-at "^\\(\\(?: \\|:+\\) *\\)")
(setq indent-chars (match-string 1)) nil)
((eq (point) (point-min)) nil)
((progn (forward-line -1) t)))
t))
(newline)
(if (not indent-chars) (newline)
(insert indent-chars))))
(defun mediawiki-link-fill-nobreak-p ()
"When filling, don't break the line for preformatted (fixed-width)
text or inside a Wiki link. See `fill-nobreak-predicate'."
(save-excursion
(let ((pos (point)))
(or (eq (char-after (line-beginning-position)) ? )
(if (re-search-backward "\\[\\[" (line-beginning-position) t)
;; Break if the link is really really long.
;; You often get this with captioned images.
(null (or (> (- pos (point)) fill-column)
(re-search-forward "\\]\\]" pos t))))))))
(defun mediawiki-fill-article ()
"Fill the entire article."
(interactive)
(save-excursion
(fill-region (point-min) (point-max))))
(defun mediawiki-unfill-article ()
"Undo filling, deleting stand-alone newlines.
Stand-alone newlines are those that do not end paragraphs, list
entries, etc."
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t)
(replace-match " " nil nil nil 1)))
(message "Stand-alone newlines deleted"))
(defun mediawiki-draft-reply ()
"Open a temporary buffer to edit a draft.
After finishing the editing: either use 'mediawiki-draft-buffer'
to send the data into the 'mediawiki-draft-data-file'. Check the
variable mediawiki-draft-send-archive."
(interactive)
(mediawiki-reply-at-point-simple)
(beginning-of-line 1)
(kill-line nil)
(save-excursion
(window-configuration-to-register mediawiki-draft-register)
(let ((buf (get-buffer-create mediawiki-draft-buffer)))
(switch-to-buffer-other-window buf)
(mediawiki-mode)
(if mediawiki-reply-with-quote
(progn
(insert "{{Quotation|")
(yank)
(insert "'''Re: ")
(insert-register mediawiki-draft-reply-register 1)
(insert "''' |~~~~}}")
(backward-char 7))
(when mediawiki-reply-with-hline
(insert "----")
(newline 1))
(yank)
(end-of-line 1))
(message " C-c C-k sends to draft, C-c C-c sends to org buffer."))))
(defun mediawiki-reply-at-point-simple ()
"Very simple function to reply to posts in the discussion forum.
You have to set the point around the signature, then the
functions inserts the following
:'''Re: [[User:foo]]'''."
(interactive)
(beginning-of-line 1)
(if mediawiki-english-or-german
(progn
(search-forward "(UTC)")
(search-backward "[[User:"))
(search-forward "(CET)")
(search-backward "[[Benutzer:"))
(if mediawiki-user-simplify-signature
(mark-word 2)
(mark-word 3))
(copy-to-register mediawiki-draft-reply-register (region-beginning) (region-end)
nil)
(end-of-line 1)
(mediawiki-terminate-paragraph-and-indent)
(insert ":'''Re: ")
(insert-register mediawiki-draft-reply-register 1)
(if mediawiki-user-simplify-signature
(insert "|]]''' ")
(insert "]]''' ")))
(defun mediawiki-goto-previous-page ()
"Pop up the previous page being editted."
(interactive)
(mediawiki-goto-relative-page -))
(defun mediawiki-goto-next-page ()
"Pop up the previous page being editted."
(interactive)
(mediawiki-goto-relative-page +))
(defun mediawiki-goto-next-link ()
"Go to the next link in the page."
(interactive)
(mediawiki-goto-relative-link))
(defun mediawiki-goto-prev-link ()
"Go to the previous link in the page."
(interactive)
(mediawiki-goto-relative-link t))
(defun mediawiki-insert-enumerate ()
"Primitive function for inserting enumerated items.
Check the variable mediawiki-enumerate-with-terminate-paragraph.
Note however that the function \\[mediawiki-terminate-paragraph]
does not work very well will longlines-mode."
(interactive)
(if mediawiki-enumerate-with-terminate-paragraph
(progn
(mediawiki-terminate-paragraph)
(insert "#"))
(newline nil)
(insert ":#")))
(defun mediawiki-insert-itemize ()
"Primitive function for inserting no enumerated items.
Check the variable mediawiki-enumerate-with-terminate-paragraph.
Note however that the function \\[mediawiki-terminate-paragraph]
does not work very well will longlines-mode."
(interactive)
(if mediawiki-enumerate-with-terminate-paragraph
(progn
(mediawiki-terminate-paragraph)
(insert "*"))
(newline nil)
(insert ":*")))
(defun mediawiki-insert-strong-emphasis ()
"Mark with strong emphasis italics.
Uses four apostrophes (e.g. ''''FOO''''). When mark is active,
surrounds region."
(interactive)
(mediawiki-insert "''''" "''''"))
(defun mediawiki-insert-bold ()
"Mark bold.
Uses three apostrophes (e.g. '''FOO'''). When mark is active,
surrounds region."
(interactive)
(mediawiki-insert "'''" "'''"))
(defun mediawiki-insert-italics ()
"Mark italics.
Uses TWO apostrophes (e.g. ''FOO''). When mark is active,
surrounds region."
(interactive)
(mediawiki-insert "''" "''"))
(defun mediawiki-insert-quotation-with-signature ()
"Mark the current region as a quotation with your signature."
(interactive)
(mediawiki-insert "{{Quotation|}}" "{{~~~~}}"))
(defun mediawiki-insert-quotation ()
"Mark the current selection as a quote.
Use the form {{Quotation}}{{}}. When mark is active,
surrounds region."
(interactive)
(mediawiki-insert "{{Quotation|}}{{" "}}"))
(defun mediawiki-insert-bible-verse-template ()
"Insert a template for the quotation of Bible verses."
(interactive)
(insert "({{niv|")
(let ((name (read-string "Name: ")))
(insert (concat name "|"))
(let ((verse (read-string "Verse: ")))
(insert (concat verse "|" name " " verse "}})")))))
(defun mediawiki-insert-user ()
"Interactively insert a user name."
(interactive)
(if mediawiki-english-or-german
(let ((user (read-string "Name of user: " )))
(insert (concat "[[User:" user "|" user "]]")))
(let ((user (read-string "Name des Benutzers: " )))
(insert (concat "[[Benutzer:" user "|" user "]]")))))
(defun mediawiki-insert-reply-prefix ()
"Quotation box of the form {{Quotation}}{{}}."
(interactive)
(beginning-of-line 1)
(search-forward "[[")
(backward-char 2)
(mark-sexp 1)
(copy-to-register mediawiki-draft-reply-register (region-beginning) (region-end)
nil)
(end-of-line 1)
(mediawiki-terminate-paragraph)
(beginning-of-line 1)
(kill-line nil)
(insert "----")
(newline 1)
(yank)
(insert ":'''Re: ")
(insert-register mediawiki-draft-reply-register 1)
(insert "''' ")
(end-of-line 1))
(defun mediawiki-insert-header ()
"Insert subheader via == (e.g. == FOO ==)."
(interactive)
(mediawiki-insert "==" "=="))
(defun mediawiki-insert-link ()
"Insert link (e.g. [[FOO]])."
(interactive)
(mediawiki-insert "[[" "]]"))
(defun mediawiki-insert-link-www ()
"Insert link (e.g. [://FOO])."
(interactive)
(mediawiki-insert "[://" "]"))
(defun mediawiki-insert-image ()
"Insert image link (e.g. [[Image:FOO]]).
Checks the variable mediawiki-english-or-german."
(interactive)
(mediawiki-insert (if mediawiki-english-or-german
"[[Image:"
"[[Bild:") "]]"))
(defun mediawiki-insert-audio ()
"Insert audio link (e.g. [[Media:FOO]])
Checks The variable mediawiki-english-or-german."
(interactive)
(mediawiki-insert (if mediawiki-english-or-german
"[[Media:"
"[[Bild:") "]]"))
(defun mediawiki-insert-signature ()
"Insert signature (e.g. \"~~~~:\")."
(interactive)
(insert "~~~~: "))
(defun mediawiki-insert-hline ()
"Insert hline (e.g. \"----\")."
(interactive)
(insert "\n----\n"))
(defun mediawiki-unfill-paragraph-or-region ()
"Unfill region.
This function does NOT explicitly search for \"soft newlines\"
as does mediawiki-unfill-region."
(interactive)
(set (make-local-variable 'paragraph-start) "[ \t\n\f]")
(set (make-local-variable 'paragraph-start)
"\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")
(set-fill-prefix)
(beginning-of-line 1)
(if use-hard-newlines
(progn
(set (make-local-variable 'use-hard-newlines) nil)
(set (make-local-variable 'sentence-end-double-space) t))
(set (make-local-variable 'sentence-end-double-space) nil)
(set (make-local-variable 'use-hard-newlines) t))
(let ((fill-column (point-max)))
(if (fboundp 'fill-paragraph-or-region)
(fill-paragraph-or-region nil)
(fill-paragraph nil))))
(defun mediawiki-start-paragraph ()
"Start a Paragraph."
(interactive)
(set (make-local-variable 'paragraph-start)
"\\*\\| \\|#\\|;\\|:\\||\\|!\\|$"))
(defun mediawiki-hardlines ()
"Set 'use-hard-newlines' to NIL."
(interactive)
(setq use-hard-newlines nil))
(defun mediawiki-next-long-line ()
"Move forward to the next long line.
Lines are considered long if their length is greater
than `fill-column'.
(defun mediawiki-unfill-paragraph-simple ()
"A very simple function for unfilling a paragraph."
(interactive)
(let ((fill-column (point-max)))
(fill-paragraph nil)))
(defun mediawiki-outline-magic-keys ()
"Set up outline magic keys.
See https://www.emacswiki.org/emacs/OutlineMagic"
(interactive)
(unless (featurep 'xemacs)
(local-set-key [(shift iso-lefttab)] 'outline-cycle)
(local-set-key [iso-left-tab] 'outline-cycle))
(local-set-key [(meta left)] 'outline-promote)
(local-set-key [(meta right)] 'outline-demote)
(local-set-key [(shift return)] 'newline-and-indent)
(local-set-key [(control left)] 'mediawiki-simple-outline-promote)
(local-set-key [(control right)] 'mediawiki-simple-outline-demote)
(local-set-key [(control up)] 'outline-move-subtree-up)
(local-set-key [(control down)] 'outline-move-subtree-down))
(add-hook 'mediawiki-mode-hook (lambda () (outline-minor-mode nil)))
(add-hook 'outline-minor-mode-hook 'mediawiki-outline-magic-keys)
(defun mediawiki-enhance-indent ()
"Indent a region using MediaWiki markup (e.g \":\")."
(interactive)
(string-rectangle (region-beginning) (region-end) ":"))
(defun mediawiki-yank-prefix ()
"Remove indent markup from region.
FIXME!!!"
(interactive)
(string-rectangle (region-beginning) (region-end) " "))
(defun mediawiki-simple-outline-promote ()
"Simple-minded promotion of current line.
This function simply deletes one \"=\" from the beginning and end
of the line. It does not promote the whole tree!"
(interactive)
(save-excursion
(beginning-of-line 1)
(search-forward "=")
(delete-char 1 nil)
(end-of-line 1)
(search-backward "=")
(delete-char 1 nil)))
(defun mediawiki-simple-outline-demote ()
"Simple-minded demotion of the current line.
This function simple adds \"=\" to the beginning and end of the
line. It does not promote the whole tree!"
(interactive)
(save-excursion
(beginning-of-line 1)
(search-forward "=")
(insert "=")
(end-of-line 1)
(search-backward "=")
(insert "=")))
(defun mediawiki-rename-buffer ()
"Make sure that the option UNIQUE is used."
(interactive)
(rename-buffer (read-string "Name of new buffer (unique): " ) 1))
(defun mediawiki-draft-buffer-desc ()
"Using the first line of the current buffer, create a short description."
(buffer-substring (point-min)
(save-excursion
(goto-char (point-min))
(end-of-line)
(if (> (- (point) (point-min)) 60)
(goto-char (+ (point-min) 60)))
(point))))
(defun mediawiki-draft-append-to-file ()
"Append a draft to the drafts file."
(let ((text (buffer-string)))
(with-temp-buffer
(insert (concat "\n\n" mediawiki-draft-leader-text "Draft: "
(read-string "Enter Subject: ") " "
(current-time-string) " "
mediawiki-draft-leader-text
"\n\n\f\n\n" text "\n\f\n"))
(if (not (bolp))
(insert "\n\n"))
(if (find-buffer-visiting mediawiki-draft-data-file)
(let ((mediawiki-draft-text (buffer-string)))
(set-buffer (get-file-buffer mediawiki-draft-data-file))
(save-excursion
(goto-char (point-max))
(insert (concat "\n" mediawiki-draft-text "\n"))
(save-buffer)))
(append-to-file (point-min) (point-max) mediawiki-draft-data-file)))))
;;;###autoload
(defun mediawiki-draft ()
"Open a temporary buffer in mediawiki-mode.
This is for editing a draft. After finishing the editing either
use \\[mediawiki-draft-buffer] to send the data into the
mediawiki-draft-data-file, or send the buffer using
\\[mediawiki-save] and insert it later into a mediawiki article."
(interactive)
(window-configuration-to-register mediawiki-draft-register)
(let ((buf (get-buffer-create mediawiki-draft-buffer)))
(switch-to-buffer-other-window buf)
(mediawiki-mode)
(message " C-c C-k sends to draft file, C-c C-c sends to org buffer.")))
(defun mediawiki-draft-page ()
"Set the current buffer as a draft buffer."
(interactive)
(mark-page)
(copy-region-as-kill (region-beginning) (region-end))
(mediawiki-draft)
(yank nil))
(defun mediawiki-draft-clipboard ()
"Mediawiki-Draft the contents of the current clipboard.
Most useful for mediawiki-drafting things from Netscape or other X Windows
application."
(interactive)
(with-temp-buffer
(insert (if (fboundp 'gui-get-selection) ; Since 25.1
(gui-get-selection)
(x-get-clipboard)))
(run-hook-with-args-until-success 'mediawiki-draft-handler-functions)))
(defun mediawiki-draft-view-draft ()
"Simple shortcut to visit the drafts file."
(interactive)
(find-file mediawiki-draft-data-file))
(defun mediawiki-mark-section ()
"Set mark at end of current logical section, and point at top."
(interactive)
(re-search-forward (concat "== " "[a-z,A-z \t]*" " =="))
(re-search-backward "^")
(set-mark (point))
(re-search-backward (concat "== " "[a-z,A-z \t]*" " "))
(when (fboundp 'zmacs-activate-region)
(zmacs-activate-region)))
(defun mediawiki-mark-signature ()
"Set mark at end of current logical section, and point at top."
(interactive)
(re-search-forward "]]") ;;[[ ]]
(re-search-backward "^")
(set-mark (point))
(re-search-backward "[[")
(when (fboundp 'zmacs-activate-region)
(zmacs-activate-region)))
(defun mediawiki-draft-copy-page-to-register ()
"Copy a page via the mediawiki-draft-register."
(interactive)
(save-excursion
(narrow-to-page nil)
(copy-to-register mediawiki-draft-page (point-min) (point-max) nil)
(message "draft page copied to wikipedia register mediawiki-draft-page.")
(widen)))
(defun mediawiki-draft-yank-page-to-register ()
"Insert a page via the mediawiki-draft-register."
(interactive)
(insert-register mediawiki-draft-page nil))
(make-local-variable 'change-major-mode-hook)
(make-local-variable 'mediawiki-edittoken)
(make-local-variable 'mediawiki-starttimestamp)
(make-local-variable 'mediawiki-basetimestamp)
(make-local-variable 'mediawiki-site)
(make-local-variable 'mediawiki-edit-form-vars)
(make-local-variable 'mediawiki-page-title)
(set (make-local-variable 'adaptive-fill-regexp) "[ ]*")
(set (make-local-variable 'comment-start-skip) "\\(?:<!\\)?-- *")
(set (make-local-variable 'comment-end-skip) " *--\\([ \n]*>\\)?")
(set (make-local-variable 'comment-start) "<!-- ")
(set (make-local-variable 'comment-end) " -->")
(set (make-local-variable 'paragraph-start)
"\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")
(set (make-local-variable 'sentence-end-double-space) nil)
(set (make-local-variable 'font-lock-multiline) t)
(set (make-local-variable 'font-lock-defaults)
'(mediawiki-font-lock-keywords t nil nil nil))
(set (make-local-variable 'fill-nobreak-predicate)
'mediawiki-link-fill-nobreak-p)
(set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]")
;; (defvar mw-pagelist-mode-map
;; (let ((map (make-sparse-keymap)))
;; (suppress-keymap map)
;; (define-key map [(return)] 'mw-pl-goto-page-at-point)
;; (define-key map "n" 'mw-pl-page-down)
;; (define-key map "C-v" 'mw-pl-page-down)
;; (define-key map [(next)] 'mw-pl-page-down)
;; (define-key map "p" 'mw-pl-page-up)
;; (define-key map "M-v" 'mw-pl-page-up)
;; (define-key map [(prior)] 'mw-pl-page-up)))
;; (define-derived-mode mw-pagelist-mode special-mode "MW-PageList")
(provide 'mediawiki)
;; Local Variables:
;; time-stamp-pattern: "20/^;; Last Modified: <%%>$"
;; End: