|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Background job to import a page into the wiki, adapted from Data Transfer |
|
5
|
|
|
* |
|
6
|
|
|
* @author Yaron Koren |
|
7
|
|
|
* @author Toni Hermoso |
|
8
|
|
|
*/ |
|
9
|
|
|
class SDImportJob extends Job { |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
function __construct( $title, $params = '', $id = 0 ) { |
|
|
|
|
|
|
12
|
|
|
parent::__construct( 'dtImport', $title, $params, $id ); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Run a dtImport job |
|
17
|
|
|
* @return boolean success |
|
18
|
|
|
*/ |
|
19
|
|
|
function run() { |
|
|
|
|
|
|
20
|
|
|
wfProfileIn( __METHOD__ ); |
|
21
|
|
|
|
|
22
|
|
|
if ( is_null( $this->title ) ) { |
|
23
|
|
|
$this->error = "dtImport: Invalid title"; |
|
24
|
|
|
wfProfileOut( __METHOD__ ); |
|
25
|
|
|
return false; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if ( method_exists( 'WikiPage', 'getContent' ) ) { |
|
29
|
|
|
$wikiPage = new WikiPage( $this->title ); |
|
30
|
|
|
if ( !$wikiPage ) { |
|
31
|
|
|
$this->error = 'dtImport: Wiki page not found "' . $this->title->getPrefixedDBkey() . '"'; |
|
32
|
|
|
wfProfileOut( __METHOD__ ); |
|
33
|
|
|
return false; |
|
34
|
|
|
} |
|
35
|
|
|
} else { |
|
36
|
|
|
// Remove old support |
|
37
|
|
|
return false; |
|
38
|
|
|
} |
|
39
|
|
|
$for_pages_that_exist = $this->params['for_pages_that_exist']; |
|
40
|
|
|
if ( $for_pages_that_exist == 'skip' && $this->title->exists() ) { |
|
41
|
|
|
return true; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// Change global $wgUser variable to the one specified by |
|
45
|
|
|
// the job only for the extent of this import. |
|
46
|
|
|
global $wgUser; |
|
|
|
|
|
|
47
|
|
|
$actual_user = $wgUser; |
|
48
|
|
|
$wgUser = User::newFromId( $this->params['user_id'] ); |
|
49
|
|
|
$text = $this->params['text']; |
|
50
|
|
|
$edit_summary = $this->params['edit_summary']; |
|
51
|
|
|
|
|
52
|
|
|
// Act according to storage here |
|
53
|
|
|
if ( $this->params['storage'] == "json" ) { |
|
54
|
|
|
// TODO: to evaluate if check destination page here or before |
|
55
|
|
|
|
|
56
|
|
|
// Handle JSON new content |
|
57
|
|
|
$contentModel = $wikipage->getContentModel(); |
|
|
|
|
|
|
58
|
|
|
if ( $contentModel === "json" || ! $wikipage->exists() ) { |
|
|
|
|
|
|
59
|
|
|
$new_content = new JSONContent( $text ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} else { |
|
63
|
|
|
|
|
64
|
|
|
if ( $this->title->exists() ) { |
|
65
|
|
|
if ( $for_pages_that_exist == 'append' ) { |
|
66
|
|
|
// MW >= 1.21 |
|
67
|
|
|
$existingText = $wikiPage->getContent()->getNativeData(); |
|
68
|
|
|
$text = $existingText . "\n" . $text; |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$new_content = new WikitextContent( $text ); |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$wikiPage->doEditContent( $new_content, $edit_summary ); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
$wgUser = $actual_user; |
|
80
|
|
|
wfProfileOut( __METHOD__ ); |
|
81
|
|
|
return true; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.