MediaWiki r3119 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r3118‎ | r3119 (on ViewVC)‎ | r3120 >
Date:07:06, 11 April 2004
Author:vibber
Status:old
Tags:
Comment:
Fiddled with Import some more. Preliminary ability to grab a given
page from an external wiki (wildly imcomplete).
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/SpecialImport.php
===================================================================
--- trunk/phase3/includes/SpecialImport.php	(revision 3118)
+++ trunk/phase3/includes/SpecialImport.php	(revision 3119)
@@ -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 @@
 	$wgOut->addWikiText( "<p>" . wfMsg( "importtext" ) . "</p>" );
 	$action = $wgTitle->escapeLocalUrl();
 	$wgOut->addHTML( "
-<form enctype='multipart/form-data' method='post' action=\"$action\">
-	<input type='hidden' name='action' value='submit' />
-	<input type='hidden' name='MAX_FILE_SIZE' value='200000' />
-	<input type='file' name='xmlimport' value='' size='40' /><br />
-	<input type='submit' value='" . htmlspecialchars( wfMsg( "uploadbtn" ) ) . "'/>
-</form>
+<fieldset>
+	<legend>Upload XML</legend>
+	<form enctype='multipart/form-data' method='post' action=\"$action\">
+		<input type='hidden' name='action' value='submit' />
+		<input type='hidden' name='source' value='upload' />
+		<input type='hidden' name='MAX_FILE_SIZE' value='200000' />
+		<input type='file' name='xmlimport' value='' size='30' />
+		<input type='submit' value='" . htmlspecialchars( wfMsg( "uploadbtn" ) ) . "'/>
+	</form>
+</fieldset>
 " );
+
+	if( !empty( $wgImportSources ) ) {
+		$wgOut->addHTML( "
+<fieldset>
+	<legend>Interwiki import</legend>
+	<form method='post' action=\"$action\">
+		<input type='hidden' name='action' value='submit' />
+		<input type='hidden' name='source' value='interwiki' />
+		<select name='interwiki'>
+" );
+		foreach( $wgImportSources as $interwiki ) {
+			$iw = htmlspecialchars( $interwiki );
+			$wgOut->addHTML( "<option value=\"$iw\">$iw</option>\n" );
+		}
+		$wgOut->addHTML( "
+		</select>
+		<input name='frompage' />
+		<input type='submit' />
+	</form>
+</fieldset>
+" );
+	}
 }
 
-function wfImportOldRevision( $revision ) {
+function wfImportOldRevision( &$revision ) {
 	global $wgOut;
 	$fname = "wfImportOldRevision";
 	
@@ -69,14 +110,11 @@
 	
 	# 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 ) . "<br />\n" );
-	
 	$res = wfQuery( $sql, DB_WRITE, $fname );
 	$numrows = wfNumRows( $res );
 	wfFreeResult( $res );
 	if( $numrows > 0 ) {
-		$wgOut->addHTML( "DIE<br />" );
-		return false;
+		return wfMsg( "importhistoryconflict" );
 	}
 	
 	$res = wfQuery( "INSERT INTO old " .
@@ -84,9 +122,8 @@
 	  "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<br />" );
 	
-	return true;
+	return wfMsg( "ok" );
 }
 
 class WikiRevision {
@@ -207,10 +244,27 @@
 	}
 	
 	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 @@
 	
 	function debug( $data ) {
 		global $wgOut;
-		# $wgOut->addHTML( htmlspecialchars( $data ) . "<br />\n" );
+		# $this->notice( "DEBUG: $data\n" );
 	}
 	
+	function notice( $data ) {
+		global $wgCommandLineMode;
+		if( $wgCommandLineMode ) {
+			print "$data\n";
+		} else {
+			global $wgOut;
+			$wgOut->addHTML( "<li>$data</li>\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 @@
 			return $this->throwXMLerror( "Element <$name> not allowed in a <revision>." );
 		}
 	}
+	
 	function out_revision( $parser, $name ) {
 		$this->debug( "out_revision $name" );
 		if( $name != "revision" ) {
@@ -387,7 +452,11 @@
 		}
 		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( "<li>" . $out . "</li>\n" );
+		}
 	}
 	
 	function in_contributor( $parser, $name, $attribs ) {
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 3118)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 3119)
@@ -25,10 +25,10 @@
 
 $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 @@
 $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 @@
 
 
 # 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 @@
 # 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();
+
 ?>

Status & tagging log

  • 01:56, 13 October 2010 ^demon (Talk | contribs) changed the status of r3119 [removed: new added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox