mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-15 03:44:02 +00:00
e72f58ca78
Inspired by this Wikitech-l discussion: https://lists.wikimedia.org/hyperkitty/list/wikitech-l@lists.wikimedia.org/thread/NWXPNHRNLEVXHSWX33H473OAWQP6CDOA/ To keep this simple for now, I am only removing redundant PHPDoc comments on constructors, and only when all the documentation for parameters completely duplicates type hints. More could be done, but that can happen later when we have better tooling. Redundant comments on constructors that take a dozen services are by far the most annoying for me and I want them gone now. Change-Id: I86cbf7d6e48035cfa06f780c8fb1b02e68709a0c
56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools;
|
|
|
|
use RedirectSpecialPage;
|
|
use SpecialPage;
|
|
use Title;
|
|
|
|
class SpecialGoToComment extends RedirectSpecialPage {
|
|
|
|
private ThreadItemStore $threadItemStore;
|
|
|
|
public function __construct(
|
|
ThreadItemStore $threadItemStore
|
|
) {
|
|
parent::__construct( 'GoToComment' );
|
|
$this->threadItemStore = $threadItemStore;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getRedirect( $subpage ) {
|
|
$results = [];
|
|
|
|
// Search for all thread items with the given ID or name, returning results from the latest
|
|
// revision of each page they appeared on.
|
|
//
|
|
// If there is exactly one result which is not transcluded from another page and in the current
|
|
// revision of its page, redirect to it.
|
|
//
|
|
// Otherwise, redirect to full search results on Special:FindComment.
|
|
|
|
if ( $subpage ) {
|
|
$threadItems = $this->threadItemStore->findNewestRevisionsById( $subpage );
|
|
foreach ( $threadItems as $item ) {
|
|
if ( $item->getRevision()->isCurrent() && !is_string( $item->getTranscludedFrom() ) ) {
|
|
$results[] = $item;
|
|
}
|
|
}
|
|
$threadItems = $this->threadItemStore->findNewestRevisionsByName( $subpage );
|
|
foreach ( $threadItems as $item ) {
|
|
if ( $item->getRevision()->isCurrent() && !is_string( $item->getTranscludedFrom() ) ) {
|
|
$results[] = $item;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( count( $results ) === 1 ) {
|
|
return Title::castFromPageIdentity( $results[0]->getPage() )->createFragmentTarget( $results[0]->getId() );
|
|
} else {
|
|
return SpecialPage::getTitleFor( 'FindComment', $subpage ?: false );
|
|
}
|
|
}
|
|
}
|