Clone this wiki locally
page = site.Pages['User:Apple/Sandbox'] page.delete(reason='Copyright violation')
Associated API: API:Delete
(optional) reason: Reason for deletion.
It is recommended to always include a clear deletion reason. (Default: empty string)
- The MediaWiki API allows you to omit the reason and generates a default reason. This functionality is not available through mwclient.
(optional) watch: If set to
True, also add this page to the logged-in user's watchlist. (Default:
(optional) unwatch: If set to
True, and this page is on the logged-in user's watchlist, remove it from the watchlist. (Default:
(optional) oldimage: Allows deleting an old revision of an file
(not the entire file description page) by specifying an
The page is deleted on the site and an entry is added to the deletion log. The method returns a dict with the following keys:
- 'title': the canonical title of the deleted page
- 'reason': the reason for deletion
- Because mwclient does not currrently support default reasons, this should always match the supplied reason.
- InsufficientPermission: The currently logged-in user does not have permission to delete the page.
APIError: Depending on the error's
- 'permissiondenied': The currently logged-in user does not have permission to delete the page.
May occur instead of
InsufficientPermissionin the case of a race condition where the user loses the delete right during the
- 'cantdelete': The page could not be deleted, usually because someone else already deleted it.
- 'unknown': Depends on error's "info" property. If set to "Unknown error: ``invalidoldimage''", indicates an invalid oldimage argument was passed.
- 'permissiondenied': The currently logged-in user does not have permission to delete the page. May occur instead of
- APIDisabledError: The site has disabled access through the MediaWiki API.
- MaximumRetriesExceeded: API call to perform the delete failed and was retried until all retries were exhausted.
Deleting a page normally, adding the page to the watchlist:
page = site.Pages['User:Apple/Sandbox'] page.delete(reason='Copyright violation', watch=True)
Deletes all file revisions of the file "Test.jpg" except the most recent one:
for page in site.Pages['File:Test.jpg'].imagehistory(): if page.has_key('archivename'): image.delete(reason='Testing', oldimage=page['archivename'])
Because it is always possible that another user may delete the file before mwclient, robust scripts should always catch APIError:
try: page = site.Pages['User:Apple/Sandbox'] page.delete(reason='Copyright violation', watch=True) except APIError, e: if e.code != 'cantdelete': # Okay if already deleted raise