-
Notifications
You must be signed in to change notification settings - Fork 1
/
wikiImporter.php
90 lines (67 loc) · 2.25 KB
/
wikiImporter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @author Nischay Nahata <nischayn22@gmail.com>
* @license GPL v2 or later
*/
error_reporting( E_STRICT );
//UNCOMMENT THIS TO SHOW ALL PHP ERRORS
error_reporting ( E_ALL );
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
include( 'settings.php' );
$settings['cookiefile'] = "cookies.tmp";
use Nischayn22\MediaWikiApi;
include( 'helperfunctions.php' );
// $content = file_get_contents( 'http://localhost/github/wikiImporter/input.txt');
// file_put_contents("output.txt", translateWikiText($content));
// dieq();
$publicApi = new MediaWikiApi($settings['publicWiki']);
echo "Logging in to public wiki\n";
$publicApi->logout();
$publicApi->login($settings['publicWikiUser'], $settings['publicWikiPassword']);
if( $settings['delete'] ) {
echo "Starting to delete pages one by one in public wiki... \n";
//get pagenames that shouldn't be deleted
$doNotDeletePages = file( $settings['doNotDeletePages'], FILE_IGNORE_NEW_LINES );
for( $i=0; $i<15; $i++ ) {
// Skip files or not
if( $i == 6 && !$settings['deleteFiles'] ) {
continue;
}
$result = $publicApi->listPageInNamespace($i);
foreach( $result as $page ) {
if( !in_array( (string)$page['title'], $doNotDeletePages ) ) {
echo "Deleting page ". (string)$page['title'] . "\n";
$publicApi->deleteById((string)$page['pageid']);
} else {
echo "Skipping page ". (string)$page['title'] . "\n";
}
}
}
//all deletion done now :)
} else {
echo "Not deleting images in the public wiki... \n";
}
//copy pages
$privateApi = new MediaWikiApi($settings['privateWiki']);
echo "Logging into private wiki now\n";
$privateApi->logout();
$privateApi->login($settings['privateWikiUser'], $settings['privateWikiPassword']);
echo "Starting to import pages, categories and files...\n";
if( count( $settings['copyNS'] ) > 0 ) {
$pages = array();
foreach( $settings['copyNS'] as $namespaceId ) {
$result = $privateApi->listPageInNamespace( $namespaceId );
foreach( $result as $page ) {
$pages[] = (string)$page['title'];
}
}
} else {
$pages = file($settings['copyPages'], FILE_IGNORE_NEW_LINES);
}
foreach($pages as $pageName) {
copypage( $pageName, false );
}
$publicApi->logout();
$privateApi->logout();
echo "All done.\n";