Marketing/Month of LibreOffice/Update script
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
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.3
//
// 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( 'Month of LibreOffice Bot' );
// Log in to the wiki
$user = 'Mike.saunders@MonthOfLibreOffice_Bot';
$pass = 'xxx';
$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 = '{{TopMenu}}{{Menu}}{{Menu.Home}}{{Lang|}}
[[File:Month_of_LibreOffice_banner.png|800px]]
=== Stickers awarded so far in the Month of LibreOffice, November 2018 ===
<big>Join the Month of LibreOffice - [https://blog.documentfoundation.org/blog/2018/05/02/the-may-2018-month-of-libreoffice-begins/#howtoget click here] to see how you can help LibreOffice, get your name on this page, and claim your sticker!</big>
<br>
{| style="border:1px solid #0369A3;border-radius:10px;margin:5px;width:100%;" cellpadding="10"
|-
| <p style="color:#0369A3;"><strong>Contributing code patches:<br /><br />' . $code_names . '</strong></p><br>
|}
{| style="border:1px solid #A33E03;border-radius:10px;margin:5px;width:100%;" cellpadding="10"
|-
| <p style="color:#A33E03;"><strong>Helping to report and confirm bugs:<br /><br />' . $qa_names . '</strong></p><br>
|}
{| style="border:1px solid #18A303;border-radius:10px;margin:5px;width:100%;" cellpadding="10"
|-
| <p style="color:#18A303;"><strong>Helping with translations:<br /><br />' . $translate_names . '</strong></p><br>
|}
{| style="border:1px solid #8E03A3;border-radius:10px;margin:5px;width:100%;" cellpadding="10"
|-
| <p style="color:#8E03A3;"><strong>Answering questions from users:<br /><br />' . $ask_names . '</strong></p><br>
|}
{| style="border:1px solid #C99C00;border-radius:10px;margin:5px;width:100%;" cellpadding="10"
|-
| <p style="color:#C99C00;"><strong>Updating documentation and the wiki:<br /><br />' . $docs_names . '</strong></p><br>
|}
{| style="border:1px solid black;border-radius:10px;margin:5px;width:100%;" cellpadding="10"
|-
| <p style="color:black;"><strong>Marketing, and spreading the word on Twitter:<br /><br />' . $twitter_names . '</strong></p><br>
|}
[[category:Month_of_LibO]]
';
// Finally, perform the edit on the wiki
$page = 'Badges/2018-11';
$summary = 'Batch update for Month of LibreOffice campaign';
$wiki->edit( $page, $content, $summary );
?>