4 * A script to read a dump of the English Wikipedia from the UseModWiki period, and to
5 * generate an XML dump in MediaWiki format.
7 * Some relevant code was ported from UseModWiki 0.92.
11 require_once( dirname( __FILE__
) . '/Maintenance.php' );
12 require_once( dirname( __FILE__
) .'/../includes/normal/UtfNormalUtil.php' );
15 class ImportUseModWikipedia
extends Maintenance
{
16 var $encodeMap, $decodeMap;
18 var $deepRenames = array(
19 'JimboWales' => 983862286,
21 'HistoryOfUnitedStatesTalk' => 984795423,
22 'MetallicA' => 985128533,
23 'PythagoreanTheorem' => 985225545,
24 'TheCanonofScripture' => 985368223,
25 'TaoTehChing' => 985368222,
26 //'TheMostRemarkableFormulaInTheWorld' => 985368221,
27 'TheRecorder' => 985368220,
28 'GladstoneOregon' => 985368219,
29 'PacificBeach' => '?',
33 var $replacements = array();
35 var $renameTextLinksOps = array(
37 'TestIgnore' => 'IgnoreTest',
40 'UnitedLocomotiveWorks' => 'Atlas Shrugged/United Locomotive Works'
43 'WikiPedia' => 'Wikipedia',
46 'John_F_Kennedy' => 'John_F._Kennedy',
49 'LarrySanger' => 'Larry_Sanger'
52 'UnitedStates' => 'United States',
55 'LibertarianisM' => 'Libertarianism'
58 'AnarchisM' => 'Anarchism',
61 'HistoryOfUnitedStatesDiscussion' => 'History_Of_United_States_Discussion'
64 'BritishEmpire' => 'British Empire'
68 'ScienceFiction' => 'Science fiction',
73 * Hack for observed substitution issues
75 var $skipSelfSubstitution = array(
76 'Pythagorean_Theorem',
77 'The_Most_Remarkable_Formula_In_The_World',
81 var $unixLineEndingsOps = array(
82 987743732 => 'Wikipedia_FAQ'
85 var $replacementsDone = array();
87 var $moveLog = array();
88 var $moveDests = array();
92 var $textCache = array();
93 var $blacklist = array();
95 var $FS, $FS1, $FS2, $FS3;
96 var $FreeLinkPattern, $UrlPattern, $LinkPattern, $InterLinkPattern;
98 var $cp1252Table = array(
132 public function __construct() {
133 parent
::__construct();
134 $this->addOption( 'datadir', 'the value of $DataDir from wiki.cgi', true, true );
135 $this->addOption( 'outfile', 'the name of the output XML file', true, true );
136 $this->initLinkPatterns();
138 $this->encodeMap
= $this->decodeMap
= array();
140 for ($source = 0; $source <= 0xff; $source++
) {
141 if ( isset( $this->cp1252Table
[$source] ) ) {
142 $dest = $this->cp1252Table
[$source];
146 $sourceChar = chr( $source );
147 $destChar = codepointToUtf8( $dest );
148 $this->encodeMap
[$sourceChar] = $destChar;
149 $this->decodeMap
[$destChar] = $sourceChar;
153 function initLinkPatterns() {
154 # Field separators are used in the URL-style patterns below.
155 $this->FS
= "\xb3"; # The FS character is a superscript "3"
156 $this->FS1
= $this->FS
. "1"; # The FS values are used to separate fields
157 $this->FS2
= $this->FS
. "2"; # in stored hashtables and other data structures.
158 $this->FS3
= $this->FS
. "3"; # The FS character is not allowed in user data.
160 $UpperLetter = "[A-Z";
161 $LowerLetter = "[a-z";
162 $AnyLetter = "[A-Za-z";
163 $AnyLetter .= "_0-9";
164 $UpperLetter .= "]"; $LowerLetter .= "]"; $AnyLetter .= "]";
166 # Main link pattern: lowercase between uppercase, then anything
167 $LpA = $UpperLetter . "+" . $LowerLetter . "+" . $UpperLetter
169 # Optional subpage link pattern: uppercase, lowercase, then anything
170 $LpB = $UpperLetter . "+" . $LowerLetter . "+" . $AnyLetter . "*";
172 # Loose pattern: If subpage is used, subpage may be simple name
173 $this->LinkPattern
= "((?:(?:$LpA)?\\/$LpB)|$LpA)";
174 $QDelim = '(?:"")?'; # Optional quote delimiter (not in output)
175 $this->LinkPattern
.= $QDelim;
177 # Inter-site convention: sites must start with uppercase letter
178 # (Uppercase letter avoids confusion with URLs)
179 $InterSitePattern = $UpperLetter . $AnyLetter . "+";
180 $this->InterLinkPattern
= "((?:$InterSitePattern:[^\\]\\s\"<>{$this->FS}]+)$QDelim)";
182 $AnyLetter = "[-,. _0-9A-Za-z]";
183 $this->FreeLinkPattern
= "($AnyLetter+)";
184 $this->FreeLinkPattern
= "((?:(?:$AnyLetter+)?\\/)?$AnyLetter+)";
185 $this->FreeLinkPattern
.= $QDelim;
187 # Url-style links are delimited by one of:
188 # 1. Whitespace (kept in output)
189 # 2. Left or right angle-bracket (< or >) (kept in output)
190 # 3. Right square-bracket (]) (kept in output)
191 # 4. A single double-quote (") (kept in output)
192 # 5. A $FS (field separator) character (kept in output)
193 # 6. A double double-quote ("") (removed from output)
195 $UrlProtocols = "http|https|ftp|afs|news|nntp|mid|cid|mailto|wais|"
196 . "prospero|telnet|gopher";
197 $UrlProtocols .= '|file';
198 $this->UrlPattern
= "((?:(?:$UrlProtocols):[^\\]\\s\"<>{$this->FS}]+)$QDelim)";
199 $ImageExtensions = "(gif|jpg|png|bmp|jpeg)";
200 $RFCPattern = "RFC\\s?(\\d+)";
201 $ISBNPattern = "ISBN:?([0-9- xX]{10,})";
205 $this->articleFileName
= '/tmp/importUseMod.' . mt_rand( 0, 0x7ffffff ) . '.tmp';
206 $this->patchFileName
= '/tmp/importUseMod.' . mt_rand( 0, 0x7ffffff ) . '.tmp';
207 $this->dataDir
= $this->getOption( 'datadir' );
208 $this->outFile
= fopen( $this->getOption( 'outfile' ), 'w' );
209 if ( !$this->outFile
) {
210 echo "Unable to open output file\n";
213 $this->writeXmlHeader();
215 $this->writeMoveLog();
216 $this->writeRevisions();
217 $this->reconcileCurrentRevs();
218 $this->writeXmlFooter();
219 unlink( $this->articleFileName
);
220 unlink( $this->patchFileName
);
224 function writeXmlHeader() {
225 fwrite( $this->outFile
, <<<EOT
226 <mediawiki xmlns="http://www.mediawiki.org/xml/export-0.3/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd" version="0.3" xml:lang="en">
228 <sitename>Wikipedia</sitename>
229 <base>http://www.wikipedia.com/</base>
230 <generator>MediaWiki 1.18alpha importUseModWikipedia.php</generator>
231 <case>case-sensitive</case>
233 <namespace key="0" />
241 function writeXmlFooter() {
242 fwrite( $this->outFile
, "</mediawiki>\n" );
245 function readRclog() {
246 $rcFile = fopen( "{$this->dataDir}/rclog", 'r' );
247 while ( $line = fgets( $rcFile ) ) {
248 $bits = explode( $this->FS3
, $line );
249 if ( count( $bits ) !== 7 ) {
250 echo "Error reading rclog\n";
254 'timestamp' => $bits[0],
255 'rctitle' => $bits[1],
256 'summary' => $bits[2],
262 $extraList = explode( $this->FS2
, $bits[6] );
264 for ( $i = 0; $i < count( $extraList ); $i +
= 2 ) {
265 $params['extra'][$extraList[$i]] = $extraList[$i +
1];
267 $this->rc
[$params['timestamp']][] = $params;
271 function writeMoveLog() {
272 $this->moveLog
= array();
273 $deepRenames = $this->deepRenames
;
274 echo "Calculating move log...\n";
275 $this->processDiffFile( array( $this, 'moveLogCallback' ) );
277 // We have the timestamp intervals, now make a guess at the actual timestamp
278 foreach ( $this->moveLog
as $newTitle => $params ) {
279 // Is there a time specified?
281 if ( isset( $deepRenames[$params['old']] ) ) {
282 $drTime = $deepRenames[$params['old']];
283 if ( $drTime !== '?' ) {
284 if ( ( !isset( $params['endTime'] ) ||
$drTime < $params['endTime'] )
285 && $drTime > $params['startTime'] )
287 $this->moveLog
[$newTitle]['timestamp'] = $drTime;
288 $this->moveLog
[$newTitle]['deep'] = true;
290 echo "{$params['old']} -> $newTitle at $drTime\n";
291 unset( $deepRenames[$params['old']] );
294 echo "WARNING: deep rename time invalid: {$params['old']}\n";
295 unset( $deepRenames[$params['old']] );
300 // Guess that it is one second after the last edit to the page before it was moved
301 $this->moveLog
[$newTitle]['timestamp'] = $params['startTime'] +
1;
302 if ( $drTime === '?' ) {
303 $this->moveLog
[$newTitle]['deep'] = true;
304 unset( $deepRenames[$params['old']] );
306 if ( isset( $params['endTime'] ) ) {
307 $this->printLatin1( "{$params['old']} -> $newTitle between " .
308 "{$params['startTime']} and {$params['endTime']}\n" );
310 $this->printLatin1( "{$params['old']} -> $newTitle after " .
311 "{$params['startTime']}\n" );
315 // Write the move log to the XML file
317 foreach ( $this->moveLog
as $newTitle => $params ) {
318 $out = "<logitem>\n" .
319 $this->element( 'id', $id++
) .
320 $this->element( 'timestamp', wfTimestamp( TS_ISO_8601
, $params['timestamp'] ) ) .
322 $this->element( 'username', 'UseModWiki admin' ) .
324 $this->element( 'type', 'move' ) .
325 $this->element( 'action', 'move' ) .
326 $this->element( 'logtitle', $params['old'] ) .
327 "<params xml:space=\"preserve\">" .
328 htmlspecialchars( $this->encode( "{$newTitle}\n1" ) ) .
331 fwrite( $this->outFile
, $out );
334 // Check for remaining deep rename entries
335 if ( $deepRenames ) {
336 echo "WARNING: the following entries in \$this->deepRenames are " .
337 "invalid, since no such move exists:\n" .
338 implode( "\n", array_keys( $deepRenames ) ) .
344 function element( $name, $value ) {
345 return "<$name>" . htmlspecialchars( $this->encode( $value ) ) . "</$name>\n";
348 function moveLogCallback( $entry ) {
349 $rctitle = $entry['rctitle'];
350 $title = $entry['title'];
351 $this->moveDests
[$rctitle] = $title;
353 if ( $rctitle === $title ) {
354 if ( isset( $this->moveLog
[$rctitle] )
355 && !isset( $this->moveLog
[$rctitle]['endTime'] ) )
357 // This is the latest time that the page could have been moved
358 $this->moveLog
[$rctitle]['endTime'] = $entry['timestamp'];
361 if ( !isset( $this->moveLog
[$rctitle] ) ) {
362 // Initialise the move log entry
363 $this->moveLog
[$rctitle] = array(
367 // Update the earliest time the page could have been moved
368 $this->moveLog
[$rctitle]['startTime'] = $entry['timestamp'];
372 function writeRevisions() {
373 $this->numGoodRevs
= 0;
375 $this->processDiffFile( array( $this, 'revisionCallback' ) );
376 echo "\n\nImported {$this->numGoodRevs} out of {$this->numRevs}\n";
379 function revisionCallback( $params ) {
380 $title = $params['rctitle'];
381 $editTime = $params['timestamp'];
383 if ( isset( $this->blacklist
[$title] ) ) {
386 $this->doPendingOps( $editTime );
388 $origText = $this->getText( $title );
389 $text = $this->patch( $origText, $params['diff'] );
390 if ( $text === false ) {
391 echo "$editTime $title attempting resolution...\n";
392 $linkSubstitutes = $this->resolveFailedDiff( $origText, $params['diff'] );
393 if ( !$linkSubstitutes ) {
394 $this->printLatin1( "$editTime $title DIFF FAILED\n" );
395 $this->blacklist
[$title] = true;
398 $this->printLatin1( "$editTime $title requires substitutions:\n" );
399 $time = $editTime - 1;
400 foreach ( $linkSubstitutes as $old => $new ) {
401 $this->printLatin1( "SUBSTITUTE $old -> $new\n" );
402 $this->renameTextLinks( $old, $new, $time-- );
404 $origText = $this->getText( $title );
405 $text = $this->patch( $origText, $params['diff'] );
406 if ( $text === false ) {
407 $this->printLatin1( "$editTime $title STILL FAILS!\n" );
408 $this->blacklist
[$title] = true;
415 $params['text'] = $text;
416 $this->saveRevision( $params );
417 $this->numGoodRevs++
;
418 #$this->printLatin1( "$editTime $title\n" );
421 function doPendingOps( $editTime ) {
422 foreach ( $this->moveLog
as $newTitle => $entry ) {
423 if ( $entry['timestamp'] <= $editTime ) {
424 unset( $this->moveLog
[$newTitle] );
425 if ( isset( $entry['deep'] ) ) {
426 $this->renameTextLinks( $entry['old'], $newTitle, $entry['timestamp'] );
431 foreach ( $this->renameTextLinksOps
as $renameTime => $replacements ) {
432 if ( $editTime >= $renameTime ) {
433 foreach ( $replacements as $old => $new ) {
434 $this->printLatin1( "SUBSTITUTE $old -> $new\n" );
435 $this->renameTextLinks( $old, $new, $renameTime );
437 unset( $this->renameTextLinksOps
[$renameTime] );
441 foreach ( $this->unixLineEndingsOps
as $fixTime => $title ) {
442 if ( $editTime >= $fixTime ) {
443 $this->printLatin1( "$fixTime $title FIXING LINE ENDINGS\n" );
444 $text = $this->getText( $title );
445 $text = str_replace( "\r", '', $text );
446 $this->saveRevision( array(
448 'timestamp' => $fixTime,
449 'extra' => array( 'name' => 'UseModWiki admin' ),
451 'summary' => 'Fixing line endings',
453 unset( $this->unixLineEndingsOps
[$fixTime] );
458 function patch( $source, $diff ) {
459 file_put_contents( $this->articleFileName
, $source );
460 file_put_contents( $this->patchFileName
, $diff );
461 $error = wfShellExec(
466 '--no-backup-if-mismatch',
468 $this->articleFileName
,
473 $text = file_get_contents( $this->articleFileName
);
474 if ( $status ||
$text === false ) {
481 function resolveFailedDiff( $origText, $diff ) {
483 $diffLines = explode( "\n", $diff );
484 for ( $i = 0; $i < count( $diffLines ); $i++
) {
485 $diffLine = $diffLines[$i];
486 if ( !preg_match( '/^(\d+)(?:,\d+)?[acd]\d+(?:,\d+)?$/', $diffLine, $m ) ) {
490 $sourceIndex = intval( $m[1] );
492 while ( $i < count( $diffLines ) && substr( $diffLines[$i], 0, 1 ) === '<' ) {
493 $context[$sourceIndex - 1] = substr( $diffLines[$i], 2 );
500 $changedLinks = array();
501 $origLines = explode( "\n", $origText );
502 foreach ( $context as $i => $contextLine ) {
503 $origLine = isset( $origLines[$i] ) ?
$origLines[$i] : '';
504 if ( $contextLine === $origLine ) {
507 $newChanges = $this->resolveTextChange( $origLine, $contextLine );
508 if ( is_array( $newChanges ) ) {
509 $changedLinks +
= $newChanges;
511 echo "Resolution failure on line " . ( $i +
1 ) . "\n";
512 $this->printLatin1( $newChanges );
516 return $changedLinks;
519 function resolveTextChange( $source, $dest ) {
520 $changedLinks = array();
521 $sourceLinks = $this->getLinkList( $source );
522 $destLinks = $this->getLinkList( $dest );
523 $newLinks = array_diff( $destLinks, $sourceLinks );
524 $removedLinks = array_diff( $sourceLinks, $destLinks );
526 // Match up the removed links with the new links
527 foreach ( $newLinks as $newLink ) {
528 $minDistance = 100000000;
529 $bestRemovedLink = false;
530 foreach ( $removedLinks as $removedLink ) {
531 $editDistance = levenshtein( $newLink, $removedLink );
532 if ( $editDistance < $minDistance ) {
533 $minDistance = $editDistance;
534 $bestRemovedLink = $removedLink;
537 if ( $bestRemovedLink !== false ) {
538 $changedLinks[$bestRemovedLink] = $newLink;
539 $newLinks = array_diff( $newLinks, array( $newLink ) );
540 $removedLinks = array_diff( $removedLinks, array( $bestRemovedLink ) );
545 foreach ( $changedLinks as $removedLink => $newLink ) {
546 $proposal = $this->substituteTextLinks( $removedLink, $newLink, $proposal );
548 if ( $proposal !== $dest ) {
550 $msg = "Source line: $source\n" .
551 "Source links: " . implode( ', ', $sourceLinks ) . "\n" .
552 "Context line: $dest\n" .
553 "Context links: " . implode( ', ', $destLinks ) . "\n" .
554 "Proposal: $proposal\n";
557 return $changedLinks;
560 function processDiffFile( $callback ) {
561 $diffFile = fopen( "{$this->dataDir}/diff_log", 'r' );
563 $delimiter = "------\n";
564 file_put_contents( $this->articleFileName
, "Describe the new page here.\n" );
566 $line = fgets( $diffFile );
568 if ( $line !== $delimiter ) {
569 echo "Invalid diff file\n";
576 $line = fgets( $diffFile );
578 if ( $line === false ) {
581 if ( $lineNum > $lastReportLine +
1000 ) {
582 $lastReportLine = $lineNum;
583 fwrite( STDERR
, "$lineNum \r" );
586 $line = trim( $line );
587 if ( !preg_match( '/^([^|]+)\|(\d+)$/', $line, $matches ) ) {
588 echo "Invalid header on line $lineNum\n";
591 list( , $title, $editTime ) = $matches;
594 $diffStartLine = $lineNum;
596 $line = fgets( $diffFile );
598 if ( $line === $delimiter ) {
601 if ( $line === false ) {
609 if ( !isset( $this->rc
[$editTime] ) ) {
610 $this->printLatin1( "$editTime $title DELETED, skipping\n" );
614 if ( count( $this->rc
[$editTime] ) == 1 ) {
615 $params = $this->rc
[$editTime][0];
619 foreach ( $this->rc
[$editTime] as $rc ) {
620 if ( $rc['rctitle'] === $title ) {
624 if ( $candidates === '' ) {
625 $candidates = $rc['rctitle'];
627 $candidates .= ', ' . $rc['rctitle'];
631 $this->printLatin1( "$editTime $title ERROR cannot resolve rclog\n" );
632 $this->printLatin1( "$editTime $title CANDIDATES: $candidates\n" );
636 $params['diff'] = $diff;
637 $params['title'] = $title;
638 $params['diffStartLine'] = $diffStartLine;
639 call_user_func( $callback, $params );
643 if ( !feof( $diffFile ) ) {
644 echo "Stopped at line $lineNum\n";
649 function reconcileCurrentRevs() {
650 foreach ( $this->textCache
as $title => $text ) {
651 $fileName = "{$this->dataDir}/page/";
652 if ( preg_match( '/^[A-Z]/', $title, $m ) ) {
655 $fileName .= 'other';
657 $fileName .= "/$title.db";
659 if ( !file_exists( $fileName ) ) {
660 $this->printLatin1( "ERROR: Cannot find page file for {$title}\n" );
664 $fileContents = file_get_contents( $fileName );
665 $page = $this->unserializeUseMod( $fileContents, $this->FS1
);
666 $section = $this->unserializeUseMod( $page['text_default'], $this->FS2
);
667 $data = $this->unserializeUseMod( $section['data'], $this->FS3
);
668 $pageText = $data['text'];
669 if ( $text !== $pageText ) {
670 $substs = $this->resolveTextChange( $text, $pageText );
671 if ( is_array( $substs ) ) {
672 foreach ( $substs as $source => $dest ) {
673 if ( isset( $this->moveLog
[$dest] ) ) {
674 $this->printLatin1( "ERROR: need deep rename: $source\n" );
676 $this->printLatin1( "ERROR: need substitute: $source -> $dest\n" );
680 $this->printLatin1( "ERROR: unresolved diff in $title:\n" );
681 wfSuppressWarnings();
682 $diff = xdiff_string_diff( $text, $pageText ) . '';
684 $this->printLatin1( "$diff\n" );
690 function makeTitle( $titleText ) {
691 return Title
::newFromText( $this->encode( $titleText ) );
694 function getText( $titleText ) {
695 if ( !isset( $this->textCache
[$titleText] ) ) {
696 return "Describe the new page here.\n";
698 return $this->textCache
[$titleText];
702 function saveRevision( $params ) {
703 $this->textCache
[$params['rctitle']] = $params['text'];
706 $this->element( 'title', $params['rctitle'] ) .
708 $this->element( 'id', $this->revId ++
) .
709 $this->element( 'timestamp', wfTimestamp( TS_ISO_8601
, $params['timestamp'] ) ) .
711 if ( isset( $params['extra']['name'] ) ) {
712 $out .= $this->element( 'username', $params['extra']['name'] );
714 if ( isset( $params['extra']['id'] ) ) {
715 $out .= $this->element( 'id', $params['extra']['id'] );
717 if ( isset( $params['host'] ) ) {
718 $out .= $this->element( 'ip', $params['host'] );
722 $this->element( 'comment', $params['summary'] ) .
723 "<text xml:space=\"preserve\">" .
724 htmlspecialchars( $this->encode( $params['text'] ) ) .
728 fwrite( $this->outFile
, $out );
731 function renameTextLinks( $old, $new, $timestamp ) {
732 $newWithUnderscores = $new;
733 $old = str_replace( '_', ' ', $old );
734 $new = str_replace( '_', ' ', $new );
736 foreach ( $this->textCache
as $title => $oldText ) {
737 if ( $newWithUnderscores === $title
738 && in_array( $title, $this->skipSelfSubstitution
) )
740 // Hack to make Pythagorean_Theorem etc. work
744 $newText = $this->substituteTextLinks( $old, $new, $oldText );
745 if ( $oldText !== $newText ) {
746 $this->saveRevision( array(
748 'timestamp' => $timestamp,
750 'extra' => array( 'name' => 'Page move link fixup script' ),
758 function substituteTextLinks( $old, $new, $text ) {
759 $this->saveUrl
= array();
763 $text = str_replace( $this->FS
, '', $text ); # Remove separators (paranoia)
764 $text = preg_replace_callback( '/(<pre>(.*?)<\/pre>)/is',
765 array( $this, 'storeRaw' ), $text );
766 $text = preg_replace_callback( '/(<code>(.*?)<\/code>)/is',
767 array( $this, 'storeRaw' ), $text );
768 $text = preg_replace_callback( '/(<nowiki>(.*?)<\/nowiki>)/s',
769 array( $this, 'storeRaw' ), $text );
771 $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\|([^\]]+)\]\]/",
772 array( $this, 'subFreeLink' ), $text );
773 $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\]\]/",
774 array( $this, 'subFreeLink' ), $text );
775 $text = preg_replace_callback( "/(\[{$this->UrlPattern}\s+([^\]]+?)\])/",
776 array( $this, 'storeRaw' ), $text );
777 $text = preg_replace_callback( "/(\[{$this->InterLinkPattern}\s+([^\]]+?)\])/",
778 array( $this, 'storeRaw' ), $text );
779 $text = preg_replace_callback( "/(\[?{$this->UrlPattern}\]?)/",
780 array( $this, 'storeRaw' ), $text );
781 $text = preg_replace_callback( "/(\[?{$this->InterLinkPattern}\]?)/",
782 array( $this, 'storeRaw' ), $text );
783 $text = preg_replace_callback( "/{$this->LinkPattern}/",
784 array( $this, 'subWikiLink' ), $text );
786 $text = preg_replace_callback( "/{$this->FS}(\d+){$this->FS}/",
787 array( $this, 'restoreRaw' ), $text ); # Restore saved text
791 function getLinkList( $text ) {
792 $this->saveUrl
= array();
793 $this->linkList
= array();
795 $text = str_replace( $this->FS
, '', $text ); # Remove separators (paranoia)
796 $text = preg_replace_callback( '/(<pre>(.*?)<\/pre>)/is',
797 array( $this, 'storeRaw' ), $text );
798 $text = preg_replace_callback( '/(<code>(.*?)<\/code>)/is',
799 array( $this, 'storeRaw' ), $text );
800 $text = preg_replace_callback( '/(<nowiki>(.*?)<\/nowiki>)/s',
801 array( $this, 'storeRaw' ), $text );
803 $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\|([^\]]+)\]\]/",
804 array( $this, 'storeLink' ), $text );
805 $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\]\]/",
806 array( $this, 'storeLink' ), $text );
807 $text = preg_replace_callback( "/(\[{$this->UrlPattern}\s+([^\]]+?)\])/",
808 array( $this, 'storeRaw' ), $text );
809 $text = preg_replace_callback( "/(\[{$this->InterLinkPattern}\s+([^\]]+?)\])/",
810 array( $this, 'storeRaw' ), $text );
811 $text = preg_replace_callback( "/(\[?{$this->UrlPattern}\]?)/",
812 array( $this, 'storeRaw' ), $text );
813 $text = preg_replace_callback( "/(\[?{$this->InterLinkPattern}\]?)/",
814 array( $this, 'storeRaw' ), $text );
815 $text = preg_replace_callback( "/{$this->LinkPattern}/",
816 array( $this, 'storeLink' ), $text );
818 return $this->linkList
;
821 function storeRaw( $m ) {
822 $this->saveUrl
[] = $m[1];
823 return $this->FS
. (count( $this->saveUrl
) - 1) . $this->FS
;
826 function subFreeLink( $m ) {
828 if ( isset( $m[2] ) ) {
834 $link = preg_replace( '/^\s+/', '', $link );
835 $link = preg_replace( '/\s+$/', '', $link );
836 if ( $link == $this->old
) {
839 $link = $oldlink; # Preserve spaces if no match
842 if ( $name !== "" ) {
846 return $this->storeRaw( array( 1 => $link ) );
849 function subWikiLink( $m ) {
851 if ( $link == $this->old
) {
853 if ( !preg_match( "/^{$this->LinkPattern}$/", $this->new ) ) {
857 return $this->storeRaw( array( 1 => $link ) );
860 function restoreRaw( $m ) {
861 return $this->saveUrl
[$m[1]];
864 function storeLink( $m ) {
865 $this->linkList
[] = $m[1];
866 return $this->storeRaw( $m );
869 function encode( $s ) {
870 return strtr( $s, $this->encodeMap
);
873 function decode( $s ) {
874 return strtr( $s, $this->decodeMap
);
877 function printLatin1( $s ) {
878 echo $this->encode( $s );
881 function unserializeUseMod( $s, $sep ) {
882 $parts = explode( $sep, $s );
884 for ( $i = 0; $i < count( $parts ); $i +
= 2 ) {
885 $result[$parts[$i]] = $parts[$i+
1];
891 $maintClass = 'ImportUseModWikipedia';
892 require_once( RUN_MAINTENANCE_IF_MAIN
);