blob: 42f7d14d45bbb7cfb2b44d95ffc46585b1203ecb (
plain)
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
|
<?php
/**
* Lets the user import an XML file to turn into wiki pages
*
* @author Yaron Koren
*/
class DTImportXML extends SpecialPage {
/**
* Constructor
*/
public function __construct( $name = 'ImportXML' ) {
parent::__construct( $name );
}
public function doesWrites() {
return true;
}
function execute( $query ) {
$this->setHeaders();
if ( ! $this->getUser()->isAllowed( 'datatransferimport' ) ) {
throw new PermissionsError( 'datatransferimport' );
}
$request = $this->getRequest();
if ( $request->getCheck( 'import_file' ) ) {
$text = DTUtils::printImportingMessage();
$uploadResult = ImportStreamSource::newFromUpload( "file_name" );
$source = $uploadResult->value;
$importSummary = $request->getVal( 'import_summary' );
$forPagesThatExist = $request->getVal( 'pagesThatExist' );
$text .= self::modifyPages( $source, $importSummary, $forPagesThatExist );
} else {
$formText = DTUtils::printFileSelector( wfMessage( 'dt_filetype_xml' )->text() );
$formText .= DTUtils::printExistingPagesHandling();
$formText .= DTUtils::printImportSummaryInput( wfMessage( 'dt_filetype_xml' )->text() );
$formText .= DTUtils::printSubmitButton();
$text = "\t" . Xml::tags( 'form',
array(
'enctype' => 'multipart/form-data',
'action' => '',
'method' => 'post'
), $formText ) . "\n";
}
$this->getOutput()->addHTML( $text );
}
function modifyPages( $source, $editSummary, $forPagesThatExist ) {
$text = "";
$xml_parser = new DTXMLParser( $source );
$xml_parser->doParse();
$jobs = array();
$job_params = array();
$job_params['user_id'] = $this->getUser()->getId();
$job_params['edit_summary'] = $editSummary;
$job_params['for_pages_that_exist'] = $forPagesThatExist;
foreach ( $xml_parser->mPages as $page ) {
$title = Title::newFromText( $page->getName() );
$job_params['text'] = $page->createText();
$jobs[] = new DTImportJob( $title, $job_params );
}
JobQueueGroup::singleton()->push( $jobs );
$text .= $this->msg( 'dt_import_success' )->numParams( count( $jobs ) )->params( 'XML' )
->parseAsBlock();
return $text;
}
}
|