function execute($query)
 {
     global $wgUser, $wgOut, $wgRequest;
     $this->setHeaders();
     if (!$wgUser->isAllowed('datatransferimport')) {
         global $wgOut;
         $wgOut->permissionRequired('datatransferimport');
         return;
     }
     if ($wgRequest->getCheck('import_file')) {
         $text = DTUtils::printImportingMessage();
         $uploadResult = ImportStreamSource::newFromUpload("file_name");
         // handling changed in MW 1.17
         if ($uploadResult instanceof Status) {
             $source = $uploadResult->value;
         } else {
             $source = $uploadResult;
         }
         $importSummary = $wgRequest->getVal('import_summary');
         $forPagesThatExist = $wgRequest->getVal('pagesThatExist');
         $text .= self::modifyPages($source, $importSummary, $forPagesThatExist);
     } else {
         $formText = DTUtils::printFileSelector('XML');
         $formText .= DTUtils::printExistingPagesHandling();
         $formText .= DTUtils::printImportSummaryInput('XML');
         $formText .= DTUtils::printSubmitButton();
         $text = "\t" . Xml::tags('form', array('enctype' => 'multipart/form-data', 'action' => '', 'method' => 'post'), $formText) . "\n";
     }
     $wgOut->addHTML($text);
 }
Esempio n. 2
0
 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('XML');
         $formText .= DTUtils::printExistingPagesHandling();
         $formText .= DTUtils::printImportSummaryInput('XML');
         $formText .= DTUtils::printSubmitButton();
         $text = "\t" . Xml::tags('form', array('enctype' => 'multipart/form-data', 'action' => '', 'method' => 'post'), $formText) . "\n";
     }
     $this->getOutput()->addHTML($text);
 }
 function execute($query)
 {
     global $wgUser, $wgOut, $wgRequest;
     $this->setHeaders();
     if (!$wgUser->isAllowed('datatransferimport')) {
         global $wgOut;
         $wgOut->permissionRequired('datatransferimport');
         return;
     }
     if ($wgRequest->getCheck('import_file')) {
         $text = DTUtils::printImportingMessage();
         $uploadResult = ImportStreamSource::newFromUpload("file_name");
         // handling changed in MW 1.17
         $uploadError = null;
         if ($uploadResult instanceof Status) {
             if ($uploadResult->isOK()) {
                 $source = $uploadResult->value;
             } else {
                 $uploadError = $wgOut->parse($uploadResult->getWikiText());
             }
         } elseif ($uploadResult instanceof WikiErrorMsg) {
             $uploadError = $uploadResult->getMessage();
         } else {
             $source = $uploadResult;
         }
         if (!is_null($uploadError)) {
             $text .= $uploadError;
             $wgOut->addHTML($text);
             return;
         }
         $encoding = $wgRequest->getVal('encoding');
         $pages = array();
         $error_msg = self::getCSVData($source->mHandle, $encoding, $pages);
         if (!is_null($error_msg)) {
             $text .= $error_msg;
             $wgOut->addHTML($text);
             return;
         }
         $importSummary = $wgRequest->getVal('import_summary');
         $forPagesThatExist = $wgRequest->getVal('pagesThatExist');
         $text .= self::modifyPages($pages, $importSummary, $forPagesThatExist);
     } else {
         $formText = DTUtils::printFileSelector('CSV');
         $utf8OptionText = "\t" . Xml::element('option', array('selected' => 'selected', 'value' => 'utf8'), 'UTF-8') . "\n";
         $utf16OptionText = "\t" . Xml::element('option', array('value' => 'utf16'), 'UTF-16') . "\n";
         $encodingSelectText = Xml::tags('select', array('name' => 'encoding'), "\n" . $utf8OptionText . $utf16OptionText . "\t") . "\n\t";
         $formText .= "\t" . Xml::tags('p', null, wfMsg('dt_import_encodingtype', 'CSV') . " " . $encodingSelectText) . "\n";
         $formText .= "\t" . '<hr style="margin: 10px 0 10px 0" />' . "\n";
         $formText .= DTUtils::printExistingPagesHandling();
         $formText .= DTUtils::printImportSummaryInput('CSV');
         $formText .= DTUtils::printSubmitButton();
         $text = "\t" . Xml::tags('form', array('enctype' => 'multipart/form-data', 'action' => '', 'method' => 'post'), $formText) . "\n";
     }
     $wgOut->addHTML($text);
 }