Attachment 'mediawiki2moin-v0.3.php.txt'
Download 1 #!/usr/local/bin/php
2 <?php
3
4
5 $host = ""; //address of the mysql server
6 $usr = ""; //username
7 $passwd = ""; //password
8 $db = ""; //database
9
10 $link = mysql_pconnect($host,$usr,$passwd) or die(mysql_error());
11 mysql_select_db($db) or die("Could not select database");
12
13 $WIKI_LINK_START = "[";
14 $WIKI_LINK_END = "]";
15 $EXTERNAL_LINK_START = "[";
16 $EXTERNAL_LINK_END = "]";
17 $EXTERNAL_LINK_DIVIDER = " ";
18
19 $not_pages = array("Block_log", "Deletion_log", "Protection_log", "Upload_log", "1movedto2", "1movedto2_redir", "About", "Aboutpage","Aboutwikipedia", "Accesskey-compareselectedversions", "Accesskey-minoredit", "Accesskey-preview", "Accesskey-save", "Accesskey-search", "Accmailtext", "Accmailtitle", "Acct_creation_throttle_hit", "Actioncomplete", "Addedwatch", "Addedwatchtext", "Addsection", "Administrators", "Affirmation", "All", "Allmessages", "Allmessagestext", "Allpages", "Alphaindexline", "Alreadyloggedin", "Alreadyrolled", "Ancientpages", "And", "Anontalk", "Anontalkpagetext", "Anonymous", "Article", "Articleexists", "Articlepage", "Asksql", "Asksqltext", "Autoblocker", "Badarticleerror", "Badfilename", "Badfiletype", "Badipaddress", "Badquery", "Badquerytext", "Badretype", "Badtitle", "Badtitletext", "Blanknamespace", "Blockedtext", "Blockedtitle", "Blockip", "Blockipsuccesssub", "Blockipsuccesstext", "Blockiptext", "Blocklink", "Blocklistline", "Blocklogentry", "Blocklogpage", "Blocklogtext", "Bold_sample", "Bold_tip", "Booksources", "Booksourcetext", "Brokenredirects", "Brokenredirectstext", "Bugreports", "Bugreportspage", "Bureaucratlog", "Bureaucratlogentry", "Bureaucrattext", "Bureaucrattitle", "Bydate", "Byname", "Bysize", "Cachederror", "Cancel", "Cannotdelete", "Cantrollback", "Categories", "Categoriespagetext", "Category", "Category_header", "Categoryarticlecount", "Changepassword", "Changes", "Clearyourcache", "Columns", "Commentedit", "Compareselectedversions", "Confirm", "Confirmcheck", "Confirmdelete", "Confirmdeletetext", "Confirmprotect", "Confirmprotecttext", "Confirmunprotect", "Confirmunprotecttext", "Contextchars", "Contextlines", "Contribslink", "Contribsub", "Contributions", "Copyright", "Copyrightpage", "Copyrightpagename", "Copyrightwarning", "Couldntremove", "Createaccount", "Createaccountmail", "Creditspage", "Cur", "Currentevents", "Currentrev", "Databaseerror", "Dateformat", "Dberrortext", "Dberrortextcl", "Deadendpages", "Debug", "Defaultns", "Defemailsubject", "Delete", "Deletecomment", "Deletedarticle", "Deletedtext", "Deleteimg", "Deleteimgcompletely", "Deletepage", "Deletesub", "Deletethispage", "Deletionlog", "Dellogpage", "Dellogpagetext", "Developerspheading", "Developertext", "Developertitle", "Diff", "Difference", "Disambiguations", "Disambiguationspage", "Disambiguationstext", "Disclaimerpage", "Disclaimers", "Doubleredirects", "Doubleredirectstext", "Edit", "Editcomment", "Editconflict", "Editcurrent", "Edithelp", "Edithelppage", "Editing", "Editingold", "Editsection", "Editthispage", "Emailflag", "Emailforlost", "Emailfrom", "Emailmessage", "Emailpage", "Emailpagetext", "Emailsend", "Emailsent", "Emailsenttext", "Emailsubject", "Emailto", "Emailuser", "Emptyfile", "Enterlockreason", "Error", "Errorpagetitle", "Exbeforeblank", "Exblank", "Excontent", "Explainconflict", "Export", "Exportcuronly", "Exporttext", "Extlink_sample", "Extlink_tip", "Faq", "Faqpage", "Feedlinks", "Filecopyerror", "Filedeleteerror", "Filedesc", "Fileexists", "Filename", "Filenotfound", "Filerenameerror", "Filesource", "Filestatus", "Fileuploaded", "Formerror", "Fromwikipedia", "Getimagelist", "Go", "Googlesearch", "Guesstimezone", "Headline_sample", "Headline_tip", "Help", "Helppage", "Hide", "Hidetoc", "Hist", "Histlegend", "History", "History_copyright", "History_short", "Historywarning", "Hr_tip", "Ignorewarning", "Illegalfilename", "Ilshowmatch", "Ilsubmit", "Image_sample", "Image_tip", "Imagelinks", "Imagelist", "Imagelisttext", "Imagepage", "Imagereverted", "Imgdelete", "Imgdesc", "Imghistlegend", "Imghistory", "Imglegend", "Import", "Importfailed", "Importhistoryconflict", "Importnotext", "Importsuccess", "Importtext", "Info_short", "Infobox", "Infobox_alert", "Infosubtitle", "Internalerror", "Intl", "Ip_range_invalid", "Ipaddress", "Ipb_expiry_invalid", "Ipbexpiry", "Ipblocklist", "Ipbreason", "Ipbsubmit", "Ipusubmit", "Ipusuccess", "Isbn", "Isredirect", "Italic_sample", "Italic_tip", "Iteminvalidname", "Largefile", "Last", "Lastmodified", "Lastmodifiedby", "Lineno", "Link_sample", "Link_tip", "Linklistsub", "Linkshere", "Linkstoimage", "Linktrail", "Listadmins", "Listform", "Listusers", "Loadhist", "Loadingrev", "Localtime", "Lockbtn", "Lockconfirm", "Lockdb", "Lockdbsuccesssub", "Lockdbsuccesstext", "Lockdbtext", "Locknoconfirm", "Login", "Loginend", "Loginerror", "Loginpagetitle", "Loginproblem", "Loginprompt", "Loginreqtext", "Loginreqtitle", "Loginsuccess", "Loginsuccesstitle", "Logout", "Logouttext", "Logouttitle", "Lonelypages", "Longpages", "Longpagewarning", "Mailerror", "Mailmypassword", "Mailnologin", "Mailnologintext", "Mainpage", "Mainpagedocfooter", "Mainpagetext", "Maintenance", "Maintenancebacklink", "Maintnancepagetext", "Makesysop", "Makesysopfail", "Makesysopname", "Makesysopok", "Makesysopsubmit", "Makesysoptext", "Makesysoptitle", "Matchtotals", "Math", "Math_bad_output", "Math_bad_tmpdir", "Math_failure", "Math_image_error", "Math_lexing_error", "Math_notexvc", "Math_sample", "Math_syntax_error", "Math_tip", "Math_unknown_error", "Math_unknown_function", "Media_sample", "Media_tip", "Minlength", "Minoredit", "Minoreditletter", "Mispeelings", "Mispeelingspage", "Mispeelingstext", "Missingarticle", "Missingimage", "Missinglanguagelinks", "Missinglanguagelinksbutton", "Missinglanguagelinkstext", "Monobook.css", "Monobook.js", "Moredotdotdot", "Move", "Movearticle", "Movedto", "Movenologin", "Movenologintext", "Movepage", "Movepagebtn", "Movepagetalktext", "Movepagetext", "Movetalk", "Movethispage", "Mycontris", "Mypage", "Mytalk", "Navigation", "Nbytes", "Nchanges", "Newarticle", "Newarticletext", "Newmessages", "Newmessageslink", "Newpage", "Newpageletter", "Newpages", "Newpassword", "Newtitle", "Newusersonly","Newwindow", "Next", "Nextn", "Nextpage", "Nlinks", "Noaffirmation", "Noarticletext", "Noblockreason", "Noconnect", "Nocontribs", "Nocookieslogin", "Nocookiesnew", "Nocreativecommons", "Nocredits", "Nodb", "Nodublincore", "Noemail", "Noemailtext", "Noemailtitle", "Nogomatch", "Nohistory", "Nolinkshere", "Nolinkstoimage", "Noname", "Nonefound", "Nospecialpagetext", "Nosuchaction", "Nosuchactiontext", "Nosuchspecialpage", "Nosuchuser", "Notacceptable", "Notanarticle", "Notargettext", "Notargettitle", "Note", "Notextmatches", "Notitlematches", "Notloggedin", "Nowatchlist", "Nowiki_sample", "Nowiki_tip", "Nstab-category", "Nstab-help", "Nstab-image", "Nstab-main", "Nstab-media", "Nstab-mediawiki", "Nstab-special", "Nstab-template", "Nstab-user", "Nstab-wp", "Numauthors", "Numedits", "Numtalkauthors", "Numtalkedits", "Numwatchers", "Nviews", "Ok", "Oldpassword", "Orig", "Orphans", "Othercontribs", "Otherlanguages", "Others", "Pagemovedsub", "Pagemovedtext", "Pagetitle", "Passwordremindertext", "Passwordremindertitle", "Passwordsent", "Perfcached", "Perfdisabled", "Perfdisabledsub", "Personaltools", "Popularpages", "Portal", "Portal-url", "Postcomment", "Poweredby", "Powersearch", "Powersearchtext", "Preferences", "Prefs-help-userdata", "Prefs-misc", "Prefs-personal", "Prefs-rc", "Prefslogintext", "Prefsnologin", "Prefsnologintext", "Prefsreset", "Preview", "Previewconflict", "Previewnote", "Prevn", "Printableversion", "Printsubtitle", "Protect", "Protectcomment", "Protectedarticle", "Protectedpage", "Protectedpagewarning", "Protectedtext", "Protectlogpage", "Protectlogtext", "Protectpage", "Protectreason", "Protectsub", "Protectthispage", "Proxyblocker", "Proxyblockreason", "Proxyblocksuccess", "Qbbrowse", "Qbedit", "Qbfind", "Qbmyoptions", "Qbpageinfo", "Qbpageoptions", "Qbsettings", "Qbsettingsnote", "Qbspecialpages", "Querybtn", "Querysuccessful", "Randompage", "Range_block_disabled", "Rchide", "Rclinks", "Rclistfrom", "Rcliu", "Rcloaderr", "Rclsub", "Rcnote", "Rcnotefrom", "Readonly", "Readonlytext", "Readonlywarning", "Recentchanges", "Recentchangescount", "Recentchangeslinked", "Recentchangestext", "Redirectedfrom", "Remembermypassword", "Removechecked", "Removedwatch", "Removedwatchtext", "Removingchecked", "Resetprefs", "Restorelink", "Resultsperpage", "Retrievedfrom", "Returnto", "Retypenew", "Reupload", "Reuploaddesc", "Reverted", "Revertimg", "Revertpage", "Revhistory", "Revisionasof", "Revnotfound", "Revnotfoundtext", "Rfcurl", "Rights", "Rollback", "Rollback_short", "Rollbackfailed", "Rollbacklink", "Rows", "Savearticle", "Savedprefs", "Savefile", "Saveprefs", "Search", "Searchdisabled", "Searchhelppage", "Searchingwikipedia", "Searchquery", "Searchresults", "Searchresultshead", "Searchresulttext", "Sectionedit", "Selectnewerversionfordiff", "Selectolderversionfordiff", "Selectonly", "Selflinks", "Selflinkstext", "Seriousxhtmlerrors", "Servertime", "Set_rights_fail", "Set_user_rights", "Setbureaucratflag", "Sharedupload", "Shortpages", "Show", "Showhideminor", "Showingresults", "Showingresultsnum", "Showlast", "Showpreview", "Showtoc", "Sig_tip", "Sitenotice", "Sitestats", "Sitestatstext", "Sitesubtitle", "Sitesupport", "Sitetitle", "Siteuser", "Siteusers", "Skin", "Spamprotectiontext", "Spamprotectiontitle", "Specialpage", "Specialpages", "Spheading", "Sqlislogged", "Sqlquery", "Statistics", "Storedversion", "Stubthreshold", "Subcategories", "Subcategorycount", "Subject", "Subjectpage", "Successfulupload", "Summary", "Sysopspheading", "Sysoptext", "Sysoptitle", "Tableform", "Talk", "Talkexists", "Talkpage", "Talkpagemoved", "Talkpagenotmoved", "Talkpagetext", "Templatesused", "Textboxsize", "Textmatches", "Thisisdeleted", "Thumbnail-more", "Timezonelegend", "Timezoneoffset", "Timezonetext", "Titlematches", "Toc", "Toolbox", "Tooltip-compareselectedversions", "Tooltip-minoredit", "Tooltip-preview", "Tooltip-save", "Tooltip-search", "Uclinks", "Ucnote", "Uctop", "Unblockip", "Unblockiptext", "Unblocklink", "Unblocklogentry", "Uncategorizedpages", "Undelete", "Undelete_short", "Undeletearticle", "Undeletebtn", "Undeletedarticle", "Undeletedtext", "Undeletehistory", "Undeletepage", "Undeletepagetext", "Undeleterevision", "Undeleterevisions", "Unexpected", "Unlockbtn", "Unlockconfirm", "Unlockdb", "Unlockdbsuccesssub", "Unlockdbsuccesstext", "Unlockdbtext", "Unprotect", "Unprotectcomment", "Unprotectedarticle", "Unprotectsub", "Unprotectthispage", "Unusedimages", "Unusedimagestext", "Unwatch", "Unwatchthispage", "Updated", "Upload", "Uploadbtn", "Uploadcorrupt", "Uploaddisabled", "Uploadedfiles", "Uploadedimage", "Uploaderror", "Uploadfile", "Uploadlink", "Uploadlog", "Uploadlogpage", "Uploadlogpagetext", "Uploadnologin", "Uploadnologintext", "Uploadtext", "Uploadwarning", "Usenewcategorypage", "User_rights_set", "Usercssjsyoucanpreview", "Usercsspreview", "Userexists", "Userjspreview", "Userlogin", "Userlogout", "Usermailererror", "Userpage", "Userstats", "Userstatstext", "Version", "Viewcount", "Viewprevnext", "Viewsource", "Viewtalkpage", "Wantedpages", "Watch", "Watchdetails", "Watcheditlist", "Watchlist", "Watchlistcontains", "Watchlistsub", "Watchmethod-list", "Watchmethod-recent", "Watchnochange", "Watchnologin", "Watchnologintext", "Watchthis", "Watchthispage", "Welcomecreation", "Whatlinkshere", "Whitelistacctext", "Whitelistacctitle", "Whitelistedittext", "Whitelistedittitle", "Whitelistreadtext", "Whitelistreadtitle", "Wikipediapage", "Wikititlesuffix", "Wlnote", "Wlsaved","Wlshowlast","Wrong_wfQuery_params","Wrongpassword","Yourdiff","Youremail","Yourname","Yournick","Yourpassword","Yourpasswordagain","Yourrealname","Yourtext");
20
21
22 $a = 0;
23 #$sql = "SELECT cur_title,cur_text FROM cur;";
24 $sql = "SELECT cur_title,cur_text FROM cur where cur_user_text not like \"MediaWiki default\" order by cur_title;";
25 $query = mysql_query($sql) or die(mysql_error());
26 while ($row = mysql_fetch_object($query)) {
27 if (!in_array($row->cur_title, $not_pages)) {
28 $title[$a] = $row->cur_title;
29 $text[$a] = $row->cur_text;
30 $a++;
31 }
32 }
33
34 $dir = "mediawiki_pages";
35
36 if(file_exists($dir)){
37 rmdirr($dir);
38 mkdir($dir);
39 }
40 else{
41 mkdir($dir);
42 }
43
44
45 chdir("./$dir") or die;
46
47
48 $a = 0;
49
50
51 while ($a < count($title)) {
52 echo "$title[$a]\n";
53
54 $title[$a] = utf8_encode(str_replace(" ", "_", $title[$a]));
55 $quoted = array();
56 $in_parenthesis = false;
57 for ($i = 0; $i < strlen($title[$a]); $i++) {
58
59 $curchar = substr ($title[$a], $i, 1);
60 if (ereg('[^a-zA-Z0-9_]', $curchar)) {
61 if (!$in_parenthesis) {
62 $quoted[] = '(';
63 $in_parenthesis = true;
64 }
65 $quoted[] = str_pad(dechex(ord($curchar)), 2, '0', STR_PAD_LEFT);
66 } else {
67 if ($in_parenthesis) {
68 $quoted[] = ')';
69 $in_parenthesis = false;
70 }
71 $quoted[] = $curchar;
72 }
73 }
74
75 if ($in_parenthesis)
76 $quoted[] = ')';
77 $title[$a] = implode('', $quoted);
78 unset($quoted);
79
80 mkdir($title[$a]);
81 chdir($title[$a]);
82 $file = fopen("current", "w");
83 fputs($file, "00000001");
84
85 fclose($file);
86
87 mkdir("revisions");
88
89 chdir("revisions");
90
91 $file = fopen("00000001", "w");
92
93 #break up one string into lines
94 $file_text = explode("\n", $text[$a]);
95
96 $file_text = change_syntax($file_text);
97
98 $b = 0;
99
100 while ($b < count($file_text)) {
101
102 fputs($file, rtrim($file_text[$b]) . "\n");
103 $b++;
104 }
105
106 unset($file_text);
107 fclose($file);
108 chdir("..");
109 chdir("..");
110 $a++;
111 }
112 chdir("..");
113 ###End of Main
114
115 function change_syntax ($textString) {
116 #$a = 0;
117
118 for($a = 0; $a < count($textString); $a++){
119 #print "str(before mod) = $textString[$a] \n";
120
121 #custom plugin
122 #if(preg_match("/\<fileshare\>.+\<\/fileshare\>/",$textString[$a])){
123 # $textString[$a] = fileShare($textString[$a]);
124 #}
125
126 #strpos : Returns the numeric position of the first occurrence of needle in the haystack string. Unlike the strrpos(), this function can take a full string as the needle parameter and the entire string will be used.
127 #substr() returns the portion of string specified by the start and length parameters.
128 #string substr ( string string, int start [, int length] )
129 if(substr($textString[$a], 0, 1) == '*'){
130 $textString[$a] = bullets($textString[$a]);
131 }
132
133 if(preg_match("/^#/",$textString[$a])){
134 $textString[$a] = numberedList( $textString[$a]);
135 }
136
137 #headings
138 if(preg_match("/^==.+==/",$textString[$a])){
139 $textString[$a] = heading( $textString[$a]);
140 }
141
142 #wikilink
143 if(preg_match("/\[\[.+\]\]/",$textString[$a])){
144 $textString[$a] = wikiLinks($textString[$a]);
145 }
146
147 #media wiki new line <br\> or <BR>
148 #must be after wiki links
149 if (preg_match("/\<br\/{0,1}\>/i", $textString[$a])) {
150 $textString[$a] = preg_replace("/\\<br\/{0,1}\>/i", "[[BR]]",$textString[$a]);
151 #print "result = $textString[$a]\n";
152 }
153 }
154
155 return $textString;
156 }
157
158
159
160 #custom plugin
161 #function fileShare($string) {
162 # $fileshare = substr($string, strpos($string, "\\\\"));
163 # $fileshare = preg_replace("/<\/fileshare>/","",$fileshare);
164 # $string = "[file:" .$fileshare ."]";
165 # return $string;
166 #}
167
168 function heading($string){
169 $theHeading = $string;
170 $headingLevel = 0;
171
172 #strip the left side '=' chars
173 while($headingLevel < strlen($theHeading)){
174 if(substr($theHeading, 0, 1) == '='){
175 $theHeading = substr($theHeading, 1);
176 }
177 else{
178 #no more ='s in front of text
179 break;
180 }
181 $headingLevel++;
182 }
183
184 #the left side '=' chars are now removed
185 #now strip right side '=' chars
186 $theHeading = substr($theHeading, 0, strpos($theHeading, '='));
187
188 $theSyntax = "";
189 #note moinmoin uses 1 less = for heading levels
190 #so mediawiki "===" is the same as moinmoin "=="
191 for($i = 1; $i < $headingLevel; $i++){
192 $theSyntax .= "=";
193 }
194
195 $string = $theSyntax ." $theHeading " .$theSyntax;
196
197 return $string;
198 }
199
200
201 function bullets ($string) {
202 $a = 0;
203 while ($a < strlen($string)) {
204 $a++;
205 if (substr($string, 1, 1) == "*")
206 $string = substr($string, 1);
207 else
208 break;
209 }
210 while ($a > 0) {
211 $string = " " . $string;
212 $a--;
213 }
214 return $string;
215 }
216
217 function numberedList ($string) {
218 if(preg_match("/^#/",$string)){
219 $string = preg_replace("/^#/", " 1.", $string);
220 }
221 elseif(preg_match("/^##/",$string)){
222 $string = preg_replace("/^##/", " 1.", $string);
223 }
224 return $string;
225 }
226
227
228 function wikiLinks ($string) {
229 global $WIKI_LINK_START;
230 global $WIKI_LINK_END;
231
232 while (strpos($string, "[[") !== false && strpos($string, "]]") !== false) {
233 #isolate link
234 $link = substr($string, strpos($string, "[[") + 2);
235 $link = substr($link, 0, strpos($link, "]]") + 0);
236
237 if (strpos($link, "|") == false){
238 #add new link syntax
239 $link = $WIKI_LINK_START ."\"". $link ."\"" .$WIKI_LINK_END;
240 }
241 else{
242 $dividerPosition = strpos($link, "|");
243
244 $wikilink = substr($link, 0, $dividerPosition);
245 $label = substr($link, $dividerPosition + 1, strlen($link) - $dividerPosition);
246
247 #remove whitespace from beginning and end
248 $label = trim($label);
249
250 $link = $WIKI_LINK_START .":" .$wikilink .": " .$label .$WIKI_LINK_END;
251 }
252
253 $string = substr($string, 0, strpos($string, "[[") - 0) . $link .substr($string, strpos($string, "]]") + 2);
254 }
255
256 return $string;
257 }
258
259
260 function externalLinks($string){
261 global $EXTERNAL_LINK_START;
262 global $EXTERNAL_LINK_END;
263 global $EXTERNAL_LINK_DIVIDER;
264
265 #external link syntax is the same except for the label divider
266
267 if(preg_match("/| /")){
268 $string = preg_replace("/| /", " ", $string);
269 }
270 elseif(preg_match("/|/")){
271 $string = preg_replace("/|/", " ", $string);
272 }
273
274 return $string;
275
276 }
277
278 function rmdirr($dir) {
279 if($objs = glob($dir."/*")){
280 foreach($objs as $obj) {
281 is_dir($obj)? rmdirr($obj) : unlink($obj);
282 }
283 }
284 rmdir($dir);
285 }
286
287 ?>
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.