Merge branch 'master' into patch_mw135_support

This commit is contained in:
Daniel Kraus
2021-03-31 19:38:19 +02:00
committed by GitHub
11 changed files with 133 additions and 87 deletions

View File

@ -1,21 +1,26 @@
# This Dockerfile can be used to create a Docker image/container # This Dockerfile can be used to create a Docker image/container
# that runs the unit tests on the LinkTitles extension. # that runs the unit tests on the LinkTitles extension.
FROM mediawiki:1.34 FROM mediawiki:1.35
MAINTAINER Daniel Kraus (https://www.bovender.de) LABEL "MAINTAINER" Daniel Kraus (https://www.bovender.de)
RUN apt update -yqq && \ RUN apt-get update -yqq && \
apt install -yqq \ apt-get install -yqq \
php7.0-sqlite \ php7.3-sqlite \
sqlite3 \ sqlite3 \
unzip \ unzip \
zip zip
RUN curl https://raw.githubusercontent.com/composer/getcomposer.org/cb19f2aa3aeaa2006c0cd69a7ef011eb31463067/web/installer -s | php -- --quiet
RUN php composer.phar install WORKDIR /var/www/html
ADD install-composer.sh install-composer.sh
RUN chmod +x install-composer.sh
RUN ./install-composer.sh
COPY . /var/www/html/extensions/LinkTitles/ COPY . /var/www/html/extensions/LinkTitles/
RUN mkdir /data && chown www-data /data RUN mkdir /data && chown www-data /data
RUN php composer.phar update
WORKDIR /var/www/html/maintenance WORKDIR /var/www/html/maintenance
RUN php install.php --pass admin --dbtype sqlite --extensions LinkTitles Tests admin RUN php install.php --pass linktitles --dbtype sqlite --extensions LinkTitles Tests admin
WORKDIR /var/www/html/tests/phpunit WORKDIR /var/www/html/tests/phpunit
CMD ["php", "phpunit.php", "--group", "bovender"] CMD ["php", "phpunit.php", "--group", "bovender"]

11
NEWS.md
View File

@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
For changes prior to version 6.0.0, please see [`NEWS.old`](news.old). For changes prior to version 6.0.0, please see [`NEWS.old`](news.old).
## [7.0.0][] - 2020-12-23
### Changed
- The minimum required version of MediaWiki is now 1.32.
### Fixed
- Fixed compatibility with MediaWiki version 1.35.
## [6.0.0][] - 2019-12-31 ## [6.0.0][] - 2019-12-31
### Changed ### Changed
@ -21,4 +31,5 @@ For changes prior to version 6.0.0, please see [`NEWS.old`](news.old).
constant (DB_SLAVE was renamed to DB_REPLICA). NOTE that the minimum constant (DB_SLAVE was renamed to DB_REPLICA). NOTE that the minimum
required version of MediaWiki is now 1.28 (which is an obsolete version). required version of MediaWiki is now 1.28 (which is an obsolete version).
[7.0.0]: https://github.com/bovender/LinkTitles/releases/tag/v7.0.0
[6.0.0]: https://github.com/bovender/LinkTitles/releases/tag/v6.0.0 [6.0.0]: https://github.com/bovender/LinkTitles/releases/tag/v6.0.0

View File

@ -1,5 +1,4 @@
LinkTitles # LinkTitles
==========
[MediaWiki extension](https://www.mediawiki.org/wiki/Extension:LinkTitles) that [MediaWiki extension](https://www.mediawiki.org/wiki/Extension:LinkTitles) that
automatically adds links to words that match titles of existing pages. automatically adds links to words that match titles of existing pages.
@ -7,9 +6,7 @@ automatically adds links to words that match titles of existing pages.
Minimum requirement: MediaWiki 1.28. Source code documentation can be Minimum requirement: MediaWiki 1.28. Source code documentation can be
found at the [Github project pages](https://bovender.github.io/LinkTitles). found at the [Github project pages](https://bovender.github.io/LinkTitles).
## Table of contents
Table of contents
-----------------
1. [Oveview](#overview) 1. [Oveview](#overview)
- [Versions](#versions) - [Versions](#versions)
@ -43,9 +40,7 @@ Table of contents
- [Testing](#testing) - [Testing](#testing)
7. [License](#license) 7. [License](#license)
## Overview
Overview
--------
The **LinkTitles** extension automatically adds links to existing page titles The **LinkTitles** extension automatically adds links to existing page titles
that occur on a given page. This will automatically cross-reference your wiki that occur on a given page. This will automatically cross-reference your wiki
@ -65,7 +60,6 @@ original content will not be modified.
once. Batch processing can either be started from a special page, or from the once. Batch processing can either be started from a special page, or from the
server's command line (see [below](#batch-processing)). server's command line (see [below](#batch-processing)).
### Versions ### Versions
This extension is [semantically versioned](http://semver.org). In short, this This extension is [semantically versioned](http://semver.org). In short, this
@ -92,9 +86,7 @@ Version | Date | Major changes ||
For more details, click the 'Details' links, see the `NEWS.md` file in the For more details, click the 'Details' links, see the `NEWS.md` file in the
repository for a user-friendly changelog, or study the commit messages. repository for a user-friendly changelog, or study the commit messages.
## Installation
Installation
------------
To obtain the extension, you can either download a compressed archive from the To obtain the extension, you can either download a compressed archive from the
[Github releases page](https://github.com/bovender/LinkTitles/releases): Choose [Github releases page](https://github.com/bovender/LinkTitles/releases): Choose
@ -115,9 +107,7 @@ Do not forget to adjust the [configuration](#configuration) to your needs.
If your MediaWiki version is really old (1.24 and older), you need to use If your MediaWiki version is really old (1.24 and older), you need to use
a [different mechanism](https://www.mediawiki.org/wiki/Manual:Extensions#Installing_an_extension). a [different mechanism](https://www.mediawiki.org/wiki/Manual:Extensions#Installing_an_extension).
## Important note for MediaWiki versions 1.32 and newer
Important note for MediaWiki versions 1.32 and newer
----------------------------------------------------
**Links can no longer be automatically added when a page is saved with **Links can no longer be automatically added when a page is saved with
MediaWiki versions 1.32 and newer.** This is because MediaWiki changed the MediaWiki versions 1.32 and newer.** This is because MediaWiki changed the
@ -138,8 +128,7 @@ A workaround is to set up a cron job for the command-line tool, e.g.
[T222413]: https://phabricator.wikimedia.org/T222413 [T222413]: https://phabricator.wikimedia.org/T222413
[467308]: https://gerrit.wikimedia.org/r/467308 [467308]: https://gerrit.wikimedia.org/r/467308
Usage ## Usage
-----
### Editing a page ### Editing a page
@ -248,9 +237,7 @@ See all available options with:
php linktitles-cli.php -h php linktitles-cli.php -h
## Configuration
Configuration
-------------
To change the configuration, set the variables in your `LocalSettings.php` file. To change the configuration, set the variables in your `LocalSettings.php` file.
The code lines below show the default values of the configuration variables. The code lines below show the default values of the configuration variables.
@ -300,10 +287,9 @@ dummy pages for variants of page titles with different cases.
Smart mode is enabled by default. You can disable it to increase performance of Smart mode is enabled by default. You can disable it to increase performance of
the extension. the extension.
### Dealing with custom namespaces ### Dealing with custom namespaces
$wgLinkTitlesSourceNamespace = []; $wgLinkTitlesSourceNamespaces = [];
Specifies additional namespaces for pages that should be processed by the Specifies additional namespaces for pages that should be processed by the
LinkTitles extension. If this is an empty array (or anything else that PHP LinkTitles extension. If this is an empty array (or anything else that PHP
@ -329,7 +315,7 @@ no links at all because there are no target namespaces at all.
#### Example: Default configuration #### Example: Default configuration
$wgLinkTitlesSourceNamespace = []; $wgLinkTitlesSourceNamespaces = [];
$wgLinkTitlesTargetNamespaces = []; $wgLinkTitlesTargetNamespaces = [];
$wgLinkTitlesSamenamespace = true; $wgLinkTitlesSamenamespace = true;
@ -338,7 +324,7 @@ namespace only (i.e., the same namespace that the source page is in).
#### Example: Custom namespace only #### Example: Custom namespace only
$wgLinkTitlesSourceNamespace = [ NS_MY_NAMESPACE]; $wgLinkTitlesSourceNamespaces = [ NS_MY_NAMESPACE];
$wgLinkTitlesTargetNamespaces = []; $wgLinkTitlesTargetNamespaces = [];
$wgLinkTitlesSamenamespace = true; $wgLinkTitlesSamenamespace = true;
@ -348,7 +334,7 @@ is in).
#### Example: Link to `NS_MAIN` only #### Example: Link to `NS_MAIN` only
$wgLinkTitlesSourceNamespace = [ NS_MY_NAMESPACE]; $wgLinkTitlesSourceNamespaces = [ NS_MY_NAMESPACE];
$wgLinkTitlesTargetNamespaces = [ NS_MAIN ]; $wgLinkTitlesTargetNamespaces = [ NS_MAIN ];
$wgLinkTitlesSamenamespace = false; $wgLinkTitlesSamenamespace = false;
@ -459,18 +445,14 @@ The `LinkTitles:Special` page performs batch processing of pages by repeatedly
calling itself. This happens to prevent timeouts on your server. The default calling itself. This happens to prevent timeouts on your server. The default
reload interval is 1 second. reload interval is 1 second.
## Development
Development As of December 2020, there is only one major branch where all development takes
----------- place. I used to follow Vincent Driessen's advice on [A successful Git
branching model](http://nvie.com/git-model), but this did not work out for me
If you wish to contribute, please issue pull requests against the `develop` after all. Pull requests from other developers were usually issued against the
branch, as I roughly follow Vincent Driessen's advice on [A successful Git `master` branch, and the constant switching between the `develop` and the `master`
branching model](http://nvie.com/git-model) (knowing that there are branches was prone to cause a mess.
[alternative workflows](http://scottchacon.com/2011/08/31/github-flow.html)).
The `master` branch contains stable releases only, so it is safe to pull the
master branch if you want to install the extension for your own Wiki.
### Contributors ### Contributors
@ -480,8 +462,7 @@ master branch if you want to install the extension for your own Wiki.
- @tetsuya-zama, bug fix - @tetsuya-zama, bug fix
- @yoshida3669, namespace-related bug fixes - @yoshida3669, namespace-related bug fixes
- Caleb Mingle (@dentafrice), bug fix - Caleb Mingle (@dentafrice), bug fix
- @paladox, bug fixes - @paladox, bug fixes and compatilibity fixes
### Testing ### Testing
@ -489,6 +470,20 @@ Starting from version 5, LinkTitles finally comes with phpunit tests. The code
is not 100% covered yet. If you find something does not work as expected, let me is not 100% covered yet. If you find something does not work as expected, let me
know and I will try to add unit tests and fix it. know and I will try to add unit tests and fix it.
#### Testing with Docker
If you have [Docker](https://www.docker.com) available, simply to this:
docker build -t bovender/linktitles .
docker run -it --rm bovender/linktitles # repeat as necessary
Or:
make build-test-container
make test # repeat as necessary
#### The Olde Way
Here's how I set up the testing environment. This may not be the canonical way Here's how I set up the testing environment. This may not be the canonical way
to do it. Basic information on testing MediaWiki can be found to do it. Basic information on testing MediaWiki can be found
[here](https://www.mediawiki.org/wiki/Manual:PHP_unit_testing). [here](https://www.mediawiki.org/wiki/Manual:PHP_unit_testing).
@ -547,9 +542,7 @@ use Ubuntu).
If you linked just the LinkTitles extension in step 5, only this extension If you linked just the LinkTitles extension in step 5, only this extension
will be tested. will be tested.
## License
License
-------
Copyright 2012-2020 Daniel Kraus <mailto:bovender@bovender.de> (GitHub: @bovender) Copyright 2012-2020 Daniel Kraus <mailto:bovender@bovender.de> (GitHub: @bovender)

View File

@ -15,7 +15,7 @@
"license-name": "GPL-2.0+", "license-name": "GPL-2.0+",
"descriptionmsg": "linktitles-desc", "descriptionmsg": "linktitles-desc",
"requires": { "requires": {
"MediaWiki": ">= 1.28.0" "MediaWiki": ">= 1.32.0"
}, },
"config": { "config": {
"LinkTitlesParseOnEdit": true, "LinkTitlesParseOnEdit": true,

View File

@ -23,6 +23,8 @@
*/ */
namespace LinkTitles; namespace LinkTitles;
use MediaWiki\MediaWikiServices;
/** /**
* Represents a page that is a potential link target. * Represents a page that is a potential link target.
*/ */
@ -149,7 +151,7 @@ class Source {
* @return boolean True if the page contains the __NOAUTOLINKS__ magic word. * @return boolean True if the page contains the __NOAUTOLINKS__ magic word.
*/ */
public function hasNoAutolinksMagicWord() { public function hasNoAutolinksMagicWord() {
return \MediaWiki\MediaWikiServices::getInstance()->getMagicWordFactory()->get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $this->getText() ); return MediaWikiServices::getInstance()->getMagicWordFactory()->get( 'MAG_LINKTITLES_NOAUTOLINKS' )->match( $this->getText() );
} }
/** /**

22
install-composer.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/sh
# This is a slightly modified version of the installer script published at
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
# It does not depend on `wget` and uses `curl` instead.
EXPECTED_CHECKSUM="$(curl -q https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]
then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
# May need to remove the explicit pinning of version 1 in the future
php composer-setup.php --quiet --1
RESULT=$?
rm composer-setup.php
exit $RESULT

View File

@ -37,7 +37,8 @@
class LinkTitlesLinkerTest extends LinkTitles\TestCase { class LinkTitlesLinkerTest extends LinkTitles\TestCase {
protected $title; protected $title;
protected function setUp() { protected function setUp(): void
{
parent::setUp(); // call last to have the Targets object invalidated after inserting the page parent::setUp(); // call last to have the Targets object invalidated after inserting the page
} }
@ -315,13 +316,13 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
// Reset namespace caches. // Reset namespace caches.
// See https://stackoverflow.com/q/45974979/270712 // See https://stackoverflow.com/q/45974979/270712
MWNamespace::getCanonicalNamespaces( true ); \MWNamespace::getCanonicalNamespaces(true);
global $wgContLang; global $wgContLang;
$wgContLang->resetNamespaces(); $wgContLang->resetNamespaces();
$this->assertTrue( MWNamespace::exists( $ns ), "The namespace with id $ns should exist!" ); $this->assertTrue( MWNamespace::exists( $ns ), "The namespace with id $ns should exist!" );
$this->insertPage( "in custom namespace", 'This is a page in a custom namespace', $ns ); $this->insertPage( "in custom namespace", 'This is a page in a custom namespace', $ns );
LinKTitles\Targets::invalidate(); LinkTitles\Targets::invalidate();
$linker = new LinkTitles\Linker( $config ); $linker = new LinkTitles\Linker( $config );
$source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config ); $source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config );
$result = $linker->linkContent( $source ); $result = $linker->linkContent( $source );

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Copyright 2012-2018 Daniel Kraus <bovender@bovender.de> ('bovender') * Copyright 2012-2018 Daniel Kraus <bovender@bovender.de> ('bovender')
* *
@ -25,11 +26,13 @@
* *
* @group bovender * @group bovender
*/ */
class SplitterTest extends MediaWikiTestCase { class SplitterTest extends \MediaWikiTestCase
{
/** /**
* @dataProvider provideSplitData * @dataProvider provideSplitData
*/ */
public function testSplit( $skipTemplates, $parseHeadings, $input, $expectedOutput ) { public function testSplit($skipTemplates, $parseHeadings, $input, $expectedOutput)
{
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
$config->skipTemplates = $skipTemplates; $config->skipTemplates = $skipTemplates;
$config->parseHeadings = $parseHeadings; $config->parseHeadings = $parseHeadings;
@ -41,7 +44,8 @@ class SplitterTest extends MediaWikiTestCase {
} }
// TODO: Add more examples. // TODO: Add more examples.
public static function provideSplitData() { public static function provideSplitData()
{
return [ return [
[ [
true, // skipTemplates true, // skipTemplates

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Copyright 2012-2018 Daniel Kraus <bovender@bovender.de> ('bovender') * Copyright 2012-2018 Daniel Kraus <bovender@bovender.de> ('bovender')
* *
@ -23,19 +24,22 @@
/** /**
* @group bovender * @group bovender
*/ */
class TargetTest extends MediaWikiTestCase { class TargetTest extends \MediaWikiTestCase
{
/** /**
* @dataProvider provideStartOnly * @dataProvider provideStartOnly
*/ */
public function testTargetWordStartOnly( $enabled, $delimiter ) { public function testTargetWordStartOnly($enabled, $delimiter)
{
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
$config->wordStartOnly = $enabled; $config->wordStartOnly = $enabled;
$target = new LinKTitles\Target(NS_MAIN, 'test page', $config); $target = new LinKTitles\Target(NS_MAIN, 'test page', $config);
$this->assertSame($delimiter, $target->wordStart); $this->assertSame($delimiter, $target->wordStart);
} }
public static function provideStartOnly() { public static function provideStartOnly()
{
return [ return [
[true, '(?<!\pL|\pN)'], [true, '(?<!\pL|\pN)'],
[false, ''] [false, '']
@ -45,14 +49,16 @@ class TargetTest extends MediaWikiTestCase {
/** /**
* @dataProvider provideEndOnly * @dataProvider provideEndOnly
*/ */
public function testTargetWordEndOnly( $enabled, $delimiter ) { public function testTargetWordEndOnly($enabled, $delimiter)
{
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
$config->wordEndOnly = $enabled; $config->wordEndOnly = $enabled;
$target = new LinKTitles\Target(NS_MAIN, 'test page', $config); $target = new LinKTitles\Target(NS_MAIN, 'test page', $config);
$this->assertSame($delimiter, $target->wordEnd); $this->assertSame($delimiter, $target->wordEnd);
} }
public static function provideEndOnly() { public static function provideEndOnly()
{
return [ return [
[true, '(?!\pL|\pN)'], [true, '(?!\pL|\pN)'],
[false, ''] [false, '']

View File

@ -22,11 +22,13 @@
namespace LinkTitles; namespace LinkTitles;
abstract class TestCase extends \MediaWikiTestCase { abstract class TestCase extends \MediaWikiTestCase {
protected function setUp() { protected function setUp(): void
{
parent::setUp(); parent::setUp();
} }
protected function tearDown() { protected function tearDown(): void
{
parent::tearDown(); parent::tearDown();
} }