Jack Phoenix has submitted this change and it was merged. Change subject: Initial commit of a new extension ......................................................................
Initial commit of a new extension Bug: T144245 Change-Id: I682db8d14eeeb53b136a12ef6a79bc7353478b7d --- A SpecialUnusedRedirects.php A UnusedRedirects.alias.php A extension.json A i18n/en.json A i18n/fi.json A i18n/fr.json 6 files changed, 266 insertions(+), 0 deletions(-) Approvals: Jack Phoenix: Verified; Looks good to me, approved diff --git a/SpecialUnusedRedirects.php b/SpecialUnusedRedirects.php new file mode 100644 index 0000000..0119fcd --- /dev/null +++ b/SpecialUnusedRedirects.php @@ -0,0 +1,188 @@ +<?php +/** + * Implements Special:UnusedRedirects. Based on core Special:UnusedRedirects' + * code by Rob Church <robc...@gmail.com>. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup SpecialPage + * @author Jack Phoenix <j...@countervandalism.net> + * @date 30 August 2016 + * @see https://phabricator.wikimedia.org/T144245 + */ + +/** + * @ingroup SpecialPage + */ +class UnusedRedirectsPage extends QueryPage { + function __construct( $name = 'UnusedRedirects' ) { + parent::__construct( $name ); + } + + public function isExpensive() { + return true; + } + + function getPageHeader() { + return $this->msg( 'unusedredirects-text' )->parseAsBlock(); + } + + public function getQueryInfo() { + return [ + 'tables' => [ + 'p1' => 'page', + 'redirect', + 'p2' => 'page', + 'pagelinks', + ], + 'fields' => [ + 'namespace' => 'p1.page_namespace', + 'title' => 'p1.page_title', + 'value' => 'p1.page_title', + 'rd_namespace', + 'rd_title', + 'rd_fragment', + 'rd_interwiki', + 'redirid' => 'p2.page_id', + ], + 'conds' => [ + 'p1.page_is_redirect' => 1, + 'pl_from IS NULL' + ], + 'join_conds' => [ + 'redirect' => [ 'LEFT JOIN', 'rd_from = p1.page_id' ], + 'p2' => [ 'LEFT JOIN', [ + 'p2.page_namespace = rd_namespace', + 'p2.page_title = rd_title' ] + ], + 'pagelinks' => [ 'LEFT JOIN', 'pl_title = p1.page_title' ] + ] + ]; + } + + function getOrderFields() { + return [ 'p1.page_namespace', 'p1.page_title' ]; + } + + /** + * Cache page existence for performance + * + * @param IDatabase $db + * @param ResultWrapper $res + */ + function preprocessResults( $db, $res ) { + if ( !$res->numRows() ) { + return; + } + + $batch = new LinkBatch; + foreach ( $res as $row ) { + $batch->add( $row->namespace, $row->title ); + $batch->addObj( $this->getRedirectTarget( $row ) ); + } + $batch->execute(); + + // Back to start for display + $res->seek( 0 ); + } + + protected function getRedirectTarget( $row ) { + if ( isset( $row->rd_title ) ) { + // ashley: added the below checks, the core code (w/o 'em) was + // returning weird results locally (things which were *not* supposed + // to be formatted like interwiki links were formatted like IW links) + // Seems that this breaks the display of fragments though, I'm not + // sure why, but it's not a big deal IMHO. + $fragment = $interwiki = ''; + if ( isset( $row->rd_fragment ) && $row->rd_fragment !== null ) { + $fragment = $row->rd_fragment; + } + if ( isset( $row->rd_interwiki ) && $row->rd_interwiki !== null ) { + $interwiki = $row->rd_interwiki; + } + return Title::makeTitle( + $row->rd_namespace, + $row->rd_title, + $fragment, + $interwiki + ); + } else { + $title = Title::makeTitle( $row->namespace, $row->title ); + $article = WikiPage::factory( $title ); + + return $article->getRedirectTarget(); + } + } + + /** + * @param Skin $skin + * @param object $result Result row + * @return string + */ + function formatResult( $skin, $result ) { + # Make a link to the redirect itself + $rd_title = Title::makeTitle( $result->namespace, $result->title ); + $rd_link = Linker::link( + $rd_title, + null, + [], + [ 'redirect' => 'no' ] + ); + + # Find out where the redirect leads + $target = $this->getRedirectTarget( $result ); + if ( $target ) { + # Make a link to the destination page + $lang = $this->getLanguage(); + $arr = $lang->getArrow() . $lang->getDirMark(); + $targetLink = Linker::link( $target ); + + return "$rd_link $arr $targetLink"; + } else { + return "<del>$rd_link</del>"; + } + } + + /** + * A should come before Z (bug 30907) + * @return bool + */ + function sortDescending() { + return false; + } + + /** + * Group this special page under the correct group in Special:SpecialPages. + * + * @return string + */ + protected function getGroupName() { + return 'maintenance'; + } + + /** + * Add the UnusedRedirects 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( 'UnusedRedirectsPage' /* class */, 'UnusedRedirects' /* special page name */ ); + return true; + } +} diff --git a/UnusedRedirects.alias.php b/UnusedRedirects.alias.php new file mode 100644 index 0000000..1f05f1c --- /dev/null +++ b/UnusedRedirects.alias.php @@ -0,0 +1,24 @@ +<?php +/** + * Aliases for the UnusedRedirects extension. + * + * @file + * @ingroup Extensions + */ + +$aliases = array(); + +/** English */ +$aliases['en'] = array( + 'UnusedRedirects' => array( 'UnusedRedirects' ), +); + +/** Finnish (suomi) */ +$aliases['fi'] = array( + 'UnusedRedirects' => array( 'Käyttämättömät ohjaukset' ), +); + +/** French (français) */ +$aliases['fr'] = array( + 'UnusedRedirects' => array( 'Redirections_inutilisées', 'RedirectionsInutilisées', 'Redirections_inutilisees', 'RedirectionsInutilisees', 'Redirections_non_utilisées', 'RedirectionsNonUtilisées', 'Redirections_non_utilisees', 'RedirectionsNonUtilisees' ), +); \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..21fab02 --- /dev/null +++ b/extension.json @@ -0,0 +1,29 @@ +{ + "name": "UnusedRedirects", + "version": "1.0", + "author": "Jack Phoenix", + "license-name": "GPL-2.0+", + "url": "https://www.mediawiki.org/wiki/Extension:UnusedRedirects", + "description": "[[Special:UnusedRedirects|Lists unused redirects]]", + "type": "specialpage", + "SpecialPages": { + "UnusedRedirects": "UnusedRedirectsPage" + }, + "MessagesDirs": { + "UnusedRedirects": [ + "i18n" + ] + }, + "ExtensionMessagesFiles": { + "UnusedRedirectsAlias": "UnusedRedirects.alias.php" + }, + "AutoloadClasses": { + "UnusedRedirectsPage": "SpecialUnusedRedirects.php" + }, + "Hooks": { + "wgQueryPages": [ + "UnusedRedirectsPage::onwgQueryPages" + ] + }, + "manifest_version": 1 +} diff --git a/i18n/en.json b/i18n/en.json new file mode 100644 index 0000000..7f21c80 --- /dev/null +++ b/i18n/en.json @@ -0,0 +1,9 @@ +{ + "@metadata": { + "authors": [ + "Jack Phoenix <j...@countervandalism.net>" + ] + }, + "unusedredirects": "Unused redirects", + "unusedredirects-text": "" +} \ No newline at end of file diff --git a/i18n/fi.json b/i18n/fi.json new file mode 100644 index 0000000..bfa30af --- /dev/null +++ b/i18n/fi.json @@ -0,0 +1,8 @@ +{ + "@metadata": { + "authors": [ + "Jack Phoenix <j...@countervandalism.net>" + ] + }, + "unusedredirects": "Käyttämättömät ohjaukset" +} \ No newline at end of file diff --git a/i18n/fr.json b/i18n/fr.json new file mode 100644 index 0000000..12eb1ed --- /dev/null +++ b/i18n/fr.json @@ -0,0 +1,8 @@ +{ + "@metadata": { + "authors": [ + "Jack Phoenix <j...@countervandalism.net>" + ] + }, + "unusedredirects": "Redirections inutilisées" +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/308323 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I682db8d14eeeb53b136a12ef6a79bc7353478b7d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UnusedRedirects Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <j...@countervandalism.net> Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits