Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
77fb0fe
Squashed commit of the following:
freephile Nov 25, 2025
f572ad5
ensure mobilediff is in the default list
freephile Nov 25, 2025
b1f8881
get the correct variable for 'denyFast'
freephile Nov 25, 2025
f323fb5
change preference config and function names around 418 HTTP header
freephile Nov 25, 2025
3337f3b
add Unit Test to cover the $denyFast branch
freephile Nov 25, 2025
5129a7f
refactor magic word "Special:" to a constant variable
freephile Nov 25, 2025
6929316
normalize list of specials and perform a single in_array check
freephile Nov 25, 2025
8480a87
update README
freephile Nov 25, 2025
2ad53d3
change tabs to spaces on new code
freephile Nov 25, 2025
e7c8982
Add resetForTesting() in stub, and tearDown() in test
freephile Nov 25, 2025
a03dd51
use I'm a teapot in HTTP header and message body
freephile Nov 25, 2025
c0f8d79
reformat lines wrapped at column 80
freephile Nov 25, 2025
3c61dae
Add docker-compose-ci and run ci on branch
freephile Nov 26, 2025
32ee503
phpcbf fixes for MediaWiki coding standards
freephile Nov 26, 2025
4badc36
expand require-dev; add scripts section
freephile Nov 26, 2025
cec1fe7
used for local development when running composer phpcs
freephile Nov 26, 2025
9a9d0fa
Add Config interface and update HooksTest for testUse418 flag
freephile Nov 26, 2025
cddfc43
do not ignore 'build' - it is a submodule and needs tracking
freephile Nov 26, 2025
c780dc9
satisfy MediaWiki coding standards with function docblocks
freephile Nov 26, 2025
83fa33b
simplify codesniffs
freephile Nov 27, 2025
23cb8cf
remove bad syntax (comments) from yaml
freephile Nov 27, 2025
262561e
fix CI in GitHub environment
freephile Nov 28, 2025
49ec45a
Add docs and fix "last" CI error
freephile Nov 28, 2025
528a7ae
Disable the ClassMatchesFilename phpcs sniff for our namespaced-stubs
freephile Nov 28, 2025
9fa0a85
remove the global config setup since these are unit tests, not integr…
freephile Nov 28, 2025
0f54394
refine setup and teardown of tests
freephile Nov 29, 2025
fe12054
skip Services tests in GitHub Actions with real MediaWiki
freephile Nov 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions .github/CI-SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# CI Setup - Docker-Based Local Testing

## ✅ Prerequisites

- Docker
- Docker Compose
- Make
- Git

## 🚀 Quick Start (Recommended)

### 1. Add docker-compose-ci as submodule
```bash
cd /home/greg/src/CrawlerProtection

# Remove build/ from .gitignore if present (it's a submodule now)
sed -i '/^build\/$/d' .gitignore

# Add the submodule
git submodule add https://github.com/gesinn-it-pub/docker-compose-ci.git build
git add .gitignore .gitmodules build Makefile
git commit -m "Add docker-compose-ci for local testing"
```

### 2. Initialize submodule (for fresh clones)
```bash
# When cloning the repo in the future, use:
git clone --recursive https://github.com/freephile/CrawlerProtection.git

# Or if already cloned without --recursive:
git submodule update --init --recursive
```

### 3. Run CI Tests
The `Makefile` is already configured. Just run:
```bash
make ci # Run all CI checks
make ci-coverage # Run with coverage
make bash # Enter container to run commands manually
make down # Stop containers
```

## 🔧 What Gets Tested

The `make ci` command runs:
- **Lint** - PHP syntax checking (parallel-lint)
- **PHPCS** - Code style validation (MediaWiki standards)
- **PHPUnit** - Unit tests

All in a container with the correct PHP version, extensions, and MediaWiki setup!

## 📋 Common Commands

```bash
# Run all tests
make ci

# Run specific tests inside container
make bash
> composer phpcs # Code style check
> composer phpcbf # Auto-fix code style
> composer phpunit # Run PHPUnit tests
> composer test # Run phpcs + phpunit

# Test with different MediaWiki versions
MW_VERSION=1.39 make ci
MW_VERSION=1.43 PHP_VERSION=8.3 make ci

# Clean up
make down
make clean
```

## 🌐 Access Wiki in Browser

Create `build/docker-compose.override.yml`:
```yaml
services:
wiki:
ports:
- 8080:8080
```

Then start: `make up` and visit http://localhost:8080

## 🔄 Update Docker CI

```bash
git submodule update --init --remote
```

## 📝 Environment Variables

Create `.env` file to customize:
```bash
MW_VERSION=1.43
PHP_VERSION=8.2
DB_TYPE=sqlite
EXTENSION=CrawlerProtection
```

## ⚡ Quick Fixes Before Commit

```bash
# Auto-fix code style issues
make bash
> composer phpcbf

# Check what will fail in CI
make ci
```

## 🐛 Troubleshooting

**"build directory not found"**
```bash
git submodule update --init --remote
```

**"Container keeps restarting"**
```bash
make down
make clean
make ci
```

**"Permission denied"**
```bash
sudo chmod -R 777 cache/
```

## 🎯 GitHub Actions Setup

Your `.github/workflows/ci.yml` already exists and will run automatically on:
- Pushes to `main` or `specialPageList` branches
- All pull requests

Check results at: https://github.com/freephile/CrawlerProtection/actions

## 🔗 Resources

- [docker-compose-ci documentation](https://github.com/gesinn-it-pub/docker-compose-ci)
- [MediaWiki coding conventions](https://www.mediawiki.org/wiki/Manual:Coding_conventions)
- Your GitHub Actions: https://github.com/freephile/CrawlerProtection/actions
56 changes: 56 additions & 0 deletions .github/DOCKER-CI-QUICKREF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Docker CI Quick Reference

## Setup (One Time)
```bash
git submodule add https://github.com/gesinn-it-pub/docker-compose-ci.git build
git add .gitignore .gitmodules build Makefile TESTING.md
git commit -m "Add docker-compose-ci for local testing"
```

## Daily Use

```bash
make ci # Run all checks (before commit)
make bash # Fix issues manually
> composer phpcbf # Auto-fix code style
make down # Clean up
```

## All Commands

| Command | Purpose |
|---------|---------|
| `make ci` | Run all CI checks (lint, phpcs, phpunit) |
| `make bash` | Enter container shell |
| `make up` | Start wiki (http://localhost:8080) |
| `make down` | Stop all containers |
| `make clean` | Remove all containers and volumes |

## Inside Container (`make bash`)

| Command | Purpose |
|---------|---------|
| `composer test` | Run phpcs + phpunit |
| `composer phpcs` | Check code style |
| `composer phpcbf` | Fix code style automatically |
| `composer phpunit` | Run unit tests |

## Test Different Versions

```bash
MW_VERSION=1.39 PHP_VERSION=8.1 make ci # Test MW 1.39 + PHP 8.1
MW_VERSION=1.43 PHP_VERSION=8.3 make ci # Test MW 1.43 + PHP 8.3
```

## Troubleshooting

```bash
make down && make clean # Nuclear option: clean everything
git submodule update --init --remote # Update docker-compose-ci
```

## See Also

- Full docs: `.github/CI-SETUP.md`
- Testing guide: `TESTING.md`
- Your CI runs: https://github.com/freephile/CrawlerProtection/actions
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- specialPageList # Add your development branch
pull_request:

env:
Expand Down Expand Up @@ -58,7 +59,7 @@ jobs:
- name: Lint
run: ./vendor/bin/parallel-lint --exclude node_modules --exclude vendor extensions/${{ env.EXTNAME }}
- name: PHP Code Sniffer
run: ./vendor/bin/phpcs -sp --standard=vendor/mediawiki/mediawiki-codesniffer/MediaWiki extensions/${{ env.EXTNAME }}
run: cd extensions/${{ env.EXTNAME }} && ../../vendor/bin/phpcs -sp

security:
name: Static Analysis
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ __pycache__/

# Distribution / packaging
.Python
build/
# do not ignore build because it is a submodule
# build/
develop-eggs/
dist/
downloads/
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "build"]
path = build
url = https://github.com/gesinn-it-pub/docker-compose-ci.git
27 changes: 27 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<ruleset name="CrawlerProtection">
<description>MediaWiki coding standards for CrawlerProtection extension</description>

<rule ref="../../vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" />
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
</rule>

<!-- Paths to check -->
<file>.</file>

<!-- Paths to ignore -->
<exclude-pattern>*/build/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*.phan/*</exclude-pattern>

<!-- Show progress -->
<arg name="colors"/>
<arg name="encoding" value="UTF-8"/>
<arg name="extensions" value="php"/>
<arg value="sp"/>

<!-- Memory limit -->
<ini name="memory_limit" value="512M"/>
</ruleset>
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-include .env
export

# setup for docker-compose-ci build directory
ifeq (,$(wildcard ./build/))
$(shell git submodule update --init --remote)
endif

EXTENSION=CrawlerProtection

# docker images
MW_VERSION?=1.43
PHP_VERSION?=8.2
DB_TYPE?=mysql
DB_IMAGE?="mariadb:11.2"

# composer
# Enables "composer update" inside of extension
# Leave empty/unset to disable, set to "true" to enable
COMPOSER_EXT?=

# nodejs
# Enables node.js related tests and "npm install"
# Leave empty/unset to disable, set to "true" to enable
NODE_JS?=

include build/Makefile
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# CrawlerProtection
Protect wikis against crawler bots

Protect wikis against crawler bots. CrawlerProtection denies **anonymous** user
access to certain MediaWiki action URLs and SpecialPages which are resource
intensive.

# Configuration

* `$wgCrawlerProtectedSpecialPages` - array of special pages to protect
(default: `[ 'mobilediff', 'recentchangeslinked', 'whatlinkshere' ]`).
Supported values are special page names or their aliases regardless of case.
You do not need to use the 'Special:' prefix. Note that you can fetch a full
list of SpecialPages defined by your wiki using the API and jq with a simple
bash one-liner like
`curl -s "[YOURWIKI]api.php?action=query&meta=siteinfo&siprop=specialpagealiases&format=json" | jq -r '.query.specialpagealiases[].aliases[]' | sort`
Of course certain Specials MUST be allowed like Special:Login so do not block
everything.
* `$wgCrawlerProtectionUse418` - drop denied requests in a quick way via
`die();` with
[418 I'm a teapot](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/418)
code (default: `false`)

67 changes: 67 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Local CI Testing with Docker

This extension uses [docker-compose-ci](https://github.com/gesinn-it-pub/docker-compose-ci) for local testing.

## Quick Start

```bash
# One-time setup (if not already done)
git submodule update --init --recursive

# Run all CI checks (lint, phpcs, phpunit)
make ci

# Auto-fix code style issues
make bash
> composer phpcbf

# Stop containers
make down
```

## Why Docker?

- ✅ Same environment as GitHub Actions CI
- ✅ Correct PHP version, extensions, and MediaWiki automatically
- ✅ No need to install MediaWiki locally
- ✅ Test against multiple MW/PHP versions easily
- ✅ Isolated from your local system

## Common Commands

```bash
make ci # Run all CI checks
make bash # Enter container shell
make up # Start wiki (http://localhost:8080)
make down # Stop containers
make clean # Remove containers and volumes
```

## Test Different Versions

```bash
# Test with MediaWiki 1.39 and PHP 8.1
MW_VERSION=1.39 PHP_VERSION=8.1 make ci

# Test with MediaWiki 1.43 and PHP 8.3
MW_VERSION=1.43 PHP_VERSION=8.3 make ci
```

## Available Composer Scripts

Inside the container (`make bash`):

```bash
composer test # Run phpcs + phpunit
composer phpcs # Check code style
composer phpcbf # Fix code style
composer phpunit # Run unit tests
```

## Update Docker CI

```bash
git submodule update --init --remote
```

See `.github/CI-SETUP.md` and `.github/DOCKER-CI-QUICKREF.md` for more details.
Loading