<?php
// I'm a DEMO bot. You don't have to use this file unless you want to.
// Runs recently changed summaries through some filters.
// Just run me once each day or so--less often on less busy sites.
// define these BEFORE including BasicBot.php if you want to override the settings in BasicBot.php:
// define('USERID','2');
// define('USERNAME','RCBot');
// define('PASSWORD','RCBotPassword');
require_once('basic_bot_intl.php');
require_once('basic_bot.php');
require_once('Snoopy.class.php');
require_once('/home/gospeltr/public_html/w/languages/Names.php');
global $wgLanguageNames;
$phpFile = '/home/gospeltr/public_html/w/extensions/dabble/cache/db.php';
$TITLES;
// print form if no data was submitted
if(!isset($_GET['whattodo'])) {
print <<<EOT
<h2>What language should we process?</h2>
<form action="trans_bot.php" method="GET" name="bot">
<input type="text" name="lang" value="language">
<input type="text" name="lc" size="2" value="LC">
<input type="text" name="page" value="page to scrape">
<input type="text" name="whattodo" value="(blank)/run/print/titles">
<input type="submit" value="submit">
</form>
EOT;
exit;
}
if($_GET['whattodo'] === 'print') {
// get the library of translations loaded up
$ldb = unserialize(file_get_contents($phpFile));
$LANGS = $ldb['l'];
$TERMS = $ldb['g'];
$db = $ldb['t'];
$RL = $_GET['lang'];
$allTranslations;
// go grab the list of articles and titles
$fetcher = new BasicBotIntl();
$fetcher->wikiFilter($_GET['page'],'ScrapePage',$summary='');
print_r($allTranslations);
exit;
}
if($_GET['whattodo'] === 'titles') {
// get the library of translations loaded up
$TITLES = unserialize(file_get_contents('/home/gospeltr/public_html/w/extensions/dabble/cache/titles.php'));
$RL = $_GET['lang'];
$botpage = "Category:" . $RL;
// go grab the list of articles and titles
$gatherTitles = new BasicBot();
$gatherTitles->SpecialFilterAll($botpage,'GatherTitles',$summary='');
exit;
}
// get the library of translations loaded up
$ldb = unserialize(file_get_contents($phpFile));
$LANGS = $ldb['l'];
$TERMS = $ldb['g'];
$db = $ldb['t'];
$RL = $_GET['lang'];
$allTranslations;
// go grab the list of articles and titles
$fetcher = new BasicBotIntl();
$fetcher->wikiFilter($_GET['page'],'ScrapePage',$summary='');
$myl = array_keys($allTranslations);
$flip = array_flip($allTranslations);
$copyBot = new BasicBotIntl();
$copyBot->ArrayFilterAll($myl,'PostCode',$summary='Automated: Added transclusion reference and categories to article source',$allTranslations);
function PostCode( $content, $params ){
global $wgLanguageNames;
global $db;
global $TERMS;
global $RL;
$resLang = $RL;
global $passv;
$res = $params[$passv];
/////////////////////
// break the language code off the title
$titleParts = explode('/', $res);
$lastPart = end($titleParts);
// test for any 2-3 letter sequence ending the title after a /
if(isset($wgLanguageNames[$lastPart])) {
$old_res = $res;
$res = str_ireplace('/'.$lastPart, '', $res);
}
else {
print "Error: $res is not a foreign resource";
exit;
}
// Decide whether this belongs to a book or a series
if ($db[$resLang][$res]['Media Type'] == 'Chapter' || $db[$resLang][$res]['Media Type'] == 'Book')
$stext = 'Book';
else
$stext = 'Series';
$flip = array_flip($params);
if ($db[$resLang][$res]['Media Type'] == 'Book'){
$book = $db[$resLang][$res]['Book/series'];
$toc = "===".$TERMS['Table of Contents'][$resLang] . "=== \n";
$chaps = count($db['TOC'][$book]);
for ($i=1; $i<=$chaps; $i++) {
$chapter = $db['TOC'][$book][$i];
//$chapter = str_ireplace($book.'/', '', $chapter);
$chapter = $chapter . '/' . $lastPart;
$tch = $flip[$chapter];
$tch = str_replace('_', ' ', $tch);
$short_tch = explode('/', $tch);
$toc = $toc . "[[$tch|{$short_tch[1]}]] \n\n";
}
// print $allTranslations;
// print "\n\n";
// print $toc;
// exit;
return <<<TOC
<div id="tran-mh">
<div style="float:right">
<table style="border: 1px solid rgb(148, 148, 148); margin: 0 0pt 10px 10px; padding: 3px 4px 5px 4px; background-color: rgb(233, 242, 254); color: rgb(51, 51, 51); font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; line-height: 13px; width: 200px;" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" style="padding: 10px 0; text-align:center"><font style="font-size: 12px; font-weight: bold;">{$TERMS['About This'][$resLang]} {$TERMS[$db[$resLang][$res]['Media Type']][$resLang]}</font></td>
</tr>
<tr>
<td valign="top" width="85"><strong>{$TERMS['Publisher'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Publisher']}|{$db[$resLang][$res]['Publisher']}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Author'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Author']}|{$db[$resLang][$res]['Author']}]] $satext</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS[$stext][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Book/series']}|{$db[$resLang][$res]['Book/series']}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Topic'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$TERMS[$db[$resLang][$res]['Topic']][$resLang]}|{$TERMS[$db[$resLang][$res]['Topic']][$resLang]}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Subtopic'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$TERMS[$db[$resLang][$res]['Subtopic']][$resLang]}|{$TERMS[$db[$resLang][$res]['Subtopic']][$resLang]}]]</td>
</tr>
<tr>
<td valign="top" style="padding-bottom: 4px;"><strong>{$TERMS['Date'][$resLang]}:</strong></td>
<td valign="top" style="padding-bottom: 4px;">[[:Category:{$db[$resLang][$res]['Date']}|{$db[$resLang][$res]['Date']}]]</td>
</tr>
<tr>
<td valign="top" style="border-top: 1px solid #999; padding-top: 4px; margin-top: 4px;"><strong>{$TERMS['Status'][$resLang]}:</strong></td>
<td valign="top" style="border-top: 1px solid #999; padding-top: 4px; margin-top: 4px;">[[:Category:{$db[$resLang][$res]['Review Status']}|{$db[$resLang][$res]['Review Status']}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Translator'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Translator']}|{$db[$resLang][$res]['Translator']}]]</td>
</tr>
<tr>
<td style="padding-bottom: 4px;"><strong>{$TERMS['Reviewer'][$resLang]}:</strong></td>
<td style="padding-bottom: 4px;">[[:Category:{$db[$resLang][$res]['Reviewer']}|{$db[$resLang][$res]['Reviewer']}]]</td>
</tr>
</table>
</div>
[[Category:{$db[$resLang][$res]['Review Status']}]]
[[Category:{$TERMS[$db[$resLang][$res]['Media Type']][$resLang]}]]
[[Category:{$TERMS[$db[$resLang][$res]['Topic']][$resLang]}]]
[[Category:{$TERMS[$db[$resLang][$res]['Subtopic']][$resLang]}]]
[[Category:{$db[$resLang][$res]['Author']}]]
[[Category:{$db[$resLang][$res]['Publisher']}]]
[[Category:{$db[$resLang][$res]['Book/series']}]]<!--
###### Needs Review template
{{ #ifeq: {{#language:{{#titleparts:{{PAGENAME}}|{{{levels}}}|{{#expr: {{{levels}}} +1 }}}}}} | English | |{{ #ifeq: {{{reviewed}}} | Final Version | | {{ #ifeq: {{{reviewed}}} | Peer Reviewed | {{PeerReviewed}} | {{NeedsReview}}}}}}}}
--></div>
$toc
TOC;
}
else {
return <<<TRB
<div id="tran-mh">
<div style="float:right">
<table style="border: 1px solid rgb(148, 148, 148); margin: 0 0pt 10px 10px; padding: 3px 4px 5px 4px; background-color: rgb(233, 242, 254); color: rgb(51, 51, 51); font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; line-height: 13px; width: 200px;" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" style="padding: 10px 0; text-align:center"><font style="font-size: 12px; font-weight: bold;">{$TERMS['About This'][$resLang]} {$TERMS[$db[$resLang][$res]['Media Type']][$resLang]}</font></td>
</tr>
<tr>
<td valign="top" width="85"><strong>{$TERMS['Publisher'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Publisher']}|{$db[$resLang][$res]['Publisher']}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Author'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Author']}|{$db[$resLang][$res]['Author']}]] $satext</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS[$stext][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Book/series']}|{$db[$resLang][$res]['Book/series']}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Topic'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$TERMS[$db[$resLang][$res]['Topic']][$resLang]}|{$TERMS[$db[$resLang][$res]['Topic']][$resLang]}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Subtopic'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$TERMS[$db[$resLang][$res]['Subtopic']][$resLang]}|{$TERMS[$db[$resLang][$res]['Subtopic']][$resLang]}]]</td>
</tr>
<tr>
<td valign="top" style="padding-bottom: 4px;"><strong>{$TERMS['Date'][$resLang]}:</strong></td>
<td valign="top" style="padding-bottom: 4px;">[[:Category:{$db[$resLang][$res]['Date']}|{$db[$resLang][$res]['Date']}]]</td>
</tr>
<tr>
<td valign="top" style="border-top: 1px solid #999; padding-top: 4px; margin-top: 4px;"><strong>{$TERMS['Status'][$resLang]}:</strong></td>
<td valign="top" style="border-top: 1px solid #999; padding-top: 4px; margin-top: 4px;">[[:Category:{$db[$resLang][$res]['Review Status']}|{$db[$resLang][$res]['Review Status']}]]</td>
</tr>
<tr>
<td valign="top"><strong>{$TERMS['Translator'][$resLang]}:</strong></td>
<td valign="top">[[:Category:{$db[$resLang][$res]['Translator']}|{$db[$resLang][$res]['Translator']}]]</td>
</tr>
<tr>
<td style="padding-bottom: 4px;"><strong>{$TERMS['Reviewer'][$resLang]}:</strong></td>
<td style="padding-bottom: 4px;">[[:Category:{$db[$resLang][$res]['Reviewer']}|{$db[$resLang][$res]['Reviewer']}]]</td>
</tr>
</table>
</div>
[[Category:{$db[$resLang][$res]['Review Status']}]]
[[Category:{$TERMS[$db[$resLang][$res]['Media Type']][$resLang]}]]
[[Category:{$TERMS[$db[$resLang][$res]['Topic']][$resLang]}]]
[[Category:{$TERMS[$db[$resLang][$res]['Subtopic']][$resLang]}]]
[[Category:{$db[$resLang][$res]['Author']}]]
[[Category:{$db[$resLang][$res]['Publisher']}]]
[[Category:{$db[$resLang][$res]['Book/series']}]]<!--
###### Needs Review template
{{ #ifeq: {{#language:{{#titleparts:{{PAGENAME}}|{{{levels}}}|{{#expr: {{{levels}}} +1 }}}}}} | English | |{{ #ifeq: {{{reviewed}}} | Final Version | | {{ #ifeq: {{{reviewed}}} | Peer Reviewed | {{PeerReviewed}} | {{NeedsReview}}}}}}}}
--></div>
{{:gt_en:{$params[$passv]}}}
TRB;
}
}
function ScrapePage($content){
global $allTranslations;
global $wgLanguageNames;
global $db;
global $RL;
$data_lines = explode(']]]', $content);
array_pop($data_lines);
foreach ($data_lines as $tvalue){
// $data_line is english_title:::trans_title
$translation = explode(':::', $tvalue);
// load up $allTranslations[foreign] = english
$foreign = str_ireplace(" ","_", $translation[1]);
$titleParts = explode('/', $translation[0]);
$lastPart = end($titleParts);
$res = str_ireplace('/'.$lastPart, '', $translation[0]);
// set aside the resource temporarily if it is a book part
$short_res = $titleParts[0]."/".$titleParts[1];
if(isset($db[$RL][$short_res]['Media Type'])){
if ($db[$RL][$short_res]['Media Type'] == 'Chapter') {
$temp_array[$translation[0]] = $foreign;
}
}
// ........otherwise just load it up
else
$allTranslations[$foreign] = $translation[0];
}
// $flip will be $..[eng] => foreign
$flip = array_flip($allTranslations);
foreach ($temp_array as $eng=>$for){
$temp_res_array = explode('/', $eng);
$temp_book = $temp_res_array[0].'/'.$temp_res_array[2];
$for_book = $flip[$temp_book];
$for_full_title = $for_book.'/'.$for;
$allTranslations[$for_full_title] = $eng;
}
//print_r($temp_array);
return $content;
}
function GatherTitles ( $content ) {
global $TITLES;
global $passv;
$final; // holds the article title (translated)
preg_match('/{{info(.)*(}){2,}/i', $content, $match);
$final = str_replace('{{info|', '', $match[0]);
$final = str_replace('}', '', $final);
$TITLES[$passv] = $final;
// save the stuff
$fp = fopen('/home/gospeltr/public_html/w/extensions/dabble/cache/titles.php', 'w+') or die("I could not open the file.");
fwrite($fp, serialize($TITLES));
fclose($fp) or die("I could save the file.");
return $content;
}
echo "Done --" . $passv;
?>