Difference between revisions of "Change user in XML export"

From Organic Design wiki
(Regex works on Linux -maybe not on OS X (go figure))
(Change source-code blocks to standard format)
 
(5 intermediate revisions by one other user not shown)
Line 7: Line 7:
 
The Usernames are specified in the <nowiki><username></nowiki> tag, by default an xml export usually dumps the current revision not the history of an article;
 
The Usernames are specified in the <nowiki><username></nowiki> tag, by default an xml export usually dumps the current revision not the history of an article;
  
{{code|<PHP>
+
==Changing ''username'' and ''id''==
perl -ne 's/(<username>)\w+?(<\/username>\s+?<id>)\d+?(<\/id>)/${1}WikiSysop${2}1${3}/g; ; print ' IN.xml > OUT.xml
+
<source lang="perl">
</PHP>
+
perl -ne 'BEGIN{$/=undef} s/(<username>)\w+?(<\/username>\s+?<id>)\d+?(<\/id>)/${1}WikiSysop${2}1${3}/g; ; print' IN.xml > OUT.xml
 +
</source>
 +
 
 +
==Changing ''timestamp'', ''username'' and ''id''==
 +
The <nowiki><timestamp>2008-12-03T09:01:22Z</timestamp></nowiki> field is also important. If it is at the current time then imports will be recorded in the recent changes.
 +
<source lang="perl">
 +
perl -ne 'BEGIN{$/=undef}
 +
$time = `date "+%Y-%m-%dT%H:%M:%SZ"`;
 +
s/(<timestamp>).+?(<\/timestamp>)/${1}${time}${2}/g;
 +
s/(<username>)\w+?(<\/username>\s+?<id>)\d+?(<\/id>)/${1}WikiSysop${2}1${3}/g;  
 +
print' IN.xml > OUT.xml
 +
</source>
 +
 
 +
The unix command to mimic mediaWikis timestamp is;
 +
<source lang="BASH">
 +
date "+%Y-%m-%dT%H:%M:%SZ"
 +
</source>
 
}}
 
}}

Latest revision as of 18:11, 22 May 2015

Procedure.svg Change user in XML export
Organic Design procedure

The Usernames are specified in the <username> tag, by default an xml export usually dumps the current revision not the history of an article;

Changing username and id

perl -ne 'BEGIN{$/=undef} s/(<username>)\w+?(<\/username>\s+?<id>)\d+?(<\/id>)/${1}WikiSysop${2}1${3}/g; ; print' IN.xml > OUT.xml

Changing timestamp, username and id

The <timestamp>2008-12-03T09:01:22Z</timestamp> field is also important. If it is at the current time then imports will be recorded in the recent changes.

perl -ne 'BEGIN{$/=undef} 
$time = `date "+%Y-%m-%dT%H:%M:%SZ"`; 
s/(<timestamp>).+?(<\/timestamp>)/${1}${time}${2}/g;
s/(<username>)\w+?(<\/username>\s+?<id>)\d+?(<\/id>)/${1}WikiSysop${2}1${3}/g; 
print' IN.xml > OUT.xml

The unix command to mimic mediaWikis timestamp is;

date "+%Y-%m-%dT%H:%M:%SZ"

}}