Skip to content

Commit 9b96099

Browse files
chore (HidePrefix): add docker-compose-ci (#2)
1 parent 657a311 commit 9b96099

File tree

13 files changed

+352
-89
lines changed

13 files changed

+352
-89
lines changed

.env-39

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# docker images
2+
MW_VERSION?=1.39
3+
PHP_VERSION?=8.1
4+
DB_TYPE?=mysql
5+
DB_IMAGE?=""

.env-40

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# docker images
2+
MW_VERSION?=1.40
3+
PHP_VERSION?=8.1
4+
DB_TYPE?=mysql
5+
DB_IMAGE?=""

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
test:
13+
14+
runs-on: ubuntu-22.04
15+
continue-on-error: ${{ matrix.experimental }}
16+
17+
strategy:
18+
matrix:
19+
include:
20+
- mediawiki_version: '1.35'
21+
php_version: 7.4
22+
database_type: mysql
23+
database_image: "mysql:5.7"
24+
coverage: true
25+
experimental: false
26+
- mediawiki_version: '1.39'
27+
php_version: 8.1
28+
database_type: mysql
29+
database_image: "mysql:8"
30+
coverage: false
31+
experimental: false
32+
- mediawiki_version: '1.40'
33+
php_version: 8.1
34+
database_type: mysql
35+
database_image: "mysql:8"
36+
coverage: false
37+
experimental: false
38+
39+
env:
40+
MW_VERSION: ${{ matrix.mediawiki_version }}
41+
PHP_VERSION: ${{ matrix.php_version }}
42+
DB_TYPE: ${{ matrix.database_type }}
43+
DB_IMAGE: ${{ matrix.database_image }}
44+
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
with:
49+
submodules: recursive
50+
51+
- name: Update submodules
52+
run: git submodule update --init --remote
53+
54+
- name: Run tests
55+
run: make ci
56+
if: matrix.coverage == false
57+
58+
- name: Run tests with coverage
59+
run: make ci-coverage
60+
if: matrix.coverage == true
61+
62+
- name: Upload code coverage
63+
uses: codecov/codecov-action@v4
64+
with:
65+
token: ${{ secrets.CODECOV_TOKEN }}
66+
files: coverage/php/coverage.xml
67+
if: matrix.coverage == true

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "build"]
2+
path = build
3+
url = https://github.com/gesinn-it-pub/docker-compose-ci.git

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
-include .env-39
2+
export
3+
4+
# setup for docker-compose-ci build directory
5+
# delete "build" directory to update docker-compose-ci
6+
7+
ifeq (,$(wildcard ./build/Makefile))
8+
$(shell git submodule update --init --remote)
9+
endif
10+
11+
EXTENSION=hide-prefix
12+
13+
# docker images
14+
MW_VERSION?=1.35
15+
PHP_VERSION?=7.4
16+
DB_TYPE?=sqlite
17+
DB_IMAGE?=""
18+
19+
# extensions
20+
# Enables installation of apt packages for gd extension
21+
# OS_PACKAGES?="zlib1g-dev libpng-dev"
22+
23+
# Enables installation of gd extension
24+
# PHP_EXTENSIONS?=gd
25+
26+
# composer
27+
# Enables "composer update" inside of extension
28+
COMPOSER_EXT?=true
29+
30+
# nodejs
31+
# Enables node.js related tests and "npm install"
32+
# NODE_JS?=true
33+
34+
# check for build dir and git submodule init if it does not exist
35+
include build/Makefile

README

Lines changed: 0 additions & 67 deletions
This file was deleted.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- README -->
2+
3+
# HidePrefix
4+
5+
The HidePrefix extension hides prefix in links and page titles.
6+
7+
For example, wikitext `[[Help:FAQ]]' normally results in link `Help:FAQ'. If this extension is
8+
enabled, result will be just `FAQ' without the `Help:' prefix.
9+
10+
The same is about page titles. Page `FAQ' in `Help' namespace normally has `Help:FAQ' title. If this
11+
extension is enabled, visible page title will be just `FAQ' without the `Help:' prefix.
12+
13+
## Download
14+
15+
git clone https://github.com/gesinn-it-pub/mediawiki-extensions-HidePrefix
16+
17+
## Installation
18+
19+
To install this extension, add the following to LocalSettings.php:
20+
21+
- wfLoadExtension("HidePrefix");
22+
23+
## License
24+
25+
GNU Affero General Public License, version 3 or any later version. See AGPL-3.0.txt file for the
26+
full license text.
27+
28+
## See also
29+
30+
* Extension HideNamespace - This extension allows drop prefix in page title and provides control
31+
(e. g. hide prefix only in pages of specific namespace, or control prefix visibility from within
32+
page content), but it does not affect links.
33+
34+
## Links
35+
36+
* Extension page: https://www.mediawiki.org/wiki/Extension:HidePrefix
37+
* Author page: https://www.mediawiki.org/wiki/User:Van_de_Bugger
38+
* License page: https://www.gnu.org/licenses/agpl.html
39+
40+
<!-- end of file -->

build

Submodule build added at db8291e

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fixes:
2+
- "/var/www/html/extensions/HidePrefix/::"

composer.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
11
{
2+
"name": "gesinn-it-pub/hide-prefix",
3+
"type": "mediawiki-extension",
4+
"description": "Used to hide prefix in links and page titles",
25
"require-dev": {
36
"mediawiki/mediawiki-codesniffer": "43.0.0",
7+
"mediawiki/mediawiki-phan-config": "0.14.0",
48
"mediawiki/minus-x": "1.1.3",
59
"php-parallel-lint/php-console-highlighter": "1.0.0",
610
"php-parallel-lint/php-parallel-lint": "1.4.0"
711
},
812
"scripts": {
913
"test": [
10-
"parallel-lint . --exclude vendor --exclude node_modules",
11-
"@phpcs",
12-
"minus-x check ."
14+
"@analyze",
15+
"@phpunit"
16+
],
17+
"test-coverage": [
18+
"@analyze",
19+
"@phpunit-coverage"
20+
],
21+
"analyze": [
22+
"@lint",
23+
"@phpcs"
1324
],
1425
"fix": [
15-
"minus-x fix .",
16-
"phpcbf"
26+
"@phpcs-fix"
1727
],
18-
"phpcs": "phpcs -p -s"
28+
"lint": "parallel-lint . --exclude vendor --exclude node_modules",
29+
"phpcs": "phpcs -ps",
30+
"phpcs-fix": "phpcbf -p",
31+
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox",
32+
"phpunit-coverage": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml",
33+
"minus-x": "minus-x check ."
1934
},
2035
"config": {
2136
"allow-plugins": {

phpunit.xml.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<phpunit colors="true">
2+
<testsuites>
3+
<testsuite name="tests">
4+
<directory>tests/phpunit/Unit</directory>
5+
</testsuite>
6+
</testsuites>
7+
<filter>
8+
<whitelist addUncoveredFilesFromWhitelist="false">
9+
<directory suffix=".php">src</directory>
10+
</whitelist>
11+
</filter>
12+
</phpunit>

src/HidePrefix.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,25 @@ class HidePrefix {
3434
* @param string &$ret
3535
* @return bool
3636
*/
37-
public static function onHtmlPageLinkRendererBegin(
38-
LinkRenderer $linkRenderer,
37+
public static function onHtmlPageLinkRendererBegin( LinkRenderer $linkRenderer,
3938
LinkTarget $target,
4039
&$text,
4140
&$extraAttribs,
4241
&$query,
43-
&$ret
44-
) {
45-
if ( isset( $text ) ) {
46-
// Hmm... Sometimes `$text' is not a string but an object of class `Message'...
47-
if ( is_string( $text ) ) {
48-
$title = Title::newFromText( $text );
49-
$targetTitle = Title::newFromLinkTarget( $target );
50-
if ( $title !== null && $targetTitle && $title->getPrefixedText() == $targetTitle->getPrefixedText() ) {
51-
$text = $target->getText();
52-
}
53-
}
54-
} else {
42+
&$ret ) {
43+
if ( !isset( $text ) ) {
5544
$text = $target->getText();
45+
return true;
5646
}
57-
return true;
47+
48+
$html = HtmlArmor::getHtml( $text );
49+
$title = Title::newFromText( $html );
50+
$targetTitle = Title::newFromLinkTarget( $target );
51+
52+
if ( $title !== null && $targetTitle && $title->getPrefixedText() === $targetTitle->getPrefixedText() ) {
53+
$text = $target->getText();
54+
}
55+
return true;
5856
}
5957

6058
/**
@@ -73,7 +71,14 @@ public static function onBeforePageDisplay( &$out, &$sk ) {
7371
return;
7472
}
7573

76-
if ( $out->getPageTitle() == $title->getPrefixedText() ) {
74+
// result example 'prefix:title', split it to use title
75+
$titleWithPrefix = $title->getPrefixedText();
76+
$titleWithoutPrefix = explode( ':', $titleWithPrefix );
77+
78+
// double check $pageTitle from $out - should contains title of given page
79+
$pageTitle = trim( $out->getPageTitle() );
80+
if ( ( $pageTitle === trim( $titleWithoutPrefix[1] ) ) ||
81+
( strpos( $pageTitle, trim( $titleWithoutPrefix[1] ) ) ) ) {
7782
$out->setPageTitle( $title->getText() );
7883
}
7984
}

0 commit comments

Comments
 (0)