3 function wfSpecialExport( $page = "" ) {
4 global $wgOut, $wgLang;
6 if( $_REQUEST['action'] == 'submit') {
7 $page = $_REQUEST['pages'];
8 $curonly = isset($_REQUEST['curonly']) ?
true : false;
14 header( "Content-type: application/xml; charset=utf-8" );
15 $pages = explode( "\n", $page );
16 $xml = pages2xml( $pages, $curonly );
21 $wgOut->addWikiText( wfMsg( "exporttext" ) );
22 $titleObj = Title
::makeTitle( NS_SPECIAL
, "Export" );
23 $action = $titleObj->getURL( "", true );
25 <form method='post' action=\"$action\">
26 <input type='hidden' name='action' value='submit' />
27 <textarea name='pages' cols='40' rows='10'></textarea><br />
28 <label><input type='checkbox' name='curonly' value='true' checked />
29 " . wfMsg( "exportcuronly" ) . "</label><br />
30 <input type='submit' />
35 function pages2xml( $pages, $curonly = false ) {
36 global $wgLanguageCode, $wgInputEncoding, $wgLang;
37 $xml = "<" . "?xml version=\"1.0\" encoding=\"UTF-8\" ?" . ">\n" .
38 "<mediawiki version=\"0.1\" xml:lang=\"$wgLanguageCode\">\n";
39 foreach( $pages as $page ) {
40 $xml .= page2xml( $page, $curonly );
42 $xml .= "</mediawiki>\n";
43 if($wgInputEncoding != "utf-8")
44 $xml = $wgLang->iconv( $wgInputEncoding, "utf-8", $xml );
48 function page2xml( $page, $curonly, $full = false ) {
49 global $wgInputCharset, $wgLang;
50 $title = Title
::NewFromText( $page );
51 if( !$title ) return "";
52 $t = wfStrencode( $title->getDBKey() );
53 $ns = $title->getNamespace();
54 $sql = "SELECT cur_id as id,cur_timestamp as timestamp,cur_user as user,cur_user_text as user_text," .
55 "cur_restrictions as restrictions,cur_comment as comment,cur_text as text FROM cur " .
56 "WHERE cur_namespace=$ns AND cur_title='$t'";
57 $res = wfQuery( $sql, DB_READ
);
58 if( $s = wfFetchObject( $res ) ) {
59 $tl = htmlspecialchars( $title->getPrefixedText() );
61 $xml .= " <title>$tl</title>\n";
63 $xml .= " <id>$s->id</id>\n";
65 if( $s->restrictions
) {
66 $xml .= " <restrictions>$s->restrictions</restrictions>\n";
69 $sql = "SELECT old_id as id,old_timestamp as timestamp, old_user as user, old_user_text as user_text," .
70 "old_comment as comment, old_text as text, old_flags as flags FROM old " .
71 "WHERE old_namespace=$ns AND old_title='$t' ORDER BY old_timestamp";
72 $res = wfQuery( $sql, DB_READ
);
74 while( $s2 = wfFetchObject( $res ) ) {
75 $xml .= revision2xml( $s2, $full, false );
78 $xml .= revision2xml( $s, $full, true );
86 function revision2xml( $s, $full, $cur ) {
87 $ts = wfTimestamp2ISO8601( $s->timestamp
);
88 $xml = " <revision>\n";
90 $xml .= " <id>$s->id</id>\n";
91 $xml .= " <timestamp>$ts</timestamp>\n";
93 $u = "<username>" . htmlspecialchars( $s->user_text
) . "</username>";
95 $u .= "<id>$s->user</id>";
97 $u = "<ip>" . htmlspecialchars( $s->user_text
) . "</ip>";
99 $xml .= " <contributor>$u</contributor>\n";
101 $xml .= " <minor/>\n";
103 if($s->comment
!= "") {
104 $c = htmlspecialchars( $s->comment
);
105 $xml .= " <comment>$c</comment>\n";
107 $t = htmlspecialchars( Article
::getRevisionText( $s, "" ) );
108 $xml .= " <text>$t</text>\n";
109 $xml .= " </revision>\n";
113 function wfTimestamp2ISO8601( $ts ) {
114 #2003-08-05T18:30:02Z
115 return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts );