Skip to content

Commit 333596c

Browse files
jeffw16Copilot
andauthored
Add Special:MobileDiff to blocklist (#4)
* Special:MobileDiff * Add coding conventions files for GitHub Copilot (#11) * Add coding conventions * Add applyTo for PHP instructions * Add extension-specific coding standards * Refactoring * Update tests/phpunit/stubs.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/phpunit/stubs.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update tests/phpunit/stubs.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix stub issue * Fix code styles --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1090a09 commit 333596c

File tree

7 files changed

+417
-5
lines changed

7 files changed

+417
-5
lines changed

.github/instructions/php.instructions.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ See Manual:Coding conventions#Indenting and alignment.
266266

267267
For anonymous functions, prefer arrow functions when the anonymous function consists only of one line. Arrow functions are more concise and readable than regular anonymous functions and neatly side-steps formatting issues that arise with single-line anonymous functions.
268268

269+
### Type declarations for variables
270+
Avoid using PHPDoc comments to declare types for local variables. Instead, use native type declarations for function parameters and return types, and use static analysis tools (like PHPStan or Psalm) to infer types of local variables.
271+
272+
Example:
273+
274+
```php
275+
private static string $nameOfVariable = '';
276+
```
277+
278+
269279
### Type declarations in function parameters
270280

271281
Use native type declarations and return type declarations when applicable. (But see #Don't add type declarations for "big" legacy classes below.)

.gitignore

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
*.manifest
32+
*.spec
33+
34+
# Unit test / coverage reports
35+
htmlcov/
36+
.tox/
37+
.nox/
38+
.coverage
39+
.coverage.*
40+
.cache
41+
nosetests.xml
42+
coverage.xml
43+
*.cover
44+
*.py,cover
45+
.hypothesis/
46+
.pytest_cache/
47+
48+
# Virtual environments
49+
venv/
50+
ENV/
51+
env/
52+
.venv/
53+
.env
54+
55+
# IDE specific files
56+
.idea/
57+
.vscode/
58+
*.swp
59+
*.swo
60+
*~
61+
.project
62+
.pydevproject
63+
.settings/
64+
*.sublime-project
65+
*.sublime-workspace
66+
67+
# OS specific files
68+
.DS_Store
69+
Thumbs.db
70+
*.bak
71+
72+
# Logs
73+
*.log
74+
logs/
75+
*.log.*
76+
77+
# Database files
78+
*.db
79+
*.sqlite
80+
*.sqlite3
81+
82+
# Environment variables
83+
.env
84+
.env.local
85+
.env.*.local
86+
87+
# Temporary files
88+
*.tmp
89+
*.temp
90+
tmp/
91+
temp/
92+
93+
# Jupyter Notebook
94+
.ipynb_checkpoints
95+
96+
# mypy
97+
.mypy_cache/
98+
.dmypy.json
99+
dmypy.json
100+
101+
# Pyre type checker
102+
.pyre/
103+
104+
# Project specific
105+
data/
106+
output/
107+
*.pkl
108+
*.pickle
109+
*.model
110+
*.h5
111+
*.weights
112+
113+
# PHP
114+
*.php~
115+
*.php.swp
116+
*.php.swo
117+
118+
# Composer
119+
vendor/
120+
composer.phar
121+
composer.lock
122+
123+
# PHP error logs
124+
php_errors.log
125+
php_error.log
126+
error_log
127+
access_log
128+
129+
# PHP sessions
130+
sess_*
131+
132+
# PHP uploads
133+
uploads/
134+
upload/
135+
136+
# PHPUnit
137+
.phpunit.result.cache
138+
phpunit.xml
139+
.phpunit.cache/
140+
141+
# PHP CS Fixer
142+
.php_cs
143+
.php_cs.cache
144+
.php-cs-fixer.cache
145+
146+
# PHP CodeSniffer
147+
phpcs.xml
148+
.phpcs-cache
149+
150+
# PHPStan
151+
phpstan.neon
152+
phpstan-baseline.neon

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"require-dev": {
3+
"phpunit/phpunit": "^9.0"
4+
},
5+
"autoload": {
6+
"psr-4": {
7+
"MediaWiki\\Extension\\CrawlerProtection\\": "includes/"
8+
}
9+
},
10+
"autoload-dev": {
11+
"psr-4": {
12+
"MediaWiki\\Extension\\CrawlerProtection\\Tests\\": "tests/phpunit/unit/"
13+
},
14+
"files": [
15+
"tests/phpunit/stubs.php",
16+
"tests/phpunit/namespaced-stubs.php"
17+
]
18+
}
19+
}

includes/Hooks.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function onMediaWikiPerformAction(
6161
$request,
6262
$mediaWiki
6363
) {
64-
$type = $request->getVal( 'type' );
64+
$type = $request->getVal( 'type' );
6565
$action = $request->getVal( 'action' );
6666
$diffId = (int)$request->getVal( 'diff' );
67-
$oldId = (int)$request->getVal( 'oldid' );
67+
$oldId = (int)$request->getVal( 'oldid' );
6868

6969
if (
7070
!$user->isRegistered()
@@ -83,7 +83,7 @@ public function onMediaWikiPerformAction(
8383
}
8484

8585
/**
86-
* Block Special:RecentChangesLinked and Special:WhatLinksHere for anonymous users.
86+
* Block Special:RecentChangesLinked, Special:WhatLinksHere, and Special:MobileDiff for anonymous users.
8787
*
8888
* @param SpecialPage $special
8989
* @param string|null $subPage
@@ -97,7 +97,7 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {
9797
}
9898

9999
$name = strtolower( $special->getName() );
100-
if ( in_array( $name, [ 'recentchangeslinked', 'whatlinkshere' ], true ) ) {
100+
if ( in_array( $name, [ 'recentchangeslinked', 'whatlinkshere', 'mobilediff' ], true ) ) {
101101
$out = $special->getContext()->getOutput();
102102
$this->denyAccess( $out );
103103
return false;
@@ -112,7 +112,7 @@ public function onSpecialPageBeforeExecute( $special, $subPage ) {
112112
* @param OutputPage $output
113113
* @return void
114114
*/
115-
protected function denyAccess( OutputPage $output ): void {
115+
protected function denyAccess( $output ): void {
116116
$output->setStatusCode( 403 );
117117
$output->addWikiTextAsInterface( wfMessage( 'crawlerprotection-accessdenied-text' )->plain() );
118118

tests/phpunit/namespaced-stubs.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
// Hook interfaces
4+
namespace MediaWiki\Hook {
5+
interface MediaWikiPerformActionHook {
6+
public function onMediaWikiPerformAction( $output, $article, $title, $user, $request, $mediaWiki );
7+
}
8+
}
9+
10+
namespace MediaWiki\SpecialPage\Hook {
11+
interface SpecialPageBeforeExecuteHook {
12+
public function onSpecialPageBeforeExecute( $special, $subPage );
13+
}
14+
}
15+
16+
// Core classes in their proper namespaces
17+
namespace MediaWiki\Output {
18+
class OutputPage {
19+
public function setStatusCode( $code ) {
20+
}
21+
public function addWikiTextAsInterface( $text ) {
22+
}
23+
public function setPageTitle( $title ) {
24+
}
25+
public function setPageTitleMsg( $msg ) {
26+
}
27+
}
28+
}
29+
30+
namespace MediaWiki\SpecialPage {
31+
class SpecialPage {
32+
public function getName() {
33+
return '';
34+
}
35+
public function getContext() {
36+
return null;
37+
}
38+
}
39+
}
40+
41+
namespace MediaWiki\User {
42+
class User {
43+
public function isRegistered() {
44+
return false;
45+
}
46+
}
47+
}
48+
49+
namespace MediaWiki\Request {
50+
class WebRequest {
51+
public function getVal( $name, $default = null ) {
52+
return $default;
53+
}
54+
}
55+
}
56+
57+
namespace MediaWiki\Title {
58+
class Title {
59+
}
60+
}
61+
62+
namespace MediaWiki\Page {
63+
class Article {
64+
}
65+
}
66+
67+
namespace MediaWiki\Actions {
68+
class ActionEntryPoint {
69+
}
70+
}

tests/phpunit/stubs.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
// Basic stubs for MediaWiki testing
4+
5+
// Stub constant - set to newer version to avoid class_alias issues
6+
if ( !defined( 'MW_VERSION' ) ) {
7+
define( 'MW_VERSION', '1.45.0' );
8+
}
9+
10+
// Stub function for wfMessage - only define if not already defined
11+
if ( !function_exists( 'wfMessage' ) ) {
12+
function wfMessage( $key ) {
13+
return new class() {
14+
public function plain() {
15+
return 'Mock message';
16+
}
17+
};
18+
}
19+
}

0 commit comments

Comments
 (0)