Merge branch 'release-5.0.2'

This commit is contained in:
Daniel Kraus
2017-09-05 13:29:02 +02:00
7 changed files with 125 additions and 66 deletions

8
NEWS
View File

@ -1,3 +1,11 @@
Version 5.0.2 (2017-09-05)
------------------------------------------------------------------------
- Fix: Better detection of <span> and <div> elements that do not have attributes.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Version 5.0.1 (2017-09-03) Version 5.0.1 (2017-09-03)
------------------------------------------------------------------------ ------------------------------------------------------------------------

View File

@ -5,7 +5,7 @@ LinkTitles
automatically adds links to words that match titles of existing pages. automatically adds links to words that match titles of existing pages.
Minimum requirements: MediaWiki 1.25, PHP 5.3. Source code documentation can be Minimum requirements: MediaWiki 1.25, PHP 5.3. Source code documentation can be
found at the [Github project pages](http://bovender.github.io/LinkTitles). found at the [Github project pages](https://bovender.github.io/LinkTitles).
Table of contents Table of contents
@ -62,7 +62,7 @@ original content will not be modified.
3. Batch mode enables Wiki administrators to process all pages in a Wiki at 3. Batch mode enables Wiki administrators to process all pages in a Wiki at
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 "wikilink")). server's command line (see [below](#batch-processing)).
### Versions ### Versions
@ -102,7 +102,7 @@ release version, e.g. `LinkTitles-5.0.0`. You may want to rename the folder to
`LinkTitles`. `LinkTitles`.
Alternatively (and preferred by the author), if you have [Git](https://git-scm.com), Alternatively (and preferred by the author), if you have [Git](https://git-scm.com),
you can pull the repository in the `extensions` folder. you can pull the repository in the usual way into the `extensions` folder.
To activate the extension, add the following to your `LocalSettings.php` file: To activate the extension, add the following to your `LocalSettings.php` file:
@ -128,7 +128,7 @@ section.
### Preventing automatic linking after minor edits ### Preventing automatic linking after minor edits
If the 'minor edit' check box is marked when you save a page, the extension will If the 'minor edit' check box is marked when you save a page, the extension will
not operate. not add links to the page.
### Viewing a page ### Viewing a page
@ -141,29 +141,30 @@ configuration variable.
### Including and excluding pages with Magic Words ### Including and excluding pages with Magic Words
Add the magic word `__NOAUTOLINKS__` to a page to prevent automatic linking of Add the magic word **`__NOAUTOLINKS__`** to a page to prevent automatic linking
page titles. of page titles.
The presence of `__NOAUTOLINKTARGET__` prevents a page from being automatically The presence of **`__NOAUTOLINKTARGET__`** prevents a page from being
linked to from other pages. automatically linked to from other pages.
### Enable or disable automatic linking for sections ### Enable or disable automatic linking for sections
To **exclude** a section on your page from automatic linking, wrap it in To **exclude** a section on your page from automatic linking, wrap it in
`<noautolinks>...</noautolinks>` tags. **`<noautolinks>...</noautolinks>`** tags.
To **include** a section on your page for automatic linking, wrap it in To **include** a section on your page for automatic linking, wrap it in
`<autolinks>...</autolinks>` tags. Of course this only makes sense if both **`<autolinks>...</autolinks>`** tags. Of course this only makes sense if both
`$wgLinkTitlesParseOnEdit` and `$wgLinkTitlesParseOnRender` are set to `false` `$wgLinkTitlesParseOnEdit` and `$wgLinkTitlesParseOnRender` are set to `false`
**or** if the page contains the `__NOAUTOLINKS__` magic word. *or* if the page contains the `__NOAUTOLINKS__` magic word.
### Namespace support ### Namespace support
By default, LinkTitles will only process pages in the `NS_MAIN` namespace (i.e., By default, LinkTitles will only process pages in the `NS_MAIN` namespace (i.e.,
'normal' Wiki pages). You can have modify the configuration to process pages in 'normal' Wiki pages). You can modify the configuration to process pages in
other 'source' namespaces as well. By default, LinkTitles will only link to pages other 'source' namespaces as well. By default, LinkTitles will only link to
that are in the same namespace as the page being edited or viewed. Again, additional pages that are in the same namespace as the page being edited or viewed. Again,
'target' namespaces may be added in the [configuration](#dealing-with-custom-namespaces). additional 'target' namespaces may be added in the
[configuration](#dealing-with-custom-namespaces).
If a page contains another page's title that is prefixed with the namespace If a page contains another page's title that is prefixed with the namespace
(e.g. `my_namspace:other page`), LinkTitles will _not_ add a link. It is assumed (e.g. `my_namspace:other page`), LinkTitles will _not_ add a link. It is assumed
@ -183,13 +184,17 @@ script.
The special page provides a simple web interface to trigger batch processing. To The special page provides a simple web interface to trigger batch processing. To
avoid blocking the web server for too long, the page will frequently reload avoid blocking the web server for too long, the page will frequently reload
itself (this can be controlled by the `$wgLinkTitlesSpecialPageReloadAfter` itself (this can be controlled by the `$wgLinkTitlesSpecialPageReloadAfter`
configuration variable that sysops can set in the `LocalSettings.php` file). configuration variable that the administrator can set in the `LocalSettings.php`
file).
For security reasons, by default only users in the 'sysop' group are allowed to For security reasons, by default only users in the 'sysop' group are allowed to
view the special page (otherwise unauthorized people could trigger a parsing of view the special page (otherwise unauthorized people could trigger a parsing of
your entire wiki). To allow other user groups to view the page as well, add a your entire wiki). To allow other user groups to view the page as well, add a
line `$wgGroupPermissions ['`<groupname>`']['linktitles-batch']` `=` `true` to line
`LocalSettings.php`.
$wgGroupPermissions ['<groupname>']['linktitles-batch'] = true;
to `LocalSettings.php`.
#### Maintenance script #### Maintenance script
@ -209,15 +214,15 @@ To continue parsing at a later time, make a note of the index number of the last
page that was processed (e.g., 37), and use the maintenance script with the page that was processed (e.g., 37), and use the maintenance script with the
`--start` option (or short `-s`) to indicate the start index: `--start` option (or short `-s`) to indicate the start index:
php LinkTitles.cli.php -s 37 php linktitles-cli.php -s 37
See all available options with: 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.
@ -247,7 +252,7 @@ depends on whether you want to have links (`[[...]]`) added to the Wiki markup.
Please note that the extension will work on a fully built page when this mode is Please note that the extension will work on a fully built page when this mode is
enabled; therefore, it *will* add links to text transcluded from templates, enabled; therefore, it *will* add links to text transcluded from templates,
regardless of the configuration setting of `LinkTitlesSkipTemplages`. regardless of the configuration setting of `$wgLinkTitlesSkipTemplates`.
You can purge the page cache and trigger rendering by adding `?action=purge` to You can purge the page cache and trigger rendering by adding `?action=purge` to
the URL. the URL.
@ -323,7 +328,6 @@ Process pages in the `NS_MY_NAMESPACE` namespace only, and add links to the
`NS_MAIN` namespace only. Do not link to pages that are in the same namespace `NS_MAIN` namespace only. Do not link to pages that are in the same namespace
as the source namespace (i.e., `NS_MY_NAMESPACE`). as the source namespace (i.e., `NS_MY_NAMESPACE`).
### Linking or skipping headings ### Linking or skipping headings
$wgLinkTitlesParseHeadings = false; $wgLinkTitlesParseHeadings = false;
@ -385,13 +389,14 @@ will have no effect.**
$wgLinkTitlesSkipTemplates = false; $wgLinkTitlesSkipTemplates = false;
If set to true, do not parse the variable text of templates, i.e. in `{{my` If set to true, do not parse the variable text of templates, i.e. in `{{my
`template|some` `variable=some` `content}}`, leave the entire text between the template|some variable=some content}}`, leave the entire text between the curly
curly brackets untouched. If set to false (default setting), the text after the brackets untouched. If set to false (default setting), the text after the pipe
pipe symbole ("|") will be parsed. symbol (`|`) will be parsed.
Note: This setting works only with parse-on-edit; it does not affect Note: This setting works only with parse-on-edit; it does not affect
parse-on-render! parse-on-render! This is because the templates have already been transcluded
(expanded) when the links are added during rendering.
### Multiple links to the same page ### Multiple links to the same page
@ -436,16 +441,16 @@ model](http://nvie.com/git-model) (knowing that there are [alternative
workflows](http://scottchacon.com/2011/08/31/github-flow.html)). workflows](http://scottchacon.com/2011/08/31/github-flow.html)).
The `master` branch contains stable releases only, so it is safe to pull the 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. master branch if you want to install the extension for your own Wiki.
### Contributors ### Contributors
- Daniel Kraus (@bovender), main developer - Daniel Kraus (@bovender), main developer
- Ulrich Strauss (@c0nnex), namespaces - Ulrich Strauss (@c0nnex), initial support for namespaces
- Brent Laabs (@labster), code review and bug fixes - Brent Laabs (@labster), code review and bug fixes
- @tetsuya-zama, bug fix - @tetsuya-zama, bug fix
- @yoshida, namespace-related bug fixes - @yoshida3669, namespace-related bug fixes
### Testing ### Testing
@ -484,7 +489,7 @@ and remove (or comment out) any lines that reference extensions or skins that
you are not going to install to your test environment. For the purposes of you are not going to install to your test environment. For the purposes of
testing the LinkTitles extension, leave the following line in place: testing the LinkTitles extension, leave the following line in place:
wfLoadExtensions( array( 'LinkTitles' )); wfLoadExtensions( 'LinkTitles' );
And ensure the settings file contains the following: And ensure the settings file contains the following:

View File

@ -9,7 +9,7 @@
], ],
"type": "parserhook", "type": "parserhook",
"url": "https://www.mediawiki.org/wiki/Extension:LinkTitles", "url": "https://www.mediawiki.org/wiki/Extension:LinkTitles",
"version": "5.0.1", "version": "5.0.2",
"license-name": "GPL-2.0+", "license-name": "GPL-2.0+",
"descriptionmsg": "linktitles-desc", "descriptionmsg": "linktitles-desc",
"requires": { "requires": {

View File

@ -135,8 +135,8 @@ class Splitter {
'<pre>.*?<\/pre>|<html>.*?<\/html>|' . // pre/html '<pre>.*?<\/pre>|<html>.*?<\/html>|' . // pre/html
'<script>.*?<\/script>|' . // script '<script>.*?<\/script>|' . // script
'<gallery>.*?<\/gallery>|' . // gallery '<gallery>.*?<\/gallery>|' . // gallery
'<div.+?>|<\/div>|' . // attributes of div elements '<div.*?>|<\/div>|' . // attributes of div elements
'<span.+?>|<\/span>|' . // attributes of span elements '<span.*?>|<\/span>|' . // attributes of span elements
'<file>[^<]*<\/file>|' . // stuff inside file elements '<file>[^<]*<\/file>|' . // stuff inside file elements
'style=".+?"|class=".+?"|' . // styles and classes (e.g. of wikitables) 'style=".+?"|class=".+?"|' . // styles and classes (e.g. of wikitables)
'<noautolinks>.*?<\/noautolinks>|' . // custom tag 'noautolinks' '<noautolinks>.*?<\/noautolinks>|' . // custom tag 'noautolinks'

View File

@ -200,6 +200,40 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
]; ];
} }
/**
* @dataProvider provideLinkContentHeadingsData
*/
public function testLinkContentHeadings( $parseHeadings, $input, $expectedOutput ) {
$config = new LinkTitles\Config();
$config->parseHeadings = $parseHeadings;
LinkTitles\Splitter::invalidate();
$source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config );
$linker = new LinkTitles\Linker( $config );
$result = $linker->linkContent( $source );
if ( !$result ) { $result = $input; }
$this->assertSame( $expectedOutput, $result );
}
public function provideLinkContentHeadingsData() {
return [
[
true, // parseHeadings
"With parseHeadings = true,\n== a heading with link target in it ==\n should be linked",
"With parseHeadings = true,\n== a heading with [[link target]] in it ==\n should be linked",
],
[
true, // parseHeadings
"With parseHeadings = true,\n== <span>a heading with link target in ity/span> ==\n should be linked",
"With parseHeadings = true,\n== <span>a heading with [[link target]] in ity/span> ==\n should be linked",
],
[
false, // parseHeadings
"With parseHeadings = false,\n== a heading with link target in it ==\n should not be linked",
"With parseHeadings = false,\n== a heading with link target in it ==\n should not be linked",
],
];
}
public function testLinkContentBlackList() { public function testLinkContentBlackList() {
$config = new LinkTitles\Config(); $config = new LinkTitles\Config();
$config->blackList = [ 'Foo', 'Link target', 'Bar' ]; $config->blackList = [ 'Foo', 'Link target', 'Bar' ];

View File

@ -86,6 +86,18 @@ class SplitterTest extends MediaWikiTestCase {
"With parseHeadings = false,\n==a heading may not be linked==", "With parseHeadings = false,\n==a heading may not be linked==",
[ "With parseHeadings = false,\n", "==a heading may not be linked==", '' ] [ "With parseHeadings = false,\n", "==a heading may not be linked==", '' ]
], ],
[
true, // skipTemplates
true, // parseHeadings
"With parseHeadings = true,\n==<span>a heading with spans may be linked</span>==\n",
[ "With parseHeadings = true,\n==", "<span>", "a heading with spans may be linked", "</span>", "==\n" ]
],
[
true, // skipTemplates
true, // parseHeadings
"With parseHeadings = true,\n==<div>a heading with divs may be linked</div>==\n",
[ "With parseHeadings = true,\n==", "<div>", "a heading with divs may be linked", "</div>", "==\n" ]
],
// Improperly formatted headings cannot be dealt with appropriately for now // Improperly formatted headings cannot be dealt with appropriately for now
// [ // [
// true, // skipTemplates // true, // skipTemplates