mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 17:59:29 +02:00
Added Namespace support
This commit is contained in:
@ -108,6 +108,7 @@
|
|||||||
global $wgLinkTitlesFirstOnly;
|
global $wgLinkTitlesFirstOnly;
|
||||||
global $wgLinkTitlesSmartMode;
|
global $wgLinkTitlesSmartMode;
|
||||||
global $wgCapitalLinks;
|
global $wgCapitalLinks;
|
||||||
|
global $wgLinkTitlesNamespaces;
|
||||||
|
|
||||||
( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'ASC' : $sort_order = 'DESC';
|
( $wgLinkTitlesPreferShortTitles ) ? $sort_order = 'ASC' : $sort_order = 'DESC';
|
||||||
( $wgLinkTitlesFirstOnly ) ? $limit = 1 : $limit = -1;
|
( $wgLinkTitlesFirstOnly ) ? $limit = 1 : $limit = -1;
|
||||||
@ -121,6 +122,23 @@
|
|||||||
'("' . implode( '", "',$wgLinkTitlesBlackList ) . '", "' .
|
'("' . implode( '", "',$wgLinkTitlesBlackList ) . '", "' .
|
||||||
LinkTitles::$currentTitle->getDbKey() . '")' );
|
LinkTitles::$currentTitle->getDbKey() . '")' );
|
||||||
|
|
||||||
|
$currentNamespace = $title->getNamespace();
|
||||||
|
|
||||||
|
// Build our weight list. Make sure current namespace is first element
|
||||||
|
$namespaces = array_unshift( array($currentNamespace), array_diff($wgLinkTitlesNamespaces, array($currentNamespace)) );
|
||||||
|
|
||||||
|
// No need for sanitiy check. we are sure that we have at least one element in the array
|
||||||
|
$weightSelect = "CASE page_namespace ";
|
||||||
|
$currentWeight = 0;
|
||||||
|
foreach ($namespaces as &$namspacevalue) {
|
||||||
|
$currentWeight = $currentWeight + 100;
|
||||||
|
$weightSelect = $weightSelect . " WHEN " . $namspacevalue . " THEN " . $currentWeight . PHP_EOL;
|
||||||
|
}
|
||||||
|
$weightSelect = $weightSelect . " END ";
|
||||||
|
|
||||||
|
$namespacesClause = str_replace( '_', ' ',
|
||||||
|
'("' . implode( '", "',$namespaces ) . '")' );
|
||||||
|
|
||||||
// Build an SQL query and fetch all page titles ordered by length from
|
// Build an SQL query and fetch all page titles ordered by length from
|
||||||
// shortest to longest. Only titles from 'normal' pages (namespace uid
|
// shortest to longest. Only titles from 'normal' pages (namespace uid
|
||||||
// = 0) are returned. Since the db may be sqlite, we need a try..catch
|
// = 0) are returned. Since the db may be sqlite, we need a try..catch
|
||||||
@ -129,21 +147,20 @@
|
|||||||
try {
|
try {
|
||||||
$res = $dbr->select(
|
$res = $dbr->select(
|
||||||
'page',
|
'page',
|
||||||
'page_title',
|
array( 'page_title', "page_namespace" , "weight" = > $weightSelect),
|
||||||
array(
|
array(
|
||||||
'page_namespace = 0',
|
|
||||||
'CHAR_LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength,
|
'CHAR_LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength,
|
||||||
'page_title NOT IN ' . $blackList,
|
'page_title NOT IN ' . $blackList,
|
||||||
),
|
),
|
||||||
__METHOD__,
|
__METHOD__,
|
||||||
array( 'ORDER BY' => 'CHAR_LENGTH(page_title) ' . $sort_order )
|
array( 'ORDER BY' => 'weight ASC, CHAR_LENGTH(page_title) ' . $sort_order )
|
||||||
);
|
);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$res = $dbr->select(
|
$res = $dbr->select(
|
||||||
'page',
|
'page',
|
||||||
'page_title',
|
'page_title',
|
||||||
array(
|
array(
|
||||||
'page_namespace = 0',
|
'page_namespace IN ' . $namespacesClause,
|
||||||
'LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength,
|
'LENGTH(page_title) >= ' . $wgLinkTitlesMinimumTitleLength,
|
||||||
'page_title NOT IN ' . $blackList,
|
'page_title NOT IN ' . $blackList,
|
||||||
),
|
),
|
||||||
@ -154,7 +171,7 @@
|
|||||||
|
|
||||||
// Iterate through the page titles
|
// Iterate through the page titles
|
||||||
foreach( $res as $row ) {
|
foreach( $res as $row ) {
|
||||||
LinkTitles::newTarget( $row->page_title );
|
LinkTitles::newTarget($row->page_namespace, $row->page_title );
|
||||||
|
|
||||||
// split the page content by [[...]] groups
|
// split the page content by [[...]] groups
|
||||||
// credits to inhan @ StackOverflow for suggesting preg_split
|
// credits to inhan @ StackOverflow for suggesting preg_split
|
||||||
@ -249,7 +266,7 @@
|
|||||||
// Build an anonymous callback function to be used in simple mode.
|
// Build an anonymous callback function to be used in simple mode.
|
||||||
private static function simpleModeCallback( array $matches ) {
|
private static function simpleModeCallback( array $matches ) {
|
||||||
if ( LinkTitles::checkTargetPage() ) {
|
if ( LinkTitles::checkTargetPage() ) {
|
||||||
return '[[' . $matches[0] . ']]';
|
return '[[' . LinkTitles::$targetTitle . "|" . $matches[0] . ']]';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -305,9 +322,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets member variables for the current target page.
|
/// Sets member variables for the current target page.
|
||||||
private static function newTarget( $title ) {
|
private static function newTarget($ns, $title ) {
|
||||||
// @todo Make this wiki namespace aware.
|
// @todo Make this wiki namespace aware.
|
||||||
LinkTitles::$targetTitle = Title::makeTitle( NS_MAIN, $title);
|
LinkTitles::$targetTitle = Title::makeTitle( $ns, $title);
|
||||||
LinkTitles::$targetContent = null;
|
LinkTitles::$targetContent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +189,10 @@
|
|||||||
/// @ingroup config
|
/// @ingroup config
|
||||||
$wgLinkTitlesTimeLimit = 0.2;
|
$wgLinkTitlesTimeLimit = 0.2;
|
||||||
|
|
||||||
|
/// Namespaces to search in weighted order.
|
||||||
|
/// Namespace of the page will always to highest weight, rest in given order
|
||||||
|
$wgLinkTitlesNamespaces = array(NS_USER);
|
||||||
|
|
||||||
/// @cond
|
/// @cond
|
||||||
$wgExtensionCredits['parserhook'][] = array(
|
$wgExtensionCredits['parserhook'][] = array(
|
||||||
'path' => __FILE__,
|
'path' => __FILE__,
|
||||||
|
66
LinkTitles.phpproj
Normal file
66
LinkTitles.phpproj
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Name>LinkTitles</Name>
|
||||||
|
<ProjectGuid>{1c5e70d9-0077-48f3-9e7a-97e6e7967c2e}</ProjectGuid>
|
||||||
|
<RootNamespace>LinkTitles</RootNamespace>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<ProjectTypeGuids>{A0786B88-2ADB-4C21-ABE8-AA2D79766269}</ProjectTypeGuids>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
<IncludeDebugInformation>true</IncludeDebugInformation>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<IncludeDebugInformation>false</IncludeDebugInformation>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="release\LinkTitles-0.0.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-0.0.2.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-0.0.4.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-0.0.5.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-0.0.6.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-0.0.7.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.0.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.1.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.2.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.2.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.3.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.3.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.3.2.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.4.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.5.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.6.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.6.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.8.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-1.8.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.0.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.1.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.1.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.2.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.2.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.2.2.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.3.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.3.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.4.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-2.4.1.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-3.0.0.tar.gz" />
|
||||||
|
<Compile Include="release\LinkTitles-3.1.0.tar.gz" />
|
||||||
|
<Compile Include=".gitignore" />
|
||||||
|
<Compile Include=".gitmodules" />
|
||||||
|
<Compile Include="Doxyfile" />
|
||||||
|
<Compile Include="LinkTitles.body.php" />
|
||||||
|
<Compile Include="LinkTitles.cli.php" />
|
||||||
|
<Compile Include="LinkTitles.i18n.magic.php" />
|
||||||
|
<Compile Include="LinkTitles.i18n.php" />
|
||||||
|
<Compile Include="LinkTitles.php" />
|
||||||
|
<Compile Include="NEWS" />
|
||||||
|
<Compile Include="README.md" />
|
||||||
|
<Compile Include="README_DOC.md" />
|
||||||
|
<Compile Include="release.sh" />
|
||||||
|
<Compile Include="SpecialLinkTitles.php" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="gh-pages" />
|
||||||
|
<Folder Include="release" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
Reference in New Issue
Block a user