From: Brion Vibber Date: Sun, 11 Apr 2004 07:06:26 +0000 (+0000) Subject: Fiddled with Import some more. Preliminary ability to grab a given X-Git-Tag: 1.3.0beta1~460 X-Git-Url: http://git.cyclocoop.org/%22.%24match%5B1%5D.%22?a=commitdiff_plain;h=b86963068ae02ec7d2b74668edfd3858efba3623;p=lhc%2Fweb%2Fwiklou.git Fiddled with Import some more. Preliminary ability to grab a given page from an external wiki (wildly imcomplete). --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index b0b9e7e872..cbb26ddb37 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -25,10 +25,10 @@ unset($wgProto); $wgScriptPath = "/wiki"; -# ATTN: Old installations used wiki.phtml and redirect.phtml - # Whether to support URLs like index.php/Page_title $wgUsePathInfo = ( strpos( php_sapi_name(), "cgi" ) === false ); +# ATTN: Old installations used wiki.phtml and redirect.phtml - # make sure that LocalSettings.php is correctly set! $wgScript = "{$wgScriptPath}/index.php"; $wgRedirectScript = "{$wgScriptPath}/redirect.php"; @@ -304,9 +304,8 @@ $wgUseImageResize = false; $wgUseImageMagick = false; $wgImageMagickConvertCommand = "/usr/bin/convert"; -# Enable experimental smarty skins (put Smarty/libs in your include_path!) -$wgUseSmarty = false; -$wgUsePHPTal = false; +# Make sure include_path is set correctly +$wgUsePHPTal = true; if( !isset( $wgCommandLineMode ) ) { $wgCommandLineMode = false; @@ -317,15 +316,14 @@ $wgRCSeconds = false; # RDF metadata toggles - $wgEnableDublinCoreRdf = false; $wgEnableCreativeCommonsRdf = false; # Override for copyright metadata. - $wgRightsPage = NULL; $wgRightsUrl = NULL; $wgRightsText = NULL; +$wgRightsIcon = NULL; # Set this to false to avoid forcing the first letter of links # to capitals. WARNING: may break links! This makes links @@ -334,4 +332,9 @@ $wgRightsText = NULL; # as links in the middle of a sentence using a lowercase initial. $wgCapitalLinks = true; +# List of interwiki prefixes for wikis we'll accept as sources +# for Special:Import (for sysops). Since complete page history +# can be imported, these should be 'trusted'. +$wgImportSources = array(); + ?> diff --git a/includes/SpecialImport.php b/includes/SpecialImport.php index 11e08827ea..a7384250a8 100644 --- a/includes/SpecialImport.php +++ b/includes/SpecialImport.php @@ -19,10 +19,25 @@ function wfSpecialImport( $page = "" ) { global $wgOut, $wgLang, $wgRequest, $wgTitle; + global $wgImportSources; if( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit') { $importer = new WikiImporter(); - if( $importer->setupFromUpload( "xmlimport" ) ) { + + switch( $wgRequest->getVal( "source" ) ) { + case "upload": + $ok = $importer->setupFromUpload( "xmlimport" ); + break; + case "interwiki": + $ok = $importer->setupFromInterwiki( + $wgRequest->getVal( "interwiki" ), + $wgRequest->getText( "frompage" ) ); + break; + default: + $ok = false; + } + + if( $ok ) { $importer->setRevisionHandler( "wfImportOldRevision" ); if( $importer->doImport() ) { # Success! @@ -39,16 +54,42 @@ function wfSpecialImport( $page = "" ) { $wgOut->addWikiText( "

" . wfMsg( "importtext" ) . "

" ); $action = $wgTitle->escapeLocalUrl(); $wgOut->addHTML( " -
- - -
- -
+
+ Upload XML +
+ + + + + +
+
" ); + + if( !empty( $wgImportSources ) ) { + $wgOut->addHTML( " +
+ Interwiki import +
+ + + + + +
+
+" ); + } } -function wfImportOldRevision( $revision ) { +function wfImportOldRevision( &$revision ) { global $wgOut; $fname = "wfImportOldRevision"; @@ -69,14 +110,11 @@ function wfImportOldRevision( $revision ) { # Make sure it doesn't already exist $sql = "SELECT 1 FROM old WHERE old_namespace=$ns AND old_title='$t' AND old_timestamp='$ts'"; - $wgOut->addHtml( htmlspecialchars( $sql ) . "
\n" ); - $res = wfQuery( $sql, DB_WRITE, $fname ); $numrows = wfNumRows( $res ); wfFreeResult( $res ); if( $numrows > 0 ) { - $wgOut->addHTML( "DIE
" ); - return false; + return wfMsg( "importhistoryconflict" ); } $res = wfQuery( "INSERT INTO old " . @@ -84,9 +122,8 @@ function wfImportOldRevision( $revision ) { "old_timestamp,inverse_timestamp,old_minor_edit,old_flags) " . "VALUES ($ns,'$t','$text','$comment',$user_id,'$user_text','$ts','$its',$minor,'$flags')", DB_WRITE, $fname ); - $wgOut->addHTML( "OK
" ); - return true; + return wfMsg( "ok" ); } class WikiRevision { @@ -207,10 +244,27 @@ class WikiImporter { } function setupFromURL( $url ) { - # FIXME - wfDebugDieBacktrace( "Not yet implemented." ); + # fopen-wrappers are normally turned off for security. + ini_set( "allow_url_fopen", true ); + $ret = $this->setupFromFile( $url ); + ini_set( "allow_url_fopen", false ); + return $ret; } + function setupFromInterwiki( $interwiki, $page ) { + $base = Title::getInterwikiLink( $interwiki ); + if( empty( $base ) ) { + return false; + } else { + $import = wfUrlencode( "Special:Export/$page" ); + $url = str_replace( "$1", $import, $base ); + $this->notice( "Importing from $url" ); + return $this->setupFromURL( $url ); + } + } + + # -------------- + function doImport() { if( empty( $this->mSource ) ) { return $this->setError( wfMsg( "importnotext" ) ); @@ -237,14 +291,24 @@ class WikiImporter { function debug( $data ) { global $wgOut; - # $wgOut->addHTML( htmlspecialchars( $data ) . "
\n" ); + # $this->notice( "DEBUG: $data\n" ); + } + + function notice( $data ) { + global $wgCommandLineMode; + if( $wgCommandLineMode ) { + print "$data\n"; + } else { + global $wgOut; + $wgOut->addHTML( "
  • $data
  • \n" ); + } } function setRevisionHandler( $functionref ) { $this->mRevisionHandler = $functionref; } - function defaultRevisionHandler( $revision ) { + function defaultRevisionHandler( &$revision ) { $this->debug( "Got revision:" ); if( is_object( $revision->title ) ) { $this->debug( "-- Title: " . $revision->title->getPrefixedText() ); @@ -380,6 +444,7 @@ class WikiImporter { return $this->throwXMLerror( "Element <$name> not allowed in a ." ); } } + function out_revision( $parser, $name ) { $this->debug( "out_revision $name" ); if( $name != "revision" ) { @@ -387,7 +452,11 @@ class WikiImporter { } xml_set_element_handler( $parser, "in_page", "out_page" ); - call_user_func( $this->mRevisionHandler, $this->workRevision ); + $out = call_user_func( $this->mRevisionHandler, &$this->workRevision, &$this ); + if( !empty( $out ) ) { + global $wgOut; + $wgOut->addHTML( "
  • " . $out . "
  • \n" ); + } } function in_contributor( $parser, $name, $attribs ) {