Ori.livneh has submitted this change and it was merged. Change subject: Initial version of Disambiguator extension ......................................................................
Initial version of Disambiguator extension Enables the designation of disambiguation pages with the __DISAMBIG__ magic word. Also provides the following: * Special Page listing all disambiguation pages * Special Page listing all pages that link to disambiguation pages * APIs for both of the above Solves bug 6754 and bug 35981 and bug 44040 See https://www.mediawiki.org/wiki/Extension:Disambiguator Change-Id: Idf9e37a576c7bb52c717f754bf09be5809391242 --- A Disambiguator.hooks.php A Disambiguator.i18n.alias.php A Disambiguator.i18n.magic.php A Disambiguator.i18n.php A Disambiguator.php A specials/SpecialDisambiguationPageLinks.php A specials/SpecialDisambiguationPages.php 7 files changed, 310 insertions(+), 0 deletions(-) Approvals: Ori.livneh: Verified; Looks good to me, approved diff --git a/Disambiguator.hooks.php b/Disambiguator.hooks.php new file mode 100644 index 0000000..ea7fc20 --- /dev/null +++ b/Disambiguator.hooks.php @@ -0,0 +1,30 @@ +<?php +/** + * Hooks for Disambiguator extension + * + * @file + * @ingroup Extensions + */ + +class DisambiguatorHooks { + /** + * @param array &$doubleUnderscoreIDs + * @return bool + */ + public static function onGetDoubleUnderscoreIDs( &$doubleUnderscoreIDs ) { + $doubleUnderscoreIDs[] = 'disambiguation'; + return true; + } + + /** + * Add the Disambiguator special pages to the list of QueryPages. This + * allows direct access via the API. + * @param array &$queryPages + * @return bool + */ + public static function onwgQueryPages( &$queryPages ) { + $queryPages[] = array( 'SpecialDisambiguationPages', 'DisambiguationPages' ); + $queryPages[] = array( 'SpecialDisambiguationPageLinks', 'DisambiguationPageLinks' ); + return true; + } +} diff --git a/Disambiguator.i18n.alias.php b/Disambiguator.i18n.alias.php new file mode 100644 index 0000000..f27e250 --- /dev/null +++ b/Disambiguator.i18n.alias.php @@ -0,0 +1,14 @@ +<?php +/** + * Aliases for special pages of the Disambiguator extension + * + * @file + * @ingroup Extensions + */ + +$specialPageAliases = array(); + +/** English (English) */ +$specialPageAliases['en'] = array( + 'DisambiguationPageLinks' => array( 'DisambiguationPageLinks' ), +); diff --git a/Disambiguator.i18n.magic.php b/Disambiguator.i18n.magic.php new file mode 100644 index 0000000..0b50339 --- /dev/null +++ b/Disambiguator.i18n.magic.php @@ -0,0 +1,14 @@ +<?php +/** + * Internationalisation file for magic words in the Disambiguator extension + * + * @file + * @ingroup Extensions + */ + +$magicWords = array(); + +/** English (English) */ +$magicWords['en'] = array( + 'disambiguation' => array( 1, '__DISAMBIG__' ), +); diff --git a/Disambiguator.i18n.php b/Disambiguator.i18n.php new file mode 100644 index 0000000..35fd3ff --- /dev/null +++ b/Disambiguator.i18n.php @@ -0,0 +1,34 @@ +<?php +/** + * Internationalisation file for the Disambiguator extension + * + * @file + * @ingroup Extensions + */ + +$messages = array(); + +/** English + */ +$messages['en'] = array( + 'disambig-desc' => 'Adds the tag <code><nowiki>__DISAMBIG__</nowiki></code> to mark [[Special:DisambiguationPages|disambiguation pages]].', + # Special:DisambiguationPages + 'disambiguationpages' => 'Disambiguation pages', + 'disambiguationpages-summary' => "The following is a list of all disambiguation pages on {{SITENAME}}.<br /> +A page is treated as a disambiguation page if the page contains the tag <code><nowiki>__DISAMBIG__</nowiki></code> (or an equivalent alias).", + # Special:DisambiguationPageLinks + 'disambiguationpagelinks' => 'Pages linking to disambiguation pages', + 'disambiguationpagelinks-summary' => "The following pages contain at least one link to a disambiguation page. +They may need to link to a more appropriate page instead.<br /> +A page is treated as a disambiguation page if the page contains the tag <code><nowiki>__DISAMBIG__</nowiki></code> (or an equivalent alias).", +); + +/** Message documentation (Message documentation) + */ +$messages['qqq'] = array( + 'disambig-desc' => '{{desc}}', + 'disambiguationpages' => 'Title of the Special Page that shows all disambiguation pages', + 'disambiguationpages-summary' => 'Header text explaining the purpose of the Special:DisambiguationPages page. It is not necessary to translate "<nowiki>__DISAMBIG__</nowiki>".', + 'disambiguationpagelinks' => 'Title of the Special Page that shows all pages with links needing disambiguation', + 'disambiguationpagelinks-summary' => 'Header text explaining the purpose of the Special:DisambiguationPageLinks page. It is not necessary to translate "<nowiki>__DISAMBIG__</nowiki>".', +); diff --git a/Disambiguator.php b/Disambiguator.php new file mode 100644 index 0000000..8281486 --- /dev/null +++ b/Disambiguator.php @@ -0,0 +1,64 @@ +<?php +/** + * Disambiguator extension + * Enables the designation of disambiguation pages with the __DISAMBIG__ + * magic word. Also provides a Special Page listing all pages that link to + * disambiguation pages. + * + * For more info see http://mediawiki.org/wiki/Extension:Disambiguator + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * This program is distributed WITHOUT ANY WARRANTY. + * + * @file + * @ingroup Extensions + * @author Ryan Kaldari + * @license MIT "Expat" License + */ + +$wgExtensionCredits['other'][] = array( + 'path' => __FILE__, + 'name' => 'Disambiguator', + 'author' => array( + 'Ryan Kaldari', + ), + 'version' => '1.0', + 'url' => 'https://www.mediawiki.org/wiki/Extension:Disambiguator', + 'descriptionmsg' => 'disambig-desc', +); + +/* Setup */ + +$dir = __DIR__; + +// Register files +$wgAutoloadClasses['DisambiguatorHooks'] = $dir . '/Disambiguator.hooks.php'; +$wgAutoloadClasses['SpecialDisambiguationPages'] = $dir . '/specials/SpecialDisambiguationPages.php'; +$wgAutoloadClasses['SpecialDisambiguationPageLinks'] = $dir . '/specials/SpecialDisambiguationPageLinks.php'; +$wgExtensionMessagesFiles['Disambiguator'] = $dir . '/Disambiguator.i18n.php'; +$wgExtensionMessagesFiles['DisambiguatorAlias'] = $dir . '/Disambiguator.i18n.alias.php'; +$wgExtensionMessagesFiles['DisambiguatorMagic'] = $dir . '/Disambiguator.i18n.magic.php'; + +// Register hooks +$wgHooks['GetDoubleUnderscoreIDs'][] = 'DisambiguatorHooks::onGetDoubleUnderscoreIDs'; +$wgHooks['wgQueryPages'][] = 'DisambiguatorHooks::onwgQueryPages'; + +// Register special pages +$wgSpecialPages['DisambiguationPages'] = 'SpecialDisambiguationPages'; +$wgSpecialPageGroups['DisambiguationPages'] = 'pages'; +$wgSpecialPages['DisambiguationPageLinks'] = 'SpecialDisambiguationPageLinks'; +$wgSpecialPageGroups['DisambiguationPageLinks'] = 'pages'; + +/* Configuration */ + +// TODO: Allow disambiguation links to be assigned a unique class +#$wgDisambiguatorIndicateLinks = true; diff --git a/specials/SpecialDisambiguationPageLinks.php b/specials/SpecialDisambiguationPageLinks.php new file mode 100644 index 0000000..712ca88 --- /dev/null +++ b/specials/SpecialDisambiguationPageLinks.php @@ -0,0 +1,86 @@ +<?php +/** + * DisambiguationPageLinks SpecialPage for Disambiguator extension + * This page lists all pages that link to disambiguation pages. + * + * @file + * @ingroup Extensions + */ + +class SpecialDisambiguationPageLinks extends QueryPage { + + /** + * Initialize the special page. + */ + public function __construct() { + parent::__construct( 'DisambiguationPageLinks' ); + } + + function isExpensive() { + return true; + } + + function isSyndicated() { + return false; + } + + function getQueryInfo() { + return array ( + 'tables' => array( + 'p1' => 'page', + 'p2' => 'page', + 'pagelinks', + 'page_props' + ), + 'fields' => array( + 'value' => 'pl_from', + 'namespace' => 'p2.page_namespace', + 'title' => 'p2.page_title', + 'to_id' => 'pp_page', + 'to_namespace' => 'p1.page_namespace', + 'to_title' => 'p1.page_title', + ), + 'conds' => array( + 'p1.page_id = pp_page', + 'pp_propname' => 'disambiguation', + 'pl_namespace = p1.page_namespace', + 'pl_title = p1.page_title', + 'p2.page_id = pl_from', + 'p2.page_namespace' => MWNamespace::getContentNamespaces() + ) + ); + } + + /** + * Order the results by namespace, title, and ID of linked page (to_id). + * @return array + */ + function getOrderFields() { + return array( 'namespace', 'title', 'to_id' ); + } + + function sortDescending() { + return false; + } + + function formatResult( $skin, $result ) { + $fromTitle = Title::newFromID( $result->value ); + $toTitle = Title::newFromID( $result->to_id ); + + $from = Linker::linkKnown( $fromTitle ); + $edit = Linker::link( + $fromTitle, + $this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->escaped(), + array(), + array( 'redirect' => 'no', 'action' => 'edit' ) + ); + $arr = $this->getLanguage()->getArrow(); + $to = Linker::linkKnown( $toTitle ); + + return "$from $edit $arr $to"; + } + + protected function getGroupName() { + return 'pages'; + } +} diff --git a/specials/SpecialDisambiguationPages.php b/specials/SpecialDisambiguationPages.php new file mode 100644 index 0000000..cb0c3f8 --- /dev/null +++ b/specials/SpecialDisambiguationPages.php @@ -0,0 +1,68 @@ +<?php +/** + * DisambiguationPages SpecialPage for Disambiguator extension + * This page lists all the disambiguation pages + * + * @file + * @ingroup Extensions + */ + +class SpecialDisambiguationPages extends QueryPage { + + /** + * Initialize the special page. + */ + public function __construct() { + parent::__construct( 'DisambiguationPages' ); + } + + function isExpensive() { + return true; + } + + function isSyndicated() { + return false; + } + + function getQueryInfo() { + return array ( + 'tables' => array( + 'page', + 'page_props' + ), + 'fields' => array( + 'value' => 'page.page_id', + 'namespace' => 'page.page_namespace', + 'title' => 'page.page_title', + ), + 'conds' => array( + 'page_id = pp_page', + 'pp_propname' => 'disambiguation', + // Exclude disambiguation templates + 'page_namespace != ' . NS_TEMPLATE + ) + ); + } + + /** + * Order the results by namespace and title. + * @return array + */ + function getOrderFields() { + return array( 'namespace', 'title' ); + } + + function sortDescending() { + return false; + } + + function formatResult( $skin, $result ) { + $title = Title::newFromID( $result->value ); + $link = Linker::linkKnown( $title ); + return $link; + } + + protected function getGroupName() { + return 'pages'; + } +} -- To view, visit https://gerrit.wikimedia.org/r/41043 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Idf9e37a576c7bb52c717f754bf09be5809391242 Gerrit-PatchSet: 15 Gerrit-Project: mediawiki/extensions/Disambiguator Gerrit-Branch: master Gerrit-Owner: Kaldari <[email protected]> Gerrit-Reviewer: Alex Monk <[email protected]> Gerrit-Reviewer: Anomie <[email protected]> Gerrit-Reviewer: Asher <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Jdlrobson <[email protected]> Gerrit-Reviewer: Kaldari <[email protected]> Gerrit-Reviewer: MZMcBride <[email protected]> Gerrit-Reviewer: Ori.livneh <[email protected]> Gerrit-Reviewer: Reedy <[email protected]> Gerrit-Reviewer: Siebrand <[email protected]> Gerrit-Reviewer: awjrichards <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
