mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 17:59:29 +02:00
Merge branch 'release-5.0.1'
This commit is contained in:
33
NEWS
33
NEWS
@ -1,6 +1,39 @@
|
|||||||
|
Version 5.0.1 (2017-09-03)
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- Fix: Detection of existing links had a bug.
|
||||||
|
- Fix: Do not crash when testing redirect target on empty page.
|
||||||
|
- Improved: Special Page can now be translated using messages.
|
||||||
|
- Improved: The comment that is added when pages are edited by the maintenance script can now be translated using a message.
|
||||||
|
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
|
||||||
|
|
||||||
Version 5.0.0 (2017-09-01)
|
Version 5.0.0 (2017-09-01)
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Version 5 is a major rewrite of the LinKTitles extension. The code is
|
||||||
|
now much better organized, and it included automatic (unit) testing,
|
||||||
|
which will greatly facilitate future maintenance and development.
|
||||||
|
|
||||||
|
Namespace support was overhauled, and a couple of **breaking changes**
|
||||||
|
were introduced in this version. Most notably, the
|
||||||
|
`$wgLinkTitlesNamespaces` configuration variable was removed and
|
||||||
|
replaced with `$wgLinKTitlesSourceNamespaces`,
|
||||||
|
`$wgLinkTitlesTargetNamespaces`, and `$wgLinkTitlesSameNamespace`.
|
||||||
|
`$wgLinKTitlesTimeLimit` was renamed to
|
||||||
|
`$wgLinkTitlesSpecialPageReloadAfter`.
|
||||||
|
|
||||||
|
Version 5 offers more fine-grained control over where to link and what
|
||||||
|
to link. In addition to the `__NOAUTOLINKS__` and
|
||||||
|
`__NOAUTOLINKSTARGET__` magic words, you can have
|
||||||
|
`<autolink>..</autolink>` and `<noautolink>..</noautolink>` tags in your
|
||||||
|
page source to explicitly include or exclude sections from linking.
|
||||||
|
|
||||||
|
Several long-standing bugs were fixed.
|
||||||
|
|
||||||
|
Please see the detailed documentation in the README.md file, and the
|
||||||
|
NEWS file.
|
||||||
- Change: The $wgLinkTitlesBatchTimeLimit configuration variable was renamed to $wgLinkTitlesSpecialPageReloadAfter.
|
- Change: The $wgLinkTitlesBatchTimeLimit configuration variable was renamed to $wgLinkTitlesSpecialPageReloadAfter.
|
||||||
- Fix: Blacklist did not always work properly
|
- Fix: Blacklist did not always work properly
|
||||||
- Fix: Contents of <noautolink> tags are now properly parsed as Wiki text.
|
- Fix: Contents of <noautolink> tags are now properly parsed as Wiki text.
|
||||||
|
@ -350,7 +350,7 @@ page titles first, as these generally tend to be more specific.
|
|||||||
|
|
||||||
### Filtering pages by title length
|
### Filtering pages by title length
|
||||||
|
|
||||||
$wgLinkTitlesMinimumTitleLength = 3;
|
$wgLinkTitlesMinimumTitleLength = 4;
|
||||||
|
|
||||||
Only link to page titles that have a certain minimum length. In my experience,
|
Only link to page titles that have a certain minimum length. In my experience,
|
||||||
very short titles can be ambiguous. For example, "mg" may be "milligrams" on a
|
very short titles can be ambiguous. For example, "mg" may be "milligrams" on a
|
||||||
|
@ -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.0",
|
"version": "5.0.1",
|
||||||
"license-name": "GPL-2.0+",
|
"license-name": "GPL-2.0+",
|
||||||
"descriptionmsg": "linktitles-desc",
|
"descriptionmsg": "linktitles-desc",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
2
gh-pages
2
gh-pages
Submodule gh-pages updated: b89d3cf098...55f2ec1fc1
@ -1,6 +1,13 @@
|
|||||||
{
|
{
|
||||||
"linktitles": "LinkTitles",
|
"linktitles": "LinkTitles",
|
||||||
"linktitles-desc": "Fügt beim Speichern von Seiten automatisch Querverweise zu vorhandenen Seiten ein.",
|
"linktitles-desc": "Fügt beim Speichern von Seiten automatisch Querverweise zu vorhandenen Seiten ein.",
|
||||||
|
"linktitles-special-info": "LinkTitles-Erweiterung: <$1>\n== Stapelverarbeitung ==\nKlicken Sie auf den Button, um die Stapelverarbeitung zu beginnen. Die Erweiterung wird nacheinander alle Seiten Ihres Wikis mit automatischen Links versehen. Um zu verhindern, daß der Server bei der Ausführung blockiert wird, wird diese Seite sich wiederholt selbst aufrufen. Um die Stapelverarbeitung abzubrechen, schließen Sie einfach diese Seite.",
|
||||||
|
"linktitles-special-submit": "Stapelverarbeitung beginnen",
|
||||||
|
"linktitles-special-progress": "== Verarbeite die Seiten... ==\nDie [$1 LinkTitles-Erweiterung] verarbeitet gerade alle Seiten Ihres Wikis.\n=== Aktuelle Seite: $2 ===",
|
||||||
|
"linktitles-special-page-count": "Seite $1 von $2.\n",
|
||||||
|
"linktitles-special-cancel-notice": "=== Um abzubrechen, schließen Sie diese Seite, oder klicken Sie den 'Stopp'-Knopf in Ihrem Browser ===\n[[Special:LinkTitles|Zu Special:LinkTitles zurückkehren.]]",
|
||||||
|
"linktitles-special-completed-info": "== Stapelverarbeitung abgeschlossen! ==\n{| class=\"wikitable\"\n|-\n| Anzahl der verarbeiteten Seiten: || $1\n|-\n| Verarbeitungsintervall [s]: || $2\n|-\n| Reloads: || $3\n|-\n| Seiten pro Reload: || $4\n|}",
|
||||||
|
"linktitles-bot-comment": "Die LinkTitles-Erweiterung hat automatisch Links zu anderen Seiten hinzugefügt ($1).",
|
||||||
"right-linktitles-batch": "LinkTitles-Stapelverarbeitung ausführen",
|
"right-linktitles-batch": "LinkTitles-Stapelverarbeitung ausführen",
|
||||||
"action-linktitles-batch": "LinkTitles-Stapelverarbeitung auszuführen"
|
"action-linktitles-batch": "LinkTitles-Stapelverarbeitung auszuführen"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
{
|
{
|
||||||
"linktitles": "LinkTitles",
|
"linktitles": "LinkTitles",
|
||||||
"linktitles-desc": "Automatically adds links to existing pages whenever a page is saved.",
|
"linktitles-desc": "Automatically adds links to existing pages whenever a page is saved.",
|
||||||
|
"linktitles-special-info": "LinkTitles extension: $1\n== Batch Linking ==\nYou can start a batch linking process by clicking on the button below. This will go through every page in the normal namespace of your Wiki and insert links automatically. This page will repeatedly reload itself, in order to prevent blocking the server. To interrupt the process, simply close this page.",
|
||||||
|
"linktitles-special-submit": "Start linking now",
|
||||||
|
"linktitles-special-progress": "== Processing pages... ==\nThe [$1 LinkTitles] extension is currently going through every page of your wiki, adding links to existing pages as appropriate.\n=== Current page: $2 ===",
|
||||||
|
"linktitles-special-page-count": "Page $1 of $2.\n",
|
||||||
|
"linktitles-special-cancel-notice": "=== To abort, close this page, or hit the 'Stop' button in your browser ===\n[[Special:LinkTitles|Return to Special:LinkTitles.]]",
|
||||||
|
"linktitles-special-completed-info": "== Batch processing completed! ==\n{| class=\"wikitable\"\n|-\n| total number of pages: || $1\n|-\n| timeout setting [s]: || $2\n|-\n| webpage reloads: || $3\n|-\n| pages scanned per reload interval: || $4\n|}",
|
||||||
|
"linktitles-bot-comment": "The LinkTitles extension automatically added links to existing pages ($1).",
|
||||||
"right-linktitles-batch": "Perform a LinkTitles batch operation",
|
"right-linktitles-batch": "Perform a LinkTitles batch operation",
|
||||||
"action-linktitles-batch": "perform a LinkTitles batch operation"
|
"action-linktitles-batch": "perform a LinkTitles batch operation"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
{
|
{
|
||||||
"linktitles": "Title of the LinkTitles extension; also used for the special page.",
|
"linktitles": "Name of the LinkTitles extension; also used for the special page.",
|
||||||
"linktitles-desc": "Description of the LinkTitles extension.",
|
"linktitles-desc": "Description of the LinkTitles extension.",
|
||||||
|
"linktitles-special-info": "Descriptive text that appears on the Special:LinkTitles page.",
|
||||||
|
"linktitles-special-submit": "Label for submit button to start linking.",
|
||||||
|
"linktitles-special-progress": "Text that is shown on the Special:LinkTitles page while batch processing is executing.",
|
||||||
|
"linktitles-special-page-count": "Number of pages.",
|
||||||
|
"linktitles-special-cancel-notice": "Informs the user how to cancel the LinkTitles batch processing.",
|
||||||
|
"linktitles-special-completed-info": "Text and statistics table that appear when batch processing has completed.",
|
||||||
|
"linktitles-bot-comment": "Comment to add when pages are processed by LinkTitles\\Extension::processPage. The parameter may take the URL the the extension's homepage.",
|
||||||
"right-linktitles-batch": "Describes the right to perform a LinkTitles batch operation.",
|
"right-linktitles-batch": "Describes the right to perform a LinkTitles batch operation.",
|
||||||
"action-linktitles-batch": "Describes the action of performing a LinkTitles batch operation."
|
"action-linktitles-batch": "Describes the action of performing a LinkTitles batch operation."
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ namespace LinkTitles;
|
|||||||
* Provides event handlers and entry points for the extension.
|
* Provides event handlers and entry points for the extension.
|
||||||
*/
|
*/
|
||||||
class Extension {
|
class Extension {
|
||||||
|
const URL = 'https://github.com/bovender/LinkTitles';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler for the PageContentSave hook.
|
* Event handler for the PageContentSave hook.
|
||||||
@ -83,7 +84,7 @@ class Extension {
|
|||||||
$content = $source->getContent()->getContentHandler()->unserializeContent( $result );
|
$content = $source->getContent()->getContentHandler()->unserializeContent( $result );
|
||||||
$source->getPage()->doEditContent(
|
$source->getPage()->doEditContent(
|
||||||
$content,
|
$content,
|
||||||
"Links to existing pages added by LinkTitles bot.", // TODO: i18n
|
\wfMessage( 'linktitles-bot-comment', self::URL ),
|
||||||
EDIT_MINOR | EDIT_FORCE_BOT,
|
EDIT_MINOR | EDIT_FORCE_BOT,
|
||||||
false, // baseRevId
|
false, // baseRevId
|
||||||
$context->getUser()
|
$context->getUser()
|
||||||
|
@ -94,7 +94,7 @@ class Linker {
|
|||||||
// A link to the current page should only be recognized if it appears in
|
// A link to the current page should only be recognized if it appears in
|
||||||
// clear text, i.e. we do not count piped links as existing links.
|
// clear text, i.e. we do not count piped links as existing links.
|
||||||
// (Similarly, by design, redirections should not be counted as existing links.)
|
// (Similarly, by design, redirections should not be counted as existing links.)
|
||||||
if ( $limit == 1 && preg_match( '/[[' . $target->getCaseSensitiveLinkValueRegex() . ']]/' , $source->getText() ) ) {
|
if ( $limit == 1 && preg_match( '/\[\[' . $target->getCaseSensitiveLinkValueRegex() . ']]/' , $source->getText() ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,25 +175,13 @@ class Special extends \SpecialPage {
|
|||||||
* and a form and button to start linking.
|
* and a form and button to start linking.
|
||||||
*/
|
*/
|
||||||
private function buildInfoPage( &$request, &$output ) {
|
private function buildInfoPage( &$request, &$output ) {
|
||||||
|
$output->addWikiMsg( 'linktitles-special-info', Extension::URL );
|
||||||
$url = $request->getRequestURL();
|
$url = $request->getRequestURL();
|
||||||
|
$submitButtonLabel = $this->msg( 'linktitles-special-submit' );
|
||||||
// TODO: Put the page contents in messages in the i18n file.
|
|
||||||
$output->addWikiText(
|
|
||||||
<<<EOF
|
|
||||||
LinkTitles extension: https://github.com/bovender/LinkTitles
|
|
||||||
|
|
||||||
== Batch Linking ==
|
|
||||||
You can start a batch linking process by clicking on the button below.
|
|
||||||
This will go through every page in the normal namespace of your Wiki and
|
|
||||||
insert links automatically. This page will repeatedly reload itself, in
|
|
||||||
order to prevent blocking the server. To interrupt the process, simply
|
|
||||||
close this page.
|
|
||||||
EOF
|
|
||||||
);
|
|
||||||
$output->addHTML(
|
$output->addHTML(
|
||||||
<<<EOF
|
<<<EOF
|
||||||
<form method="post" action="${url}">
|
<form method="post" action="${url}">
|
||||||
<input type="submit" value="Start linking" />
|
<input type="submit" value="$submitButtonLabel" />
|
||||||
<input type="hidden" name="s" value="0" />
|
<input type="hidden" name="s" value="0" />
|
||||||
</form>
|
</form>
|
||||||
EOF
|
EOF
|
||||||
@ -211,34 +199,18 @@ EOF
|
|||||||
$progress = $index / $end * 100;
|
$progress = $index / $end * 100;
|
||||||
$percent = sprintf("%01.1f", $progress);
|
$percent = sprintf("%01.1f", $progress);
|
||||||
|
|
||||||
$output->addWikiText(
|
$output->addWikiMsg( 'linktitles-special-progress', Extension::URL, $curTitle );
|
||||||
|
$pageInfo = $this->msg( 'linktitles-page-count', $index, $end );
|
||||||
|
$output->addWikiMsg( 'linktitles-special-page-count', $index, $end );
|
||||||
|
$output->addHTML( // TODO: do not use the style attribute (to make it work with CSP-enabled sites)
|
||||||
<<<EOF
|
<<<EOF
|
||||||
== Processing pages... ==
|
<div style="width:100%; padding:2px; border:1px solid #000; position: relative; margin-bottom:16px;">
|
||||||
The [https://github.com/bovender/LinkTitles LinkTitles]
|
<span style="position: absolute; left: 50%; font-weight:bold; color:#555;">${percent}%</span>
|
||||||
extension is currently going through every page of your wiki, adding links to
|
|
||||||
existing pages as appropriate.
|
|
||||||
|
|
||||||
=== Current page: $curTitle ===
|
|
||||||
EOF
|
|
||||||
);
|
|
||||||
$output->addHTML(
|
|
||||||
<<<EOF
|
|
||||||
<p>Page ${index} of ${end}.</p>
|
|
||||||
<div style="width:100%; padding:2px; border:1px solid #000; position: relative;
|
|
||||||
margin-bottom:16px;">
|
|
||||||
<span style="position: absolute; left: 50%; font-weight:bold; color:#555;">
|
|
||||||
${percent}%
|
|
||||||
</span>
|
|
||||||
<div style="width:${progress}%; background-color:#bbb; height:20px; margin:0;"></div>
|
<div style="width:${progress}%; background-color:#bbb; height:20px; margin:0;"></div>
|
||||||
</div>
|
</div>
|
||||||
EOF
|
EOF
|
||||||
);
|
);
|
||||||
$output->addWikiText(
|
$output->addWikiMsg( 'linktitles-special-cancel-notice' );
|
||||||
<<<EOF
|
|
||||||
=== To abort, close this page, or hit the 'Stop' button in your browser ===
|
|
||||||
[[Special:LinkTitles|Return to Special:LinkTitles.]]
|
|
||||||
EOF
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -275,20 +247,8 @@ EOF
|
|||||||
*/
|
*/
|
||||||
private function addCompletedInfo( &$output, $start, $end, $reloads ) {
|
private function addCompletedInfo( &$output, $start, $end, $reloads ) {
|
||||||
$pagesPerReload = sprintf('%0.1f', $end / $reloads);
|
$pagesPerReload = sprintf('%0.1f', $end / $reloads);
|
||||||
$output->addWikiText(
|
$output->addWikiMsg( 'linktitltes-special-completed-info', $end,
|
||||||
<<<EOF
|
$config->specialPageReloadAfter, $reloads, $pagesPerReload
|
||||||
== Batch processing completed! ==
|
|
||||||
{| class="wikitable"
|
|
||||||
|-
|
|
||||||
| total number of pages: || ${end}
|
|
||||||
|-
|
|
||||||
| timeout setting [s]: || {$config->specialPageReloadAfter}
|
|
||||||
|-
|
|
||||||
| webpage reloads: || ${reloads}
|
|
||||||
|-
|
|
||||||
| pages scanned per reload interval: || ${pagesPerReload}
|
|
||||||
|}
|
|
||||||
EOF
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,6 @@ class Target {
|
|||||||
* @param String &$title Title of the target page
|
* @param String &$title Title of the target page
|
||||||
*/
|
*/
|
||||||
public function __construct( $namespace, $title, Config &$config ) {
|
public function __construct( $namespace, $title, Config &$config ) {
|
||||||
// print "\n>>>namespace=$namespace;title=$title<<<\n";
|
|
||||||
$this->title = \Title::makeTitleSafe( $namespace, $title );
|
$this->title = \Title::makeTitleSafe( $namespace, $title );
|
||||||
$this->titleValue = $this->title->getTitleValue();
|
$this->titleValue = $this->title->getTitleValue();
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
@ -95,7 +94,7 @@ class Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getPrefixedTitleText() {
|
public function getPrefixedTitleText() {
|
||||||
return $this->getNsPrefix() . $this->getTitleText();
|
return $this->title->getPrefixedText();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,11 +203,8 @@ class Target {
|
|||||||
// If checking for redirects is enabled and the target page does
|
// If checking for redirects is enabled and the target page does
|
||||||
// indeed redirect to the current page, return the page title as-is
|
// indeed redirect to the current page, return the page title as-is
|
||||||
// (unlinked).
|
// (unlinked).
|
||||||
if ( $this->config->checkRedirect ) {
|
if ( $this->config->checkRedirect && $this->redirectsTo( $source ) ) {
|
||||||
$redirectTitle = $this->getContent()->getUltimateRedirectTarget();
|
|
||||||
if ( $redirectTitle && $redirectTitle->equals( $source->getTitle() ) ) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// If the magic word __NOAUTOLINKTARGET__ is enabled and the target
|
// If the magic word __NOAUTOLINKTARGET__ is enabled and the target
|
||||||
// page does indeed contain this magic word, return the page title
|
// page does indeed contain this magic word, return the page title
|
||||||
@ -229,4 +225,16 @@ class Target {
|
|||||||
public function isSameTitle( Source $source) {
|
public function isSameTitle( Source $source) {
|
||||||
return $this->title->equals( $source->getTitle() );
|
return $this->title->equals( $source->getTitle() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether this target redirects to the source.
|
||||||
|
* @param Source $source Source page.
|
||||||
|
* @return bool True if the target redirects to the source.
|
||||||
|
*/
|
||||||
|
public function redirectsTo( $source ) {
|
||||||
|
if ( $this->getContent() ) {
|
||||||
|
$redirectTitle = $this->getContent()->getUltimateRedirectTarget();
|
||||||
|
return $redirectTitle && $redirectTitle->equals( $source->getTitle() );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,6 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addDBData() {
|
public function addDBData() {
|
||||||
$this->title = $this->insertPage( 'source page', 'This page is the test page' )['title'];
|
$this->title = $this->insertPage( 'source page', 'This page is the test page' )['title'];
|
||||||
$this->insertPage( 'link target', 'This page serves as a link target' );
|
$this->insertPage( 'link target', 'This page serves as a link target' );
|
||||||
@ -83,7 +82,6 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideLinkContentSmartModeData
|
* @dataProvider provideLinkContentSmartModeData
|
||||||
*/
|
*/
|
||||||
@ -217,40 +215,45 @@ class LinkTitlesLinkerTest extends LinkTitles\TestCase {
|
|||||||
// Tests for namespace handling are commented out until I find a way to add
|
// Tests for namespace handling are commented out until I find a way to add
|
||||||
// a custom namespace during testing. (The assertTrue assertion below fails.)
|
// a custom namespace during testing. (The assertTrue assertion below fails.)
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * @dataProvider provideLinkContentNamespacesData
|
* @dataProvider provideLinkContentNamespacesData
|
||||||
// */
|
*/
|
||||||
// public function testLinkContentNamespaces( $namespaces, $input, $expectedOutput ) {
|
public function testLinkContentTargetNamespaces( $namespaces, $input, $expectedOutput ) {
|
||||||
// $ns = 4000;
|
$config = new LinkTitles\Config();
|
||||||
// $this->setMwGlobals( [
|
$config->targetNamespaces = $namespaces;
|
||||||
// "wgExtraNamespaces[$ns]" => 'custom_namespace'
|
|
||||||
// ] );
|
|
||||||
// // global $wgExtraNamespaces;
|
|
||||||
// // global $wgContentNamespaces;
|
|
||||||
// // $wgContentNamespaces[] = $ns;
|
|
||||||
// // $wgExtraNamespaces[$ns] = 'custom_adsf';
|
|
||||||
// $this->insertPage( 'in custom namespace', 'This is a page in a custom namespace', $ns );
|
|
||||||
// $this->assertTrue( MWNamespace::exists( $ns ), "The name space with id $ns should exist!" );
|
|
||||||
// LinKTitles\Targets::invalidate();
|
|
||||||
// $config = new LinkTitles\Config();
|
|
||||||
// $config->namespaces = $namespaces;
|
|
||||||
// $linker = new LinkTitles\Linker( $config );
|
|
||||||
// $this->assertSame( $expectedOutput, $linker->linkContent( $this->title, $input ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public function provideLinkContentNamespacesData() {
|
$ns = 4000;
|
||||||
// return [
|
$nsText = 'customnamespace';
|
||||||
// [
|
$this->mergeMwGlobalArrayValue( 'wgExtraNamespaces', [ $ns => $nsText ] );
|
||||||
// [], // namespaces
|
|
||||||
// 'With namespaces = [], page in custom namespace should not be linked',
|
|
||||||
// 'With namespaces = [], page in custom namespace should not be linked'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// [ 4000 ], // namespaces
|
|
||||||
// 'With namespaces = [ 4000 ], page in custom namespace should be linked',
|
|
||||||
// 'With namespaces = [ 4000 ], page [[custom_namespace:in custom namespace]] should be linked'
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
// Reset namespace caches.
|
||||||
|
// See https://stackoverflow.com/q/45974979/270712
|
||||||
|
MWNamespace::getCanonicalNamespaces( true );
|
||||||
|
global $wgContLang;
|
||||||
|
$wgContLang->resetNamespaces();
|
||||||
|
$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 );
|
||||||
|
LinKTitles\Targets::invalidate();
|
||||||
|
$linker = new LinkTitles\Linker( $config );
|
||||||
|
$source = LinkTitles\Source::createFromTitleAndText( $this->title, $input, $config );
|
||||||
|
$result = $linker->linkContent( $source );
|
||||||
|
if ( !$result ) { $result = $input; }
|
||||||
|
$this->assertSame( $expectedOutput, $result );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideLinkContentNamespacesData() {
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
[], // namespaces
|
||||||
|
'With targetNamespaces = [], page in custom namespace should not be linked',
|
||||||
|
'With targetNamespaces = [], page in custom namespace should not be linked'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[ 4000 ], // namespaces
|
||||||
|
'With targetNamespaces = [ 4000 ], page in custom namespace should be linked',
|
||||||
|
'With targetNamespaces = [ 4000 ], page [[customnamespace:In custom namespace|in custom namespace]] should be linked'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,15 @@
|
|||||||
*/
|
*/
|
||||||
class TargetsTest extends LinkTitles\TestCase {
|
class TargetsTest extends LinkTitles\TestCase {
|
||||||
|
|
||||||
/**
|
|
||||||
* This test asserts that the list of potential link targets is 0
|
|
||||||
* @return [type] [description]
|
|
||||||
*/
|
|
||||||
public function testTargets() {
|
public function testTargets() {
|
||||||
|
$config = new LinkTitles\Config();
|
||||||
|
// Include the custom namespace with index 4000 in the count. This is a
|
||||||
|
// very ugly hack. If the custom namespace index in
|
||||||
|
// LinkTitlesLinkerTest::testLinkContentTargetNamespaces() is every changed,
|
||||||
|
// this test will fail.
|
||||||
|
$config->targetNamespaces = [ 4000 ];
|
||||||
$title = \Title::newFromText( 'link target' );
|
$title = \Title::newFromText( 'link target' );
|
||||||
$targets = LinkTitles\Targets::singleton( $title, new LinkTitles\Config() );
|
$targets = LinkTitles\Targets::singleton( $title, $config );
|
||||||
|
|
||||||
// Count number of articles: Inspired by updateArticleCount.php maintenance
|
// Count number of articles: Inspired by updateArticleCount.php maintenance
|
||||||
// script: https://doc.wikimedia.org/mediawiki-core/master/php/updateArticleCount_8php_source.html
|
// script: https://doc.wikimedia.org/mediawiki-core/master/php/updateArticleCount_8php_source.html
|
||||||
|
Reference in New Issue
Block a user