How to export all pages from mediawiki into individual page files?
<p>Related to 
<a href="http://stackoverflow.com/questions/6739999/how-to-export-text-from-all-pages-of-a-mediawiki">How to export text from all pages of a MediaWiki?</a>, but I want the output be individual text files named using the page title.</p>

<pre><code>SELECT page_title, page_touched, old_text
FROM revision,page,text
WHERE revision.rev_id=page.page_latest
AND text.old_id=revision.rev_text_id;
</code></pre>

<p>works to dump it into stdout and all pages in one go.</p>

<p>How to split them and dump into individual files?</p>

<p><strong>SOLVED</strong></p>

<p>First dump into one single file:</p>

<pre><code>SELECT page_title, page_touched, old_text
FROM revision,page,text 
WHERE revision.rev_id=page.page_latest AND text.old_id=revision.rev_text_id AND page_namespace!='6' AND page_namespace!='8' AND  page_namespace!='12'
INTO OUTFILE '/tmp/wikipages.csv' 
FIELDS TERMINATED BY '\n' 
ESCAPED BY ''
LINES TERMINATED BY '\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n';
</code></pre>

<p>Then split it into individual file, use python:</p>

<pre><code>with open('wikipages.csv', 'rb') as f:
  alltxt = f.read().split('\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n')

  for row in alltxt:
    one = row.split('\n')
    name = one[0].replace('/','-')
    try:
      del one[0]
      del one[0]
    except:
      continue
    txt = '\n'.join(one)
    of = open('/tmp/wikipages/' + name + '.txt', 'w')
    of.write(txt)
    of.close()
</code></pre>

<p>In case you have some python knowledge you can utilize <code>mwclient</code> library to achieve this:</p>

<ol>
<li>install Python 2.7 <code>sudo apt-get install python2.7</code> ( see <a href="http://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu">http://askubuntu.com/questions/101591/how-do-i-install-python-2-7-2-on-ubuntu</a> in case of troubles )</li>
<li>install mwclient via <code>pip install mwclient</code></li>
<li><p>run python script below</p>

<pre><code>import mwclient
wiki = mwclient.Site(('http', 'you-wiki-domain.com'), '/')
for page in wiki.Pages:
  file = open(page.page_title, 'w')
  file.write(page.text())
  file.close()
</code></pre></li>
</ol>

<p>see mwclient page <a href="https://github.com/mwclient/mwclient" rel="nofollow">https://github.com/mwclient/mwclient</a> for reference</p>

python mysql mediawiki