* 2005-03-14
*
* @todo document
- * @package MediaWiki
- * @subpackage Maintenance
+ * @file
+ * @ingroup Maintenance
*/
if( php_sapi_name() != 'cli' ) {
- die( "Please customize the settings and run me from the command line." );
+ echo "Please customize the settings and run me from the command line.";
+ die( -1 );
}
/** Set these correctly! */
$FS3 = $FS."3" ;
# Unicode sanitization tools
-require_once( '../includes/normal/UtfNormal.php' );
+require_once( dirname( dirname( __FILE__ ) ) . '/includes/normal/UtfNormal.php' );
$usercache = array();
function importPages()
{
global $wgRootDirectory;
-
+
$gt = '>';
- echo <<<END
+ echo <<<XML
<?xml version="1.0" encoding="UTF-8" ?$gt
<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.1/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xml:lang="en">
<!-- generated by importUseModWiki.php -->
-END;
+XML;
$letters = array(
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
if( is_dir( $dir ) )
importPageDirectory( $dir );
}
- echo <<<END
+ echo <<<XML
</mediawiki>
-END;
+XML;
}
function importPageDirectory( $dir, $prefix = "" )
echo "\n<!-- Checking page directory " . xmlCommentSafe( $dir ) . " -->\n";
$mydir = opendir( $dir );
while( $entry = readdir( $mydir ) ) {
+ $m = array();
if( preg_match( '/^(.+)\.db$/', $entry, $m ) ) {
echo importPage( $prefix . $m[1] );
} else {
function fetchPage( $title )
{
- global $FS,$FS1,$FS2,$FS3, $wgRootDirectory;
-
+ global $FS1,$FS2,$FS3, $wgRootDirectory;
+
$fname = $wgRootDirectory . "/page/" . useModFilename( $title ) . ".db";
if( !file_exists( $fname ) ) {
- die( "Couldn't open file '$fname' for page '$title'.\n" );
+ echo "Couldn't open file '$fname' for page '$title'.\n";
+ die( -1 );
}
-
+
$page = splitHash( $FS1, file_get_contents( $fname ) );
$section = splitHash( $FS2, $page["text_default"] );
$text = splitHash( $FS3, $section["data"] );
-
+
return array2object( array( "text" => $text["text"] , "summary" => $text["summary"] ,
"minor" => $text["minor"] , "ts" => $section["ts"] ,
"username" => $section["username"] , "host" => $section["host"] ) );
function fetchKeptPages( $title )
{
- global $FS,$FS1,$FS2,$FS3, $wgRootDirectory, $wgTimezoneCorrection;
-
+ global $FS1,$FS2,$FS3, $wgRootDirectory;
+
$fname = $wgRootDirectory . "/keep/" . useModFilename( $title ) . ".kp";
if( !file_exists( $fname ) ) return array();
-
+
$keptlist = explode( $FS1, file_get_contents( $fname ) );
array_shift( $keptlist ); # Drop the junk at beginning of file
-
+
$revisions = array();
foreach( $keptlist as $rev ) {
$section = splitHash( $FS2, $rev );
function importPage( $title )
{
global $usercache;
-
+
echo "\n<!-- Importing page " . xmlCommentSafe( $title ) . " -->\n";
$page = fetchPage( $title );
$newtitle = xmlsafe( str_replace( '_', ' ', recodeText( $title ) ) );
-
+
$munged = mungeFormat( $page->text );
if( $munged != $page->text ) {
/**
*/
$revisions = array( $page );
}
- $xml = <<<END
+ $xml = <<<XML
<page>
<title>$newtitle</title>
-END;
+XML;
# History
$revisions = array_merge( $revisions, fetchKeptPages( $title ) );
if(count( $revisions ) == 0 ) {
- return $sql;
+ return NULL; // Was "$sql", which does not appear to be defined.
}
-
+
foreach( $revisions as $rev ) {
$text = xmlsafe( recodeText( $rev->text ) );
$minor = ($rev->minor ? '<minor/>' : '');
- list( $userid, $username ) = checkUserCache( $rev->username, $rev->host );
+ list( /* $userid */ , $username ) = checkUserCache( $rev->username, $rev->host );
$username = xmlsafe( recodeText( $username ) );
$timestamp = xmlsafe( timestamp2ISO8601( $rev->ts ) );
$comment = xmlsafe( recodeText( $rev->summary ) );
-
- $xml .= <<<END
+
+ $xml .= <<<XML
<revision>
<timestamp>$timestamp</timestamp>
<contributor><username>$username</username></contributor>
<text>$text</text>
</revision>
-END;
+XML;
}
$xml .= "</page>\n\n";
return $xml;
* XML output invalid, so be sure to strip them out.
*/
$string = UtfNormal::cleanUp( $string );
-
+
$string = htmlspecialchars( $string );
return $string;
}
$staged = preg_replace_callback(
'/(<nowiki>.*?<\\/nowiki>|(?:http|https|ftp):\\S+|\[\[[^]\\n]+]])/s',
'nowikiPlaceholder', $text );
-
+
# This is probably not 100% correct, I'm just
# glancing at the UseModWiki code.
$upper = "[A-Z]";
$camel = "(?:$upper+$lower+$upper+$any*)";
$subpage = "(?:\\/$any+)";
$substart = "(?:\\/$upper$any*)";
-
+
$munged = preg_replace( "/(?!\\[\\[)($camel$subpage*|$substart$subpage*)\\b(?!\\]\\]|>)/",
'[[$1]]', $staged );
-
+
$final = preg_replace( '/' . preg_quote( placeholder() ) . '/es',
'array_shift( $nowiki )', $munged );
return $final;
return placeholder();
}
-?>
+