Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Wiki video uploading bot. Development by AleksandrT.
<?php
require_once './mediawikibot.class.php';
require_once '(db connection)';
define('WIKI_DOMAIN', 'https://commons.wikimedia.org');
define('WIKI_WIKI', '/w');
define('WIKI_USERNAME', 'SpreadthesignBot');
define('WIKI_PASSWORD', '');
define('WIKI_COOKIES', '/tmp/wikibot_cookies.tmp');
define('WIKI_USERAGENT', 'SpreadthesignBot/0.1 (http://www.spreadthesign.com/; info@spreadthesign.com)');
$basePath = '/videos';
$bot = new MediaWikiBot();
// Wiki login
if (($res = $bot->login()) !== NULL) {
die('Login failed. ' . print_r($res, 1));
}
// Get edit token from wiki
$response = $bot->query(array(
'prop' => 'info',
'titles' => 'Foo',
'intoken' => 'edit',
));
$editToken = isset($response['query']['pages'][-1]['edittoken'])
? $response['query']['pages'][-1]['edittoken'] : NULL;
// Get video data
//English for categories and wordclass
$CLASS = Dictionary::getAllClasses(1);
$CATEGORY = Category::getAllCategories(MASTER_CID);
$r = mysql_query("SELECT v.ID, d.cID, d.Word, DATE( v.Timestamp ) AS Created, dm.Class, c.SLC,
dm.Category, dm.Definition AS Description, st.Translation AS WordLanguage,
(SELECT st.Translation FROM SiteTranslation st, SiteTranslationMagnet stm WHERE
stm.Reference = CONCAT( c.CC, '_LANG' ) AND mID = stm.ID AND cID = 1) AS CategoryLangiage
FROM Video v
INNER JOIN DictionaryVideo dv ON ( dv.vID = v.ID )
INNER JOIN Dictionary d ON ( d.ID = dv.dID )
INNER JOIN DictionaryMagnet dm ON ( dm.ID = d.mID )
INNER JOIN Country c ON ( c.ID = d.cID AND c.Enabled = 1)
INNER JOIN SiteTranslationMagnet stm ON ( stm.Reference = CONCAT( c.CC, '_LANG' ) )
INNER JOIN SiteTranslation st ON ( st.mID = stm.ID AND st.cID = d.cID )
WHERE v.uID =1
AND v.WikiCommons IS NULL
AND v.ID >99
LIMIT 0,10");
while ($row = mysql_fetch_assoc($r)) {
$vid = $row['ID'];
$cid = $row['cID'];
$word = $row['Word'];
$desc = $row['Description'];
$date = $row['Created'];
$class = $row['Class'];
$category = $row['Category'];
$language = $row['WordLanguage'];
$categoryLanguage = $row['CategoryLangiage'];
$slc = $row['SLC'];
if (isset($CLASS[$class])) {
$desc .= " ({$CLASS[$class]})";
}
$text = <<<"EOT"
=={{int:filedesc}}==
{{Information
|description={{$categoryLanguage|1=$desc}}
|date=$date
|source={{STS-link|$vid}}
|author={{Spread the sign}}
|permission={{STS-cooperation}}
|other_versions=
|other_fields=
}}
[[category:$categoryLanguage sign language]]
[[category:Videos of sign language in $categoryLanguage]]
EOT;
// Add category:wordclass (English)
if (isset($CLASS[$class])) {
$text .= "\n[[Category:{$CLASS[$class]}]]\n"
}
// Upload to wiki
$response = $bot->upload(array(
'filename' => "$slc-$word-spreadthesign-$vid.ogv",
'file' => "@{$basePath}/ogv/$cid/$vid.ogv",
'text' => $text,
'token' => $editToken,
));
// Check response status
if (!isset($response['upload']['result']) || $response['upload']['result'] != 'Success') {
die("Failed to upload video ID: $vid\n" . print_r($response, 1));
}
// Persist wiki filename
$safe = Utils::safe($response['upload']['filename']);
mysql_query("UPDATE Video SET WikiCommons = '$safe' WHERE ID = $vid LIMIT 1");
$url = $response['upload']['imageinfo']['descriptionurl'];
$name = $response['upload']['filename'];
echo "<a href=\"$url\">$name</a>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.