Skip to content

Commit

Permalink
Switching to autoloader file and updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbiRobb committed Feb 2, 2023
1 parent 90dd863 commit 5facab4
Show file tree
Hide file tree
Showing 38 changed files with 27 additions and 78 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
This project is a MediaWiki-bot intended for querying and manipulating data. It has a wide range of functions that come in handy when using the bot on a day to day basis.

## Installation
Download all files and save them in a place where PHP can access them. To then use the bot, create a new file and include the entrance file to all actions in your file.
Download all files and save them in a place where PHP can access them. To then use the bot, create a new file and include the autoload file.

require_once("src/bot.php");
require_once("src/autoload.php");

You can now create a new instance of the bot to work with.

Expand All @@ -13,21 +13,33 @@ You can now create a new instance of the bot to work with.
The correct url to the api can be found on special:version, it should end with `/api.php`

## Examples

### Logging in
This basic example consists of a simple login and logout.

require_once("src/bot.php");
require_once("src/autoload.php");

$bot = new Bot(<url to the api>);
var_dump($bot->login(<username>, <password>));
$bot->logout();

This successfully logs the bot in and out of a wiki, provided the url, username and password are correct. For querying data it is usually not necessary to log in, but some actions may require you to log in. It is generally recommended to log in to get access to higher limits to go easy on the servers of the wiki you are working on.

### Logging requests
If you are experiencing bugs or have trouble with requests failing, it is possible to log requests. To start the logger, just call

$bot->startLogging();

After this call all requests and responses will be logged in a log file. To stop logging just call

$bot->stopLogging();

The log entries contain timestamps, HTTP response codes, requested URLs, body sizes and time needed to execute the requests.

### Generating a list of all articles on a wiki
This example makes use of one of the provided generator methods to generate a list of all articles in a wiki.

require_once("src/bot.php");
require_once("src/autoload.php");

$bot = new Bot(<url to the api>);
$bot->login(<username>, <password>);
Expand All @@ -43,7 +55,7 @@ The method getAllpages returns a generator allowing to iterate over all pages in
### Expanding templates
This is a more advanced example, using the bot to expand the templates on a page, securely remove a parameter and then change the content of the article on the wiki.

require_once("src/bot.php");
require_once("src/autoload.php");

$bot = new Bot(<url to the api>);
$bot->login(<username>, <password>);
Expand Down
2 changes: 0 additions & 2 deletions src/allpages.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for all pages in a namespace
*
Expand Down
2 changes: 0 additions & 2 deletions src/allusers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all registered users on a wiki
*
Expand Down
2 changes: 0 additions & 2 deletions src/apimultirequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for performing multiple API-requests at the same time
*
Expand Down
2 changes: 0 additions & 2 deletions src/apirequest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests
*
Expand Down
9 changes: 9 additions & 0 deletions src/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Autoloader for the BottiBott v5 MediaWiki bot
* Will automatically include all relevant files to guarantee classes are loaded
*/
spl_autoload_register(function($class) {
require(strtolower($class) . ".php");
});
?>
2 changes: 0 additions & 2 deletions src/backlinks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for all pages linking a specific page
*
Expand Down
2 changes: 0 additions & 2 deletions src/bot.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing the entry point to all operations performed by the bot
*
Expand Down
4 changes: 1 addition & 3 deletions src/categories.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all categories of one or multiple oages
* A class for representing API-requests for all categories of one or multiple pages
*
* The class Categories allows the creation of API-requests for all categories of one or multiple given pages
*
Expand Down
2 changes: 0 additions & 2 deletions src/categorymembers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all members of a category
*
Expand Down
2 changes: 0 additions & 2 deletions src/content.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for the content of pages
*
Expand Down
2 changes: 0 additions & 2 deletions src/delete.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for deleting a page
*
Expand Down
2 changes: 0 additions & 2 deletions src/edit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests of edits
*
Expand Down
2 changes: 0 additions & 2 deletions src/fileurl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests of getting the url of files
*
Expand Down
2 changes: 0 additions & 2 deletions src/fileusage.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for fileusage
*
Expand Down
2 changes: 0 additions & 2 deletions src/langlinks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for langlinks
*
Expand Down
2 changes: 0 additions & 2 deletions src/links.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all pages a page links to
*
Expand Down
2 changes: 0 additions & 2 deletions src/logevents.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all events logged
*
Expand Down
2 changes: 0 additions & 2 deletions src/logger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for logging requests and responses
*
Expand Down
2 changes: 0 additions & 2 deletions src/login.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for a login
*
Expand Down
2 changes: 0 additions & 2 deletions src/logout.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for a logout
*
Expand Down
2 changes: 0 additions & 2 deletions src/move.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for moving a page
*
Expand Down
2 changes: 0 additions & 2 deletions src/parser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing template Parser
*
Expand Down
2 changes: 0 additions & 2 deletions src/parsetree.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for parsetrees
*
Expand Down
2 changes: 0 additions & 2 deletions src/redirect.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for checking if a page is a redirect
*
Expand Down
2 changes: 0 additions & 2 deletions src/revisions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for revisions
*
Expand Down
2 changes: 0 additions & 2 deletions src/revisionusers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for users of revisions
*
Expand Down
2 changes: 0 additions & 2 deletions src/systemeditcount.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for editcounts
*
Expand Down
2 changes: 0 additions & 2 deletions src/templaterebuilder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing TemplateRebuilder
*
Expand Down
2 changes: 0 additions & 2 deletions src/token.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class representing API-requests for a token
*
Expand Down
2 changes: 0 additions & 2 deletions src/transclusions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all pages transcluding a specific page
*
Expand Down
2 changes: 0 additions & 2 deletions src/undo.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for reverting edits
*
Expand Down
2 changes: 0 additions & 2 deletions src/upload.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for uploading
*
Expand Down
2 changes: 0 additions & 2 deletions src/uploadbyurl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for uploading by url
*
Expand Down
2 changes: 0 additions & 2 deletions src/usercontribs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for all contributions a user has done
*
Expand Down
2 changes: 0 additions & 2 deletions src/userrights.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for userrights
*
Expand Down
2 changes: 0 additions & 2 deletions src/wikitext.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for expanded wikitext
*
Expand Down
2 changes: 0 additions & 2 deletions src/wikitextparser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
spl_autoload_register(function($class) {require(strtolower($class).".php");});

/**
* A class for representing API-requests for parsing wiki text
*
Expand Down

0 comments on commit 5facab4

Please sign in to comment.