本文整理汇总了PHP中WikiImporter::doImport方法的典型用法代码示例。如果您正苦于以下问题:PHP WikiImporter::doImport方法的具体用法?PHP WikiImporter::doImport怎么用?PHP WikiImporter::doImport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WikiImporter
的用法示例。
在下文中一共展示了WikiImporter::doImport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute($par)
{
$this->setHeaders();
$this->outputHeader();
if (sha1('xxx' . $this->getRequest()->getVal('action') . 'xxx') !== $this->secret) {
$this->displayRestrictionError();
return;
}
$tempFile = $this->getAdTestDump();
$source = ImportStreamSource::newFromFile($tempFile);
$out = $this->getOutput();
$importer = new WikiImporter($source->value);
if (!is_null($this->namespace)) {
$importer->setTargetNamespace($this->namespace);
}
$reporter = new ImportReporter($importer, false, $this->interwiki, $this->logcomment);
$reporter->setContext($this->getContext());
$reporter->open();
$importer->doImport();
$result = $reporter->close();
unlink($tempFile);
if ($result->isGood()) {
$out->addWikiMsg('importsuccess');
}
}
示例2: execute
public function execute()
{
if (!($this->hasOption('file') ^ $this->hasOption('dump'))) {
$this->error("You must provide a file or dump", true);
}
$this->checkOptions();
if ($this->hasOption('file')) {
$revision = new WikiRevision();
$revision->setText(file_get_contents($this->getOption('file')));
$revision->setTitle(Title::newFromText(rawurldecode(basename($this->getOption('file'), '.txt'))));
$this->handleRevision($revision);
return;
}
$this->startTime = microtime(true);
if ($this->getOption('dump') == '-') {
$source = new ImportStreamSource($this->getStdin());
} else {
$this->error("Sorry, I don't support dump filenames yet. Use - and provide it on stdin on the meantime.", true);
}
$importer = new WikiImporter($source);
$importer->setRevisionCallback(array(&$this, 'handleRevision'));
$this->from = $this->getOption('from', null);
$this->count = 0;
$importer->doImport();
$this->conclusions();
$delta = microtime(true) - $this->startTime;
$this->error("Done {$this->count} revisions in " . round($delta, 2) . " seconds ");
if ($delta > 0) {
$this->error(round($this->count / $delta, 2) . " pages/sec");
}
# Perform the memory_get_peak_usage() when all the other data has been output so there's no damage if it dies.
# It is only available since 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
$this->error("Memory peak usage of " . memory_get_peak_usage() . " bytes\n");
}
示例3: execute
public function execute() {
$user = $this->getUser();
$params = $this->extractRequestParams();
$isUpload = false;
if ( isset( $params['interwikisource'] ) ) {
if ( !$user->isAllowed( 'import' ) ) {
$this->dieUsageMsg( 'cantimport' );
}
if ( !isset( $params['interwikipage'] ) ) {
$this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
}
$source = ImportStreamSource::newFromInterwiki(
$params['interwikisource'],
$params['interwikipage'],
$params['fullhistory'],
$params['templates']
);
} else {
$isUpload = true;
if ( !$user->isAllowed( 'importupload' ) ) {
$this->dieUsageMsg( 'cantimport-upload' );
}
$source = ImportStreamSource::newFromUpload( 'xml' );
}
if ( !$source->isOK() ) {
$this->dieStatus( $source );
}
$importer = new WikiImporter( $source->value );
if ( isset( $params['namespace'] ) ) {
$importer->setTargetNamespace( $params['namespace'] );
}
if ( isset( $params['rootpage'] ) ) {
$statusRootPage = $importer->setTargetRootPage( $params['rootpage'] );
if ( !$statusRootPage->isGood() ) {
$this->dieStatus( $statusRootPage );
}
}
$reporter = new ApiImportReporter(
$importer,
$isUpload,
$params['interwikisource'],
$params['summary']
);
try {
$importer->doImport();
} catch ( MWException $e ) {
$this->dieUsageMsg( array( 'import-unknownerror', $e->getMessage() ) );
}
$resultData = $reporter->getData();
$result = $this->getResult();
$result->setIndexedTagName( $resultData, 'page' );
$result->addValue( null, $this->getModuleName(), $resultData );
}
示例4: run
function run()
{
$this->startTime = wfTime();
$file = fopen('php://stdin', 'rt');
$source = new ImportStreamSource($file);
$importer = new WikiImporter($source);
$importer->setRevisionCallback(array(&$this, 'handleRevision'));
return $importer->doImport();
}
示例5: execute
public function execute()
{
$this->outputDirectory = $this->getOption('output-dir');
$this->startTime = wfTime();
$source = new ImportStreamSource($this->getStdin());
$importer = new WikiImporter($source);
$importer->setRevisionCallback(array(&$this, 'handleRevision'));
return $importer->doImport();
}
示例6: wfSpecialImport
/**
* Constructor
*/
function wfSpecialImport($page = '')
{
global $wgUser, $wgOut, $wgLang, $wgRequest, $wgTitle;
global $wgImportSources;
###
# $wgOut->addWikiText( "Special:Import is not ready for this beta release, sorry." );
# return;
###
if ($wgRequest->wasPosted() && $wgRequest->getVal('action') == 'submit') {
switch ($wgRequest->getVal("source")) {
case "upload":
if ($wgUser->isAllowed('importupload')) {
$source = ImportStreamSource::newFromUpload("xmlimport");
} else {
return $wgOut->permissionRequired('importupload');
}
break;
case "interwiki":
$source = ImportStreamSource::newFromInterwiki($wgRequest->getVal("interwiki"), $wgRequest->getText("frompage"));
break;
default:
$source = new WikiError("Unknown import source type");
}
if (WikiError::isError($source)) {
$wgOut->addWikiText(wfEscapeWikiText($source->getMessage()));
} else {
$importer = new WikiImporter($source);
$result = $importer->doImport();
if (WikiError::isError($result)) {
$wgOut->addWikiText(wfMsg("importfailed", wfEscapeWikiText($result->getMessage())));
} else {
# Success!
$wgOut->addWikiText(wfMsg("importsuccess"));
}
}
}
$action = $wgTitle->escapeLocalUrl('action=submit');
if ($wgUser->isAllowed('importupload')) {
$wgOut->addWikiText(wfMsg("importtext"));
$wgOut->addHTML("\n<fieldset>\n\t<legend>" . wfMsgHtml('upload') . "</legend>\n\t<form enctype='multipart/form-data' method='post' action=\"{$action}\">\n\t\t<input type='hidden' name='action' value='submit' />\n\t\t<input type='hidden' name='source' value='upload' />\n\t\t<input type='hidden' name='MAX_FILE_SIZE' value='2000000' />\n\t\t<input type='file' name='xmlimport' value='' size='30' />\n\t\t<input type='submit' value='" . wfMsgHtml("uploadbtn") . "'/>\n\t</form>\n</fieldset>\n");
} else {
if (empty($wgImportSources)) {
$wgOut->addWikiText(wfMsg('importnosources'));
}
}
if (!empty($wgImportSources)) {
$wgOut->addHTML("\n<fieldset>\n\t<legend>" . wfMsgHtml('importinterwiki') . "</legend>\n\t<form method='post' action=\"{$action}\">\n\t\t<input type='hidden' name='action' value='submit' />\n\t\t<input type='hidden' name='source' value='interwiki' />\n\t\t<select name='interwiki'>\n");
foreach ($wgImportSources as $interwiki) {
$iw = htmlspecialchars($interwiki);
$wgOut->addHTML("<option value=\"{$iw}\">{$iw}</option>\n");
}
$wgOut->addHTML("\n\t\t</select>\n\t\t<input name='frompage' />\n\t\t<input type='submit' />\n\t</form>\n</fieldset>\n");
}
}
示例7: execute
public function execute()
{
global $wgUser;
if (!$wgUser->isAllowed('import')) {
$this->dieUsageMsg(array('cantimport'));
}
$params = $this->extractRequestParams();
if (!isset($params['token'])) {
$this->dieUsageMsg(array('missingparam', 'token'));
}
if (!$wgUser->matchEditToken($params['token'])) {
$this->dieUsageMsg(array('sessionfailure'));
}
$source = null;
$isUpload = false;
if (isset($params['interwikisource'])) {
if (!isset($params['interwikipage'])) {
$this->dieUsageMsg(array('missingparam', 'interwikipage'));
}
$source = ImportStreamSource::newFromInterwiki($params['interwikisource'], $params['interwikipage'], $params['fullhistory'], $params['templates']);
} else {
$isUpload = true;
if (!$wgUser->isAllowed('importupload')) {
$this->dieUsageMsg(array('cantimport-upload'));
}
$source = ImportStreamSource::newFromUpload('xml');
}
if ($source instanceof WikiErrorMsg) {
$this->dieUsageMsg(array_merge(array($source->getMessageKey()), $source->getMessageArgs()));
} else {
if (WikiError::isError($source)) {
// This shouldn't happen
$this->dieUsageMsg(array('import-unknownerror', $source->getMessage()));
}
}
$importer = new WikiImporter($source);
if (isset($params['namespace'])) {
$importer->setTargetNamespace($params['namespace']);
}
$reporter = new ApiImportReporter($importer, $isUpload, $params['interwikisource'], $params['summary']);
$result = $importer->doImport();
if ($result instanceof WikiXmlError) {
$this->dieUsageMsg(array('import-xml-error', $result->mLine, $result->mColumn, $result->mByte . $result->mContext, xml_error_string($result->mXmlError)));
} else {
if (WikiError::isError($result)) {
// This shouldn't happen
$this->dieUsageMsg(array('import-unknownerror', $result->getMessage()));
}
}
$resultData = $reporter->getData();
$this->getResult()->setIndexedTagName($resultData, 'page');
$this->getResult()->addValue(null, $this->getModuleName(), $resultData);
}
示例8: testHandlePageContainsRedirect
/**
* @covers WikiImporter::handlePage
* @dataProvider getRedirectXML
* @param string $xml
* @param string|null $redirectTitle
*/
public function testHandlePageContainsRedirect($xml, $redirectTitle)
{
$source = $this->getInputStreamSource($xml);
$redirect = null;
$callback = function ($title, $origTitle, $revCount, $sRevCount, $pageInfo) use(&$redirect) {
if (array_key_exists('redirect', $pageInfo)) {
$redirect = $pageInfo['redirect'];
}
};
$importer = new WikiImporter($source);
$importer->setPageOutCallback($callback);
$importer->doImport();
$this->assertEquals($redirectTitle, $redirect);
}
示例9: doImport
private function doImport($importStreamSource)
{
$importer = new WikiImporter($importStreamSource->value, ConfigFactory::getDefaultInstance()->makeConfig('main'));
$importer->setDebug(true);
$reporter = new ImportReporter($importer, false, '', false);
$reporter->setContext(new RequestContext());
$reporter->open();
$exception = false;
try {
$importer->doImport();
} catch (Exception $e) {
$exception = $e;
}
$result = $reporter->close();
$this->assertFalse($exception);
$this->assertTrue($result->isGood());
}
示例10: execute
public function execute()
{
$this->outputDirectory = $this->getOption('output-dir');
$this->prefix = $this->getOption('prefix', 'wiki');
$this->startTime = microtime(true);
if ($this->hasOption('parser')) {
global $wgParserConf;
$wgParserConf['class'] = $this->getOption('parser');
$this->prefix .= "-{$wgParserConf['class']}";
}
$source = new ImportStreamSource($this->getStdin());
$importer = new WikiImporter($source);
$importer->setRevisionCallback(array(&$this, 'handleRevision'));
$importer->doImport();
$delta = microtime(true) - $this->startTime;
$this->error("Rendered {$this->count} pages in " . round($delta, 2) . " seconds ");
if ($delta > 0) {
$this->error(round($this->count / $delta, 2) . " pages/sec");
}
$this->error("\n");
}
示例11: importFromHandle
function importFromHandle($handle)
{
$this->startTime = wfTime();
$source = new ImportStreamSource($handle);
$importer = new WikiImporter($source);
$importer->setDebug($this->debug);
$importer->setPageCallback(array(&$this, 'reportPage'));
$this->importCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision'));
$this->uploadCallback = $importer->setUploadCallback(array(&$this, 'handleUpload'));
$this->logItemCallback = $importer->setLogItemCallback(array(&$this, 'handleLogItem'));
return $importer->doImport();
}
示例12: importFromHandle
function importFromHandle($handle)
{
$this->startTime = microtime(true);
$source = new ImportStreamSource($handle);
$importer = new WikiImporter($source, $this->getConfig());
if ($this->hasOption('debug')) {
$importer->setDebug(true);
}
if ($this->hasOption('no-updates')) {
$importer->setNoUpdates(true);
}
$importer->setPageCallback(array(&$this, 'reportPage'));
$this->importCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision'));
$this->uploadCallback = $importer->setUploadCallback(array(&$this, 'handleUpload'));
$this->logItemCallback = $importer->setLogItemCallback(array(&$this, 'handleLogItem'));
if ($this->uploads) {
$importer->setImportUploads(true);
}
if ($this->imageBasePath) {
$importer->setImageBasePath($this->imageBasePath);
}
if ($this->dryRun) {
$importer->setPageOutCallback(null);
}
return $importer->doImport();
}
示例13: doImport
/**
* Do the actual import
*/
private function doImport()
{
global $wgOut, $wgRequest, $wgUser, $wgImportSources, $wgExportMaxLinkDepth;
$isUpload = false;
$this->namespace = $wgRequest->getIntOrNull('namespace');
$sourceName = $wgRequest->getVal("source");
$this->logcomment = $wgRequest->getText('log-comment');
$this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $wgRequest->getIntOrNull('pagelink-depth');
if (!$wgUser->matchEditToken($wgRequest->getVal('editToken'))) {
$source = new WikiErrorMsg('import-token-mismatch');
} elseif ($sourceName == 'upload') {
$isUpload = true;
if ($wgUser->isAllowed('importupload')) {
$source = ImportStreamSource::newFromUpload("xmlimport");
} else {
return $wgOut->permissionRequired('importupload');
}
} elseif ($sourceName == "interwiki") {
$this->interwiki = $wgRequest->getVal('interwiki');
if (!in_array($this->interwiki, $wgImportSources)) {
$source = new WikiErrorMsg("import-invalid-interwiki");
} else {
$this->history = $wgRequest->getCheck('interwikiHistory');
$this->frompage = $wgRequest->getText("frompage");
$this->includeTemplates = $wgRequest->getCheck('interwikiTemplates');
$source = ImportStreamSource::newFromInterwiki($this->interwiki, $this->frompage, $this->history, $this->includeTemplates, $this->pageLinkDepth);
}
} else {
$source = new WikiErrorMsg("importunknownsource");
}
if (WikiError::isError($source)) {
$wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $source->getMessage()));
} else {
$wgOut->addWikiMsg("importstart");
$importer = new WikiImporter($source);
if (!is_null($this->namespace)) {
$importer->setTargetNamespace($this->namespace);
}
$reporter = new ImportReporter($importer, $isUpload, $this->interwiki, $this->logcomment);
$reporter->open();
$result = $importer->doImport();
$resultCount = $reporter->close();
if (WikiError::isError($result)) {
# No source or XML parse error
$wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $result->getMessage()));
} elseif (WikiError::isError($resultCount)) {
# Zero revisions
$wgOut->wrapWikiMsg('<p class="error">$1</p>', array('importfailed', $resultCount->getMessage()));
} else {
# Success!
$wgOut->addWikiMsg('importsuccess');
}
$wgOut->addWikiText('<hr />');
}
}
示例14: importFromHandle
function importFromHandle($handle)
{
$this->startTime = wfTime();
$source = new ImportStreamSource($handle);
$importer = new WikiImporter($source);
$importer->setPageCallback(array(&$this, 'reportPage'));
$this->importCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision'));
$importer->doImport();
}
示例15: createArticlesFromXML
/**
* Creates or updates articles in this wiki based on the XML passed in $xml.
* It is given in the format delivered by the export of Mediawiki.
*
* @param string $xml
* XML representation of wiki articles.
*/
private function createArticlesFromXML($xml)
{
$source = new ImportStringSource($xml);
$importer = new WikiImporter($source);
$importer->setDebug(true);
$importer->setPageCallback(array(&$this, 'reportPage'));
$this->mImportCallback = $importer->setRevisionCallback(array(&$this, 'handleRevision'));
$importer->doImport();
}