2004-08-15 19:54:15 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-06-21 12:59:04 +00:00
|
|
|
* 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.,
|
2010-06-21 13:16:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-06-21 12:59:04 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-14 19:19:41 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2023-04-03 18:41:41 +00:00
|
|
|
|
|
|
|
|
namespace MediaWiki\Specials;
|
|
|
|
|
|
2020-10-06 17:55:00 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
|
|
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
2024-10-01 17:28:06 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\QueryPage;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-04-03 18:41:41 +00:00
|
|
|
use Skin;
|
|
|
|
|
use stdClass;
|
2023-04-19 15:35:34 +00:00
|
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\IResultWrapper;
|
2017-02-19 05:03:13 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2024-05-13 20:18:10 +00:00
|
|
|
* List of redirects to another redirecting page.
|
|
|
|
|
*
|
|
|
|
|
* The software will by default not follow double redirects, to prevent loops.
|
|
|
|
|
* Editors are encouraged to fix these, and can discover them via this page.
|
2010-06-21 12:59:04 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2019-04-14 15:14:22 +00:00
|
|
|
class SpecialDoubleRedirects extends QueryPage {
|
2020-10-06 17:55:00 +00:00
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private IContentHandlerFactory $contentHandlerFactory;
|
|
|
|
|
private LinkBatchFactory $linkBatchFactory;
|
2020-10-06 17:55:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param IContentHandlerFactory $contentHandlerFactory
|
|
|
|
|
* @param LinkBatchFactory $linkBatchFactory
|
2023-04-19 15:35:34 +00:00
|
|
|
* @param IConnectionProvider $dbProvider
|
2020-10-06 17:55:00 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
IContentHandlerFactory $contentHandlerFactory,
|
|
|
|
|
LinkBatchFactory $linkBatchFactory,
|
2023-04-19 15:35:34 +00:00
|
|
|
IConnectionProvider $dbProvider
|
2020-10-06 17:55:00 +00:00
|
|
|
) {
|
|
|
|
|
parent::__construct( 'DoubleRedirects' );
|
|
|
|
|
$this->contentHandlerFactory = $contentHandlerFactory;
|
|
|
|
|
$this->linkBatchFactory = $linkBatchFactory;
|
2023-04-19 15:35:34 +00:00
|
|
|
$this->setDatabaseProvider( $dbProvider );
|
2004-08-15 19:54:15 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2015-08-20 13:02:54 +00:00
|
|
|
public function isExpensive() {
|
2012-09-24 17:44:57 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 00:17:37 +00:00
|
|
|
public function isSyndicated() {
|
2012-09-24 17:44:57 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-18 00:17:37 +00:00
|
|
|
protected function sortDescending() {
|
2012-09-24 17:44:57 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2004-08-15 19:54:15 +00:00
|
|
|
|
2020-05-18 00:17:37 +00:00
|
|
|
protected function getPageHeader() {
|
2011-12-22 20:37:55 +00:00
|
|
|
return $this->msg( 'doubleredirectstext' )->parseAsBlock();
|
2004-08-15 19:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
2020-05-18 01:16:17 +00:00
|
|
|
private function reallyGetQueryInfo( $namespace = null, $title = null ) {
|
2007-08-22 21:52:44 +00:00
|
|
|
$limitToTitle = !( $namespace === null && $title === null );
|
2016-02-17 09:09:32 +00:00
|
|
|
$retval = [
|
|
|
|
|
'tables' => [
|
2012-09-19 12:20:32 +00:00
|
|
|
'ra' => 'redirect',
|
|
|
|
|
'rb' => 'redirect',
|
|
|
|
|
'pa' => 'page',
|
|
|
|
|
'pb' => 'page'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'fields' => [
|
2012-09-19 12:20:32 +00:00
|
|
|
'namespace' => 'pa.page_namespace',
|
|
|
|
|
'title' => 'pa.page_title',
|
|
|
|
|
|
2017-08-04 02:58:29 +00:00
|
|
|
'b_namespace' => 'pb.page_namespace',
|
|
|
|
|
'b_title' => 'pb.page_title',
|
2022-07-12 03:30:26 +00:00
|
|
|
'b_fragment' => 'ra.rd_fragment',
|
2012-09-19 12:20:32 +00:00
|
|
|
|
|
|
|
|
// Select fields from redirect instead of page. Because there may
|
|
|
|
|
// not actually be a page table row for this target (e.g. for interwiki redirects)
|
2017-08-04 02:58:29 +00:00
|
|
|
'c_namespace' => 'rb.rd_namespace',
|
|
|
|
|
'c_title' => 'rb.rd_title',
|
|
|
|
|
'c_fragment' => 'rb.rd_fragment',
|
|
|
|
|
'c_interwiki' => 'rb.rd_interwiki',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'conds' => [
|
2012-09-19 12:20:32 +00:00
|
|
|
'ra.rd_from = pa.page_id',
|
|
|
|
|
|
2017-02-20 22:31:04 +00:00
|
|
|
// Filter out redirects where the target goes interwiki (T42353).
|
2012-09-19 12:20:32 +00:00
|
|
|
// This isn't an optimization, it is required for correct results,
|
|
|
|
|
// otherwise a non-double redirect like Bar -> w:Foo will show up
|
|
|
|
|
// like "Bar -> Foo -> w:Foo".
|
2023-10-03 17:29:38 +00:00
|
|
|
'ra.rd_interwiki' => '',
|
2012-09-19 12:20:32 +00:00
|
|
|
|
|
|
|
|
'pb.page_namespace = ra.rd_namespace',
|
|
|
|
|
'pb.page_title = ra.rd_title',
|
|
|
|
|
|
|
|
|
|
'rb.rd_from = pb.page_id',
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
];
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
if ( $limitToTitle ) {
|
|
|
|
|
$retval['conds']['pa.page_namespace'] = $namespace;
|
|
|
|
|
$retval['conds']['pa.page_title'] = $title;
|
2007-08-22 21:52:44 +00:00
|
|
|
}
|
2013-04-14 19:18:38 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
return $retval;
|
2007-08-22 21:52:44 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2015-08-20 13:02:54 +00:00
|
|
|
public function getQueryInfo() {
|
2010-12-22 14:16:25 +00:00
|
|
|
return $this->reallyGetQueryInfo();
|
2006-04-20 21:52:30 +00:00
|
|
|
}
|
2004-08-15 19:54:15 +00:00
|
|
|
|
2020-05-18 00:17:37 +00:00
|
|
|
protected function getOrderFields() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'ra.rd_namespace', 'ra.rd_title' ];
|
2004-08-15 19:54:15 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2013-04-14 19:18:38 +00:00
|
|
|
/**
|
|
|
|
|
* @param Skin $skin
|
2020-11-15 12:40:46 +00:00
|
|
|
* @param stdClass $result Result row
|
2013-04-14 19:18:38 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2020-05-18 00:17:37 +00:00
|
|
|
public function formatResult( $skin, $result ) {
|
2017-08-04 02:58:29 +00:00
|
|
|
// If no Title B or C is in the query, it means this came from
|
|
|
|
|
// querycache (which only saves the 3 columns for title A).
|
2012-09-19 12:20:32 +00:00
|
|
|
// That does save the bulk of the query cost, but now we need to
|
|
|
|
|
// get a little more detail about each individual entry quickly
|
|
|
|
|
// using the filter of reallyGetQueryInfo.
|
2017-08-10 20:26:08 +00:00
|
|
|
$deep = false;
|
|
|
|
|
if ( $result ) {
|
|
|
|
|
if ( isset( $result->b_namespace ) ) {
|
|
|
|
|
$deep = $result;
|
|
|
|
|
} else {
|
|
|
|
|
$qi = $this->reallyGetQueryInfo(
|
|
|
|
|
$result->namespace,
|
|
|
|
|
$result->title
|
|
|
|
|
);
|
2024-05-04 10:30:43 +00:00
|
|
|
$deep = $this->getDatabaseProvider()->getReplicaDatabase()->newSelectQueryBuilder()
|
|
|
|
|
->queryInfo( $qi )
|
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchRow();
|
2007-08-22 21:52:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
2017-08-04 02:58:29 +00:00
|
|
|
|
|
|
|
|
$titleA = Title::makeTitle( $result->namespace, $result->title );
|
|
|
|
|
|
2016-11-30 00:05:22 +00:00
|
|
|
$linkRenderer = $this->getLinkRenderer();
|
2017-08-10 20:26:08 +00:00
|
|
|
if ( !$deep ) {
|
2016-11-30 00:05:22 +00:00
|
|
|
return '<del>' . $linkRenderer->makeLink( $titleA, null, [], [ 'redirect' => 'no' ] ) . '</del>';
|
2005-04-24 04:16:50 +00:00
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2015-11-06 09:36:59 +00:00
|
|
|
// if the page is editable, add an edit link
|
|
|
|
|
if (
|
|
|
|
|
// check user permissions
|
2021-03-02 23:59:56 +00:00
|
|
|
$this->getAuthority()->isAllowed( 'edit' ) &&
|
2015-11-06 09:36:59 +00:00
|
|
|
// check, if the content model is editable through action=edit
|
2020-10-06 17:55:00 +00:00
|
|
|
$this->contentHandlerFactory->getContentHandler( $titleA->getContentModel() )
|
2020-01-18 20:25:04 +00:00
|
|
|
->supportsDirectEditing()
|
2015-11-06 09:36:59 +00:00
|
|
|
) {
|
2016-11-30 00:05:22 +00:00
|
|
|
$edit = $linkRenderer->makeKnownLink(
|
2015-11-06 09:36:59 +00:00
|
|
|
$titleA,
|
2016-11-30 00:05:22 +00:00
|
|
|
$this->msg( 'parentheses', $this->msg( 'editlink' )->text() )->text(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
2016-11-30 00:05:22 +00:00
|
|
|
[ 'action' => 'edit' ]
|
2015-11-06 09:36:59 +00:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$edit = '';
|
|
|
|
|
}
|
2011-10-08 09:12:42 +00:00
|
|
|
|
2024-10-07 08:19:09 +00:00
|
|
|
$arrow = $this->getLanguage()->getArrow();
|
|
|
|
|
$contentLanguage = $this->getContentLanguage();
|
|
|
|
|
$bdiAttrs = [
|
|
|
|
|
'dir' => $contentLanguage->getDir(),
|
|
|
|
|
'lang' => $contentLanguage->getHtmlCode(),
|
|
|
|
|
];
|
|
|
|
|
$linkA = Html::rawElement( 'bdi', $bdiAttrs, $linkRenderer->makeKnownLink(
|
2017-08-04 02:58:29 +00:00
|
|
|
$titleA,
|
|
|
|
|
null,
|
|
|
|
|
[],
|
|
|
|
|
[ 'redirect' => 'no' ]
|
2024-10-01 17:28:06 +00:00
|
|
|
) );
|
2017-08-04 02:58:29 +00:00
|
|
|
|
2017-08-10 20:26:08 +00:00
|
|
|
$titleB = Title::makeTitle( $deep->b_namespace, $deep->b_title );
|
2022-07-12 03:30:26 +00:00
|
|
|
// We show fragment, but don't link to it, as it probably doesn't exist anymore.
|
|
|
|
|
$titleBFrag = Title::makeTitle( $deep->b_namespace, $deep->b_title, $deep->b_fragment );
|
2024-10-07 08:19:09 +00:00
|
|
|
$linkB = Html::rawElement( 'bdi', $bdiAttrs, $linkRenderer->makeKnownLink(
|
2009-06-07 18:45:52 +00:00
|
|
|
$titleB,
|
2022-07-12 03:30:26 +00:00
|
|
|
$titleBFrag->getFullText(),
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[ 'redirect' => 'no' ]
|
2024-10-01 17:28:06 +00:00
|
|
|
) );
|
2011-10-08 09:12:42 +00:00
|
|
|
|
2017-08-04 02:58:29 +00:00
|
|
|
$titleC = Title::makeTitle(
|
2017-08-10 20:26:08 +00:00
|
|
|
$deep->c_namespace,
|
|
|
|
|
$deep->c_title,
|
|
|
|
|
$deep->c_fragment,
|
|
|
|
|
$deep->c_interwiki
|
2017-08-04 02:58:29 +00:00
|
|
|
);
|
2024-10-07 08:19:09 +00:00
|
|
|
$linkC = Html::rawElement( 'bdi', $bdiAttrs,
|
2024-10-01 17:28:06 +00:00
|
|
|
$linkRenderer->makeKnownLink( $titleC, $titleC->getFullText() )
|
|
|
|
|
);
|
2007-08-22 21:52:44 +00:00
|
|
|
|
2024-10-01 17:28:06 +00:00
|
|
|
return ( "{$linkA} {$edit} {$arrow} {$linkB} {$arrow} {$linkC}" );
|
2004-08-15 19:54:15 +00:00
|
|
|
}
|
2013-03-07 20:15:54 +00:00
|
|
|
|
2019-06-24 19:24:20 +00:00
|
|
|
public function execute( $par ) {
|
|
|
|
|
$this->addHelpLink( 'Help:Redirects' );
|
|
|
|
|
parent::execute( $par );
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 09:36:59 +00:00
|
|
|
/**
|
|
|
|
|
* Cache page content model and gender distinction for performance
|
|
|
|
|
*
|
|
|
|
|
* @param IDatabase $db
|
2018-04-04 12:52:10 +00:00
|
|
|
* @param IResultWrapper $res
|
2015-11-06 09:36:59 +00:00
|
|
|
*/
|
2020-05-18 00:17:37 +00:00
|
|
|
public function preprocessResults( $db, $res ) {
|
2015-11-06 09:36:59 +00:00
|
|
|
if ( !$res->numRows() ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-06 17:55:00 +00:00
|
|
|
$batch = $this->linkBatchFactory->newLinkBatch();
|
2015-11-06 09:36:59 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$batch->add( $row->namespace, $row->title );
|
2017-08-04 02:58:29 +00:00
|
|
|
if ( isset( $row->b_namespace ) ) {
|
2015-11-06 09:36:59 +00:00
|
|
|
// lazy loaded when using cached results
|
2017-08-04 02:58:29 +00:00
|
|
|
$batch->add( $row->b_namespace, $row->b_title );
|
2015-11-06 09:36:59 +00:00
|
|
|
}
|
2017-08-04 02:58:29 +00:00
|
|
|
if ( isset( $row->c_interwiki ) && !$row->c_interwiki ) {
|
2015-11-06 09:36:59 +00:00
|
|
|
// lazy loaded when using cached result, not added when interwiki link
|
2017-08-04 02:58:29 +00:00
|
|
|
$batch->add( $row->c_namespace, $row->c_title );
|
2015-11-06 09:36:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$batch->execute();
|
|
|
|
|
|
|
|
|
|
// Back to start for display
|
|
|
|
|
$res->seek( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-07 20:15:54 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
|
return 'maintenance';
|
|
|
|
|
}
|
2004-08-15 19:54:15 +00:00
|
|
|
}
|
2023-04-03 18:41:41 +00:00
|
|
|
|
2024-03-07 21:56:58 +00:00
|
|
|
/** @deprecated class alias since 1.41 */
|
2023-04-03 18:41:41 +00:00
|
|
|
class_alias( SpecialDoubleRedirects::class, 'SpecialDoubleRedirects' );
|