Phriction Welcome in gitpull.it, a Phabricator instance! First steps with boz-mw MediaWiki API framework History Version 15 vs 16
Version 15 vs 16
Version 15 vs 16
Edits
Edits
- Edit by valerio.bozzolan, Version 16
- May 26 2021 02:43
- Edit by valerio.bozzolan, Version 15
- May 26 2021 02:38
- ·improve example
« Previous Change | Next Change » |
Edit Older Version 15... | Edit Older Version 16... |
Content Changes
Content Changes
This is `boz-mw`, //another MediaWiki API handler in PHP// with batteries included! It has a tons of features that will make your head spin!
This is a library to interact with MediaWiki and Wikibase APIs. There are also some [[ first_steps_with_boz-mw/tools/ | boz-mw command line tools ]].
## Features
You may ask what we can offer to you:
* read/write support for Wikidata
* read/write support for Wikimedia Commons' **Structured Data**
* **file upload** support for Wikimedia Commons
* support for some other known wiki(s)
* support for your custom wiki
* lightweight project, well designed using [[ https://en.wikipedia.org/wiki/Object-oriented_programming | OOP ]]
Actually, this framework is useful for:
* developers, to create bots
* command line users for our [[ #Command line tools ]]
## Download
```
git clone https://gitpull.it/source/boz-mw.git
```
## Command line tools
See [[ first_steps_with_boz-mw/tools/ | command line tools ]].
### Command line script `replace.php`
The [replace.php](https://gitpull.it/source/boz-mw/browse/master/tools/#replace-script-tt-class-remarkup) allows you to do some sobstitutions in a wiki.
### Command line script `mega-export.php`
The [mega-export.php](https://gitpull.it/source/boz-mw/browse/master/tools/#mega-export-tt-class-remarkup) allows you to export the _full_ page history of whatever page.
## API framework showcase
Here some usage examples.
### Start: select your wiki
First of all you should init a wiki:
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
// load Wikidata
$wikidata = wikidata();
// load Wikidata (this is the same)
// $wikidata = wiki( 'wikidatawiki' );
// load Wikidata (this is the same)
// $wikidata = \wm\Wikidata::instance();
// load Wikipedia in Italian (this is the same)
$itwiki = itwiki();
// load Wikipedia in Italian (this is the same)
// $itwiki = wiki( 'itwiki' );
// load Wikimedia Commons
$commons = commons();
// load Wikimedia Commons (this is the same)
// $commons = wiki( 'commonswiki' );
// load Wikimedia Commons (this is the same)
// $commons = \wm\Commons::instance();
// load Meta-Wiki
$meta = meta();
// load Meta-wiki (this is the same)
// $meta = wiki( 'metawiki' );
// load Meta-wiki this is the same
// $meta = \wm\MetaWiki::instance();
```
### Basic API query
To obtain a simple information from the server (no continuation support):
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
// load it.wiki
$wiki = itwiki();
$response =
$wiki->fetch( [
'action' => 'query',
'prop' => 'info',
'titles' => 'Pagina principale',
] );
// get the first result (the only one)
$page = $response->query->pages[ 0 ];
// show interesting information
print_r( $page->title );
print_r( $page->pageid );
```
Note: See [[ https://meta.wikimedia.org/w/api.php?action=help&modules=query | MediaWiki API action=query documentation ]].
### API query with continuation
To obtain a long result set from the server (with continuation support):
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wiki = itwiki();
$request =
$wiki->createQuery( [
'action' => 'query',
'list' => 'categorymembers',
'cmtitle' => 'Categoria:Software con licenza GNU GPL',
] );
foreach( $request as $response ) {
$pages = $response->query->categorymembers ?? null;
foreach( $pages as $page ) {
// do something
var_dump( $page->pageid );
var_dump( $page->ns );
var_dump( $page->title );
print_r( $page );
}
}
```
NOTE: See [[ https://meta.wikimedia.org/w/api.php?action=help&modules=query%2Bcategorymembers | MediaWiki API action=query list=categorymembers documentation ]].
### Login and Edit API query
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wiki = itwiki();
$user = '';
$password = '';
$wiki->login( $user, $password );
$wiki->edit( [
'title' => 'Special:Nothing',
'text' => 'My wikitext',
'summary' => 'My edit summary',
] );
```
NOTE: See [[ https://mediawiki.org/w/api.php?action=help&modules=edit | MediaWiki action=edit documentation ]]. Yes, the `token` parameter is automatically handled for you automagically.
You can also call `login()` without parameters if you specify a global username and password on the top of your script:
```
\mw\API::$DEFAULT_USERNAME = '':
\mw\API::$DEFAULT_PASSWORD = '';
```
### Wikidata SPARQL query
What if you want to list all the [cats from Wikidata](https://query.wikidata.org/#%23Cats%0ASELECT%20%3Fitem%20%3FitemLabel%20%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ146.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D)?
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wikidata = wikidata();
// you should know how to build a SPARQL query
$query = 'SELECT ?item ?itemLabel WHERE {';
$query .= ' ?item wdt:P31 wd:Q146 ';
$query .= ' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } ';
$query .= '}';
// query Wikidata and decode the response
$rows = $wikidata::querySPARQL( $query );
// for each cat
foreach( $rows as $row ) {
// example: 'http://www.wikidata.org/entity/Q5317221'
$url = $row->item->value;
// example: 'Q5317221'
$id = basename( $url );
// example: 'Dusty the Klepto Kitty'
$itemLabel = $row->itemLabel->value;
echo "Found cat ID: $id. Name: $itemLabel \n";
}
```
### Wikidata edit API
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$data = new \wb\DataModel();
// add a Commons category
$statement = new \wb\StatementCommonsCategory( 'P373', 'Test category name' );
$data->addClaim( $statement );
// set a new label value
$label = \wb\Label( 'en', "New label" );
$data->setLabel( $label );
// save
\wm\Wikidata::instance()->editEntity(
'id' => 'Q4115189',
'data' => $data->getJSON(),
] );
```
### Upload API query
Uploading a file requires to respect the [RFC1341](https://tools.ietf.org/html/rfc1341) about an HTTP multipart request.
Well, we made it easy:
```
<?php
require 'boz-mw/autoload.php';
// this can be an URL or a local pathname
$photo_url = 'http://.../libre-image.jpg';
$wiki->upload( [
'comment' => 'upload file about...',
'text' => 'bla bla [[bla]]',
'filename' => 'Libre image.jpg',
\network\ContentDisposition::createFromNameURLType( 'file', $photo_url, 'image/jpg' ),
] );
```
NOTE: See [[ https://www.mediawiki.org/wiki/Special:ApiHelp/upload | MediaWiki API action=upload documentation ]].
Eventually see the [[ https://gitpull.it/source/boz-mw/browse/master/include/class-network%5CContentDisposition.php | ContentDisposition ]] class for some other constructors.
### Where to test
Please use your own wiki to test this framework or at least use the Wikimedia Wikis' Sandboxes!
Some known pages you can destroy:
* https://www.wikidata.org/wiki/Q4115189
* https://it.wikipedia.org/wiki/Wikipedia:Pagina_delle_prove_di_Wikidata
* https://en.wikipedia.org/wiki/Wikipedia:Wikidata/Wikidata_Sandbox
* etc.
### Other examples?
Feel free to fork and improve this documentation! Or just look inside the `/include` directory where there is some inline documentation for you!
## Troubleshooting
You can enable debug mode with `bozmw_debug()`. Example:
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
bozmw_debug();
// other code
```
## Known usages
* [MediaWikiOrphanizerBot](https://github.com/valerio-bozzolan/MediaWikiOrphanizerBot)
* [ItalianWikipediaDeletionBot](https://github.com/valerio-bozzolan/ItalianWikipediaDeletionBot)
* [ItalianWikipediaListAdmins](https://github.com/valerio-bozzolan/ItalianWikipediaListAdmins)
* [Wikimedia Commons volleyball players uploader bot](https://gitpull.it/source/Wikimedia-Valerio-Bozzolan-bot-tasks/browse/master/2019-05-commons-volleyball-players-upload/)
* [2018 MiBACT Wikidata fixed](https://github.com/valerio-bozzolan/Wikimedia-Valerio-Bozzolan-bot-tasks/tree/master/2018-09-mibact-fixer)
* [2018 Wiki loves monuments CH](https://github.com/valerio-bozzolan/Wikimedia-Valerio-Bozzolan-bot-tasks/tree/master/2018-08-wiki-loves-monuments-switzerland)
* [wiki-users-leaflet](https://github.com/valerio-bozzolan/wiki-users-leaflet/) hosted at [WMF Labs](https://tools.wmflabs.org/it-wiki-users-leaflet/)
This is `boz-mw`, //another MediaWiki API handler in PHP// with batteries included! It has a tons of features that will make your head spin!
This is a library to interact with MediaWiki and Wikibase APIs. There are also some [[ first_steps_with_boz-mw/tools/ | boz-mw command line tools ]].
## Features
You may ask what we can offer to you:
* read/write support for Wikidata
* read/write support for Wikimedia Commons' **Structured Data**
* **file upload** support for Wikimedia Commons
* support for some other known wiki(s)
* support for your custom wiki
* lightweight project, well designed using [[ https://en.wikipedia.org/wiki/Object-oriented_programming | OOP ]]
Actually, this framework is useful for:
* developers, to create bots
* command line users for our [[ #Command line tools ]]
## Download
```
git clone https://gitpull.it/source/boz-mw.git
```
## Command line tools
See [[ first_steps_with_boz-mw/tools/ | command line tools ]].
### Command line script `replace.php`
The [replace.php](https://gitpull.it/source/boz-mw/browse/master/tools/#replace-script-tt-class-remarkup) allows you to do some sobstitutions in a wiki.
### Command line script `mega-export.php`
The [mega-export.php](https://gitpull.it/source/boz-mw/browse/master/tools/#mega-export-tt-class-remarkup) allows you to export the _full_ page history of whatever page.
## API framework showcase
Here some usage examples.
### Start: select your wiki
First of all you should init a wiki:
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
// load Wikidata
$wikidata = wikidata();
// load Wikidata (this is the same)
// $wikidata = wiki( 'wikidatawiki' );
// load Wikidata (this is the same)
// $wikidata = \wm\Wikidata::instance();
// load Wikipedia in Italian (this is the same)
$itwiki = itwiki();
// load Wikipedia in Italian (this is the same)
// $itwiki = wiki( 'itwiki' );
// load Wikimedia Commons
$commons = commons();
// load Wikimedia Commons (this is the same)
// $commons = wiki( 'commonswiki' );
// load Wikimedia Commons (this is the same)
// $commons = \wm\Commons::instance();
// load Meta-Wiki
$meta = meta();
// load Meta-wiki (this is the same)
// $meta = wiki( 'metawiki' );
// load Meta-wiki this is the same
// $meta = \wm\MetaWiki::instance();
```
### Basic API query
To obtain a simple information from the server (no continuation support):
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
// load it.wiki
$wiki = itwiki();
$response =
$wiki->fetch( [
'action' => 'query',
'prop' => 'info',
'titles' => 'Pagina principale',
] );
// get the first result (the only one)
$page = $response->query->pages[ 0 ];
// show interesting information
print_r( $page->title );
print_r( $page->pageid );
```
Note: See [[ https://meta.wikimedia.org/w/api.php?action=help&modules=query | MediaWiki API action=query documentation ]].
### API query with continuation
To obtain a long result set from the server (with continuation support):
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wiki = itwiki();
$request =
$wiki->createQuery( [
'action' => 'query',
'list' => 'categorymembers',
'cmtitle' => 'Categoria:Software con licenza GNU GPL',
] );
foreach( $request as $response ) {
$pages = $response->query->categorymembers ?? null;
foreach( $pages as $page ) {
// do something
var_dump( $page->pageid );
var_dump( $page->ns );
var_dump( $page->title );
print_r( $page );
}
}
```
NOTE: See [[ https://meta.wikimedia.org/w/api.php?action=help&modules=query%2Bcategorymembers | MediaWiki API action=query list=categorymembers documentation ]].
### Login and Edit API query
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wiki = itwiki();
// insert here your wiki username and password
$user = '';
$password = '';
$wiki->login( $user, $password );
$wiki->edit( [
'title' => 'Wikipedia:Pagina delle prove',
'text' => 'My test wikitext with boz-mw (sorry for this test)',
'summary' => 'My test edit summary with boz-mw (sorry for this test)',
] );
```
NOTE: See [[ https://mediawiki.org/w/api.php?action=help&modules=edit | MediaWiki action=edit documentation ]]. Yes, the `token` parameter is automatically handled for you automagically.
You can also call `login()` without parameters if you specify a global username and password on the top of your script:
```
\mw\API::$DEFAULT_USERNAME = '':
\mw\API::$DEFAULT_PASSWORD = '';
```
### Wikidata SPARQL query
What if you want to list all the [cats from Wikidata](https://query.wikidata.org/#%23Cats%0ASELECT%20%3Fitem%20%3FitemLabel%20%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ146.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D)?
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wikidata = wikidata();
// you should know how to build a SPARQL query
$query = 'SELECT ?item ?itemLabel WHERE {';
$query .= ' ?item wdt:P31 wd:Q146 ';
$query .= ' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } ';
$query .= '}';
// query Wikidata and decode the response
$rows = $wikidata::querySPARQL( $query );
// for each cat
foreach( $rows as $row ) {
// example: 'http://www.wikidata.org/entity/Q5317221'
$url = $row->item->value;
// example: 'Q5317221'
$id = basename( $url );
// example: 'Dusty the Klepto Kitty'
$itemLabel = $row->itemLabel->value;
echo "Found cat ID: $id. Name: $itemLabel \n";
}
```
### Wikidata edit API
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$data = new \wb\DataModel();
// add a Commons category
$statement = new \wb\StatementCommonsCategory( 'P373', 'Test category name' );
$data->addClaim( $statement );
// set a new label value
$label = \wb\Label( 'en', "New label" );
$data->setLabel( $label );
// save
\wm\Wikidata::instance()->editEntity(
'id' => 'Q4115189',
'data' => $data->getJSON(),
] );
```
### Upload API query
Uploading a file requires to respect the [RFC1341](https://tools.ietf.org/html/rfc1341) about an HTTP multipart request.
Well, we made it easy:
```
<?php
require 'boz-mw/autoload.php';
// this can be an URL or a local pathname
$photo_url = 'http://.../libre-image.jpg';
$wiki->upload( [
'comment' => 'upload file about...',
'text' => 'bla bla [[bla]]',
'filename' => 'Libre image.jpg',
\network\ContentDisposition::createFromNameURLType( 'file', $photo_url, 'image/jpg' ),
] );
```
NOTE: See [[ https://www.mediawiki.org/wiki/Special:ApiHelp/upload | MediaWiki API action=upload documentation ]].
Eventually see the [[ https://gitpull.it/source/boz-mw/browse/master/include/class-network%5CContentDisposition.php | ContentDisposition ]] class for some other constructors.
### Where to test
Please use your own wiki to test this framework or at least use the Wikimedia Wikis' Sandboxes!
Some known pages you can destroy:
* https://www.wikidata.org/wiki/Q4115189
* https://it.wikipedia.org/wiki/Wikipedia:Pagina_delle_prove_di_Wikidata
* https://en.wikipedia.org/wiki/Wikipedia:Wikidata/Wikidata_Sandbox
* etc.
### Other examples?
Feel free to fork and improve this documentation! Or just look inside the `/include` directory where there is some inline documentation for you!
## Troubleshooting
You can enable debug mode with `bozmw_debug()`. Example:
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
bozmw_debug();
// other code
```
## Known usages
* [MediaWikiOrphanizerBot](https://github.com/valerio-bozzolan/MediaWikiOrphanizerBot)
* [ItalianWikipediaDeletionBot](https://github.com/valerio-bozzolan/ItalianWikipediaDeletionBot)
* [ItalianWikipediaListAdmins](https://github.com/valerio-bozzolan/ItalianWikipediaListAdmins)
* [Wikimedia Commons volleyball players uploader bot](https://gitpull.it/source/Wikimedia-Valerio-Bozzolan-bot-tasks/browse/master/2019-05-commons-volleyball-players-upload/)
* [2018 MiBACT Wikidata fixed](https://github.com/valerio-bozzolan/Wikimedia-Valerio-Bozzolan-bot-tasks/tree/master/2018-09-mibact-fixer)
* [2018 Wiki loves monuments CH](https://github.com/valerio-bozzolan/Wikimedia-Valerio-Bozzolan-bot-tasks/tree/master/2018-08-wiki-loves-monuments-switzerland)
* [wiki-users-leaflet](https://github.com/valerio-bozzolan/wiki-users-leaflet/) hosted at [WMF Labs](https://tools.wmflabs.org/it-wiki-users-leaflet/)
This is `boz-mw`, //another MediaWiki API handler in PHP// with batteries included! It has a tons of features that will make your head spin!
This is a library to interact with MediaWiki and Wikibase APIs. There are also some [[ first_steps_with_boz-mw/tools/ | boz-mw command line tools ]].
## Features
You may ask what we can offer to you:
* read/write support for Wikidata
* read/write support for Wikimedia Commons' **Structured Data**
* **file upload** support for Wikimedia Commons
* support for some other known wiki(s)
* support for your custom wiki
* lightweight project, well designed using [[ https://en.wikipedia.org/wiki/Object-oriented_programming | OOP ]]
Actually, this framework is useful for:
* developers, to create bots
* command line users for our [[ #Command line tools ]]
## Download
```
git clone https://gitpull.it/source/boz-mw.git
```
## Command line tools
See [[ first_steps_with_boz-mw/tools/ | command line tools ]].
### Command line script `replace.php`
The [replace.php](https://gitpull.it/source/boz-mw/browse/master/tools/#replace-script-tt-class-remarkup) allows you to do some sobstitutions in a wiki.
### Command line script `mega-export.php`
The [mega-export.php](https://gitpull.it/source/boz-mw/browse/master/tools/#mega-export-tt-class-remarkup) allows you to export the _full_ page history of whatever page.
## API framework showcase
Here some usage examples.
### Start: select your wiki
First of all you should init a wiki:
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
// load Wikidata
$wikidata = wikidata();
// load Wikidata (this is the same)
// $wikidata = wiki( 'wikidatawiki' );
// load Wikidata (this is the same)
// $wikidata = \wm\Wikidata::instance();
// load Wikipedia in Italian (this is the same)
$itwiki = itwiki();
// load Wikipedia in Italian (this is the same)
// $itwiki = wiki( 'itwiki' );
// load Wikimedia Commons
$commons = commons();
// load Wikimedia Commons (this is the same)
// $commons = wiki( 'commonswiki' );
// load Wikimedia Commons (this is the same)
// $commons = \wm\Commons::instance();
// load Meta-Wiki
$meta = meta();
// load Meta-wiki (this is the same)
// $meta = wiki( 'metawiki' );
// load Meta-wiki this is the same
// $meta = \wm\MetaWiki::instance();
```
### Basic API query
To obtain a simple information from the server (no continuation support):
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
// load it.wiki
$wiki = itwiki();
$response =
$wiki->fetch( [
'action' => 'query',
'prop' => 'info',
'titles' => 'Pagina principale',
] );
// get the first result (the only one)
$page = $response->query->pages[ 0 ];
// show interesting information
print_r( $page->title );
print_r( $page->pageid );
```
Note: See [[ https://meta.wikimedia.org/w/api.php?action=help&modules=query | MediaWiki API action=query documentation ]].
### API query with continuation
To obtain a long result set from the server (with continuation support):
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wiki = itwiki();
$request =
$wiki->createQuery( [
'action' => 'query',
'list' => 'categorymembers',
'cmtitle' => 'Categoria:Software con licenza GNU GPL',
] );
foreach( $request as $response ) {
$pages = $response->query->categorymembers ?? null;
foreach( $pages as $page ) {
// do something
var_dump( $page->pageid );
var_dump( $page->ns );
var_dump( $page->title );
print_r( $page );
}
}
```
NOTE: See [[ https://meta.wikimedia.org/w/api.php?action=help&modules=query%2Bcategorymembers | MediaWiki API action=query list=categorymembers documentation ]].
### Login and Edit API query
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wiki = itwiki();
// insert here your wiki username and password
$user = '';
$password = '';
$wiki->login( $user, $password );
$wiki->edit( [
'title' => 'Special:Nothing'Wikipedia:Pagina delle prove',
'text' => 'My test wikitext't with boz-mw (sorry for this test)',
'summary' => 'My test edit summary'ry with boz-mw (sorry for this test)',
] );
```
NOTE: See [[ https://mediawiki.org/w/api.php?action=help&modules=edit | MediaWiki action=edit documentation ]]. Yes, the `token` parameter is automatically handled for you automagically.
You can also call `login()` without parameters if you specify a global username and password on the top of your script:
```
\mw\API::$DEFAULT_USERNAME = '':
\mw\API::$DEFAULT_PASSWORD = '';
```
### Wikidata SPARQL query
What if you want to list all the [cats from Wikidata](https://query.wikidata.org/#%23Cats%0ASELECT%20%3Fitem%20%3FitemLabel%20%0AWHERE%20%0A%7B%0A%20%20%3Fitem%20wdt%3AP31%20wd%3AQ146.%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D)?
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$wikidata = wikidata();
// you should know how to build a SPARQL query
$query = 'SELECT ?item ?itemLabel WHERE {';
$query .= ' ?item wdt:P31 wd:Q146 ';
$query .= ' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } ';
$query .= '}';
// query Wikidata and decode the response
$rows = $wikidata::querySPARQL( $query );
// for each cat
foreach( $rows as $row ) {
// example: 'http://www.wikidata.org/entity/Q5317221'
$url = $row->item->value;
// example: 'Q5317221'
$id = basename( $url );
// example: 'Dusty the Klepto Kitty'
$itemLabel = $row->itemLabel->value;
echo "Found cat ID: $id. Name: $itemLabel \n";
}
```
### Wikidata edit API
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
$data = new \wb\DataModel();
// add a Commons category
$statement = new \wb\StatementCommonsCategory( 'P373', 'Test category name' );
$data->addClaim( $statement );
// set a new label value
$label = \wb\Label( 'en', "New label" );
$data->setLabel( $label );
// save
\wm\Wikidata::instance()->editEntity(
'id' => 'Q4115189',
'data' => $data->getJSON(),
] );
```
### Upload API query
Uploading a file requires to respect the [RFC1341](https://tools.ietf.org/html/rfc1341) about an HTTP multipart request.
Well, we made it easy:
```
<?php
require 'boz-mw/autoload.php';
// this can be an URL or a local pathname
$photo_url = 'http://.../libre-image.jpg';
$wiki->upload( [
'comment' => 'upload file about...',
'text' => 'bla bla [[bla]]',
'filename' => 'Libre image.jpg',
\network\ContentDisposition::createFromNameURLType( 'file', $photo_url, 'image/jpg' ),
] );
```
NOTE: See [[ https://www.mediawiki.org/wiki/Special:ApiHelp/upload | MediaWiki API action=upload documentation ]].
Eventually see the [[ https://gitpull.it/source/boz-mw/browse/master/include/class-network%5CContentDisposition.php | ContentDisposition ]] class for some other constructors.
### Where to test
Please use your own wiki to test this framework or at least use the Wikimedia Wikis' Sandboxes!
Some known pages you can destroy:
* https://www.wikidata.org/wiki/Q4115189
* https://it.wikipedia.org/wiki/Wikipedia:Pagina_delle_prove_di_Wikidata
* https://en.wikipedia.org/wiki/Wikipedia:Wikidata/Wikidata_Sandbox
* etc.
### Other examples?
Feel free to fork and improve this documentation! Or just look inside the `/include` directory where there is some inline documentation for you!
## Troubleshooting
You can enable debug mode with `bozmw_debug()`. Example:
```
<?php
require 'boz-mw/autoload-with-laser-cannon.php';
bozmw_debug();
// other code
```
## Known usages
* [MediaWikiOrphanizerBot](https://github.com/valerio-bozzolan/MediaWikiOrphanizerBot)
* [ItalianWikipediaDeletionBot](https://github.com/valerio-bozzolan/ItalianWikipediaDeletionBot)
* [ItalianWikipediaListAdmins](https://github.com/valerio-bozzolan/ItalianWikipediaListAdmins)
* [Wikimedia Commons volleyball players uploader bot](https://gitpull.it/source/Wikimedia-Valerio-Bozzolan-bot-tasks/browse/master/2019-05-commons-volleyball-players-upload/)
* [2018 MiBACT Wikidata fixed](https://github.com/valerio-bozzolan/Wikimedia-Valerio-Bozzolan-bot-tasks/tree/master/2018-09-mibact-fixer)
* [2018 Wiki loves monuments CH](https://github.com/valerio-bozzolan/Wikimedia-Valerio-Bozzolan-bot-tasks/tree/master/2018-08-wiki-loves-monuments-switzerland)
* [wiki-users-leaflet](https://github.com/valerio-bozzolan/wiki-users-leaflet/) hosted at [WMF Labs](https://tools.wmflabs.org/it-wiki-users-leaflet/)
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register