9use MediaWiki\Cache\LinkBatchFactory;
34 private $mungedQuery =
false;
44 private function setParams( array $params ) {
45 $this->mQuery = $params[
'query'];
46 $this->mNs = $params[
'namespace'];
47 $this->mProt = $params[
'protocol'];
52 LinkBatchFactory $linkBatchFactory,
55 parent::__construct(
'LinkSearch' );
58 $this->urlUtils = $urlUtils;
72 $out->getMetadata()->setPreventClickjacking(
false );
75 $target = $request->getVal(
'target', $par ??
'' );
76 $namespace = $request->getIntOrNull(
'namespace' );
80 if ( $prot !==
'//' ) {
81 $protocols_list[] = $prot;
85 $target2 = Parser::normalizeLinkUrl( $target );
87 $bits = $this->urlUtils->parse( $target );
88 if ( isset( $bits[
'scheme'] ) && isset( $bits[
'delimiter'] ) ) {
89 $protocol = $bits[
'scheme'] . $bits[
'delimiter'];
91 if ( str_starts_with( strtolower( $target ), strtolower( $protocol ) ) ) {
92 $target2 = substr( $target, strlen( $protocol ) );
101 '<nowiki>' . $this->
getLanguage()->commaList( $protocols_list ) .
'</nowiki>',
102 count( $protocols_list )
110 'label-message' =>
'linksearch-pat',
111 'default' => $target,
118 'type' =>
'namespaceselect',
119 'name' =>
'namespace',
120 'label-message' =>
'linksearch-ns',
121 'default' => $namespace,
124 'cssclass' =>
'namespaceselector',
128 $htmlForm = HTMLForm::factory(
'ooui', $fields, $this->
getContext() );
129 $htmlForm->setSubmitTextMsg(
'linksearch-ok' );
130 $htmlForm->setWrapperLegendMsg(
'linksearch' );
132 $htmlForm->setMethod(
'get' );
133 $htmlForm->prepareForm()->displayForm(
false );
136 if ( $target !=
'' ) {
139 'namespace' => $namespace,
140 'protocol' => $protocol ] );
141 parent::execute( $par );
142 if ( $this->mungedQuery ===
false ) {
143 $out->addWikiMsg(
'linksearch-error' );
147 if ( $ignoredDomains ) {
149 'linksearch-text-ignored-domains',
151 array_map(
static fn ( $domain ) =>
"<code>$domain</code>", $ignoredDomains )
153 count( $ignoredDomains )
169 $params[
'target'] = $this->mProt . $this->mQuery;
171 $params[
'namespace'] = $this->mNs;
179 $dbr = $this->
getDatabaseProvider()->getReplicaDatabase( ExternalLinksTable::VIRTUAL_DOMAIN );
181 $field =
'el_to_domain_index';
183 'urldomain' =>
'el_to_domain_index',
184 'urlpath' =>
'el_to_path'
186 if ( $this->mQuery ===
'*' && $this->mProt !==
'' ) {
187 if ( $this->mProt !==
null ) {
188 $this->mungedQuery = [
189 $dbr->expr( $field, IExpression::LIKE,
new LikeValue( $this->mProt, $dbr->anyString() ) ),
192 $this->mungedQuery = [
193 $dbr->expr( $field, IExpression::LIKE,
new LikeValue(
'http://', $dbr->anyString() ) )
194 ->or( $field, IExpression::LIKE,
new LikeValue(
'https://', $dbr->anyString() ) ),
198 $this->mungedQuery = LinkFilter::getQueryConditions( $this->mQuery, [
199 'protocol' => $this->mProt,
200 'oneWildcard' =>
true,
203 if ( $this->mungedQuery ===
false ) {
205 return [
'tables' =>
'page',
'fields' =>
'page_id',
'conds' =>
'0=1' ];
208 $orderBy = [
'el_id' ];
211 'tables' => [
'page',
'externallinks' ],
213 'namespace' =>
'page_namespace',
214 'title' =>
'page_title',
219 ...$this->mungedQuery,
221 'options' => [
'ORDER BY' => $orderBy ]
225 $retval[
'conds'][
'page_namespace'] = $this->mNs;
247 $title =
new TitleValue( (
int)$result->namespace, $result->title );
249 $url = LinkFilter::reverseIndexes( $result->urldomain ) . $result->urlpath;
253 return $this->
msg(
'linksearch-line' )->rawParams( $urlLink, $pageLink )->escaped();
278 return max( parent::getMaxResults(), 60000 );
284 ExternalLinksTable::VIRTUAL_DOMAIN,
291class_alias( SpecialLinkSearch::class,
'SpecialLinkSearch' );
A class containing constants representing the names of configuration variables.
const ExternalLinksIgnoreDomains
Name constant for the ExternalLinksIgnoreDomains setting, for use with Config::get()
const UrlProtocols
Name constant for the UrlProtocols setting, for use with Config::get()
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
setDatabaseProvider(IConnectionProvider $databaseProvider)
executeLBFromResultWrapper(IResultWrapper $res, $ns=null)
Creates a new LinkBatch object, adds all pages from the passed result wrapper (MUST include title and...
setLinkBatchFactory(LinkBatchFactory $linkBatchFactory)
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getPageTitle( $subpage=false)
Get a self-referential title object.
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
getFullTitle()
Return the full title, including $par.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.