Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
require('Init.php');
$wiki = Peachy::newWiki( 'rb-enwiki' );
$config = $wiki->get_configuration();
if( !file_exists($config['svg-logos']) ) {
pecho("Getting the logos...\n");
$logos = $wiki->categorymembers( 'Category:All non-free logos', array( 6 ) );
pecho("\tDone!\n");
pecho("\tSaving...\n");
file_put_contents( $config['svg-logos'], serialize($logos) );
}
else {
$logos = unserialize( file_get_contents($config['svg-logos']) );
}
if( !file_exists($config['svg-vectors']) ) {
pecho("Getting the vectors...\n");
$vectors = $wiki->categorymembers( 'Category:Vector images of trademarks', array( 6 ) );
pecho("Done!\n");
pecho("Saving...\n");
file_put_contents( $config['svg-vectors'], serialize($vectors) );
}
else {
$vectors = unserialize( file_get_contents($config['svg-vectors']) );
}
if( !file_exists($config['svg-logosvg']) ) {
pecho("\nNow processing images (Looking for SVGs)...\n");
$svg_logo = array();
foreach( array_values($logos) as $logo )
{
$bits = explode('.', $logo);
if( strtolower($bits[(count($bits) - 1)]) == 'svg' && !in_array( $logo, $vectors ) ) {
$svg_logo[] = $logo;
}
}
pecho("Done!\n");
pecho("Saving...\n");
file_put_contents( $config['svg-logosvg'], serialize($svg_logo) );
}
else {
$svg_logo = unserialize( file_get_contents($config['svg-logosvg']) );
}
// No longer needed
unset($logos, $vectors);
$non_free_logo_regex_page = new Page( $wiki, 'User:FinalRapture/NonFreeLogoRegex' );
preg_match( '/<pre>(.*?)<\/pre>/', $non_free_logo_regex_page->get_text(), $nflr_match );
$non_free_logo_regex = $nflr_match[1];
unset($non_free_logo_regex_page, $nflr_match);
pecho("\nProcessing images...\n");
foreach( $svg_logo as $image_name )
{
// Just double check...
$bits = explode('.', $image_name);
if( strtolower($bits[(count($bits) - 1)]) != 'svg' ) continue;
pecho("Processing $image_name\n");
$image = new Page( $wiki, $image_name );
$image_text = $otext = $image->get_text();
if( preg_match( $non_free_logo_regex, $image_text, $logo_match )
&& !preg_match( '/\{\{(SVG[ -]?Logo|SVG-Trademark)/i', $image_text ) ) {
pecho("\tAdding {{SVG-Logo}}\n");
$image_text = str_replace( $logo_match[0], $logo_match[0] . "\n{{SVG-Logo}}", $image_text );
if( $image_text != $otext ) {
pecho("\tSaving...: ");
//$image->edit($image_text, 'Adding {{[[Template:SVG-Logo|SVG-Logo]]}} ([[WP:BOT|BOT]])', true);
pecho("\n");
continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment