RailWAM/Library

The **RailWAM Library** provides several WAM-related JavaScript methods for use in other scripts.

***NOTE:** This library is intended for developers. You do not need to import it for a regular RailWAM installation.*

## Usage

Import the RailWAM Library by adding the following statement to your JavaScript code:

```
mw.loader.implement('rw.api',['/load.php?debug=false&lang=en&mode=articles&skin=oasis&missingCallback=importArticleMissing&articles=u%3Adev%3AMediaWiki%3ARailWAM%2Flib.js&only=scripts'], {}, {});

```

To ensure that the library is ready before calling any of its methods, attach a function that executes dependent code to the `rw.api.ready` hook. This function will be executed when the library is ready.

```
mw.hook('rw.api.ready').add(myFunctionName);

```
**For wikis using RailWAM**, this library is already imported. However, you should still use the `rw.api.ready` hook for any code dependent on it.

## Global Values

These global values can be accessed through `rw.config`.

 `minDate` | number
 `wamLangs` | array

## Methods

### `rw.data`

* {string|number|array} log - Log page name(s)
* {function} success - Function to be executed after data is loaded

  \*{Object} data - WAM data
* {function} error - Function to be executed on error

  \*@param {Object} Empty object
***Required:***
**`{number} dateId`** - date of latest day to retrieve data for in seconds
**`{number} days`** - Number of days to retrieve WAM data for
***Optional:***
**`{boolean} excludeBlacklist`** - Exclude wikis with Content Warning
**`{string} inURL`** - Search wiki URL fragments
**`{number} wikis`** - Number of wikis to retrieve data for (max 20)
**`{Object} logged`** - Object containing logged data
**`{number} offset`** - Entries offset from data beginning
**`{string} sortDirection`** - ASC (ascending) or DESC (descending)
**`{number} verticalId`** - Vertical id of wikis
**`{number} wikiId`** - numerical wiki ID
**`{string} wikiLang`** - Language of wikis
**`{function} callback`** - Executed once all data has been retrieved

**`{Object} data`** - All retrieved data
**`{number} dateId`** - See "dateId" above
**`{function} complete`** - Executed upon completion (success or error) of each AJAX request

**`{Object} data`** - All retrieved data (at execution time)
**`{number} dateId`** - Date of this day in seconds
**`{function} success`** - Executed upon success of each AJAX request

**`{Object} data`** - All retrieved data (at execution time)
**`{number} dateId`** - Date of this day in seconds
**`{function} error`** - Executed upon failure of each AJAX request

**`{Object} data`** - All retrieved data (at execution time)
**`{number} dateId`** - Date of this day in seconds
**`{function} exists`** - Executed if day's has already been retrieved

**`{Object} data`** - All retrieved data (at execution time)
                                    \* {number} wikiId - numerical wiki ID
                                    \* {Object} logged - Object containing logged data
                                    \* {function} callback - Executed once all data has been retrieved
                                    \*   @param {Object} data - All retrieved data
                                    \*   @param {number} dateId - See "dateId" above
                                    \* {function} complete - Executed upon completion (success or error) of AJAX request
                                    \*   @param {Object} data - All retrieved data
                                    \*   @param {number} dateId - Date of this day in seconds
                                    \* {function} success - Executed upon success of AJAX request
                                    \*   @param {Object} data - All retrieved data
                                    \*   @param {number} dateId - Date of this day in seconds
                                    \* {function} error - Executed upon failure of AJAX request
                                    \*   @param {Object} data - All retrieved data
                                    \*   @param {number} dateId - Date of this day in seconds
                                     \* {Object} data - WAM data
                                     \* {string} log - Log page name
                                     \* {string} summary - Edit summary
                                     \* {boolean} bot - Whether this edit should be marked as a bot edit
                                                       ! NOTE: User must have the bot flag on their account !
                                     \* {function} callback - Executed after data logged
                                         \* {Object} data - See "data"
                                     \* {function} complete - Executed if AJAX request completes (succeeds or fails)
                                         \* {Object} data - See "data"
                                     \* {function} success - Executed if logging succeeds
                                         \* {Object} data - See "data"
                                     \* {function} error - Executed if logging fails
                                         \* {Object} data - See "data"