Skip to content

Instantly share code, notes, and snippets.

@VDK
Last active September 24, 2015 22:17
Show Gist options
  • Save VDK/6959f9c1c1cc1f5b0186 to your computer and use it in GitHub Desktop.
Save VDK/6959f9c1c1cc1f5b0186 to your computer and use it in GitHub Desktop.
Generates a Macros file for the iMacros browser extention that when processed by said extension creates redirects on the Dutch language Wikipedia
<html>
<head><title>Redirects builder</title>
<meta charset="UTF-8">
<script type="text/javascript">
function myFunction(){
document.getElementById('row0').focus();
document.getElementById('row0').click();
}
</script>
<body onLoad="myFunction()">
<?php
$wrong_titles = array ('buitengebied', 'zie ook', 'externe links');
$page = $_GET['page'];
$string = file_get_contents ('https://nl.wikipedia.org/w/api.php?action=parse&prop=sections&format=json&page='.urlencode('Lijst van gemeentelijke monumenten in '.$page));
$vars = json_decode($string, true);
$myfile = fopen( "redirects.iim", "w") or die("Unable to open file!");
$places = array();
$text = 'VERSION BUILD=8920312 RECORDER=FX
SET !TIMEOUT 200
SET !EXTRACT_TEST_POPUP NO
FILTER TYPE=IMAGES STATUS=ON
TAB OPEN
TAB T=2';
if (isset($vars['parse'])){
foreach ($vars['parse']['sections'] as $section) {
if(!in_array(strtolower($section['line']), $wrong_titles)){
$test = json_decode(file_get_contents('https://nl.wikipedia.org/w/api.php?action=query&format=json&titles='.urlencode('Lijst van gemeentelijke monumenten in '.$section['line'])), true);
if (isset($test['query']['pages']['-1'])){
array_push($places, $section['line']);
$text .='
URL GOTO=https://nl.wikipedia.org/w/index.php?title=Lijst_van_gemeentelijke_monumenten_in_'.urlencode($section['line']).'&action=edit
TAG POS=1 TYPE=TEXTAREA FORM=ID:editform ATTR=ID:wpTextbox1 CONTENT=#REDIRECT[[Lijst<SP>van<SP>gemeentelijke<SP>monumenten<SP>in<SP>'.str_replace(" ", "<sp>", $page.'#'.$section['line']).']]
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:editform ATTR=ID:wpSave
WAIT seconds=2';
}
else{
echo "<a href='http://nl.wikipedia.org/wiki/Lijst_van_gemeentelijke_monumenten_in_".urlencode(str_replace(" ", "_", $section['line']))."' target='_blank'>
Lijst van gemeentelijke monumenten in ".$section['line']."</a> bestaat al.<br/>";
}
}
}
$text .="\nTAB CLOSE\nTAB T=1";
fwrite($myfile, $text);
fclose($myfile);
}
else{
echo "Error";
}
$text = "";
echo "<ul>";
foreach ($places as $key => $value) {
echo "<li><input type='text' value='* [[Lijst van gemeentelijke monumenten in ".$value."]]' onClick='this.setSelectionRange(0, this.value.length)' style='width:500px' id='row".$key."' /></li>";
$vars = json_decode(file_get_contents ("https://nl.wikipedia.org/w/api.php?action=parse&format=json&page=Lijst%20van%20rijksmonumenten%20in%20".urlencode($value)."&redirects=false&prop="), true);
if (isset($vars['parse']) && count($vars['parse']['redirects']) == 0 ){ //it isn't a redirect
$text.= "start chrome https://nl.wikipedia.org/w/index.php?title=Lijst_van_rijksmonumenten_in_".urlencode(str_replace(" ", "_", $value))."^&action=edit^&section=1\n";
}
$text.= "start chrome http://nl.wikipedia.org/wiki/".urlencode(str_replace(" ", "_", $value))."#Zie_ook\n";
}
$myfile = fopen( "open_tabs.bat", "w") or die("Unable to open file!");
fwrite($myfile, $text);
fclose($myfile);
?>
<li><a href="./redirects.iim" id="download" download>Download iim</a></li>
<li><a href="./open_tabs.bat" id="download2" download>Download batch</a></li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment