Mail-to-wiki gateway

From Meta, a Wikimedia project coordination wiki
Jump to: navigation, search
Ambox outdated content.svg

This page is kept for historical interest. Its content is outdated or maybe wrong.

You may find more up-to-date information on the www.mediawiki.org website.

MediaWiki logo

See bugzilla:831 mail-to-wiki gateway: allow adding or creation of page through SMS or E-Mail

This is the start of a new page, which describes the script editpage.php, which basically allows creation from a received mail, from commandline or from a file.

It supports

  • append to a page
  • prepend to page or
  • create new page

The idea of mail-to-wiki gateways is not new, you can easily find these references:

Started by --Wikinaut mail 20:39, 21 Mar 2005 (UTC)


$version        = '1.14-alpha (March 21, 2005)';
$progname       = 'editpage.php';

/*
        Disclaimer:
        ===========

        Please use at your own risk: the script leaves currently the server and wikiuser passwords in the
        temporary directory. These files should be deleted after use of the script.

        editpage.php
        ============

        Edit a wikipage ...
        ... by sending commands from the commandline or others scripts
        ... as if you are user($wikiuser) - see below

        tested with: Mediawiki 1.3.7, 1.3.11, 1.5 (CVS HEAD)

        M.Arndt/T.Gries Feb./March 2005

        Bug reports and improvements:
        mailto:mail@tgries.de

        1.14    21.03.2005      alpha release for publication on http://bugzilla.wikimedia.org/show_bug.cgi?id=831
                                see also for links to further documentation
        1.10    13.03.2005      "add" as synonym to append; html_entities on an existing wiki page are not escaped again
                                UTF-8, quoted-printable, ISO-8859-1 handling of Subject and body
        1.08    10.03.2005      using tempname
        1.07    08.03.2005      removing <HTML> tags; remove leading empty lines
        1.06    07.03.2005      tablestyle
        1.05    06.03.2005      allow parameters in stdin
        1.04    04.03.2005      read page text from stdin; first version which works with procmail
        1.03    03.03.2005      Version for Tomer (bot developer)
        1.02    03.03.2005      \n inserts a newline character into the wikipage;
                                -f filename : read everything from a file
        1.01    27.02.2005      compatibel with older version which uses wpEdittime
        1.00    26.02.2005      Initial version adapted for Mediawiki 1.3.11 which uses wpEditToken

        Usage:   php editpage.php [ -a | -p | -o ] "Pagename" "A new text for this page" ["Edit Summary"]
                 php editpage.php [ -a | -p | -o ] -f filename ["Pagename" ["Edit Summary"]]

        <mode> ::=   -a | -append -add (default)
                        -p | -prepend
                        -o | -overwrite -replace -new -create

                        -s      read everything from stdin ["Pagename"]

                                pagename, edit summary, page text
                                are read from stdin

                                The optional "Pagename" on commandline is used as default page

                        -f      parameter to read everything from a file;
                                parameters in first three lines of the file
                                the sequence of the parameters does not matter
                                take precedence over command line parameters

                        Content of file:

                                <mode>:<pagename>   This replaces the two lines Mode: and Page in the first example.
                                Summary:<edit summary>
                                <body>

                        Alternative:

                                Mode:<mode>
                                Page:<pagename>
                                <body>

        Example:
        php editpage.php -a "Test" "* This is a new line generated by ~~~~." "A very first test."
        php editpage.php -f testfile.txt

        foo:

        add:Test
        Summary: This and that, an edit summary
        * This is a text for the wiki page.
        ----
        <EOF>

        If (Edit)Summary is empty, then the Subject text will be used as (Edit)Summary.


        Example for a procmail configuration file ($keyword = mail2wiki)

        .procmail (the 'c' instructs procmail to file an additional mail copy in your mail folder)
        :0c:
        * ^Subject: mail2wiki
        | formail -k -X Date: -X From: -X Subject: -X Content-Type: -X Content-Transfer-Encoding: | /home/www/wikiextensions/editpage/editpage.php -s

        To Do:

        1.      change curl exec calls to internal php-curl calls
        2.      correct treatment of multipart mails (e.g. plain-text _and_ html)
                use PHP:PEAL for this
        3.      relax current strict deletion of HTML tags, everything in < >

        The code uses UTF-8 coding internally and assumes, that the Wiki input encoding is UTF-8, too.

*******************************************
*
*       make your customizations here
*
*******************************************/

        $wikiname       = "localhost/testwiki";               // Wiki-URL, becomes later http://$wikiname/index.php?......
        $auth           = "user:password";            // credentials serveruser:serverpassword for server login

        $wikiuser       = "EditScript";                       // the script logs into this wiki-user account (change it)
        $wikiuserpw     = "nada--zero";                       // and uses this password (change it)

        $scriptdir      = "/home/www/wikiextensions/editpage";        // directory of script and three curl templates (read-only)
        $tempdir        = $scriptdir."/tmp";          // path to a writable temporary directory

        $defaultpage    = 'Wikimail';                   // page name of page for error messages
        $defaultpage    = $progname."_errorlog";      // page name of page for error messages

        $keyword        = '';                           // a keyword, which must be first word in Subject: mail header
                                                        // in order to trigger any action
        $tablestyle     = true;                         // From: and Subject: mail headers are formatted using wiki table syntax
        $ShowSummaryOnPage = false;
        $ShowSubjectOnPage = false;

        $category       = '[[Category:wikimail]]';      // The scripts automatically adds the category (if not yet present)

/******************************************/