* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
/**
<tr>
<td></td>
<td>
- Transfer pages into namespace: " .
+ " . wfMsgHtml( 'import-interwiki-namespace' ) . " " .
HTMLnamespaceselector( $namespace, '' ) . "
</td>
</tr>
$wgOut->addHtml( "<ul>\n" );
}
- function reportPage( $title, $origTitle, $revisionCount ) {
+ function reportPage( $title, $origTitle, $revisionCount, $successCount ) {
global $wgOut, $wgUser, $wgLang, $wgContLang;
$skin = $wgUser->getSkin();
$this->mPageCount++;
- $localCount = $wgLang->formatNum( $revisionCount );
- $contentCount = $wgContLang->formatNum( $revisionCount );
+ $localCount = $wgLang->formatNum( $successCount );
+ $contentCount = $wgContLang->formatNum( $successCount );
$wgOut->addHtml( "<li>" . $skin->makeKnownLinkObj( $title ) .
" " .
- wfMsgHtml( 'import-revision-count', $localCount ) .
+ wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
"</li>\n" );
- $log = new LogPage( 'import' );
- if( $this->mIsUpload ) {
- $detail = wfMsgForContent( 'import-logentry-upload-detail',
- $contentCount );
- $log->addEntry( 'upload', $title, $detail );
- } else {
- $interwiki = '[[:' . $this->mInterwiki . ':' .
- $origTitle->getPrefixedText() . ']]';
- $detail = wfMsgForContent( 'import-logentry-interwiki-detail',
- $contentCount, $interwiki );
- $log->addEntry( 'interwiki', $title, $detail );
+ if( $successCount > 0 ) {
+ $log = new LogPage( 'import' );
+ if( $this->mIsUpload ) {
+ $detail = wfMsgForContent( 'import-logentry-upload-detail',
+ $contentCount );
+ $log->addEntry( 'upload', $title, $detail );
+ } else {
+ $interwiki = '[[:' . $this->mInterwiki . ':' .
+ $origTitle->getPrefixedText() . ']]';
+ $detail = wfMsgForContent( 'import-logentry-interwiki-detail',
+ $contentCount, $interwiki );
+ $log->addEntry( 'interwiki', $title, $detail );
+ }
+
+ $comment = $detail; // quick
+ $dbw = wfGetDB( DB_MASTER );
+ $nullRevision = Revision::newNullRevision(
+ $dbw, $title->getArticleId(), $comment, true );
+ $nullRevision->insertOn( $dbw );
}
-
- $comment = $detail; // quick
- $dbw = wfGetDB( DB_MASTER );
- $nullRevision = Revision::newNullRevision(
- $dbw, $title->getArticleId(), $comment, true );
- $nullRevId = $nullRevision->insertOn( $dbw );
}
function close() {
/**
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
class WikiRevision {
var $title = null;
if( is_object( $title ) ) {
$this->title = $title;
} elseif( is_null( $title ) ) {
- throw new MWException( "WikiRevision given a null title in import." );
+ throw new MWException( "WikiRevision given a null title in import. You may need to adjust \$wgLegalTitleChars." );
} else {
throw new MWException( "WikiRevision given non-object title in import." );
}
}
function importOldRevision() {
- $fname = "WikiImporter::importOldRevision";
- $dbw =& wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER );
# Sneak a single revision into place
$user = User::newFromName( $this->getUser() );
$created = true;
} else {
$created = false;
- }
- # FIXME: Check for exact conflicts
+ $prior = Revision::loadFromTimestamp( $dbw, $this->title, $this->timestamp );
+ if( !is_null( $prior ) ) {
+ // FIXME: this could fail slightly for multiple matches :P
+ wfDebug( __METHOD__ . ": skipping existing revision for [[" .
+ $this->title->getPrefixedText() . "]], timestamp " .
+ $this->timestamp . "\n" );
+ return false;
+ }
+ }
+
# FIXME: Use original rev_id optionally
# FIXME: blah blah blah
if( $created ) {
wfDebug( __METHOD__ . ": running onArticleCreate\n" );
Article::onArticleCreate( $this->title );
- } else {
- if( $changed ) {
- wfDebug( __METHOD__ . ": running onArticleEdit\n" );
- Article::onArticleEdit( $this->title );
- }
- }
- if( $created || $changed ) {
+
+ wfDebug( __METHOD__ . ": running create updates\n" );
+ $article->createUpdates( $revision );
+
+ } elseif( $changed ) {
+ wfDebug( __METHOD__ . ": running onArticleEdit\n" );
+ Article::onArticleEdit( $this->title );
+
wfDebug( __METHOD__ . ": running edit updates\n" );
$article->editUpdates(
$this->getText(),
/**
*
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
*/
class WikiImporter {
var $mSource = null;
* @private
*/
function importRevision( &$revision ) {
- $dbw =& wfGetDB( DB_MASTER );
- $dbw->deadlockLoop( array( &$revision, 'importOldRevision' ) );
+ $dbw = wfGetDB( DB_MASTER );
+ return $dbw->deadlockLoop( array( &$revision, 'importOldRevision' ) );
}
/**
* @param Title $title
* @param Title $origTitle
* @param int $revisionCount
+ * @param int $successCount number of revisions for which callback returned true
* @private
*/
- function pageOutCallback( $title, $origTitle, $revisionCount ) {
+ function pageOutCallback( $title, $origTitle, $revisionCount, $successCount ) {
if( is_callable( $this->mPageOutCallback ) ) {
call_user_func( $this->mPageOutCallback, $title, $origTitle,
- $revisionCount );
+ $revisionCount, $successCount );
}
}
xml_set_element_handler( $parser, "in_siteinfo", "out_siteinfo" );
} elseif( $name == 'page' ) {
$this->workRevisionCount = 0;
+ $this->workSuccessCount = 0;
xml_set_element_handler( $parser, "in_page", "out_page" );
} else {
return $this->throwXMLerror( "Expected <page>, got <$name>" );
xml_set_element_handler( $parser, "in_mediawiki", "out_mediawiki" );
$this->pageOutCallback( $this->pageTitle, $this->origTitle,
- $this->workRevisionCount );
+ $this->workRevisionCount, $this->workSuccessCount );
$this->workTitle = null;
$this->workRevision = null;
$this->workRevisionCount = 0;
+ $this->workSuccessCount = 0;
$this->pageTitle = null;
$this->origTitle = null;
}
}
xml_set_element_handler( $parser, "in_page", "out_page" );
- $out = call_user_func_array( $this->mRevisionCallback,
+ $ok = call_user_func_array( $this->mRevisionCallback,
array( &$this->workRevision, &$this ) );
- if( !empty( $out ) ) {
- global $wgOut;
- $wgOut->addHTML( "<li>" . $out . "</li>\n" );
+ if( $ok ) {
+ $this->workSuccessCount++;
}
}
}
-/** @package MediaWiki */
class ImportStringSource {
function ImportStringSource( $string ) {
$this->mString = $string;
}
}
-/** @package MediaWiki */
class ImportStreamSource {
function ImportStreamSource( $handle ) {
$this->mHandle = $handle;
return fread( $this->mHandle, 32768 );
}
- function newFromFile( $filename ) {
+ static function newFromFile( $filename ) {
$file = @fopen( $filename, 'rt' );
if( !$file ) {
return new WikiErrorMsg( "importcantopen" );
return new ImportStreamSource( $file );
}
- function newFromUpload( $fieldname = "xmlimport" ) {
+ static function newFromUpload( $fieldname = "xmlimport" ) {
$upload =& $_FILES[$fieldname];
if( !isset( $upload ) || !$upload['name'] ) {
return $ret;
}
- function newFromInterwiki( $interwiki, $page, $history=false ) {
- $base = Title::getInterwikiLink( $interwiki );
+ public static function newFromInterwiki( $interwiki, $page, $history=false ) {
$link = Title::newFromText( "$interwiki:Special:Export/$page" );
- if( empty( $base ) || empty( $link ) ) {
+ if( is_null( $link ) || $link->getInterwiki() == '' ) {
return new WikiErrorMsg( 'importbadinterwiki' );
} else {
$params = $history ? 'history=1' : '';