Scripts to handle Mediawiki content, using the RESTful API.
These scripts depend on the Snoopy PHP net client to simulate a browser.
/src - the sources
/src/wrappers - classes to call the API using PHP
/src/example.ini - an example configuration file. Copy this.
/src/exampleBasicImportCSV.php - basic PHP script to import a spreadsheet.
/src/exampleAdvancedImportCSV.php - same as above, but can customize the result.
/test - unit tests
/test/testdata - data used for testing
The CSV importer will create a new page or add a new version to an existing page (but only if data has changed!). Data will generally be presented as a table.
Before the spreadsheet can be imported, please do the following:
- Export the spreadsheet into CSV format.
- Make sure the CSV is in UTF-8, else convert it, e.g. using Notepad.
The table created from the spreadsheet will be inserted into a mediawiki page. Pages are formated using a template stored in a local file (the Mediawiki templating system is not required).
- To create your own page template, copy test/testdata/Test.tpl to e.g. src/page.tpl.
- Add the newly created .tpl file to Git ignore
- Edit the file to suit your requirements.
- Get Snoopy
- Download from Snoopy PHP net client.
- Put Snoopy.class.php into one of the directories specified in your php.ini include_path directive (e.g. /etc/php5/cli/php.ini).
- Copy example.ini as e.g. config.ini and edit it to suit your configuration. Add your configuration to Git ignore.
- For a simple spreadsheet import, copy exampleBasicImportsCSV.php to e.g. runImportCSV.php
- In the newly created file, make sure the following settings are correct:
- The path to the CSV file
- The path to the page template (a local file path, not a URL!)
- The name of the page to be created
- The path to the configuration file
If you require more control over the format of the wiki table being created, you can extend CSVImporter and overwrite the makeWikiTable method. See exampleAdvancedImportCSV.php for how to do this.
Tests are written using PHPUnit. Please run the tests, specially if you edit the source code.
- Get PHP Unit
- Copy example.ini as e.g. test.ini and edit it to suit your configuration. Add your configuration to Git ignore.
- In each test file, make sure the path to the test configuration file is correct.