{"id":24182981,"url":"https://github.com/ms609/citation-bot","last_synced_at":"2025-04-06T21:15:18.769Z","repository":{"id":33330627,"uuid":"36975411","full_name":"ms609/citation-bot","owner":"ms609","description":"Citation bot is a tool to expand and format references at Wikipedia. It retrieves citation data from a variety of sources including CrossRef (DOI), PMID, PMC and JSTOR, and returns a formatted citation.  Report bugs at https://en.wikipedia.org/wiki/User_talk:Citation_bot","archived":false,"fork":false,"pushed_at":"2025-02-15T15:26:19.000Z","size":29811,"stargazers_count":58,"open_issues_count":1,"forks_count":25,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-02-15T15:49:43.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://en.wikipedia.org/wiki/User:Citation_bot/use","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ms609.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-06T09:55:48.000Z","updated_at":"2025-02-15T15:26:22.000Z","dependencies_parsed_at":"2023-10-24T21:26:19.135Z","dependency_job_id":"8b016f88-c062-4b34-b43a-be04343429f8","html_url":"https://github.com/ms609/citation-bot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms609%2Fcitation-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms609%2Fcitation-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms609%2Fcitation-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ms609%2Fcitation-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ms609","download_url":"https://codeload.github.com/ms609/citation-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247550690,"owners_count":20956987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-13T08:45:55.400Z","updated_at":"2025-04-06T21:15:18.736Z","avatar_url":"https://github.com/ms609.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://github.com/ms609/citation-bot/actions/workflows/test-suite.yml/badge.svg)](https://github.com/ms609/citation-bot/actions/workflows/test-suite.yml)\n[![Build Status](https://github.com/ms609/citation-bot/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ms609/citation-bot/actions/workflows/codeql-analysis.yml)\n[![Build Status](https://github.com/ms609/citation-bot/actions/workflows/php-static.yml/badge.svg)](https://github.com/ms609/citation-bot/actions/workflows/php-static.yml)\n[![Build Status](https://github.com/ms609/citation-bot/actions/workflows/php-static2.yml/badge.svg)](https://github.com/ms609/citation-bot/actions/workflows/php-static2.yml)\n[![Build Status](https://github.com/ms609/citation-bot/actions/workflows/php-security.yml/badge.svg)](https://github.com/ms609/citation-bot/actions/workflows/php-security.yml)\n[![codecov](https://codecov.io/gh/ms609/citation-bot/branch/master/graph/badge.svg)](https://codecov.io/gh/ms609/citation-bot)\n[![Project Status: Inactive - The project has reached a stable, usable state but is no longer being actively developed; support/maintenance will be provided as time allows.](https://www.repostatus.org/badges/latest/inactive.svg)](https://www.repostatus.org/#inactive)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n[![PHP ](https://img.shields.io/badge/PHP-8.2-blue.svg)](https://www.php.net)\n[![GitHub issues](https://img.shields.io/github/issues/ms609/citation-bot.png)](https://github.com/ms609/citation-bot/issues)\n\n\n# Citation bot\n\n## GitHub repository details\nThere are one to two main branches of the bot: \n- The **master** code is implemented at https://citations.toolforge.org/, and is intended for public use.\n- When needed, the **development** branch is intended for major restructuring and testing, and is implemented at https://citations-dev.toolforge.org/ .  \n\n## Overview\n\nThis is some basic documentation about what this bot is and how some of the parts connect.\n\nThis is more properly a bot-gadget-tool combination. The parts are:\n\n* DOIBot, found in `index.html` (web frontend) and `process_page.php` (information is\n  POSTed to this and it does the citation expansion; backend). This automatically\n  posts a new page revision with expanded citations and thus requires a bot account.\n  All activity takes place on Tool Labs.\n* Citation expander (https://en.wikipedia.org/wiki/MediaWiki:Gadget-citations.js) + `gadgetapi.php`. This\n  is comprises an Ajax front-end in the on-wiki gadget and a PHP backend API.\n* `generate_template.php` creates the wiki reference given an identifier (for example: https://citations.toolforge.org/generate_template.php?doi=10.1109/SCAM.2013.6648183)\n\nBugs and requested changes are listed here: https://en.wikipedia.org/wiki/User_talk:Citation_bot.\n\n## Structure\n\nBasic structure of a Citation bot script:\n* the `env.php` that defines configuration constants (you can create it from `env.php.example`)\n* the `setup.php` that sets up the functions needed (usually, you don't need to modify this file)\n* the Page functions to fetch/expand/post the page's text\n\n\nA quick tour of the main files:\n* `constants.php`: constants defined\n* `WikipediaBot.php`: functions to facilitate HTTP access to the Wikipedia API.\n* `NameTools.php`: defines name functions\n* `setup.php`: sets up needed functions, requires most of the other files listed here\n* `expandFns.php`: a variety of functions\n* `apiFunctions.php`: sets up needed functions for expanding pmid/doi/etc\n* `Zotero.php`: URL expansion related functions organized in a static class \n\nClass files:\n* `Page.php`: Represents an individual page to expand citations on. Key methods are\n  `Page::get_text_from()`, `Page::expand_text()`, and `Page::write()`.\n* `Template.php`: most of the actual expansion happens here.\n  `Template::add_if_new()` is generally (but not always) used to add\n   parameters to the updated template; `Template::tidy()` cleans up the\n   template, but may add parameters as well and have side effects.\n* `Comment.php`: Handles comments, nokwiki, etc. tags\n* `Parameter.php`: contains information about template parameter names, values,\n   and metadata, and methods to parse template parameters.\n\n## Style and structure notes\n\nConstants and definitions should be provided in `constants.php`.\nClasses should be in individual files. The code is generally written densely. \nBeware assignments in conditionals, one-line `if`/`foreach`/`else` statements, \nand action taking place through method calls that take place in assignments or equality checks. \nAlso beware the difference between `else if` and `elseif`.\n\n## Deployment\n\nThe bot requires PHP \u003e= 8.2.\n\nTo run the bot from a new environment, you will need to create an `env.php` file (if one doesn't already exist) that sets the needed authentication tokens as environment variables. To do this, you can rename `env.php.example` to `env.php`, set the variables in the file, and then make sure the file is not world readable or writable:\n\n    chmod o-rwx env.php\n\n To run the bot as a webservice from WM Toolforge:\n\n    become citations[-dev]\n    webservice stop\n    webservice --backend=kubernetes php8.2 start\n\nOr for testing in the shell:\n\n    webservice --backend=kubernetes php8.2 shell\n\nBefore entering the k8s shell, it may be necessary to install phpunit (as wget is not available in the k8s shell).\n\n## Running on the command line\nIn order to run on the command line one needs OAuth tokens as documented in `env.php.example` (there are additional API keys that are needed to run some functions).  Change BOT_USER_AGENT in `setup.php` to something else. Use composer to `composer require mediawiki/oauthclient:dev-master`.  Then the bot can be run such as:\n\n    /usr/bin/php ./process_page.php \"Covid Watch|Water|COVID-19_apps\" --slow --savetofiles\n    \nThe command line tool will also accept `page_list.txt` and `page_list2.txt` as page names.  In those cases the bot expect a file of such name to contain a single line of | seperated page names.  This code requires PHP 8.2 with optional packages included: php82-mbstring php82-sockets php82-opcache php82-openssl php82-xmlrpc php82-gettext php82-curl php82-intl php82-iconv\n\nCommand line parameters:\n* `--slow` - retrieve bibcodes and expand urls\n* `--savetofiles` - save processed pages as files (with .md extension) instead of submitting them to Wikipedia\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fms609%2Fcitation-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fms609%2Fcitation-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fms609%2Fcitation-bot/lists"}