Skip to content

Commit 8671b15

Browse files
committed
added copy_images option
1 parent 5c13d00 commit 8671b15

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

helperfunctions.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ function copypage( $pageName, $recursivelyCalled = true ) {
1212
$parts = explode( ':', $pageName );
1313
$content = $privateApi->readPage($pageName);
1414

15-
if ( empty($content) ) {
16-
// write to file that reading failed
17-
echo "Page read error...Check if page exists and is accessible \n";
18-
echo "logging page name in failed_pages.txt\n";
19-
file_put_contents( 'failed_pages.txt' , $pageName . "\n", FILE_APPEND );
20-
return;
21-
}
15+
if ( empty($content) ) {
16+
// write to file that reading failed
17+
echo "Page read error...Check if page exists and is accessible \n";
18+
echo "logging page name in failed_pages.txt\n";
19+
file_put_contents( 'failed_pages.txt' , $pageName . "\n", FILE_APPEND );
20+
return;
21+
}
2222

2323
if( count( $parts ) === 2 && $parts[0] === 'File') { // files are handled here
2424
$rawFileUrl = $privateApi->getFileUrl($pageName);
@@ -43,28 +43,32 @@ function copypage( $pageName, $recursivelyCalled = true ) {
4343
}
4444

4545
// now copy normal page
46-
if ($settings['create'])
47-
{
46+
if ($settings['create']) {
4847
$data = $publicApi->createPage($pageName, $content);
4948
} else {
5049
$data = $publicApi->editPage($pageName, $content);
5150
}
51+
5252
if ( $data == null ) {
5353
// write to file that copy failed
5454
echo "logging page name in failed_pages.txt\n";
5555
file_put_contents( 'failed_pages.txt' , $pageName . "\n", FILE_APPEND );
5656
}
5757

58-
// Now import images linked on the page
59-
echo "Finding file links in $pageName ...\n";
60-
$result = $privateApi->listImagesOnPage($pageName);
61-
if( $result ) {
62-
foreach( $result as $image ) {
63-
echo "Link found to " . (string)$image['title'] . " \n";
64-
copypage( (string)$image['title'] );
58+
if ($settings['copy_images']) {
59+
// Now import images linked on the page
60+
echo "Finding file links in $pageName ...\n";
61+
$result = $privateApi->listImagesOnPage($pageName);
62+
if( $result ) {
63+
foreach( $result as $image ) {
64+
echo "Link found to " . (string)$image['title'] . " \n";
65+
copypage( (string)$image['title'] );
66+
}
67+
} else {
68+
echo "No file links found\n";
6569
}
6670
} else {
67-
echo "No file links found\n";
71+
echo "Skipping files\n";
6872
}
6973

7074
// Now copy category members too

settings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@
4040

4141
// Whether to only create new pages, otherwise we will edit pages and override stuff
4242
$settings['create'] = false;
43+
44+
// Whether to copy over images found in wikitext
45+
$settings['copy_images'] = true;

wikiImporter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
$publicApi->logout();
2121
$publicApi->login($settings['publicWikiUser'], $settings['publicWikiPassword']);
2222

23-
echo "Starting to delete pages one by one in public wiki... \n";
23+
2424

2525
if( $settings['delete'] ) {
26+
27+
echo "Starting to delete pages one by one in public wiki... \n";
28+
2629
//get pagenames that shouldn't be deleted
2730
$doNotDeletePages = file( $settings['doNotDeletePages'], FILE_IGNORE_NEW_LINES );
2831

@@ -46,7 +49,7 @@
4649

4750
//all deletion done now :)
4851
} else {
49-
echo "Not deleting anything because the settings says so\n";
52+
echo "Not deleting images in the public wiki... \n";
5053
}
5154

5255
//copy pages

0 commit comments

Comments
 (0)