API:Import
This page is part of the MediaWiki API documentation. |
Language: | English |
---|
Quick overview:
- Quick start guide
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Search suggestions
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
MediaWiki version: | = 1.15 |
Contents
Token[edit | edit source]
To import pages, an import token is required. This token is equal to the edit token and the same for all pages, but changes at every login. An import token can be obtained as follows: Obtaining an import token
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <query> <pages> <page pageid="1" ns="0" title="Main Page" touched="2007-09-03T20:32:21Z" lastrevid="20" counter="20" length="470" importtoken="58b54e0bab4a1d3fd3f7653af38e75cb+\" /> </pages> </query> </api> |
The above content has been placed in a collapsed box for improved usability. |
Importing pages[edit | edit source]
Pages can be imported with action=import, either by uploading an XML file or by specifying a page from another wiki (also known as transwikiing).
Parameters[edit | edit source]
Parameters marked with (upload) are only used when importing an uploaded XML file. Similarly, parameters marked with (interwiki) are only used when importing from another wiki (transwiki).
token
: The token obtained in the previous request. Take care to urlencode the trailing +\ as %2B%5Csummary
: Summary for the import log (optional)xml
: Uploaded XML file (upload)interwikisource
: Wiki to import from (interwiki)- The possible values for this parameter differ per wiki, see $wgImportSources. If the list of possible values for this parameter is empty, interwiki imports are disabled
interwikipage
: Title of the page to import (interwiki)fullhistory
: If set, import the full history rather than just the current revision (interwiki)namespace
: Namespace to import to. If not set, don't change the page's namespace (interwiki)templates
: Import all included templates as well (interwiki)
Example[edit | edit source]
Note: In these examples, all parameters are passed in a GET request just for the sake of simplicity. However, action=import requires POST requests; GET requests will cause an error.
Interwiki[edit | edit source]
Import meta:Help:ParserFunctions to the Manual namespace (namespace 100) with full history
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <import> <page ns="100" title="Manual:ParserFunctions" revisions="104" /> </import> </api> |
The above content has been placed in a collapsed box for improved usability. |
XML file[edit | edit source]
Import XML dump dump.xml (from Special:Export) to the Manual namespace (namespace 100)
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <import> <page ns="100" title="Manual:ParserFunctions" revisions="104" /> </import> </api> |
The above content has been placed in a collapsed box for improved usability. |
When uploading a file, you need to use multipart/form-data
as Content-Type or enctype, application/x-www-form-urlencoded
will not work. The parameter xml is not a file name, but the actual content of a file.
Ruby source code example using httpclient (assumes login cookies are already in @headers)
res = HTTPClient.post(@api_url, { :action => 'import', :xml => File.open("dump.xml"), :token => token, :format => 'xml'}, @headers)
Possible errors[edit | edit source]
All errors are formatted as:
<error code="code" info="info">
- code: notoken
- info: The token parameter must be set
- code: cantimport
- info: You don't have permission to import pages
- code: cantimport-upload
- info: You don't have permission to import uploaded pages
- code: nointerwikipage
- info: The interwikipage parameter must be set
- code: nofile
- info: You didn't upload a file
- code: filetoobig
- info: The file you uploaded is bigger than the maximum upload size
- code: partialupload
- info: The file was only partially uploaded
- code: notempdir
- info: The temporary upload directory is missing
- This generally means the server is broken or misconfigured
- info: The temporary upload directory is missing
- code: cantopenfile
- info: Couldn't open the uploaded file
- This generally means the server is broken or misconfigured
- info: Couldn't open the uploaded file
- code: badinterwiki
- info: Invalid interwiki title specified
- code: import-unknownerror
- info: Unknown error on import: ``error''