Marketing/Month of LibreOffice/Update script

From The Document Foundation Wiki
Jump to: navigation, search

This is the PHP script that uses Chris G's Botclasses to update the wiki with new badges. Each day, add new names in list format to the following text files:

  • code.txt (code contributions)
  • qa.txt (bugs confirmed)
  • translate.txt (translations)
  • ask.txt (good Ask.LibreOffice answers)
  • docs.txt (documentation contributions
  • twitter.txt (mentions of #libreoffice)

Note: each day, simply add names to the end of each text file. The PHP script removes duplicates.

<?php
        // Script to update badges page on LibreOffice Wiki
        // Public Domain - created by mike.saunders@documentfoundation.org - v1.1.2
        //
        // Place list of names in: code.txt qa.txt translate.txt ask.txt docs.txt twitter.txt

        // Set up classes
        include( 'botclasses.php' );
        $wiki = new wikipedia;
        $wiki->url = "https://wiki.documentfoundation.org/api.php";
        $wiki->setUserAgent( 'User-Agent: FooBot (http://mediawiki.org/wiki/User:FooBot)' );

        // Log in to the wiki
        $user = 'monthoflibreoffice_bot';
        $pass = 'xxxxxxxxxxxxx';
        $wiki->login( $user, $pass );

        // Remove duplicated names in lists
        system( 'cat code.txt | sort | uniq > tmp.txt; mv tmp.txt code.txt' );
        system( 'cat qa.txt | sort | uniq > tmp.txt; mv tmp.txt qa.txt' );
        system( 'cat translate.txt | sort | uniq > tmp.txt; mv tmp.txt translate.txt' );
        system( 'cat ask.txt | sort | uniq > tmp.txt; mv tmp.txt ask.txt' );
        system( 'cat docs.txt | sort | uniq > tmp.txt; mv tmp.txt docs.txt' );
        system( 'cat twitter.txt | sort | uniq > tmp.txt; mv tmp.txt twitter.txt' );

        // Load lists into variables
        $code_names = file_get_contents( 'code.txt' );
        $qa_names = file_get_contents( 'qa.txt' );
        $translate_names = file_get_contents( 'translate.txt' );
        $ask_names = file_get_contents( 'ask.txt' );
        $docs_names = file_get_contents( 'docs.txt' );
        $twitter_names = file_get_contents( 'twitter.txt' );

        // Turn into comma-separated lists (without final comma)
        $code_names = rtrim(trim(str_replace(PHP_EOL, ', ', $code_names)), ',');
        $qa_names = rtrim(trim(str_replace(PHP_EOL, ', ', $qa_names)), ',');
        $translate_names = rtrim(trim(str_replace(PHP_EOL, ', ', $translate_names)), ',');
        $ask_names = rtrim(trim(str_replace(PHP_EOL, ', ', $ask_names)), ',');
        $docs_names = rtrim(trim(str_replace(PHP_EOL, ', ', $docs_names)), ',');
        $twitter_names = rtrim(trim(str_replace(PHP_EOL, ', ', $twitter_names)), ',');

        // Generate content to be added to wiki page
        $content = '[[File:Month_of_libreoffice_november16.png]]

=== These are the badges awarded so far - try to get them all! ===
<big>Want to get a badge? [https://blog.documentfoundation.org/blog/2016/11/01/the-november-2016-month-of-libreoffice-begins/#howtoget See this page] for information on how to participate.</big>

<br>

{| style="border:1px solid blue;border-radius:10px;margin:5px;" cellpadding="10"
|-
| [[File:Badge_code.png|400px]]
| <p style="color:blue;"><strong>' . $code_names . '</strong></p><br>
[https://twitter.com/share?text=I%20got%20a%20badge%20for%20contributing%20to%20@LibreOffice! {{hilite|Share on Twitter}}] | [https://www.facebook.com/sharer/sharer.php?u=https://wiki.documentfoundation.org/Badges/2016-05 {{hilite|Share on Facebook}}] | [https://wiki.documentfoundation.org/images/thumb/c/c4/Badge_code.png/200px-Badge_code.png {{hilite|Small badge for your site}}]
|}


{| style="border:1px solid red;border-radius:10px;margin:5px;" cellpadding="10"
|-
| [[File:Badge_qa.png|400px]]
| <p style="color:red;"><strong>' . $qa_names . '</strong></p><br>
[https://twitter.com/share?text=I%20got%20a%20badge%20for%20contributing%20to%20@LibreOffice! {{hilite|Share on Twitter}}] | [https://www.facebook.com/sharer/sharer.php?u=https://wiki.documentfoundation.org/Badges/2016-05 {{hilite|Share on Facebook}}] | [https://wiki.documentfoundation.org/images/thumb/3/31/Badge_qa.png/200px-Badge_qa.png {{hilite|Small badge for your site}}]
|}


{| style="border:1px solid green;border-radius:10px;margin:5px;" cellpadding="10"
|-
| [[File:Badge_translate.png|400px]]
| <p style="color:green;"><strong>' . $translate_names . '</strong></p><br>
[https://twitter.com/share?text=I%20got%20a%20badge%20for%20contributing%20to%20@LibreOffice! {{hilite|Share on Twitter}}] | [https://www.facebook.com/sharer/sharer.php?u=https://wiki.documentfoundation.org/Badges/2016-05 {{hilite|Share on Facebook}}] | [https://wiki.documentfoundation.org/images/thumb/a/a0/Badge_translate.png/200px-Badge_translate.png {{hilite|Small badge for your site}}]
|}


{| style="border:1px solid purple;border-radius:10px;margin:5px;" cellpadding="10"
|-
| [[File:Badge_ask.png|400px]]
| <p style="color:purple;"><strong>' . $ask_names . '</strong></p><br>
[https://twitter.com/share?text=I%20got%20a%20badge%20for%20contributing%20to%20@LibreOffice! {{hilite|Share on Twitter}}] | [https://www.facebook.com/sharer/sharer.php?u=https://wiki.documentfoundation.org/Badges/2016-05 {{hilite|Share on Facebook}}] | [https://wiki.documentfoundation.org/images/thumb/3/31/Badge_ask.png/200px-Badge_ask.png {{hilite|Small badge for your site}}]
|}


{| style="border:1px solid orange;border-radius:10px;margin:5px;" cellpadding="10"
|-
| [[File:Badge_docs.png|400px]]
| <p style="color:orange;"><strong>' . $docs_names . '</strong></p><br>
[https://twitter.com/share?text=I%20got%20a%20badge%20for%20contributing%20to%20@LibreOffice! {{hilite|Share on Twitter}}] | [https://www.facebook.com/sharer/sharer.php?u=https://wiki.documentfoundation.org/Badges/2016-05 {{hilite|Share on Facebook}}] | [https://wiki.documentfoundation.org/images/thumb/4/4a/Badge_docs.png/200px-Badge_docs.png {{hilite|Small badge for your site}}]
|}


{| style="border:1px solid brown;border-radius:10px;margin:5px;" cellpadding="10"
|-
| [[File:Badge_social.png|400px]]
| <p style="color:brown;"><strong>' . $twitter_names . '</strong></p><br>
[https://twitter.com/share?text=I%20got%20a%20badge%20for%20contributing%20to%20@LibreOffice! {{hilite|Share on Twitter}}] | [https://www.facebook.com/sharer/sharer.php?u=https://wiki.documentfoundation.org/Badges/2016-05 {{hilite|Share on Facebook}}] | [https://wiki.documentfoundation.org/images/thumb/3/38/Badge_social.png/200px-Badge_social.png {{hilite|Small badge for your site}}]
|}
';

        // Finally, perform the edit on the wiki
        $page = 'Badges/2016-11';
        $summary = 'Batch update for Month of LibreOffice marketing campaign badges';
        $wiki->edit( $page, $content, $summary );
?>