├── .gitignore ├── ChangeLog ├── LICENSE ├── README.mediawiki └── mediawiki.el /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled 2 | *.elc 3 | 4 | # Packaging 5 | .cask 6 | 7 | # Backups 8 | *~ 9 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2015-04-03 Mark A. Hershberger 2 | 3 | * mediawiki.el: Various cleanups for flycheck. Move to github and 4 | git from Launchpad and bzr. Clean up last bits of wikimedia.el. 5 | * README.mediawiki: README file for github. Use mediawiki markup 6 | instead of Markdown since it just seems right. 7 | 8 | 2012-05-27 Mark A. Hershberger 9 | 10 | * mediawiki.el (mediawiki-debug): Add (and use) debugging customization. 11 | 12 | 2012-01-18 Mark A. Hershberger 13 | 14 | * mediawiki.el (mediawiki-save-page): Update for enwiki blackout 15 | when I didn't get an edit token. 16 | 17 | 2011-11-28 Mark A. Hershberger 18 | 19 | * mediawiki.el (url-bit-for-url, url-url-for-url) 20 | (url-password-for-url): Define only if undefined. Perhaps some 21 | others. 22 | (mediawiki-logged-in-p): specify secure or not. 23 | (url-http-post): Start to add support for multipart-form-data. 24 | 25 | 2011-09-05 Mark A. Hershberger 26 | 27 | * mediawiki.el (mediawiki-logged-in-p): Update test to check if 28 | cookes exist instead of just checking if mediawiki-site is set. 29 | (mediawiki-edit): return buffer that was just 30 | opened. Log in if cookies don't exist yet. 31 | 32 | 2010-07-11 Mark A. Hershberger 33 | 34 | * mediawiki.el (mediawiki-edit, mediawiki-mode): Make sure the 35 | buffer page title is set and mediawiki-page-title is 36 | buffer-local. (LP#603262, LP#603265) 37 | (mediawiki-font-lock-keywords): Add support for semantic relations 38 | and semantic variable replacement. (LP#604051) 39 | (mediawiki-site-extract): Change error message when sitename is 40 | nil. (LP#604044) 41 | (mediawiki-api-call): Don't strip the call result down to just the 42 | XML attribs. (LP#604042) 43 | (mediawiki-do-login, mediawiki-api-query-revisions): Extract 44 | necessary bits with adjusted api-call. (LP#604042) 45 | 46 | 2010-07-10 Mark A. Hershberger 47 | 48 | * mediawiki.el (mediawiki-edit): Force point to beginning of 49 | buffer. (LP#546851) 50 | (mediawiki-goto-relative-link): New function. Use noerror 51 | argument. (LP#604045) 52 | (mediawiki-goto-prev-link, mediawiki-goto-next-link): 53 | Use new mediawiki-goto-relative-link. 54 | 55 | 2010-07-02 Mark A. Hershberger 56 | 57 | * mediawiki.el (url-http-create-request): Work around bug in url.el. 58 | (mediawiki-edittoken, mediawiki-starttimestamp) 59 | (mediawiki-basetimestamp): New buffer-local variables to enable 60 | the API. 61 | (mediawiki-make-api-url, mediawiki-api-call): New functions to 62 | enable the API 63 | (mediawiki-open): Update use of mediawiki-edit 64 | (mediawiki-edit): Rewrite to use API and make it function 65 | uniformly for all calls. Remove dependency on buffer-local 66 | mediawiki-site. 67 | (mediawiki-get-form-vars): Simplify + make it handle 68 | elements without value attributes. 69 | (mediawiki-save-page): Rewrite to use API. 70 | (mediawiki-site): Use API. Remove callbacks aren't used. 71 | (mediawiki-site-extract): Trigger error for non-existant site. 72 | (mediawiki-api-param): New utility function for setting parameters 73 | like the MW API wants. 74 | (mediawiki-page-get-title): New utility function to extract a 75 | title from a page in the pagelist structure that the MW API 76 | returns. 77 | (mediawiki-page-get-revision): New utility function to extract a 78 | revision from a the pagelist structure. 79 | (mediawiki-pagelist-find-page): New utility function to extract 80 | the entire page structure from a pagelist structure 81 | (mediawiki-api-query-title): New function. Query the API and get 82 | the current revision of the page. 83 | (mediawiki-do-logout, mediawiki-do-login): Use the API. 84 | 85 | 2010-06-23 Mark A. Hershberger 86 | 87 | * mediawiki.el: Clean up byte compilation warnings. 88 | (mediawiki-make-url): Remove url-hexify-string in favor of 89 | mm-url-form-encode-xwfu. 90 | (mediawiki-get-edit-form-vars): Clean up and simplify permission 91 | checking. Use (message) instead of error to make messages less 92 | confusing. 93 | (mediawiki-site-password): Typo meant we weren't really getting 94 | the password. 95 | (mediawiki-do-login): Check to make sure we actually have a form 96 | variable. 97 | (mediawiki-view-source): New variable to show when we're viewing 98 | source. 99 | (mediawiki-pop-buffer-hook): New hook. 100 | (mediawiki-pop-to-buffer): New functon to run hook on buffer.xo 101 | (mediawiki-get, mediawiki-goto-relative-page): Use hook. 102 | 103 | 2010-04-26 Mark A. Hershberger 104 | 105 | * mediawiki.el (url-compat-retrieve): Add help function so this 106 | works with older versions of url.el like those found in Xemacs. 107 | (url-http-get): Use url-compat-retrieve. 108 | (url-http-post): Delete any nil parameters. Use url-compat-retrieve. 109 | (url-http-response-post-process): Follow redirects. Need to add a 110 | redirect limit. 111 | (mediawiki-make-url): Make the URL properly if there is no action parameter. 112 | (mediawiki-get-edit-form-vars): Refactor generic form-reading 113 | functionality to mediawiki-get-form-vars. 114 | (mediawiki-get-form-vars): New function. 115 | (mediawiki-do-login): Rewrite so that new MW token parameter is 116 | used for login. 117 | (mediawiki-page-at-point): Identify and qualify sub-pages. 118 | (mediawiki-mode): Remove any bindings that use C-h. 119 | (mediawiki-insert): Fix mediawiki-insert using adopted patch from Bug#563127 120 | 121 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | 663 | -------------------------------------------------------------------------------- /README.mediawiki: -------------------------------------------------------------------------------- 1 | == mediawiki.el -- Edit mediawiki sites from emacs == 2 | 3 | This version of mediawiki.el represents a merging of wikipedia-mode.el (maintained by Uwe Brauer) from [http://www.emacswiki.org/emacs/wikipedia-mode.el EmacsWiki] for its font-lock code, menu, draft mode, replying and convenience functions to produce mediawiki.el 2.0. 4 | 5 | === Installation === 6 | 7 | If you use [http://melpa.org/#/mediawiki MELPA], you can install via the M-x package-list-packages interface. This is preferrable as you will have access to updates automatically. 8 | 9 | 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. 10 | 11 | ==== Configuration and use ==== 12 | 13 | M-x customize-group RET mediawiki RET 14 | *dink* *dink* 15 | M-x mediawiki-site RET Wikipedia RET 16 | 17 | Open a wiki file: M-x mediawiki-open 18 | Save a wiki buffer: C-x C-s 19 | Save a wiki buffer with a different name: C-x C-w 20 | 21 | ==== About Security ==== 22 | 23 | Although there is a place to put your password when you customize this package, there is no need to store your password in plain text. 24 | 25 | If mediawiki sees that the password is empty, then it will use [https://www.gnu.org/software/emacs/manual/html_mono/auth.html the auth-source library] to retrieve the password. This will allow you to use encryption to store your passwords. 26 | 27 | 28 | === TODO === 29 | 30 | * Change customization to explicitly tell mediawiki.el to use the auth-source library. 31 | * Optionally use org-mode formatting for editing and translate that to mw 32 | * Move url-* methods to url-http 33 | * Use the MW API to support searching, etc. 34 | * Clean up and thoroughly test imported wikimedia.el code 35 | * Improve language support. Currently there is a toggle for English or German. This should probably just be replaced with the ability to use MediaWiki's i18n files in json format. 36 | -------------------------------------------------------------------------------- /mediawiki.el: -------------------------------------------------------------------------------- 1 | ;;; mediawiki.el --- mediawiki frontend 2 | 3 | ;; Copyright (C) 2008, 2009, 2010, 2011, 2015 Mark A. Hershberger 4 | 5 | ;; Original Authors: Jerry , 6 | ;; Chong Yidong for wikipedia.el, 7 | ;; Uwe Brauer for wikimedia.el 8 | ;; Author: Mark A. Hershberger 9 | ;; Created: Sep 17 2004 10 | ;; Keywords: mediawiki wikipedia network wiki 11 | ;; URL: https://github.com/hexmode/mediawiki-el 12 | ;; Last Modified: <2020-07-11 22:45:06 mah> 13 | 14 | (defconst mediawiki-version "2.3.1" 15 | "Current version of mediawiki.el.") 16 | 17 | ;; This file is NOT (yet) part of GNU Emacs. 18 | 19 | ;; This program is free software: you can redistribute it and/or modify 20 | ;; it under the terms of the GNU General Public License as published by 21 | ;; the Free Software Foundation, either version 3 of the License, or 22 | ;; (at your option) any later version. 23 | 24 | ;; This program is distributed in the hope that it will be useful, 25 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27 | ;; GNU General Public License for more details. 28 | 29 | ;; You should have received a copy of the GNU General Public License 30 | ;; along with this program. If not, see . 31 | 32 | ;;; Commentary: 33 | 34 | ;; This version of mediawiki.el represents a merging of 35 | ;; wikipedia-mode.el (maintained by Uwe Brauer ) 36 | ;; from https://www.emacswiki.org/emacs/wikipedia-mode.el for its 37 | ;; font-lock code, menu, draft mode, replying and convenience 38 | ;; functions to produce mediawiki.el 2.0. 39 | 40 | ;;; Installation 41 | 42 | ;; If you use ELPA, you can install via the M-x package-list-packages 43 | ;; interface. This is preferrable as you will have access to updates 44 | ;; automatically. 45 | 46 | ;; Otherwise, just make sure this file is in your load-path (usually 47 | ;; ~/.emacs.d is included) and put (require 'mediawiki.el) in your 48 | ;; ~/.emacs or ~/.emacs.d/init.el file. 49 | 50 | ;;; Howto: 51 | ;; M-x customize-group RET mediawiki RET 52 | ;; *dink* *dink* 53 | ;; M-x mediawiki-site RET Wikipedia RET 54 | ;; 55 | ;; Open a wiki file: M-x mediawiki-open 56 | ;; Save a wiki buffer: C-x C-s 57 | ;; Save a wiki buffer with a different name: C-x C-w 58 | 59 | ;;; TODO 60 | 61 | ;; * Optionally use org-mode formatting for editing and translate 62 | ;; that to mw 63 | ;; * Move url-* methods to url-http 64 | ;; * Use the MW API to support searching, etc. 65 | ;; * Clean up and thoroughly test imported wikimedia.el code 66 | ;; * Improve language support. Currently there is a toggle for 67 | ;; English or German. This should probably just be replaced with 68 | ;; customizable words given MediaWiki's wide language support. 69 | 70 | ;;; Changes 71 | 72 | ;; 2.2.7: 73 | ;; * Add the ability to accept the domain 74 | ;; * Fix false failures when site isn't found. 75 | 76 | ;; 2.2.6: 77 | ;; * Moved to github 78 | ;; * Code cleanup, flycheck 79 | 80 | ;; Since 2.2.4.2 81 | ;; * Move to github 82 | ;; * Added Readme.mediawiki to with information about security. 83 | 84 | ;; Since 2.2.4.1: 85 | ;; * Add the forgotten customizable mediawiki-debug. 86 | 87 | ;; Since 2.2.4: 88 | ;; * Made it clearer where debugging information is found when 89 | ;; mediawiki-debug is non-nil by adding messages to the message 90 | ;; buffer when debug buffers are killed. 91 | 92 | ;;; History 93 | 94 | ;; From the News section of wikipedia.el comes this bit, kept here for 95 | ;; reference later. 96 | ;; (4) "Draft", "send" and "reply" (for discussion pages) 97 | ;; abilities `based' on ideas of John Wigleys remember.el: see 98 | ;; the functions wikipedia-draft-* 99 | ;; RATIONALE: This comes handy in 2 situations 100 | ;; 1. You are editing articles which various authors (this I 101 | ;; think is the usual case), you then want not to submit 102 | ;; your edit immediately but want to copy it somewhere and 103 | ;; to continue later. You can use the following functions 104 | ;; for doing that: 105 | ;; wikipedia-draft-buffer \C-c\C-b 106 | ;; wikipedia-draft-region \C-c\C-r 107 | ;; then the buffer/region will be appended to the 108 | ;; wikipedia-draft-data-file (default is 109 | ;; "~/Wiki/discussions/draft.wiki", which you can visit via 110 | ;; wikipedia-draft-view-draft) and it will be 111 | ;; surrounded by the ^L marks in order to set a page. 112 | ;; moreover on top on that a section header == will be 113 | ;; inserted, which consists of the Word Draft, a subject 114 | ;; you are asked for and a date stamp. 115 | ;; 116 | ;; Another possibility consists in using the function 117 | ;; wikipedia-draft, bound to \C-c \C-m then a new buffer 118 | ;; will opened already in wikipedia mode. You edit and then 119 | ;; either can send the content of the buffer to the 120 | ;; wikipedia-draft-data-file in the same manner as 121 | ;; described above using the function 122 | ;; wikipedia-draft-buffer (bound to \C-c\C-k) 123 | ;; 124 | ;; BACK: In order to copy/send the content of temporary 125 | ;; buffer or of a page in the wikipedia-draft-data-file 126 | ;; back in to your wikipedia file, use the function 127 | ;; wikipedia-send-draft-to-mozex bound to "\C-c\C-c". You 128 | ;; will be asked to which buffer to copy your text! 129 | ;; 130 | ;; 131 | ;; 2. You want to reply in a discussion page to a specific 132 | ;; contribution, you can use either the function 133 | ;; 134 | ;; \\[wikipedia-reply-at-point-simple] bound to [(meta shift r)] 135 | ;; which inserts a newline, a hline, and the signature of 136 | ;; the author. Or can use 137 | ;; \\[wikipedia-draft-reply] bound [(meta r)] 138 | ;; which does the same as wikipedia-reply-at-point-simple 139 | ;; but in a temporary draft buffer. 140 | ;; 141 | ;; BACK: In order to copy/send the content of that buffer 142 | ;; back in to your wikipedia file, use the function 143 | ;; \\[wikipedia-send-draft-to-mozex] bound to "\C-c\C-c". You 144 | ;; will be asked to which buffer to copy your text! If 145 | ;; you want a copy to be send to your draft file, use 146 | ;; the variable wikipedia-draft-send-archive 147 | ;; 148 | 149 | ;;; Code: 150 | 151 | (require 'url-http) 152 | (require 'mml) 153 | (require 'mm-url) 154 | (require 'ring) 155 | (require 'subr-x) 156 | (eval-when-compile 157 | (require 'cl) 158 | (require 'mml) 159 | ;; Below copied from url-http to avoid compilation warnings 160 | (defvar url-http-extra-headers) 161 | (defvar url-http-target-url) 162 | (defvar url-http-proxy) 163 | (defvar url-http-connection-opened) 164 | ;; This should only be used in xemacs, anyway 165 | (setq byte-compile-not-obsolete-funcs (list 'assoc-ignore-case))) 166 | 167 | ;; As of 2010-06-22, these functions are in Emacs 168 | (unless (fboundp 'url-bit-for-url) 169 | (defun url-bit-for-url (method lookfor url) 170 | (when (fboundp 'auth-source-user-or-password) 171 | (let* ((urlobj (url-generic-parse-url url)) 172 | (bit (funcall method urlobj)) 173 | (methods (list 'url-recreate-url 174 | 'url-host))) 175 | (if (and (not bit) (> (length methods) 0)) 176 | (auth-source-user-or-password 177 | lookfor (funcall (pop methods) urlobj) (url-type urlobj)) 178 | bit))))) 179 | 180 | (unless (fboundp 'url-user-for-url) 181 | (defun url-user-for-url (url) 182 | "Attempt to use .authinfo to find a user for this URL." 183 | (url-bit-for-url 'url-user "login" url))) 184 | 185 | (unless (fboundp 'url-password-for-url) 186 | (defun url-password-for-url (url) 187 | "Attempt to use .authinfo to find a password for this URL." 188 | (url-bit-for-url 'url-password "password" url))) 189 | 190 | (when (fboundp 'url-http-create-request) 191 | (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" 192 | (let ((url-http-target-url (url-generic-parse-url "http://example.com/")) 193 | (url-http-data "test") (url-http-version "1.0") (url-http-referer "test") 194 | url-http-method url-http-attempt-keepalives url-extensions-header 195 | url-http-extra-headers url-http-proxy url-mime-charset-string) 196 | (url-http-create-request))) 197 | (defun url-http-create-request (&optional ref-url) 198 | "Create an HTTP request for `url-http-target-url', referred to by REF-URL." 199 | (declare (special proxy-info 200 | url-http-method url-http-data 201 | url-http-extra-headers)) 202 | (let* ((extra-headers) 203 | (request nil) 204 | (no-cache (cdr-safe (assoc "Pragma" url-http-extra-headers))) 205 | (using-proxy url-http-proxy) 206 | (proxy-auth (if (or (cdr-safe (assoc "Proxy-Authorization" 207 | url-http-extra-headers)) 208 | (not using-proxy)) 209 | nil 210 | (let ((url-basic-auth-storage 211 | 'url-http-proxy-basic-auth-storage)) 212 | (url-get-authentication url-http-target-url nil 'any nil)))) 213 | (real-fname (concat (url-filename url-http-target-url) 214 | (with-no-warnings 215 | (url-recreate-url-attributes url-http-target-url)))) 216 | (host (url-host url-http-target-url)) 217 | (auth (if (cdr-safe (assoc "Authorization" url-http-extra-headers)) 218 | nil 219 | (url-get-authentication (or 220 | (and (boundp 'proxy-info) 221 | proxy-info) 222 | url-http-target-url) nil 'any nil)))) 223 | (if (equal "" real-fname) 224 | (setq real-fname "/")) 225 | (setq no-cache (and no-cache (string-match "no-cache" no-cache))) 226 | (if auth 227 | (setq auth (concat "Authorization: " auth "\r\n"))) 228 | (if proxy-auth 229 | (setq proxy-auth (concat "Proxy-Authorization: " proxy-auth "\r\n"))) 230 | 231 | ;; Protection against stupid values in the referer 232 | (if (and ref-url (stringp ref-url) (or (string= ref-url "file:nil") 233 | (string= ref-url ""))) 234 | (setq ref-url nil)) 235 | 236 | ;; We do not want to expose the referer if the user is paranoid. 237 | (if (or (memq url-privacy-level '(low high paranoid)) 238 | (and (listp url-privacy-level) 239 | (memq 'lastloc url-privacy-level))) 240 | (setq ref-url nil)) 241 | 242 | ;; url-http-extra-headers contains an assoc-list of 243 | ;; header/value pairs that we need to put into the request. 244 | (setq extra-headers (mapconcat 245 | (lambda (x) 246 | (concat (car x) ": " (cdr x))) 247 | url-http-extra-headers "\r\n")) 248 | (if (not (equal extra-headers "")) 249 | (setq extra-headers (concat extra-headers "\r\n"))) 250 | 251 | ;; This was done with a call to `format'. Concatting parts has 252 | ;; the advantage of keeping the parts of each header together and 253 | ;; allows us to elide null lines directly, at the cost of making 254 | ;; the layout less clear. 255 | (setq request 256 | ;; We used to concat directly, but if one of the strings happens 257 | ;; to being multibyte (even if it only contains pure ASCII) then 258 | ;; every string gets converted with `string-MAKE-multibyte' which 259 | ;; turns the 127-255 codes into things like latin-1 accented chars 260 | ;; (it would work right if it used `string-TO-multibyte' instead). 261 | ;; So to avoid the problem we force every string to be unibyte. 262 | (mapconcat 263 | ;; FIXME: Instead of `string-AS-unibyte' we'd want 264 | ;; `string-to-unibyte', so as to properly signal an error if one 265 | ;; of the strings contains a multibyte char. 266 | 'string-as-unibyte 267 | (delq nil 268 | (list 269 | ;; The request 270 | (or url-http-method "GET") " " 271 | (if using-proxy (url-recreate-url url-http-target-url) real-fname) 272 | " HTTP/" url-http-version "\r\n" 273 | ;; Version of MIME we speak 274 | "MIME-Version: 1.0\r\n" 275 | ;; (maybe) Try to keep the connection open 276 | "Connection: " (if (or using-proxy 277 | (not url-http-attempt-keepalives)) 278 | "close" "keep-alive") "\r\n" 279 | ;; HTTP extensions we support 280 | (if url-extensions-header 281 | (format 282 | "Extension: %s\r\n" url-extensions-header)) 283 | ;; Who we want to talk to 284 | (if (/= (url-port url-http-target-url) 285 | (url-scheme-get-property 286 | (url-type url-http-target-url) 'default-port)) 287 | (format 288 | "Host: %s:%d\r\n" host (url-port url-http-target-url)) 289 | (format "Host: %s\r\n" host)) 290 | ;; Who its from 291 | (if url-personal-mail-address 292 | (concat 293 | "From: " url-personal-mail-address "\r\n")) 294 | ;; Encodings we understand 295 | (if url-mime-encoding-string 296 | (concat 297 | "Accept-encoding: " url-mime-encoding-string "\r\n")) 298 | (if url-mime-charset-string 299 | (concat 300 | "Accept-charset: " url-mime-charset-string "\r\n")) 301 | ;; Languages we understand 302 | (if url-mime-language-string 303 | (concat 304 | "Accept-language: " url-mime-language-string "\r\n")) 305 | ;; Types we understand 306 | "Accept: " (or url-mime-accept-string "*/*") "\r\n" 307 | ;; User agent 308 | (url-http-user-agent-string) 309 | ;; Proxy Authorization 310 | proxy-auth 311 | ;; Authorization 312 | auth 313 | ;; Cookies 314 | (url-cookie-generate-header-lines host real-fname 315 | (equal "https" (url-type url-http-target-url))) 316 | ;; If-modified-since 317 | (if (and (not no-cache) 318 | (member url-http-method '("GET" nil))) 319 | (let ((tm (url-is-cached url-http-target-url))) 320 | (if tm 321 | (concat "If-modified-since: " 322 | (url-get-normalized-date tm) "\r\n")))) 323 | ;; Whence we came 324 | (if ref-url (concat 325 | "Referer: " ref-url "\r\n")) 326 | extra-headers 327 | ;; Length of data 328 | (if url-http-data 329 | (concat 330 | "Content-length: " (number-to-string 331 | (length url-http-data)) 332 | "\r\n")) 333 | ;; End request 334 | "\r\n" 335 | ;; Any data 336 | url-http-data "\r\n")) 337 | "")) 338 | (url-http-debug "Request is: \n%s" request) 339 | request)))) 340 | 341 | ;; There are some versions of emacs that don't have 342 | ;; mm-url-encode-multipart-form-data. 343 | ;; See https://lists.gnu.org/archive/html/emacs-diffs/2014-11/msg00167.html 344 | (unless (fboundp 'mm-url-encode-multipart-form-data) 345 | (defun mm-url-encode-multipart-form-data (pairs &optional boundary) 346 | "Return PAIRS encoded in multipart/form-data." 347 | ;; RFC1867 348 | 349 | ;; Get a good boundary 350 | (unless boundary 351 | (setq boundary (mml-compute-boundary '()))) 352 | 353 | (concat 354 | 355 | ;; Start with the boundary 356 | "--" boundary "\r\n" 357 | 358 | ;; Create name value pairs 359 | (mapconcat 360 | 'identity 361 | ;; Delete any returned items that are empty 362 | (delq nil 363 | (mapcar (lambda (data) 364 | 365 | (cond 366 | ((consp (car data)) 367 | (let ((fieldname (cadar data)) 368 | (filename (caadar data)) 369 | (mimetype (car (caadar data))) 370 | (content (caar (caadar data)))) 371 | 372 | (concat 373 | ;; Encode the name 374 | "Content-Disposition: form-data; name=\"" fieldname "\"\r\n" 375 | "Content-Type: " mimetype "\r\n" 376 | "Content-Transfer-Encoding: binary\r\n\r\n" 377 | content 378 | "\r\n"))) 379 | 380 | ((stringp (car data)) 381 | ;; For each pair 382 | 383 | (concat 384 | ;; Encode the name 385 | "Content-Disposition: form-data; name=\"" 386 | (car data) "\"\r\n" 387 | "Content-Type: text/plain; charset=utf-8\r\n" 388 | "Content-Transfer-Encoding: binary\r\n\r\n" 389 | 390 | (cond ((stringp (cdr data)) 391 | (cdr data)) 392 | ((integerp (cdr data)) 393 | (int-to-string (cdr data)))) 394 | 395 | "\r\n")) 396 | (t (error "I don't handle this")))) 397 | pairs)) 398 | ;; use the boundary as a separator 399 | (concat "--" boundary "\r\n")) 400 | 401 | ;; put a boundary at the end. 402 | "--" boundary "--\r\n"))) 403 | 404 | ;; Not defined in my Xemacs 405 | (unless (fboundp 'assoc-string) 406 | (defun assoc-string (key list &optional case-fold) 407 | (if case-fold 408 | (assoc-ignore-case key list) 409 | (assoc key list)))) 410 | 411 | (defun url-compat-retrieve (url post-process buffer callback cbargs) 412 | "Function to compatibly retrieve a URL. 413 | Some provision is made for different versions of Emacs version. 414 | POST-PROCESS is the function to call for post-processing. 415 | BUFFER is the buffer to store the result in. CALLBACK will be 416 | called in BUFFER with CBARGS, if given." 417 | (let ((url-user-agent (concat 418 | (if (not (eq url-user-agent 'default)) 419 | (string-trim (if (functionp url-user-agent) 420 | (funcall url-user-agent) 421 | url-user-agent)) 422 | "") 423 | " mediawiki.el " mediawiki-version "\r\n"))) 424 | (cond ((boundp 'url-be-asynchronous) ; Sniff w3 lib capability 425 | (if callback 426 | (setq url-be-asynchronous t) 427 | (setq url-be-asynchronous nil)) 428 | (url-retrieve url t) 429 | (when (not url-be-asynchronous) 430 | (let ((result (funcall post-process buffer))) 431 | result))) 432 | (t (if callback 433 | (url-retrieve url post-process 434 | (list buffer callback cbargs)) 435 | (with-current-buffer (url-retrieve-synchronously url) 436 | (funcall post-process buffer))))))) 437 | 438 | (defvar url-http-get-post-process 'url-http-response-post-process) 439 | (defun url-http-get (url &optional headers buffer callback cbargs) 440 | "Convenience method to use method 'GET' to retrieve URL. 441 | HEADERS is the optional headers to send. BUFFER is where the 442 | result will be stored. CALLBACK will be called in BUFFER with 443 | CBARGS, if given." 444 | (let* ((url-request-extra-headers (if headers headers 445 | (if url-request-extra-headers 446 | url-request-extra-headers 447 | (cons nil nil)))) 448 | (url-request-method "GET")) 449 | 450 | (when (url-basic-auth url) 451 | (add-to-list 'url-request-extra-headers 452 | (cons "Authorization" (url-basic-auth url)))) 453 | (url-compat-retrieve url url-http-get-post-process 454 | buffer callback cbargs))) 455 | 456 | (defvar url-http-post-post-process 'url-http-response-post-process) 457 | (defun url-http-post (url parameters &optional multipart headers buffer 458 | callback cbargs) 459 | "Convenience method to use method 'POST' to retrieve URL. 460 | PARAMETERS are the parameters to put the the body. If MULTIPART 461 | is t, then multipart/form-data will be used. Otherwise, 462 | applicaton/x-www-form-urlencoded is used. HEADERS is the 463 | optional headers to send. BUFFER is where the result will be 464 | stored. CALLBACK will be called in BUFFER with CBARGS, if 465 | given." 466 | 467 | (let* ((url-request-extra-headers 468 | (if headers headers 469 | (when url-request-extra-headers url-request-extra-headers))) 470 | (boundary (int-to-string (random))) 471 | (cs 'utf-8) 472 | (content-type 473 | (if multipart 474 | (concat "multipart/form-data, boundary=" boundary) 475 | (format "application/x-www-form-urlencoded; charset=%s" cs))) 476 | (url-request-method "POST") 477 | (url-request-coding-system cs) 478 | (url-request-data 479 | (if multipart 480 | (mm-url-encode-multipart-form-data 481 | parameters boundary) 482 | (mm-url-encode-www-form-urlencoded (delq nil parameters))))) 483 | (mapc 484 | (lambda (pair) 485 | (let ((key (car pair)) 486 | (val (cdr pair))) 487 | (if (assoc key url-request-extra-headers) 488 | (setcdr (assoc key url-request-extra-headers) val) 489 | (add-to-list 'url-request-extra-headers 490 | (cons key val))))) 491 | (list 492 | (cons "Connection" "close") 493 | (cons "Content-Type" content-type))) 494 | 495 | (url-compat-retrieve url url-http-post-post-process 496 | buffer callback cbargs))) 497 | 498 | (defun url-http-response-post-process (status &optional buffer 499 | callback cbargs) 500 | "Default post-processor for an HTTP POST request response. 501 | STATUS is the HTTP status code. BUFFER, CALLBACK, and CBARGS are 502 | passed as well from the original POST request." 503 | (declare (special url-http-end-of-headers)) 504 | (let ((kill-this-buffer (current-buffer))) 505 | (when (and (integerp status) (not (< status 300))) 506 | (mediawiki-debug kill-this-buffer "url-http-response-post-process:1") 507 | (error "Oops! Invalid status: %d" status)) 508 | 509 | (when (or (not (boundp 'url-http-end-of-headers)) 510 | (not url-http-end-of-headers)) 511 | (mediawiki-debug kill-this-buffer "url-http-response-post-process:2") 512 | (error "Oops! Don't see end of headers!")) 513 | 514 | ;; FIXME: need to limit redirects 515 | (if (and (listp status) 516 | (eq (car status) :redirect)) 517 | (progn 518 | (message (concat "Redirecting to " (cadr status))) 519 | (url-http-get (cadr status) nil buffer callback cbargs)) 520 | 521 | (goto-char url-http-end-of-headers) 522 | (forward-line) 523 | 524 | (let ((str (decode-coding-string 525 | (buffer-substring-no-properties (point) (point-max)) 526 | 'utf-8))) 527 | (mediawiki-debug (current-buffer) "url-http-response-post-process:3") 528 | (when buffer 529 | (set-buffer buffer) 530 | (insert str) 531 | (goto-char (point-min)) 532 | (set-buffer-modified-p nil)) 533 | (when callback 534 | (apply callback (list str cbargs))) 535 | (when (not (or callback buffer)) 536 | str))))) 537 | 538 | (defgroup mediawiki nil 539 | "A mode for editting pages on MediaWiki sites." 540 | :tag "MediaWiki" 541 | :group 'applications) 542 | 543 | (defcustom mediawiki-site-default "Wikipedia" 544 | "The default mediawiki site to point to. 545 | Set here for the default and use `mediawiki-site' to set it 546 | per-session later." 547 | :type 'string 548 | :tag "MediaWiki Site Default" 549 | :group 'mediawiki) 550 | 551 | (defcustom mediawiki-debug nil 552 | "Turn on debugging (non-nil)." 553 | :type 'boolean 554 | :tag "MediaWiki Debugging" 555 | :group 'mediawiki) 556 | 557 | (defcustom mediawiki-site-alist '(("Wikipedia" 558 | "https://en.wikipedia.org/w/" 559 | "username" 560 | "password" 561 | nil 562 | "Main Page")) 563 | "A list of MediaWiki websites." 564 | :tag "MediaWiki sites" 565 | :group 'mediawiki 566 | :type '(alist :tag "Site Name" 567 | :key-type (string :tag "Site Name") 568 | :value-type (list :tag "Parameters" 569 | (string :tag "URL") 570 | (string :tag "Username") 571 | (string :tag "Password") 572 | (choice :tag "Provide LDAP Domain?" 573 | (string) 574 | (other :tag "No" nil)) 575 | (string :tag "First Page" 576 | :description "First page to open when `mediawiki-site' is called for this site")))) 577 | 578 | (defcustom mediawiki-pop-buffer-hook '() 579 | "List of functions to execute after popping to a buffer. 580 | Can be used to to open the whole buffer." 581 | :options '(delete-other-windows) 582 | :type 'hook 583 | :group 'mediawiki) 584 | 585 | (defvar mediawiki-page-history '() 586 | "Assoc list of visited pages on this MW site.") 587 | 588 | (defvar mediawiki-enumerate-with-terminate-paragraph nil 589 | "*Before insert enumerate/itemize do \\[mediawiki-terminate-paragraph].") 590 | 591 | (defvar mediawiki-english-or-german t 592 | "*Variable in order to set the english (t) or german (nil) environment.") 593 | 594 | (defcustom mediawiki-user-simplify-signature t 595 | "Simplify other user's signatures." 596 | :type 'boolean 597 | :group 'mediawiki) 598 | 599 | (defgroup mediawiki-draft nil 600 | "A mode to mediawiki-draft information." 601 | :group 'mediawiki) 602 | 603 | ;;; User Variables: 604 | 605 | (defcustom mediawiki-debug nil 606 | "Keep buffers around for debugging purposes." 607 | :type 'boolean 608 | :group 'mediawiki) 609 | 610 | (defcustom mediawiki-draft-mode-hook nil 611 | "*Functions run upon entering mediawiki-draft-mode." 612 | :type 'hook 613 | :group 'mediawiki-draft) 614 | 615 | (defcustom mediawiki-draft-register ?R 616 | "The register in which the window configuration is stored." 617 | :type 'character 618 | :group 'mediawiki-draft) 619 | 620 | (defcustom mediawiki-draft-filter-functions nil 621 | "*Functions run to filter mediawiki-draft data. 622 | All functions are run in the mediawiki-draft buffer." 623 | :type 'hook 624 | :group 'mediawiki-draft) 625 | 626 | (defcustom mediawiki-draft-handler-functions '(mediawiki-draft-append-to-file) 627 | "*Functions run to process mediawiki-draft data. 628 | Each function is called with the current buffer narrowed to what the 629 | user wants mediawiki-drafted. 630 | If any function returns non-nil, the data is assumed to have been 631 | recorded somewhere by that function." 632 | :type 'hook 633 | :group 'mediawiki-draft) 634 | 635 | (defcustom mediawiki-draft-data-file "~/Wiki/discussions/draft.wiki" 636 | "*The file in which to store the wikipedia drafts." 637 | :type 'file 638 | :group 'mediawiki-draft) 639 | 640 | (defcustom mediawiki-draft-reply-register ?M 641 | "The register in which the window configuration is stored." 642 | :type 'character 643 | :group 'mediawiki-draft) 644 | 645 | (defcustom mediawiki-draft-page ?S ;Version:1.37 646 | "The register in which the a page of the wiki draft file is stored." 647 | :type 'character 648 | :group 'mediawiki-draft) 649 | 650 | 651 | (defcustom mediawiki-draft-leader-text "== " 652 | "*The text used to begin each mediawiki-draft item." 653 | :type 'string 654 | :group 'mediawiki-draft) 655 | 656 | (defvar mediawiki-reply-with-hline nil 657 | "*Whether to use a hline as a header seperator in the reply.") 658 | 659 | (defvar mediawiki-reply-with-quote nil 660 | "*Whether to use a quotation tempalate or not.") 661 | 662 | (defvar mediawiki-imenu-generic-expression 663 | (list '(nil "^==+ *\\(.*[^\n=]\\)==+" 1)) 664 | "Imenu expression for `mediawiki-mode'. See `imenu-generic-expression'.") 665 | 666 | (defvar mediawiki-login-success "pt-logout" 667 | "String to look for in HTML response. 668 | This will be used to verify a successful login.") 669 | 670 | (defvar mediawiki-permission-denied 671 | "[^;]The action you have requested is limited" 672 | "String that indicates permission has been denied. 673 | Note that it should not match the mediawiki.el file itself since 674 | it is sometimes put on MediaWiki sites.") 675 | 676 | (defvar mediawiki-view-source 677 | "ca-viewsource" 678 | "String that indicates you cannot edit this page.") 679 | 680 | (defvar mediawiki-site nil 681 | "The current mediawiki site from `mediawiki-site-alist'. 682 | If not set, defaults to `mediawiki-site-default'.") 683 | 684 | (defvar mediawiki-site-info nil 685 | "Holds the site information fetched in this session.") 686 | 687 | (defvar mediawiki-argument-pattern "?title=%s&action=%s" 688 | "Format of the string to append to URLs. 689 | Two string arguments are expected: first is a title and then an 690 | action.") 691 | 692 | (defvar mediawiki-URI-pattern 693 | "https?://\\([^/:]+\\)\\(:\\([0-9]+\\)\\)?/" 694 | "Pattern match for a URI. 695 | Expected to match something like this: 696 | https://mediawiki.sf.net/index.php 697 | Passwords in the URL are not supported yet") 698 | 699 | (defvar mediawiki-page-uri nil 700 | "The URI of the page corresponding to the current buffer. 701 | This is used to determine the base URI of the wiki engine as well 702 | as group and page name.") 703 | 704 | (defvar mediawiki-page-title nil 705 | "The title of the page corresponding to the current buffer.") 706 | 707 | (defvar mediawiki-edittoken nil 708 | "The edit token for this page.") 709 | (defvar mediawiki-starttimestamp nil 710 | "The starttimestamp for this page.") 711 | (defvar mediawiki-basetimestamp nil 712 | "The base timestamp for this page.") 713 | 714 | (defvar mediawiki-page-ring nil 715 | "Ring that holds names of buffers we navigate through.") 716 | 717 | (defvar mediawiki-page-ring-index 0) 718 | 719 | (defvar font-mediawiki-sedate-face 'font-mediawiki-sedate-face 720 | "Face to use for mediawiki minor keywords.") 721 | (defvar font-mediawiki-italic-face 'font-mediawiki-italic-face 722 | "Face to use for mediawiki italics.") 723 | (defvar font-mediawiki-bold-face 'font-mediawiki-bold-face 724 | "Face to use for mediawiki bolds.") 725 | (defvar font-mediawiki-math-face 'font-mediawiki-math-face 726 | "Face to use for mediawiki math environments.") 727 | (defvar font-mediawiki-string-face 'font-mediawiki-string-face 728 | "Face to use for strings.") 729 | (defvar font-mediawiki-verbatim-face 'font-mediawiki-verbatim-face 730 | "Face to use for text in verbatim macros or environments.") 731 | 732 | (defface font-mediawiki-bold-face 733 | `((((class grayscale) (background light)) 734 | :foreground "DimGray" 735 | :weight bold) 736 | (((class grayscale) (background dark)) 737 | :foreground "LightGray" 738 | :weight bold) 739 | (((class color) (background light)) 740 | :foreground "DarkOliveGreen" 741 | :weight bold) 742 | (((class color) (background dark)) 743 | :foreground "OliveDrab" 744 | :weight bold) 745 | (t 746 | :weight bold)) 747 | "Face used to highlight text to be typeset in bold." 748 | :group 'font-mediawiki-highlighting-faces) 749 | 750 | (defface font-mediawiki-italic-face 751 | `((((class grayscale) (background light)) 752 | :foreground "DimGray" 753 | :slant italic) 754 | (((class grayscale) (background dark)) 755 | :foreground "LightGray" 756 | :slant italic) 757 | (((class color) (background light)) 758 | :foreground "DarkOliveGreen" 759 | :slant italic) 760 | (((class color) (background dark)) 761 | :foreground "OliveDrab" 762 | :slant italic) 763 | (t 764 | :slant italic)) 765 | "Face used to highlight text to be typeset in italic." 766 | :group 'font-mediawiki-highlighting-faces) 767 | 768 | (defface font-mediawiki-math-face 769 | `((((class grayscale) (background light)) 770 | :foreground "DimGray" 771 | :underline t) 772 | (((class grayscale) (background dark)) 773 | :foreground "LightGray" 774 | :underline t) 775 | (((class color) (background light)) 776 | :foreground "SaddleBrown" 777 | :underline t) 778 | (((class color) (background dark)) 779 | :foreground "burlywood" 780 | :underline t) 781 | (t 782 | :underline t)) 783 | "Face used to highlight math." 784 | :group 'font-mediawiki-highlighting-faces) 785 | 786 | (defface font-mediawiki-sedate-face 787 | '((((class grayscale) (background light)) 788 | :foreground "DimGray") 789 | (((class grayscale) (background dark)) 790 | :foreground "LightGray") 791 | (((class color) (background light)) 792 | :foreground "DimGray") 793 | (((class color) (background dark)) 794 | :foreground "LightGray")) 795 | "Face used to highlight sedate stuff." 796 | :group 'font-mediawiki-highlighting-faces) 797 | 798 | (defface font-mediawiki-string-face 799 | `((((type tty) (class color)) 800 | :foreground "green" 801 | :slant italic) 802 | (((class grayscale) (background light)) 803 | :foreground "DimGray" 804 | :slant italic) 805 | (((class grayscale) (background dark)) 806 | :foreground "LightGray" 807 | :slant italic) 808 | (((class color) (background light)) 809 | :foreground "RosyBrown" 810 | :slant italic) 811 | (((class color) (background dark)) 812 | :foreground "LightSalmon" 813 | :slant italic) 814 | (t 815 | :slant italic)) 816 | "Face used to highlight strings." 817 | :group 'font-mediawiki-highlighting-faces) 818 | 819 | (defface font-mediawiki-warning-face 820 | `((((class grayscale)(background light)) 821 | :foreground "DimGray" 822 | :weight bold) 823 | (((class grayscale)(background dark)) 824 | :foreground "LightGray" 825 | :weight bold) 826 | (((class color)(background light)) 827 | :foreground "red" 828 | :weight bold) 829 | (((class color)(background dark)) 830 | :foreground "red" 831 | :weight bold) 832 | (t 833 | :weight bold)) 834 | "Face for important keywords." 835 | :group 'font-mediawiki-highlighting-faces) 836 | 837 | (defface font-mediawiki-verbatim-face 838 | `((((class grayscale) (background light)) 839 | :foreground "DimGray" 840 | :inherit fixed-pitch) 841 | (((class grayscale) (background dark)) 842 | :foreground "LightGray" 843 | :inherit fixed-pitch) 844 | (((class color) (background light)) 845 | :foreground "SaddleBrown" 846 | :inherit fixed-pitch) 847 | (((class color) (background dark)) 848 | :foreground "burlywood" 849 | :inherit fixed-pitch) 850 | (t 851 | :inherit fixed-pitch)) 852 | "Face used to highlight TeX verbatim environments." 853 | :group 'font-mediawiki-highlighting-faces) 854 | 855 | (defvar mediawiki-simple-tags 856 | '("b" "big" "blockquote" "br" "caption" "code" "center" "cite" "del" 857 | "dfn" "dl" "em" "i" "ins" "kbd" "math" "nowiki" "ol" "pre" "samp" 858 | "small" "strike" "strong" "sub" "sup" "tt" "u" "ul" "var") 859 | "Tags that do not accept arguments.") 860 | 861 | (defvar mediawiki-complex-tags 862 | '("a" "div" "font" "table" "td" "th" "tr") 863 | "Tags that accept arguments.") 864 | 865 | (defvar mediawiki-url-protocols 866 | '("ftp" "gopher" "http" "https" "mailto" "news") 867 | "Valid protocols for URLs in Wikipedia articles.") 868 | 869 | (defvar mediawiki-draft-buffer "*MW-Draft*" 870 | "The name of the wikipedia-draft (temporary) data entry buffer.") 871 | 872 | (defvar mediawiki-edit-form-vars nil) 873 | 874 | (defvar mediawiki-font-lock-keywords 875 | (list 876 | 877 | ;; Apostrophe-style text markup 878 | (cons "''''\\([^']\\|[^']'\\)*?\\(''''\\|\n\n\\)" 879 | 'font-lock-builtin-face) 880 | (cons "'''\\([^']\\|[^']'\\)*?\\('''\\|\n\n\\)" 881 | ;'font-lock-builtin-face) 882 | 'font-mediawiki-bold-face) 883 | (cons "''\\([^']\\|[^']'\\)*?\\(''\\|\n\n\\)" 884 | 'font-mediawiki-italic-face) 885 | 886 | ;; Headers and dividers 887 | (list "^\\(==+\\)\\(.*\\)\\(\\1\\)" 888 | '(1 font-lock-builtin-face) 889 | ;'(2 mediawiki-header-face) 890 | '(2 font-mediawiki-sedate-face) 891 | '(3 font-lock-builtin-face)) 892 | (cons "^-----*" 'font-lock-builtin-face) 893 | 894 | ;; Bare URLs and ISBNs 895 | (cons (concat "\\(^\\| \\)" (regexp-opt mediawiki-url-protocols t) 896 | "://[-A-Za-z0-9._\/~%+&#?!=()@]+") 897 | 'font-lock-variable-name-face) 898 | (cons "\\(^\\| \\)ISBN [-0-9A-Z]+" 'font-lock-variable-name-face) 899 | 900 | ;; Colon indentation, lists, definitions, and tables 901 | (cons "^\\(:+\\|[*#]+\\||[}-]?\\|{|\\)" 'font-lock-builtin-face) 902 | (list "^\\(;\\)\\([^:\n]*\\)\\(:?\\)" 903 | '(1 font-lock-builtin-face) 904 | '(2 font-lock-keyword-face) 905 | '(3 font-lock-builtin-face)) 906 | 907 | ;; Tags and comments 908 | (list (concat "\\(\\)") 910 | '(1 font-lock-builtin-face t t) 911 | '(2 font-lock-function-name-face t t) 912 | '(3 font-lock-builtin-face t t)) 913 | (list (concat "\\(<]\\|\"[^\"]*\"\\|'[^']*'\\)*\\)?\\)\\(>\\)") 916 | '(1 font-lock-builtin-face t t) 917 | '(2 font-lock-function-name-face t t) 918 | '(3 font-lock-keyword-face t t) 919 | '(4 font-lock-builtin-face t t)) 920 | (cons (concat "") 921 | '(0 font-lock-comment-face t t)) 922 | 923 | ;; External Links 924 | (list (concat "\\(\\[\\)\\(\\(?:" 925 | (regexp-opt mediawiki-url-protocols) 926 | "\\)://[-A-Za-z0-9._\/~%-+&#?!=()@]+\\)\\(\\(?: [^]\n]*\\)?\\)\\(\\]\\)") 927 | '(1 font-lock-builtin-face t t) 928 | '(2 font-lock-variable-name-face t t) 929 | '(3 font-lock-keyword-face t t) 930 | '(4 font-lock-builtin-face t t)) 931 | 932 | ;; Wiki links 933 | '("\\(\\[\\[\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)" 934 | (1 font-lock-builtin-face t t) 935 | (2 font-lock-variable-name-face t t) 936 | (3 font-lock-builtin-face t t) 937 | (4 font-lock-keyword-face t t) 938 | (5 font-lock-builtin-face t t)) 939 | 940 | ;; Semantic relations 941 | '("\\(\\[\\[\\)\\([^]\n|]*\\)\\(::\\)\\([^]\n|]*\\)\\(|?\\)\\([^]\n]*\\)\\(\\]\\]\\)" 942 | (1 font-lock-builtin-face t t) 943 | (2 font-lock-variable-name-face t t) 944 | (3 font-lock-builtin-face t t) 945 | (4 font-lock-constant-face t t) 946 | (5 font-lock-builtin-face t t) 947 | (6 font-lock-keyword-face t t) 948 | (7 font-lock-builtin-face t t)) 949 | 950 | ;; Wiki variables 951 | '("\\({{\\)\\(.+?\\)\\(}}\\)" 952 | (1 font-lock-builtin-face t t) 953 | (2 font-lock-variable-name-face t t) 954 | (3 font-lock-builtin-face t t)) 955 | 956 | ;; Semantic variables 957 | '("\\({{{\\)\\(.+?\\)\\(}}}\\)" 958 | (1 font-lock-builtin-face t t) 959 | (2 font-lock-variable-name-face t t) 960 | (3 font-lock-builtin-face t t)) 961 | 962 | ;; Character entity references 963 | (cons "&#?[a-zA-Z0-9]+;" '(0 font-lock-type-face t t)) 964 | 965 | ;; Preformatted text 966 | (cons "^ .*$" '(0 font-lock-constant-face t t)) 967 | 968 | ;; Math environment (uniform highlight only, no TeX markup) 969 | (list "\\(\\(\n?.\\)*?\\)" 970 | '(1 font-lock-keyword-face t t)))) 971 | 972 | (defvar mediawiki-draft-send-archive t 973 | "*Archive the reply.") 974 | 975 | (defvar mediawiki-draft-mode-map ()) 976 | 977 | (defvar mediawiki-debug-buffer " *MediaWiki Debug*") 978 | 979 | (defun mediawiki-debug-line (line) 980 | "Log a LINE to BUFFER." 981 | (when mediawiki-debug 982 | (with-current-buffer (get-buffer-create mediawiki-debug-buffer) 983 | (goto-char (point-max)) 984 | (insert "\n") 985 | (insert line)))) 986 | 987 | (defun mediawiki-debug (buffer function) 988 | "The debug handler. 989 | When debugging is turned on, log the name of the BUFFER with the 990 | FUNCTION that called the debugging function, so it can be 991 | examined. If debugging is off, just kill the buffer. This 992 | allows you to see what is being sent to and from the server." 993 | (when mediawiki-debug 994 | (mediawiki-debug-line 995 | (concat 996 | "\n\n=-=-=-=-=-=-=-=\n" 997 | function "\n\n" 998 | (with-current-buffer buffer 999 | (buffer-string))))) 1000 | (kill-buffer buffer)) 1001 | 1002 | (defun mediawiki-translate-pagename (name) 1003 | "Given NAME, return the typical name that MediaWiki would use. 1004 | Right now, this only means replacing \"_\" with \" \"." 1005 | (if (or (not name) (string= name "")) 1006 | "Main Page" 1007 | (mapconcat 'identity (split-string name "_" t) " "))) 1008 | 1009 | (defun mediawiki-make-api-url (&optional sitename) 1010 | "Translate SITENAME (or MEDIAWIKI-SITE if not given) to a URL." 1011 | (format (let* ((my-parsed (url-generic-parse-url 1012 | (mediawiki-site-url (or sitename mediawiki-site)))) 1013 | (my-path (url-filename my-parsed))) 1014 | (when (or (string= my-path "") (not (string= (substring my-path -1) "/"))) 1015 | (setq my-path (concat my-path "/"))) 1016 | (setf (url-filename my-parsed) (concat my-path "api.php")) 1017 | (url-recreate-url my-parsed)))) 1018 | 1019 | (defun mediawiki-raise (result type notif) 1020 | "Show a TYPE of information from the RESULT to the user using NOTIF" 1021 | (when (assq type (cddr result)) 1022 | (mapc (lambda (err) 1023 | (let ((label (or (cdr (assq 'code err)) 1024 | (car err))) 1025 | (info (or (cdr (assq 'info err)) 1026 | (cddr err)))) 1027 | (when info 1028 | (funcall notif label info)))) 1029 | 1030 | ;; Poor man's attempt at backward compatible xml form handling 1031 | (if (listp (cdr (assq type (cddr result)))) 1032 | (cdr (assq type (cddr result))) 1033 | (cddr (assq type (cddr result))))))) 1034 | 1035 | (defun mediawiki-api-call (sitename action &optional args) 1036 | "Wrapper for making an API call to SITENAME. 1037 | ACTION is the API action. ARGS is a list of arguments." 1038 | (mediawiki-debug-line (format "\n\n----\nFor %s (action=%s):\n\n %s\n" sitename action 1039 | (mm-url-encode-multipart-form-data 1040 | (delq nil args) "=="))) 1041 | (let* ((raw (url-http-post (mediawiki-make-api-url sitename) 1042 | (append args (list (cons "format" "xml") 1043 | (cons "action" action))))) 1044 | (result (assoc 'api 1045 | (with-temp-buffer 1046 | (insert raw) 1047 | (xml-parse-region (point-min) (point-max)))))) 1048 | (unless result 1049 | (error "There was an error parsing the result of the API call")) 1050 | 1051 | (mediawiki-raise result 'warnings 1052 | (lambda (label info) 1053 | (message "Warning (%s) %s" label info))) 1054 | (mediawiki-raise result 'info 1055 | (lambda (label info) 1056 | (message "(%s) %s" label info))) 1057 | (mediawiki-raise result 'error 1058 | (lambda (label info) 1059 | (error "(%s) %s" label info))) 1060 | 1061 | (if (cddr result) 1062 | (let ((action-res (assq (intern action) (cddr result)))) 1063 | (unless action-res 1064 | (error "Didn't see action name in the result list")) 1065 | 1066 | action-res) 1067 | t))) 1068 | 1069 | (defun mediawiki-make-url (title action &optional sitename) 1070 | "Return a url when given a TITLE, ACTION and, optionally, SITENAME." 1071 | (format (concat (mediawiki-site-url (or sitename mediawiki-site)) 1072 | (if action 1073 | mediawiki-argument-pattern 1074 | "?title=%s")) 1075 | (mm-url-form-encode-xwfu 1076 | (mediawiki-translate-pagename title)) 1077 | action)) 1078 | 1079 | (defun mediawiki-open (name) 1080 | "Open a wiki page specified by NAME from the mediawiki engine." 1081 | (interactive 1082 | (let* ((hist (cdr (assoc-string mediawiki-site mediawiki-page-history)))) 1083 | (list (read-string "Wiki Page: " nil 'hist)))) 1084 | (when (or (not (stringp name)) 1085 | (string-equal "" name)) 1086 | (error "Need to specify a name")) 1087 | (mediawiki-edit mediawiki-site name)) 1088 | 1089 | (defun mediawiki-reload () 1090 | "Reload the page from the server." 1091 | (interactive) 1092 | (when (not mediawiki-site) 1093 | (setq mediawiki-site (mediawiki-prompt-for-site))) 1094 | (let ((title mediawiki-page-title)) 1095 | (if title 1096 | (mediawiki-open title) 1097 | (error "Error: %s is not a mediawiki document" (buffer-name))))) 1098 | 1099 | (defun mediawiki-add-page-history (sitename title) 1100 | "Update SITENAME's page history with TITLE." 1101 | (let ((hist (cdr (assoc-string sitename mediawiki-page-history)))) 1102 | (unless hist 1103 | (add-to-list 'mediawiki-page-history (cons sitename ""))) 1104 | (setcdr (assoc-string sitename mediawiki-page-history) (append (list title) hist)))) 1105 | 1106 | (defun mediawiki-edit (sitename title) 1107 | "Edit wiki page on SITENAME named TITLE." 1108 | (when (not (ring-p mediawiki-page-ring)) 1109 | (setq mediawiki-page-ring (make-ring 30))) 1110 | 1111 | (let ((pagetitle (mediawiki-translate-pagename title))) 1112 | 1113 | (mediawiki-add-page-history sitename title) 1114 | (with-current-buffer (get-buffer-create 1115 | (concat sitename ": " pagetitle)) 1116 | (unless (mediawiki-logged-in-p sitename) 1117 | (mediawiki-do-login sitename)) 1118 | (ring-insert mediawiki-page-ring (current-buffer)) 1119 | (delete-region (point-min) (point-max)) 1120 | (mediawiki-mode) 1121 | (setq mediawiki-site sitename) 1122 | (set-buffer-file-coding-system 'utf-8) 1123 | (insert (or (mediawiki-get sitename pagetitle) "")) 1124 | 1125 | (set-buffer-modified-p nil) 1126 | (setq buffer-undo-list t) 1127 | (buffer-enable-undo) 1128 | (mediawiki-pop-to-buffer (current-buffer)) 1129 | (setq mediawiki-page-title pagetitle) 1130 | (goto-char (point-min)) 1131 | (current-buffer)))) 1132 | 1133 | (defun mediawiki-get-edit-form-vars (buffer) 1134 | "Extract the form variables from a page. 1135 | Messages are displayed if permission is denied in some way. 1136 | This should only be called from a BUFFER in mediawiki-mode as the 1137 | variables it sets there will be local to that buffer." 1138 | 1139 | (let* ((str (with-current-buffer buffer (buffer-string))) 1140 | (args (mediawiki-get-form-vars str "id" "editform"))) 1141 | (if args 1142 | (with-current-buffer buffer 1143 | (setq mediawiki-edit-form-vars args)) 1144 | (cond 1145 | ((string-match mediawiki-permission-denied str) 1146 | (message "Permission Denied")) 1147 | ((string-match mediawiki-view-source str) 1148 | ;; FIXME set read-only flag 1149 | (message "Editing of this page is disabled, here is the source")))))) 1150 | 1151 | (defun mediawiki-get-form-vars (str attribute value) 1152 | "Look in STR for form element with ATTRIBUTE set to VALUE." 1153 | ;; Find the form 1154 | (when (string-match 1155 | (concat "
]*" attribute "=[\"']" value "['\"][^>]*>") 1156 | str) 1157 | 1158 | (let* ((start-form (match-end 0)) 1159 | (end-form (when (string-match "
" str start-form) 1160 | (match-beginning 0))) 1161 | (form (substring str start-form end-form)) 1162 | (start (string-match 1163 | "]*name=[\"']\\([^\"']+\\)['\"][^>]*\\)>" 1164 | form)) 1165 | (vars '(nil))) 1166 | 1167 | ;; Continue until we can't find any more input elements 1168 | (while start 1169 | 1170 | ;; First, capture the place where we'll start next. Have 1171 | ;; to do this here since match-end doesn't seem to let you 1172 | ;; specify the string you were matching against, unlike 1173 | ;; match-string 1174 | (setq start (match-end 0)) 1175 | 1176 | ;; Capture the string that defines this element 1177 | (let ((el (match-string 1 form)) 1178 | ;; get the element name 1179 | (el-name (match-string 2 form))) 1180 | 1181 | ;; figure out if this is a submit button and skip it if it is. 1182 | (when (not (string-match "type=[\"']submit['\"]" el)) 1183 | (add-to-list 'vars 1184 | (if (string-match "value=[\"']\\([^\"']*\\)['\"]" el) 1185 | (cons el-name (match-string 1 el)) 1186 | (cons el-name nil))))) 1187 | 1188 | (setq start 1189 | (string-match 1190 | "]*name=[\"']\\([^\"']+\\)['\"][^>]*\\)>" 1191 | form start))) 1192 | vars))) 1193 | 1194 | (defun mediawiki-logged-in-p (&optional sitename) 1195 | "Return t if we have cookies for the SITENAME." 1196 | (let ((urlobj (url-generic-parse-url 1197 | (mediawiki-site-url (or sitename mediawiki-site))))) 1198 | (url-cookie-retrieve 1199 | (url-host urlobj) 1200 | (url-filename urlobj) 1201 | (equal "https" (url-type urlobj))))) 1202 | 1203 | (defun mediawiki-pop-to-buffer (buffer) 1204 | "Pop to BUFFER and then execute a hook." 1205 | (pop-to-buffer buffer) 1206 | (run-hooks 'mediawiki-pop-buffer-hook)) 1207 | 1208 | (defun mediawiki-api-param (value) 1209 | "Convert VALUE into a usable form for the MediaWiki API. 1210 | * Concat a list into a bar-separated string, 1211 | * Turn an integer into a string, or 1212 | * Just return the string" 1213 | (cond 1214 | ((integerp value) (int-to-string value)) 1215 | ((stringp value) value) 1216 | ((listp value) (mapconcat 'identity value "|")) 1217 | (t (error "Don't know what to do with %s" value)))) 1218 | 1219 | (defun mediawiki-api-query-revisions (sitename title props &optional limit) 1220 | "Get a list of revisions and properties for a given page. 1221 | SITENAME is the site to use. TITLE is a string containing one 1222 | title or a list of titles. PROPS are the revision properites to 1223 | fetch. LIMIT is the upper bound on the number of results to give." 1224 | (when (or (eq nil title) (string= "" title)) 1225 | (error "No title passed!")) 1226 | (let ((qresult (mediawiki-api-call 1227 | sitename "query" 1228 | (list (cons "prop" (mediawiki-api-param (list "info" "revisions"))) 1229 | (cons "titles" (mediawiki-api-param title)) 1230 | (when limit 1231 | (cons "rvlimit" (mediawiki-api-param limit))) 1232 | (cons "rvprop" (mediawiki-api-param props)))))) 1233 | (if (eq t qresult) 1234 | (error "No results for revision query.") 1235 | (cddr qresult)))) 1236 | 1237 | (defun mediawiki-page-get-title (page) 1238 | "Given a PAGE from a pagelist structure, extract the title." 1239 | (cdr (assq 'title (cadr page)))) 1240 | 1241 | (defun mediawiki-page-get-revision (page revision &optional bit) 1242 | "Given a PAGE, extract a REVISION from the pagelist structure. 1243 | If BIT is 'content, then return the content only. Otherwise, 1244 | return only the items that BIT matches. If BIT isn't given, 1245 | return the whole revision structure." 1246 | (let ((rev (cdr (nth revision (cddr (assq 'revisions (cddr page))))))) 1247 | (cond 1248 | ((eq bit 'content) 1249 | (cadr rev)) 1250 | ((assoc bit (car rev)) 1251 | (cdr (assoc bit (car rev)))) 1252 | (t rev)))) 1253 | 1254 | (defun mediawiki-pagelist-find-page (pagelist title) 1255 | "Given PAGELIST, extract the informaton for TITLE." 1256 | (let ((pl (cddr (assq 'pages pagelist))) 1257 | page current) 1258 | (while (and (not page) 1259 | (setq current (pop pl))) 1260 | ;; This fails when underbars are here instead of spaces, 1261 | ;; so we make sure that it has the mediawiki pagename 1262 | (when (string= (mediawiki-page-get-title current) 1263 | (mediawiki-translate-pagename title)) 1264 | (setq page current))) 1265 | page)) 1266 | 1267 | (defun mediawiki-api-query-title (sitename title) 1268 | "Query SITENAME for TITLE." 1269 | (let* ((pagelist (mediawiki-api-query-revisions 1270 | sitename title 1271 | (list "ids" "timestamp" "flags" "comment" "user" "content")))) 1272 | (mediawiki-pagelist-find-page pagelist title))) 1273 | 1274 | (defun mediawiki-get (sitename title) 1275 | "Query SITENAME for the content of TITLE." 1276 | (let ((page (mediawiki-api-query-title sitename title))) 1277 | (mediawiki-save-metadata sitename page) 1278 | (mediawiki-page-get-revision page 0 'content))) 1279 | 1280 | (defun mediawiki-page-get-metadata (page item) 1281 | "Using PAGE, extract ITEM." 1282 | (cdr (assoc item (cadr page)))) 1283 | 1284 | (defun mediawiki-save-metadata (sitename page) 1285 | "Set per-buffer variables for all the SITENAME data for PAGE." 1286 | (setq mediawiki-site sitename) 1287 | (setq mediawiki-page-title 1288 | (mediawiki-page-get-metadata page 'title)) 1289 | (setq mediawiki-edittoken 1290 | (mediawiki-page-get-metadata page 'edittoken)) 1291 | (setq mediawiki-basetimestamp 1292 | (mediawiki-page-get-revision page 0 'timestamp)) 1293 | (setq mediawiki-starttimestamp 1294 | (mediawiki-page-get-metadata page 'starttimestamp))) 1295 | 1296 | (defun mediawiki-save (&optional summary) 1297 | "Save the current buffer as a page on the current site. 1298 | Prompt for a SUMMARY if one isn't given." 1299 | (interactive "sSummary: ") 1300 | (when (not (eq major-mode 'mediawiki-mode)) 1301 | (error "Not a mediawiki-mode buffer")) 1302 | (if mediawiki-page-title 1303 | (mediawiki-save-page 1304 | mediawiki-site 1305 | mediawiki-page-title 1306 | summary 1307 | (buffer-substring-no-properties (point-min) (point-max))) 1308 | (error "Error: %s is not a mediawiki document" (buffer-name)))) 1309 | 1310 | (defun mediawiki-prompt-for-page () 1311 | "Prompt for a page name and return the answer." 1312 | (let* ((prompt (concat "Page" 1313 | (when mediawiki-page-title 1314 | (format " (default %s)" mediawiki-page-title)) 1315 | ": ")) 1316 | (answer (completing-read prompt '()))) 1317 | (if (string= "" answer) 1318 | mediawiki-page-title 1319 | answer))) 1320 | 1321 | (defun mediawiki-prompt-for-summary () 1322 | "Prompt for a summary and return the answer." 1323 | (completing-read "Summary: " '())) 1324 | 1325 | (defun mediawiki-save-on (&optional sitename name summary) 1326 | "On SITENAME, save a page with NAME and SUMMARY." 1327 | (interactive) 1328 | (when (not sitename) 1329 | (setq sitename (mediawiki-prompt-for-site))) 1330 | (when (not name) 1331 | (setq name (mediawiki-translate-pagename (mediawiki-prompt-for-page)))) 1332 | (when (not summary) 1333 | (setq summary (mediawiki-prompt-for-summary))) 1334 | 1335 | (setq mediawiki-site (mediawiki-do-login sitename)) 1336 | (mediawiki-get mediawiki-site name) 1337 | (mediawiki-save-as name summary)) 1338 | 1339 | (defun mediawiki-save-as (&optional name summary) 1340 | "Save a page on the current site wite NAME and SUMMARY." 1341 | (interactive "sSave As: \nsSummary: ") 1342 | (if name 1343 | (mediawiki-save-page 1344 | mediawiki-site 1345 | name 1346 | summary 1347 | (buffer-substring-no-properties (point-min) (point-max))) 1348 | (error "Error: %s is not a mediawiki document" (buffer-name)))) 1349 | 1350 | (defun mediawiki-save-and-bury (&optional summary) 1351 | "Prompt for a SUMMARY, save the page, then bury the buffer." 1352 | (interactive "sSummary: ") 1353 | (mediawiki-save summary) 1354 | (bury-buffer)) 1355 | 1356 | (defun mediawiki-site-extract (sitename index) 1357 | "Using 'mediawiki-site-alist' and SITENAME, find the nth item using INDEX." 1358 | (let* ((site (assoc sitename mediawiki-site-alist)) 1359 | (bit (nth index site))) 1360 | (cond 1361 | ((eq nil sitename) 1362 | (error "Sitename isn't set")) 1363 | ((eq nil site) 1364 | (error "Couldn't find a site named: %s" sitename)) 1365 | ((stringp bit) 1366 | bit) 1367 | (nil)))) 1368 | 1369 | (defun mediawiki-site-url (sitename) 1370 | "Get the url for a given SITENAME." 1371 | (mediawiki-site-extract sitename 1)) 1372 | 1373 | (defmacro mediawiki-site-user-pass (sitename index method) 1374 | "Fetch the user or pass if provided, or use authinfo if not." 1375 | `(let* ((arg (mediawiki-site-extract ,sitename ,index)) 1376 | (auth (funcall ,method (mediawiki-site-url ,sitename)))) 1377 | (if (and arg (> (string-width arg) 0)) 1378 | arg 1379 | auth))) 1380 | 1381 | (defun mediawiki-site-username (sitename) 1382 | "Get the username for a given SITENAME." 1383 | (mediawiki-site-user-pass sitename 2 'url-user-for-url)) 1384 | 1385 | (defun mediawiki-site-password (sitename) 1386 | "Get the password for a given SITENAME." 1387 | (mediawiki-site-user-pass sitename 3 'url-password-for-url)) 1388 | 1389 | (defun mediawiki-site-domain (sitename) 1390 | "Get the LDAP domain for a given SITENAME." 1391 | (let ((domain (mediawiki-site-extract sitename 4))) 1392 | (when (and domain (not (string= "" domain))) 1393 | domain))) 1394 | 1395 | (defun mediawiki-site-first-page (sitename) 1396 | "Get the first page for a given SITENAME." 1397 | (let ((page (mediawiki-site-extract sitename 5))) 1398 | (if (or (not page) (string= page "")) 1399 | "Main Page"))) 1400 | 1401 | (defun mediawiki-site-get-token (sitename type) 1402 | "Get token(s) for SITENAME of TYPE type." 1403 | (cdr 1404 | (caadar 1405 | (cddr (mediawiki-api-call sitename "query" 1406 | (list (cons "meta" "tokens") 1407 | (cons "type" type))))))) 1408 | 1409 | (defun mediawiki-do-login (&optional sitename username password domain) 1410 | "Log into SITENAME using USERNAME, PASSWORD and DOMAIN. 1411 | Store cookies for future authentication." 1412 | (interactive) 1413 | (when (not sitename) 1414 | (setq sitename (mediawiki-prompt-for-site))) 1415 | 1416 | (setq mediawiki-site nil) ; This wil be set once we are 1417 | ; logged in 1418 | 1419 | ;; Possibly save info once we have it, eh? 1420 | (lexical-let* ((user (or (mediawiki-site-username sitename) 1421 | username 1422 | (read-string "Username: "))) 1423 | (pass (or (mediawiki-site-password sitename) 1424 | password 1425 | (read-passwd "Password: "))) 1426 | (dom-loaded (mediawiki-site-domain sitename)) 1427 | (dom (when dom-loaded 1428 | (if (string= "" dom-loaded) 1429 | (read-string "LDAP Domain: ") 1430 | dom-loaded))) 1431 | (sitename sitename) 1432 | (token (mediawiki-site-get-token sitename "login")) 1433 | (args (list (cons "lgname" user) 1434 | (cons "lgpassword" pass) 1435 | (when token 1436 | (cons "lgtoken" token)) 1437 | (when dom 1438 | (cons "lgdomain" dom)))) 1439 | (result (cadr (mediawiki-api-call sitename "login" args)))) 1440 | (when (string= (cdr (assq 'result result)) "NeedToken") 1441 | (setq result 1442 | (cadr (mediawiki-api-call sitename "login" 1443 | (append 1444 | args (list (cons "lgtoken" 1445 | (cdr (assq 'token result))))))))) 1446 | (when (string= "Success" (cdr (assoc 'result result))) 1447 | sitename))) 1448 | 1449 | (defun mediawiki-do-logout (&optional sitename) 1450 | "Log out of SITENAME." 1451 | (interactive) 1452 | (when (not sitename) 1453 | (setq sitename (mediawiki-prompt-for-site))) 1454 | 1455 | (mediawiki-api-call sitename "logout" nil) 1456 | (setq mediawiki-site nil)) 1457 | 1458 | (defun mediawiki-save-page (sitename title summary content &optional trynum) 1459 | "On SITENAME, save the current page using TITLE, SUMMARY, and CONTENT." 1460 | ;; FIXME error checking, conflicts! 1461 | (when (and trynum (< trynum 0)) 1462 | (error "Too many tries.")) 1463 | (let ((trynum (or trynum 3)) 1464 | (token (mediawiki-site-get-token sitename "csrf"))) 1465 | (condition-case err 1466 | (progn 1467 | (mediawiki-api-call sitename "edit" 1468 | (list (cons "title" 1469 | (mediawiki-translate-pagename title)) 1470 | (cons "text" content) 1471 | (cons "summary" summary) 1472 | (cons "token" token) 1473 | (cons "basetimestamp" 1474 | (or mediawiki-basetimestamp "now")) 1475 | (cons "starttimestamp" 1476 | (or mediawiki-starttimestamp "now")))) 1477 | (message "Saved %s to %s" title sitename)) 1478 | (error (progn (message "try #%d: %s " trynum 1479 | (concat "Retry because of error: " (cadr err))) 1480 | (mediawiki-retry-save-page 1481 | sitename title summary content trynum))))) 1482 | (set-buffer-modified-p nil)) 1483 | 1484 | (defun mediawiki-retry-save-page (sitename title summary content trynum) 1485 | "Refresh the edit token and then try to save the current page using TITLE, 1486 | SUMMARY, and CONTENT on SITENAME." 1487 | (let ((try (if trynum 1488 | (- trynum 1) 1489 | 3))) 1490 | (mediawiki-do-login sitename) 1491 | (setq mediawiki-edittoken (mediawiki-site-get-token sitename "csrf")) 1492 | (mediawiki-save-page sitename title summary content try))) 1493 | 1494 | (defun mediawiki-browse (&optional buffer) 1495 | "Open the BUFFER in a browser. 1496 | If BUFFER is not given, the current buffer is used." 1497 | (interactive) 1498 | (if mediawiki-page-title 1499 | (browse-url (mediawiki-make-url mediawiki-page-title "view")) 1500 | (with-current-buffer buffer 1501 | (browse-url (mediawiki-make-url mediawiki-page-title "view"))))) 1502 | 1503 | (defun mediawiki-prompt-for-site () 1504 | "Prompt the user for a site." 1505 | (let* ((prompt (concat "Sitename" 1506 | (when mediawiki-site 1507 | (format " (default %s)" mediawiki-site)) 1508 | ": ")) 1509 | (answer (completing-read prompt mediawiki-site-alist nil t))) 1510 | (if (string= "" answer) 1511 | mediawiki-site 1512 | answer))) 1513 | 1514 | ;;;###autoload 1515 | (defun mediawiki-site (&optional site) 1516 | "Set up mediawiki.el for a SITE. 1517 | Without an argument, use `mediawiki-site-default'. 1518 | Interactively, prompt for a SITE." 1519 | (interactive) 1520 | (when (not site) 1521 | (setq site (mediawiki-prompt-for-site))) 1522 | (when (or (eq nil mediawiki-site) 1523 | (not (string-equal site mediawiki-site))) 1524 | (setq mediawiki-site (mediawiki-do-login site))) 1525 | (mediawiki-edit site (mediawiki-site-first-page site))) 1526 | 1527 | (defun mediawiki-open-page-at-point () 1528 | "Open a new buffer with the page at point." 1529 | (interactive) 1530 | (mediawiki-open (mediawiki-page-at-point))) 1531 | 1532 | (defun mediawiki-page-at-point () 1533 | "Return the page name under point. 1534 | Typically, this means anything enclosed in [[PAGE]]." 1535 | (let ((pos (point)) 1536 | (eol (point-at-eol)) 1537 | (bol (point-at-bol))) 1538 | (save-excursion 1539 | (let* ((start (when (search-backward "[[" bol t) 1540 | (+ (point) 2))) 1541 | (end (when (search-forward "]]" eol t) 1542 | (- (point) 2))) 1543 | (middle (progn 1544 | (goto-char start) 1545 | (when (search-forward "|" end t) 1546 | (1- (point))))) 1547 | (pagename (when (and 1548 | (not (eq nil start)) 1549 | (not (eq nil end)) 1550 | (<= pos end) 1551 | (>= pos start)) 1552 | (buffer-substring-no-properties 1553 | start (or middle end))))) 1554 | (if (string= "/" 1555 | (substring pagename 0 1)) 1556 | (concat mediawiki-page-title pagename) 1557 | pagename))))) 1558 | 1559 | (defun mediawiki-next-header () 1560 | "Move point to the end of the next section header." 1561 | (interactive) 1562 | (let ((oldpoint (point))) 1563 | (end-of-line) 1564 | (if (re-search-forward "\\(^==+\\).*\\1" (point-max) t) 1565 | (beginning-of-line) 1566 | (goto-char oldpoint) 1567 | (message "No section headers after point.")))) 1568 | 1569 | (defun mediawiki-prev-header () 1570 | "Move point to the start of the previous section header." 1571 | (interactive) 1572 | (unless (re-search-backward "\\(^==+\\).*\\1" (point-min) t) 1573 | (message "No section headers before point."))) 1574 | 1575 | (defun mediawiki-terminate-paragraph () ;Version:1.58 1576 | "End a paragraph by any means necessary. 1577 | In a list, start a new list item; in a paragraph, start a new paragraph; 1578 | if the current paragraph is colon indented, the new 1579 | paragraph will be indented in the same way." 1580 | (interactive) 1581 | (let (indent-chars) 1582 | (save-excursion 1583 | (beginning-of-line) 1584 | (while (cond ((looking-at "^$") nil) 1585 | ((looking-at "^\\(\\(?: \\|:+\\|[#*]+\\) *\\)") 1586 | (setq indent-chars (match-string 1)) nil) 1587 | ((eq (point) (point-min)) nil) 1588 | ((progn (forward-line -1) t))) 1589 | t)) 1590 | (newline) (if (not indent-chars) (newline) 1591 | (insert indent-chars)))) 1592 | 1593 | (defun mediawiki-terminate-paragraph-and-indent () 1594 | "In a list, start a new list item. 1595 | In a paragraph, start a new paragraph but *,# will be ignored; if 1596 | the current paragraph is colon indented, the new paragraph will 1597 | be indented in the same way." 1598 | (interactive) 1599 | (let (indent-chars) 1600 | (save-excursion 1601 | (beginning-of-line) 1602 | (while (cond ((looking-at "^$") nil) 1603 | ((looking-at "^\\(\\(?: \\|:+\\) *\\)") 1604 | (setq indent-chars (match-string 1)) nil) 1605 | ((eq (point) (point-min)) nil) 1606 | ((progn (forward-line -1) t))) 1607 | t)) 1608 | (newline) 1609 | (if (not indent-chars) (newline) 1610 | (insert indent-chars)))) 1611 | 1612 | 1613 | (defun mediawiki-link-fill-nobreak-p () 1614 | "When filling, don't break the line for preformatted (fixed-width) 1615 | text or inside a Wiki link. See `fill-nobreak-predicate'." 1616 | (save-excursion 1617 | (let ((pos (point))) 1618 | (or (eq (char-after (line-beginning-position)) ? ) 1619 | (if (re-search-backward "\\[\\[" (line-beginning-position) t) 1620 | ;; Break if the link is really really long. 1621 | ;; You often get this with captioned images. 1622 | (null (or (> (- pos (point)) fill-column) 1623 | (re-search-forward "\\]\\]" pos t)))))))) 1624 | 1625 | (defun mediawiki-fill-article () 1626 | "Fill the entire article." 1627 | (interactive) 1628 | (save-excursion 1629 | (fill-region (point-min) (point-max)))) 1630 | 1631 | (defun mediawiki-unfill-article () 1632 | "Undo filling, deleting stand-alone newlines. 1633 | Stand-alone newlines are those that do not end paragraphs, list 1634 | entries, etc." 1635 | (interactive) 1636 | (save-excursion 1637 | (goto-char (point-min)) 1638 | (while (re-search-forward ".\\(\n\\)\\([^# *;:|!\n]\\|----\\)" nil t) 1639 | (replace-match " " nil nil nil 1))) 1640 | (message "Stand-alone newlines deleted")) 1641 | 1642 | (defun mediawiki-draft-reply () 1643 | "Open a temporary buffer to edit a draft. 1644 | After finishing the editing: either use 'mediawiki-draft-buffer' 1645 | to send the data into the 'mediawiki-draft-data-file'. Check the 1646 | variable mediawiki-draft-send-archive." 1647 | (interactive) 1648 | (mediawiki-reply-at-point-simple) 1649 | (beginning-of-line 1) 1650 | (kill-line nil) 1651 | (save-excursion 1652 | (window-configuration-to-register mediawiki-draft-register) 1653 | (let ((buf (get-buffer-create mediawiki-draft-buffer))) 1654 | (switch-to-buffer-other-window buf) 1655 | (mediawiki-mode) 1656 | (if mediawiki-reply-with-quote 1657 | (progn 1658 | (insert "{{Quotation|") 1659 | (yank) 1660 | (insert "'''Re: ") 1661 | (insert-register mediawiki-draft-reply-register 1) 1662 | (insert "''' |~~~~}}") 1663 | (backward-char 7)) 1664 | (when mediawiki-reply-with-hline 1665 | (insert "----") 1666 | (newline 1)) 1667 | (yank) 1668 | (end-of-line 1)) 1669 | (message " C-c C-k sends to draft, C-c C-c sends to org buffer.")))) 1670 | 1671 | (defun mediawiki-reply-at-point-simple () 1672 | "Very simple function to reply to posts in the discussion forum. 1673 | You have to set the point around the signature, then the 1674 | functions inserts the following 1675 | :'''Re: [[User:foo]]'''." 1676 | (interactive) 1677 | (beginning-of-line 1) 1678 | (if mediawiki-english-or-german 1679 | (progn 1680 | (search-forward "(UTC)") 1681 | (search-backward "[[User:")) 1682 | (search-forward "(CET)") 1683 | (search-backward "[[Benutzer:")) 1684 | (if mediawiki-user-simplify-signature 1685 | (mark-word 2) 1686 | (mark-word 3)) 1687 | (copy-to-register mediawiki-draft-reply-register (region-beginning) (region-end) nil) 1688 | (end-of-line 1) 1689 | (mediawiki-terminate-paragraph-and-indent) 1690 | (insert ":'''Re: ") 1691 | (insert-register mediawiki-draft-reply-register 1) 1692 | (if mediawiki-user-simplify-signature 1693 | (insert "|]]''' ") 1694 | (insert "]]''' "))) 1695 | 1696 | (defmacro mediawiki-goto-relative-page (direction) 1697 | "Go to the next page in DIRECTION." 1698 | `(let ((buff (ring-ref mediawiki-page-ring 1699 | (setq mediawiki-page-ring-index 1700 | (,direction mediawiki-page-ring-index 1))))) 1701 | (while (not (buffer-live-p buff)) 1702 | (setq buff 1703 | (ring-ref mediawiki-page-ring 1704 | (setq mediawiki-page-ring-index 1705 | (,direction mediawiki-page-ring-index 1))))) 1706 | (mediawiki-pop-to-buffer buff))) 1707 | 1708 | (defun mediawiki-goto-previous-page () 1709 | "Pop up the previous page being editted." 1710 | (interactive) 1711 | (mediawiki-goto-relative-page -)) 1712 | 1713 | (defun mediawiki-goto-next-page () 1714 | "Pop up the previous page being editted." 1715 | (interactive) 1716 | (mediawiki-goto-relative-page +)) 1717 | 1718 | (defun mediawiki-goto-relative-link (&optional backward) 1719 | "Move point to a link. 1720 | If BACKWARD is t, will search backwards." 1721 | (let* ((search (if backward 're-search-backward 1722 | 're-search-forward)) 1723 | (limitfunc (if backward 'point-min 1724 | 'point-max)) 1725 | (point (funcall search "\\[\\[.+\\]\\]" (funcall limitfunc) t))) 1726 | (when point 1727 | (let ((point (match-beginning 0))) 1728 | (goto-char (+ point 2)))))) 1729 | 1730 | (defun mediawiki-goto-next-link () 1731 | "Go to the next link in the page." 1732 | (interactive) 1733 | (mediawiki-goto-relative-link)) 1734 | 1735 | (defun mediawiki-goto-prev-link () 1736 | "Go to the previous link in the page." 1737 | (interactive) 1738 | (mediawiki-goto-relative-link t)) 1739 | 1740 | (defvar mediawiki-enumerate-with-terminate-paragraph nil 1741 | "*Before insert enumerate/itemize do \\[mediawiki-terminate-paragraph].") 1742 | 1743 | (defun mediawiki-insert-enumerate () 1744 | "Primitive function for inserting enumerated items. 1745 | Check the variable mediawiki-enumerate-with-terminate-paragraph. 1746 | Note however that the function \\[mediawiki-terminate-paragraph] 1747 | does not work very well will longlines-mode." 1748 | (interactive) 1749 | (if mediawiki-enumerate-with-terminate-paragraph 1750 | (progn 1751 | (mediawiki-terminate-paragraph) 1752 | (insert "#")) 1753 | (newline nil) 1754 | (insert ":#"))) 1755 | 1756 | (defun mediawiki-insert-itemize () 1757 | "Primitive function for inserting no enumerated items. 1758 | Check the variable mediawiki-enumerate-with-terminate-paragraph. 1759 | Note however that the function \\[mediawiki-terminate-paragraph] 1760 | does not work very well will longlines-mode." 1761 | (interactive) 1762 | (if mediawiki-enumerate-with-terminate-paragraph 1763 | (progn 1764 | (mediawiki-terminate-paragraph) 1765 | (insert "*")) 1766 | (newline nil) 1767 | (insert ":*"))) 1768 | 1769 | (defun mediawiki-insert (pre post) 1770 | "Wrap the current region with PRE and POST." 1771 | (if (or (and (boundp 'zmacs-region-active-p) zmacs-region-active-p) 1772 | (and (boundp 'transient-mark-mode) transient-mark-mode mark-active)) 1773 | (let ((beg (region-beginning)) 1774 | (end (region-end))) 1775 | (save-excursion 1776 | (goto-char beg) 1777 | (insert pre) 1778 | (goto-char (+ end (string-width pre))) 1779 | (insert post))) 1780 | (insert (concat pre " " post)) 1781 | (backward-char (+ 1 (string-width post))))) 1782 | 1783 | (defun mediawiki-insert-strong-emphasis () 1784 | "Mark with strong emphasis italics. 1785 | Uses four apostrophes (e.g. ''''FOO''''). When mark is active, 1786 | surrounds region." 1787 | (interactive) 1788 | (mediawiki-insert "''''" "''''")) 1789 | 1790 | (defun mediawiki-insert-bold () 1791 | "Mark bold. 1792 | Uses three apostrophes (e.g. '''FOO'''). When mark is active, 1793 | surrounds region." 1794 | (interactive) 1795 | (mediawiki-insert "'''" "'''")) 1796 | 1797 | 1798 | (defun mediawiki-insert-italics () 1799 | "Mark italics. 1800 | Uses TWO apostrophes (e.g. ''FOO''). When mark is active, 1801 | surrounds region." 1802 | (interactive) 1803 | (mediawiki-insert "''" "''")) 1804 | 1805 | (defun mediawiki-insert-quotation-with-signature () 1806 | "Mark the current region as a quotation with your signature." 1807 | (interactive) 1808 | (mediawiki-insert "{{Quotation|}}" "{{~~~~}}")) 1809 | 1810 | (defun mediawiki-insert-quotation () 1811 | "Mark the current selection as a quote. 1812 | Use the form {{Quotation}}{{}}. When mark is active, 1813 | surrounds region." 1814 | (interactive) 1815 | (mediawiki-insert "{{Quotation|}}{{" "}}")) 1816 | 1817 | (defun mediawiki-insert-bible-verse-template () 1818 | "Insert a template for the quotation of Bible verses." 1819 | (interactive) 1820 | (insert "({{niv|") 1821 | (let ((name (read-string "Name: "))) 1822 | (insert (concat name "|")) 1823 | (let ((verse (read-string "Verse: "))) 1824 | (insert (concat verse "|" name " " verse "}})"))))) 1825 | 1826 | (defun mediawiki-insert-user () 1827 | "Interactively insert a user name." 1828 | (interactive) 1829 | (if mediawiki-english-or-german 1830 | (let ((user (read-string "Name of user: " ))) 1831 | (insert (concat "[[User:" user "|" user "]]"))) 1832 | (let ((user (read-string "Name des Benutzers: " ))) 1833 | (insert (concat "[[Benutzer:" user "|" user "]]"))))) 1834 | 1835 | (defun mediawiki-insert-reply-prefix () 1836 | "Quotation box of the form {{Quotation}}{{}}." 1837 | (interactive) 1838 | (beginning-of-line 1) 1839 | (search-forward "[[") 1840 | (backward-char 2) 1841 | (mark-sexp 1) 1842 | (copy-to-register mediawiki-draft-reply-register (region-beginning) (region-end) nil) 1843 | (end-of-line 1) 1844 | (mediawiki-terminate-paragraph) 1845 | (beginning-of-line 1) 1846 | (kill-line nil) 1847 | (insert "----") 1848 | (newline 1) 1849 | (yank) 1850 | (insert ":'''Re: ") 1851 | (insert-register mediawiki-draft-reply-register 1) 1852 | (insert "''' ") 1853 | (end-of-line 1)) 1854 | 1855 | (defun mediawiki-insert-header () 1856 | "Insert subheader via == (e.g. == FOO ==)." 1857 | (interactive) 1858 | (mediawiki-insert "==" "==")) 1859 | 1860 | (defun mediawiki-insert-link () 1861 | "Insert link (e.g. [[FOO]])." 1862 | (interactive) 1863 | (mediawiki-insert "[[" "]]")) 1864 | 1865 | (defun mediawiki-insert-link-www () 1866 | "Insert link (e.g. [://FOO])." 1867 | (interactive) 1868 | (mediawiki-insert "[://" "]")) 1869 | 1870 | (defun mediawiki-insert-image () 1871 | "Insert image link (e.g. [[Image:FOO]]). 1872 | Checks the variable mediawiki-english-or-german." 1873 | (interactive) 1874 | (mediawiki-insert (if mediawiki-english-or-german 1875 | "[[Image:" 1876 | "[[Bild:") "]]")) 1877 | 1878 | (defun mediawiki-insert-audio () 1879 | "Insert audio link (e.g. [[Media:FOO]]) 1880 | Checks The variable mediawiki-english-or-german." 1881 | (interactive) 1882 | (mediawiki-insert (if mediawiki-english-or-german 1883 | "[[Media:" 1884 | "[[Bild:") "]]")) 1885 | 1886 | (defun mediawiki-insert-signature () 1887 | "Insert signature (e.g. \"~~~~:\")." 1888 | (interactive) 1889 | (insert "~~~~: ")) 1890 | 1891 | (defun mediawiki-insert-hline () 1892 | "Insert hline (e.g. \"----\")." 1893 | (interactive) 1894 | (insert "\n----\n")) 1895 | 1896 | (defun mediawiki-unfill-paragraph-or-region () 1897 | "Unfill region. 1898 | This function does NOT explicitly search for \"soft newlines\" 1899 | as does mediawiki-unfill-region." 1900 | (interactive) 1901 | (set (make-local-variable 'paragraph-start) "[ \t\n\f]") 1902 | (set (make-local-variable 'paragraph-start) 1903 | "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$") 1904 | (set-fill-prefix) 1905 | (beginning-of-line 1) 1906 | 1907 | (if use-hard-newlines 1908 | (progn 1909 | (set (make-local-variable 'use-hard-newlines) nil) 1910 | (set (make-local-variable 'sentence-end-double-space) t)) 1911 | (set (make-local-variable 'sentence-end-double-space) nil) 1912 | (set (make-local-variable 'use-hard-newlines) t)) 1913 | (let ((fill-column (point-max))) 1914 | (if (fboundp 'fill-paragraph-or-region) 1915 | (fill-paragraph-or-region nil) 1916 | (fill-paragraph nil)))) 1917 | 1918 | (defun mediawiki-start-paragraph () 1919 | "Start a Paragraph." 1920 | (interactive) 1921 | (set (make-local-variable 'paragraph-start) 1922 | "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$")) 1923 | 1924 | (defun mediawiki-hardlines () 1925 | "Set 'use-hard-newlines' to NIL." 1926 | (interactive) 1927 | (setq use-hard-newlines nil)) 1928 | 1929 | (defun mediawiki-next-long-line () 1930 | "Move forward to the next long line. 1931 | Lines are considered long if their length is greater 1932 | than `fill-column'. 1933 | 1934 | TODO: When function reaches end of buffer, 'save-excursion' to 1935 | starting point. Generalise to make `previous-long-line'." 1936 | (interactive) 1937 | ;; global-variable: fill-column 1938 | (if (= (forward-line) 0) 1939 | (let ((line-length 1940 | (save-excursion 1941 | (end-of-line) 1942 | (current-column)))) 1943 | (if (<= line-length fill-column) 1944 | (mediawiki-next-long-line) 1945 | (message "Long line found"))) 1946 | ;; Stop, end of buffer reached. 1947 | (error "Long line not found"))) 1948 | 1949 | (defun mediawiki-unfill-paragraph-simple () 1950 | "A very simple function for unfilling a paragraph." 1951 | (interactive) 1952 | (let ((fill-column (point-max))) 1953 | (fill-paragraph nil))) 1954 | 1955 | (defun mediawiki-outline-magic-keys () 1956 | "Set up outline magic keys. 1957 | See https://www.emacswiki.org/emacs/OutlineMagic" 1958 | (interactive) 1959 | (unless (featurep 'xemacs) 1960 | (local-set-key [(shift iso-lefttab)] 'outline-cycle) 1961 | (local-set-key [iso-left-tab] 'outline-cycle)) 1962 | (local-set-key [(meta left)] 'outline-promote) 1963 | (local-set-key [(meta right)] 'outline-demote) 1964 | (local-set-key [(shift return)] 'newline-and-indent) 1965 | (local-set-key [(control left)] 'mediawiki-simple-outline-promote) 1966 | (local-set-key [(control right)] 'mediawiki-simple-outline-demote) 1967 | (local-set-key [(control up)] 'outline-move-subtree-up) 1968 | (local-set-key [(control down)] 'outline-move-subtree-down)) 1969 | (add-hook 'mediawiki-mode-hook (lambda () (outline-minor-mode nil))) 1970 | (add-hook 'outline-minor-mode-hook 'mediawiki-outline-magic-keys) 1971 | 1972 | (defun mediawiki-enhance-indent () 1973 | "Indent a region using MediaWiki markup (e.g \":\")." 1974 | (interactive) 1975 | (string-rectangle (region-beginning) (region-end) ":")) 1976 | 1977 | (defun mediawiki-yank-prefix () 1978 | "Remove indent markup from region. 1979 | FIXME!!!" 1980 | (interactive) 1981 | (string-rectangle (region-beginning) (region-end) " ")) 1982 | 1983 | (defun mediawiki-simple-outline-promote () 1984 | "Simple-minded promotion of current line. 1985 | This function simply deletes one \"=\" from the beginning and end 1986 | of the line. It does not promote the whole tree!" 1987 | (interactive) 1988 | (save-excursion 1989 | (beginning-of-line 1) 1990 | (search-forward "=") 1991 | (delete-char 1 nil) 1992 | (end-of-line 1) 1993 | (search-backward "=") 1994 | (delete-char 1 nil))) 1995 | 1996 | (defun mediawiki-simple-outline-demote () 1997 | "Simple-minded demotion of the current line. 1998 | This function simple adds \"=\" to the beginning and end of the 1999 | line. It does not promote the whole tree!" 2000 | (interactive) 2001 | (save-excursion 2002 | (beginning-of-line 1) 2003 | (search-forward "=") 2004 | (insert "=") 2005 | (end-of-line 1) 2006 | (search-backward "=") 2007 | (insert "="))) 2008 | 2009 | (defun mediawiki-rename-buffer () 2010 | "Make sure that the option UNIQUE is used." 2011 | (interactive) 2012 | (rename-buffer (read-string "Name of new buffer (unique): " ) 1)) 2013 | 2014 | (defsubst mediawiki-draft-time-to-seconds (time) 2015 | "Convert TIME to a floating point number." 2016 | (+ (* (car time) 65536.0) 2017 | (cadr time) 2018 | (/ (or (car (cdr (cdr time))) 0) 1000000.0))) 2019 | 2020 | (defsubst mediawiki-draft-mail-date (&optional rfc822-p) 2021 | "Return a simple date. 2022 | If RFC822-P is passed, use RFC822 format." 2023 | (if rfc822-p 2024 | (format-time-string "%a, %e %b %Y %T %z" (current-time)) 2025 | (format-time-string "%c" (current-time)))) 2026 | 2027 | (defun mediawiki-draft-buffer-desc () 2028 | "Using the first line of the current buffer, create a short description." 2029 | (buffer-substring (point-min) 2030 | (save-excursion 2031 | (goto-char (point-min)) 2032 | (end-of-line) 2033 | (if (> (- (point) (point-min)) 60) 2034 | (goto-char (+ (point-min) 60))) 2035 | (point)))) 2036 | 2037 | (defun mediawiki-draft-append-to-file () 2038 | "Append a draft to the drafts file." 2039 | (let ((text (buffer-string))) 2040 | (with-temp-buffer 2041 | (insert (concat "\n\n" mediawiki-draft-leader-text "Draft: " 2042 | (read-string "Enter Subject: ") " " 2043 | (current-time-string) " " 2044 | mediawiki-draft-leader-text 2045 | "\n\n\f\n\n" text "\n\f\n")) 2046 | (if (not (bolp)) 2047 | (insert "\n\n")) 2048 | (if (find-buffer-visiting mediawiki-draft-data-file) 2049 | (let ((mediawiki-draft-text (buffer-string))) 2050 | (set-buffer (get-file-buffer mediawiki-draft-data-file)) 2051 | (save-excursion 2052 | (goto-char (point-max)) 2053 | (insert (concat "\n" mediawiki-draft-text "\n")) 2054 | (save-buffer))) 2055 | (append-to-file (point-min) (point-max) mediawiki-draft-data-file))))) 2056 | 2057 | ;;;###autoload 2058 | (defun mediawiki-draft () 2059 | "Open a temporary buffer in mediawiki-mode. 2060 | This is for editing a draft. After finishing the editing either 2061 | use \\[mediawiki-draft-buffer] to send the data into the 2062 | mediawiki-draft-data-file, or send the buffer using 2063 | \\[mediawiki-save] and insert it later into a mediawiki article." 2064 | (interactive) 2065 | (window-configuration-to-register mediawiki-draft-register) 2066 | (let ((buf (get-buffer-create mediawiki-draft-buffer))) 2067 | (switch-to-buffer-other-window buf) 2068 | (mediawiki-mode) 2069 | (message " C-c C-k sends to draft file, C-c C-c sends to org buffer."))) 2070 | 2071 | (defun mediawiki-draft-page () 2072 | "Set the current buffer as a draft buffer." 2073 | (interactive) 2074 | (mark-page) 2075 | (copy-region-as-kill (region-beginning) (region-end)) 2076 | (mediawiki-draft) 2077 | (yank nil)) 2078 | 2079 | (defun mediawiki-draft-region (&optional begin end) 2080 | "Mediawiki-draft the data from BEGIN to END. 2081 | If called from within the mediawiki-draft buffer, BEGIN and END are ignored, 2082 | and the entire buffer will be mediawiki-drafted. If called from any other 2083 | buffer, that region, plus any context information specific to that 2084 | region, will be mediawiki-drafted." 2085 | (interactive) 2086 | (let ((b (or begin (min (point) (or (mark) (point-min))))) 2087 | (e (or end (max (point) (or (mark) (point-max)))))) 2088 | (save-restriction 2089 | (narrow-to-region b e) 2090 | (run-hook-with-args-until-success 'mediawiki-draft-handler-functions) 2091 | (when (equal mediawiki-draft-buffer (buffer-name)) 2092 | (mediawiki-debug (current-buffer) "mediawiki-draft-region") 2093 | (jump-to-register mediawiki-draft-register))))) 2094 | 2095 | (defun mediawiki-draft-buffer () 2096 | "Mediawiki-draft-buffer sends the contents of the current (temporary) 2097 | buffer to the mediawiki-draft-buffer, see the variable 2098 | mediawiki-draft-data-file." 2099 | (interactive) 2100 | (mediawiki-draft-region (point-min) (point-max))) 2101 | 2102 | (defun mediawiki-draft-clipboard () 2103 | "Mediawiki-Draft the contents of the current clipboard. 2104 | Most useful for mediawiki-drafting things from Netscape or other X Windows 2105 | application." 2106 | (interactive) 2107 | (with-temp-buffer 2108 | (insert (if (fboundp 'gui-get-selection) ; Since 25.1 2109 | (gui-get-selection) 2110 | (x-get-clipboard))) 2111 | (run-hook-with-args-until-success 'mediawiki-draft-handler-functions))) 2112 | 2113 | (defun mediawiki-draft-view-draft () 2114 | "Simple shortcut to visit the drafts file." 2115 | (interactive) 2116 | (find-file mediawiki-draft-data-file)) 2117 | 2118 | (defun mediawiki-mark-section () 2119 | "Set mark at end of current logical section, and point at top." 2120 | (interactive) 2121 | (re-search-forward (concat "== " "[a-z,A-z \t]*" " ==")) 2122 | (re-search-backward "^") 2123 | (set-mark (point)) 2124 | (re-search-backward (concat "== " "[a-z,A-z \t]*" " ")) 2125 | (when (fboundp 'zmacs-activate-region) 2126 | (zmacs-activate-region))) 2127 | 2128 | (defun mediawiki-mark-signature () 2129 | "Set mark at end of current logical section, and point at top." 2130 | (interactive) 2131 | (re-search-forward "]]") ;;[[ ]] 2132 | (re-search-backward "^") 2133 | (set-mark (point)) 2134 | (re-search-backward "[[") 2135 | (when (fboundp 'zmacs-activate-region) 2136 | (zmacs-activate-region))) 2137 | 2138 | (defun mediawiki-draft-copy-page-to-register () 2139 | "Copy a page via the mediawiki-draft-register." 2140 | (interactive) 2141 | (save-excursion 2142 | (narrow-to-page nil) 2143 | (copy-to-register mediawiki-draft-page (point-min) (point-max) nil) 2144 | (message "draft page copied to wikipedia register mediawiki-draft-page.") 2145 | (widen))) 2146 | 2147 | (defun mediawiki-draft-yank-page-to-register () 2148 | "Insert a page via the mediawiki-draft-register." 2149 | (interactive) 2150 | (insert-register mediawiki-draft-page nil)) 2151 | 2152 | (defun mediawiki-draft-send (target-buffer) 2153 | "Copy the current page in the drafts file to TARGET-BUFFER. 2154 | If 'mediawiki-draft-send-archive' is t, then additionally the 2155 | text will be archived in the draft.wiki file." 2156 | (interactive "bTarget buffer: ") 2157 | (mediawiki-draft-copy-page-to-register) 2158 | (switch-to-buffer target-buffer) 2159 | (end-of-line 1) 2160 | (newline 1) 2161 | (mediawiki-draft-yank-page-to-register) 2162 | (message "The page has been sent (copied) to the mozex file!") 2163 | (switch-to-buffer "*MW-Draft*") 2164 | (when mediawiki-draft-send-archive 2165 | (let ((text (buffer-string))) 2166 | (with-temp-buffer 2167 | (insert (concat "\n\n" mediawiki-draft-leader-text) 2168 | (insert-register mediawiki-draft-reply-register 1) 2169 | (insert (concat " " (current-time-string) " " 2170 | mediawiki-draft-leader-text "\n\n\f\n\n" 2171 | text "\n\f\n")) 2172 | (if (not (bolp)) 2173 | (insert "\n\n")) 2174 | (if (find-buffer-visiting mediawiki-draft-data-file) 2175 | (let ((mediawiki-draft-text (buffer-string))) 2176 | (set-buffer (get-file-buffer mediawiki-draft-data-file)) 2177 | (save-excursion 2178 | (goto-char (point-max)) 2179 | (insert (concat "\n" mediawiki-draft-text "\n")) 2180 | (save-buffer))) 2181 | (append-to-file (point-min) (point-max) 2182 | mediawiki-draft-data-file))))) 2183 | (when (equal mediawiki-draft-buffer (buffer-name)) 2184 | (mediawiki-debug (current-buffer) "mediawiki-draft-send")) 2185 | (switch-to-buffer target-buffer))) 2186 | 2187 | (define-derived-mode mediawiki-draft-mode text-mode "MW-Draft" 2188 | "Major mode for output from \\[mediawiki-draft]. 2189 | \\ This buffer is used to collect data that 2190 | you want mediawiki-draft. Just hit \\[mediawiki-draft-region] when 2191 | you're done entering, and it will go ahead and file the data for 2192 | latter retrieval, and possible indexing. 2193 | \\{mediawiki-draft-mode-map}" 2194 | (kill-all-local-variables) 2195 | (indented-text-mode) 2196 | (define-key mediawiki-draft-mode-map "\C-c\C-k" 'mediawiki-draft-buffer) 2197 | (define-key mediawiki-draft-mode-map "\C-c\C-d" 'mediawiki-draft-buffer)) 2198 | 2199 | (defvar mediawiki-mode-map nil "Keymap for `mediawiki-mode'.") 2200 | (progn 2201 | (setq mediawiki-mode-map (make-sparse-keymap "mediawiki")) 2202 | (define-key mediawiki-mode-map [menu-bar mediawiki] 2203 | (cons "MediaWiki" mediawiki-mode-map)) 2204 | (define-key mediawiki-mode-map [unfill-article] 2205 | '("Unfill article" . mediawiki-unfill-article)) 2206 | (define-key mediawiki-mode-map [fill-article] 2207 | '("Fill article" . mediawiki-fill-article)) 2208 | (define-key mediawiki-mode-map [separator-fill] '("--")) 2209 | (define-key mediawiki-mode-map [next-header] 2210 | '("Next header" . mediawiki-next-header)) 2211 | (define-key mediawiki-mode-map [prev-header] 2212 | '("Previous header" . mediawiki-prev-header)) 2213 | (define-key mediawiki-mode-map [separator-header] '("--")) 2214 | (define-key mediawiki-mode-map [outline] 2215 | '("Toggle Outline Mode..." . outline-minor-mode)) 2216 | 2217 | (define-key mediawiki-mode-map "\M-n" 'mediawiki-next-header) 2218 | (define-key mediawiki-mode-map "\C-c\C-n" 'mediawiki-next-long-line) 2219 | (define-key mediawiki-mode-map "\M-p" 'mediawiki-prev-header) 2220 | (define-key mediawiki-mode-map [(meta down)] 'mediawiki-next-header) 2221 | (define-key mediawiki-mode-map [(meta up)] 'mediawiki-prev-header) 2222 | (define-key mediawiki-mode-map "\C-j" 'mediawiki-terminate-paragraph) 2223 | 2224 | (define-key mediawiki-mode-map "\C-c\C-q" 'mediawiki-unfill-article) 2225 | (define-key mediawiki-mode-map "\C-c\M-q" 'mediawiki-fill-article) 2226 | (define-key mediawiki-mode-map "\C-c\M-u" 'mediawiki-unfill-paragraph-or-region) 2227 | (define-key mediawiki-mode-map "\C-c\C-u" 'mediawiki-unfill-paragraph-simple) 2228 | (define-key mediawiki-mode-map "\C-c\C-f\C-s" 'mediawiki-insert-strong-emphasis) 2229 | (define-key mediawiki-mode-map "\C-c\C-f\C-b" 'mediawiki-insert-bold) 2230 | (define-key mediawiki-mode-map "\C-c\C-f\C-i" 'mediawiki-insert-italics) 2231 | (define-key mediawiki-mode-map "\C-c\C-f\C-e" 'mediawiki-insert-header) 2232 | (define-key mediawiki-mode-map "\C-c\C-f\C-l" 'mediawiki-insert-link) 2233 | (define-key mediawiki-mode-map "\C-c\C-f\C-u" 'mediawiki-insert-user) 2234 | (define-key mediawiki-mode-map "\C-c\C-f\C-q" 'mediawiki-insert-quotation) 2235 | (define-key mediawiki-mode-map "\C-c\C-f\C-v" 'mediawiki-insert-bible-verse-template) 2236 | (define-key mediawiki-mode-map "\C-c\C-w" 'mediawiki-insert-signature) 2237 | (define-key mediawiki-mode-map "\C-c\C-l" 'mediawiki-insert-hline) 2238 | (define-key mediawiki-mode-map [(meta f7)] 'mediawiki-draft) 2239 | (define-key mediawiki-mode-map [(meta f8)] 'mediawiki-reply-at-point-simple) 2240 | (define-key mediawiki-mode-map [(meta f9)] 'mediawiki-draft-view-draft) 2241 | (define-key mediawiki-mode-map "\C-c\C-r" 'mediawiki-reply-at-point-simple) 2242 | (define-key mediawiki-mode-map "\C-cr" 'mediawiki-draft-region) 2243 | (define-key mediawiki-mode-map [(meta r)] 'mediawiki-draft-reply) 2244 | (define-key mediawiki-mode-map "\C-c\C-m" 'mediawiki-draft) 2245 | (define-key mediawiki-mode-map "\C-c\C-b" 'mediawiki-draft-region) 2246 | (define-key mediawiki-mode-map "\C-c\C-d" 'mediawiki-draft-buffer) 2247 | (define-key mediawiki-mode-map "\C-c\C-k" 'mediawiki-draft-buffer) 2248 | (define-key mediawiki-mode-map "\C-c\C-p" 'mediawiki-draft-copy-page-to-register) 2249 | (define-key mediawiki-mode-map "\C-c\C-c" 'mediawiki-draft-send) 2250 | (define-key mediawiki-mode-map "\C-c\C-s" 'mediawiki-draft-yank-page-to-register) 2251 | 2252 | (define-key mediawiki-mode-map [(control meta prior)] 'mediawiki-enhance-indent) 2253 | (define-key mediawiki-mode-map [(control meta next)] 'mediawiki-yank-prefix) 2254 | (define-key mediawiki-mode-map [(meta return)] 'mediawiki-insert-enumerate) 2255 | (define-key mediawiki-mode-map [(meta control return)] 'mediawiki-insert-enumerate-nonewline) 2256 | ;; private setting 2257 | (define-key mediawiki-mode-map [(shift return)] 'newline-and-indent) 2258 | (define-key mediawiki-mode-map "\C-\\" 'mediawiki-insert-itemize) 2259 | (define-key mediawiki-mode-map [(control return)] 'mediawiki-insert-itemize) 2260 | (define-key mediawiki-mode-map "\C-ca" 'auto-capitalize-mode) 2261 | ;; (define-key mediawiki-mode-map "\C-ci" 'set-input-method) 2262 | ;; (define-key mediawiki-mode-map "\C-ct" 'toggle-input-method) 2263 | 2264 | (define-key mediawiki-mode-map [(backtab)] 'mediawiki-goto-prev-link) 2265 | (define-key mediawiki-mode-map [(tab)] 'mediawiki-goto-next-link) 2266 | (define-key mediawiki-mode-map "\M-g" 'mediawiki-reload) 2267 | (define-key mediawiki-mode-map "\C-x\C-s" 'mediawiki-save) 2268 | (define-key mediawiki-mode-map "\C-c\C-c" 'mediawiki-save-and-bury) 2269 | (define-key mediawiki-mode-map "\C-x\C-w" 'mediawiki-save-as) 2270 | (define-key mediawiki-mode-map "\C-c\C-o" 'mediawiki-open) 2271 | (define-key mediawiki-mode-map "\M-p" 2272 | 'mediawiki-goto-previous-page) 2273 | (define-key mediawiki-mode-map "\M-n" 'mediawiki-goto-next-page) 2274 | (define-key mediawiki-mode-map [(control return)] 2275 | 'mediawiki-open-page-at-point)) 2276 | 2277 | (define-derived-mode mediawiki-mode text-mode "MW" 2278 | "Major mode for editing articles written in the markup language 2279 | used by Mediawiki. 2280 | 2281 | Wikipedia articles are usually unfilled: newline characters are not 2282 | used for breaking paragraphs into lines. Unfortunately, Emacs does not 2283 | handle word wrapping yet. As a workaround, mediawiki-mode turns on 2284 | longlines-mode automatically. In case something goes wrong, the 2285 | following commands may come in handy: 2286 | 2287 | \\[mediawiki-fill-article] fills the buffer. 2288 | \\[mediawiki-unfill-article] unfills the buffer. 2289 | 2290 | Be warned that function can be dead slow, better use mediawiki-unfill-paragraph-or-region. 2291 | \\[mediawiki-unfill-paragraph-or-region] unfills the paragraph 2292 | \\[mediawiki-unfill-paragraph-simple] does the same but simpler. 2293 | 2294 | The following commands put in markup structures. 2295 | \\[mediawiki-insert-strong-emphasis] inserts italics 2296 | \\[mediawiki-insert-bold] inserts bold text 2297 | \\[mediawiki-insert-italics] italics 2298 | \\[mediawiki-insert-header] header 2299 | \\[mediawiki-insert-link] inserts a link 2300 | 2301 | The following commands are also defined: 2302 | \\[mediawiki-insert-user] inserts user name 2303 | \\[mediawiki-insert-signature] inserts ~~~~ 2304 | \\[mediawiki-insert-enumerate] inserts enumerate type structures 2305 | \\[mediawiki-insert-itemize] inserts itemize type structures 2306 | \\[mediawiki-insert-hline] inserts a hline 2307 | 2308 | The draft functionality 2309 | \\[mediawiki-draft] 2310 | \\[mediawiki-draft-region] 2311 | \\[mediawiki-draft-view-draft] 2312 | \\[mediawiki-draft-page] 2313 | \\[mediawiki-draft-buffer] 2314 | 2315 | Replying and sending functionality 2316 | \\[mediawiki-reply-at-point-simple] 2317 | \\[mediawiki-draft-reply] 2318 | 2319 | The register functionality 2320 | \\[mediawiki-copy-page-to-register] 2321 | \\[defun mediawiki-insert-page-to-register] 2322 | 2323 | Some simple editing commands. 2324 | \\[mediawiki-enhance-indent] 2325 | \\[mediawiki-yank-prefix] 2326 | \\[mediawiki-unfill-paragraph-or-region] 2327 | 2328 | \\[mediawiki-terminate-paragraph] starts a new list item or paragraph in a context-aware manner. 2329 | \\[mediawiki-next-header] moves to the next (sub)section header. 2330 | \\[mediawiki-prev-header] moves to the previous (sub)section header." 2331 | 2332 | (make-local-variable 'change-major-mode-hook) 2333 | (make-local-variable 'mediawiki-edittoken) 2334 | (make-local-variable 'mediawiki-starttimestamp) 2335 | (make-local-variable 'mediawiki-basetimestamp) 2336 | (make-local-variable 'mediawiki-site) 2337 | (make-local-variable 'mediawiki-edit-form-vars) 2338 | (make-local-variable 'mediawiki-page-title) 2339 | (set (make-local-variable 'adaptive-fill-regexp) "[ ]*") 2340 | (set (make-local-variable 'comment-start-skip) "\\(?:\\)?") 2342 | (set (make-local-variable 'comment-start) "") 2344 | (set (make-local-variable 'paragraph-start) 2345 | "\\*\\| \\|#\\|;\\|:\\||\\|!\\|$") 2346 | (set (make-local-variable 'sentence-end-double-space) nil) 2347 | (set (make-local-variable 'font-lock-multiline) t) 2348 | (set (make-local-variable 'font-lock-defaults) 2349 | '(mediawiki-font-lock-keywords t nil nil nil)) 2350 | (set (make-local-variable 'fill-nobreak-predicate) 2351 | 'mediawiki-link-fill-nobreak-p) 2352 | (set (make-local-variable 'auto-fill-inhibit-regexp) "^[ *#:|;]") 2353 | 2354 | ;; Support for outline-minor-mode. No key conflicts, so we'll use 2355 | ;; the normal outline-mode prefix. 2356 | (set (make-local-variable 'outline-regexp) "==+") 2357 | (when (boundp 'outline-minor-mode-prefix) 2358 | (set (make-local-variable 'outline-minor-mode-prefix) "\C-c\C-o")) 2359 | ; (set (make-local-variable 'outline-regexp) "=+") 2360 | ; (set (make-local-variable 'outline-regexp) ":") 2361 | 2362 | ;; Turn on the Imenu automatically. 2363 | (when menu-bar-mode 2364 | (set (make-local-variable 'imenu-generic-expression) 2365 | mediawiki-imenu-generic-expression) 2366 | (imenu-add-to-menubar "Contents")) 2367 | 2368 | (modify-syntax-entry ?< "(>" mediawiki-mode-syntax-table) 2369 | (modify-syntax-entry ?> ")<" mediawiki-mode-syntax-table)) 2370 | 2371 | ;; (defvar mw-pagelist-mode-map 2372 | ;; (let ((map (make-sparse-keymap))) 2373 | ;; (suppress-keymap map) 2374 | ;; (define-key map [(return)] 'mw-pl-goto-page-at-point) 2375 | ;; (define-key map "n" 'mw-pl-page-down) 2376 | ;; (define-key map "C-v" 'mw-pl-page-down) 2377 | ;; (define-key map [(next)] 'mw-pl-page-down) 2378 | ;; (define-key map "p" 'mw-pl-page-up) 2379 | ;; (define-key map "M-v" 'mw-pl-page-up) 2380 | ;; (define-key map [(prior)] 'mw-pl-page-up))) 2381 | 2382 | ;; (define-derived-mode mw-pagelist-mode special-mode "MW-PageList") 2383 | 2384 | (provide 'mediawiki) 2385 | 2386 | ;; Local Variables: 2387 | ;; time-stamp-pattern: "20/^;; Last Modified: <%%>$" 2388 | ;; End: 2389 | 2390 | ;;; mediawiki.el ends here 2391 | --------------------------------------------------------------------------------