Kategorien
FreewarWiki:Bot/Skripts/AllPagesBot.php: Unterschied zwischen den Versionen
< FreewarWiki:Bot | Skripts
SniGG (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „ <pre> <?php include('botclasses.php'); $wiki = new wikipedia; $wiki->url = "http://www.fwwiki.de/api.php"; $wiki->setUserAgent( 'User-Agent: FooBot (http…“) |
SniGG (Diskussion | Beiträge) (Title mit Leerzeichen an den Anfang) |
||
Zeile 34: | Zeile 34: | ||
// as an array | // as an array | ||
function iterate ( $wiki, $namespaces, $pageTitles ) { | function iterate ( $wiki, $namespaces, $pageTitles ) { | ||
$wiki_pages = ""; | |||
foreach ( $namespaces as $namespace ) { | foreach ( $namespaces as $namespace ) { | ||
Zeile 40: | Zeile 41: | ||
$apfrom = ''; | $apfrom = ''; | ||
while ( !$done ) { | while ( !$done ) { | ||
$query = "?action=query&format=php&list=allpages&aplimit= | $query = "?action=query&format=php&list=allpages&aplimit=5000&apnamespace=$namespace&rawcontinue"; | ||
if ( $apfrom != "" ) { | if ( $apfrom != "" ) { | ||
$query .= "&apcontinue=$apfrom"; | $query .= "&apcontinue=$apfrom"; | ||
Zeile 51: | Zeile 52: | ||
} | } | ||
foreach ( $ret['query']['allpages'] as $thisPage ) { | foreach ( $ret['query']['allpages'] as $thisPage ) { | ||
$text = "'". addslashes($thisPage['title']) . "', \r\n"; | |||
if(strpos($thisPage['title'], " ") !== false) | |||
$wiki_pages = $text . $wiki_pages; | |||
else | |||
$wiki_pages .= $text; | |||
} | } | ||
} | } | ||
$wiki_pages = '<?php $page_cache = array(' . $wiki_pages; | |||
$wiki_pages .= '); return $page_cache;'; | |||
fwrite ( $pageTitles, $wiki_pages ); | |||
} | } | ||
} | } | ||
fclose ( $pageTitles ); | fclose ( $pageTitles ); | ||
</pre> | </pre> |
Aktuelle Version vom 7. Februar 2016, 20:26 Uhr
<?php include('botclasses.php'); $wiki = new wikipedia; $wiki->url = "http://www.fwwiki.de/api.php"; $wiki->setUserAgent( 'User-Agent: FooBot (http://mediawiki.org/wiki/User:FooBot)' ); /* All the login stuff. */ $user = 'Dein Nutzername'; $pass = 'Dein Passwort'; $wiki->login( $user, $pass ); $namespaces = range( 0, 15 ); // Default namespaces // Extra namespaces #$namespaces[] = 500; $namespaces = array_filter( $namespaces, "notFile" ); // Filter out the File: namespace $pageTitlesFile = 'PageTitles.php'; $pageTitlesNs6File = 'PageTitlesNs6.txt'; $pageTitles = fopen ( $pageTitlesFile, 'w' ); $pageTitlesNs6 = fopen ( $pageTitlesNs6File, 'w' ); iterate ( $wiki, $namespaces, $pageTitles ); // Everything but File: namespace iterate ( $wiki, array ( 6), $pageTitlesNs6 ); // Only the File: namespace // Filter out the File: namespace function notFile ( $var ) { return ( $var != 6 ); } // Retrieve the data and store it in the file // as an array function iterate ( $wiki, $namespaces, $pageTitles ) { $wiki_pages = ""; foreach ( $namespaces as $namespace ) { $done = false; $apfrom = ''; while ( !$done ) { $query = "?action=query&format=php&list=allpages&aplimit=5000&apnamespace=$namespace&rawcontinue"; if ( $apfrom != "" ) { $query .= "&apcontinue=$apfrom"; } $ret = $wiki->query ( $query ); if ( !isset ( $ret['query-continue'] ) ) { $done = true; } else { $apfrom = $ret['query-continue']['allpages']['apcontinue']; } foreach ( $ret['query']['allpages'] as $thisPage ) { $text = "'". addslashes($thisPage['title']) . "', \r\n"; if(strpos($thisPage['title'], " ") !== false) $wiki_pages = $text . $wiki_pages; else $wiki_pages .= $text; } } $wiki_pages = '<?php $page_cache = array(' . $wiki_pages; $wiki_pages .= '); return $page_cache;'; fwrite ( $pageTitles, $wiki_pages ); } } fclose ( $pageTitles );