+ function __construct( $name = 'LinkSearch' ) {
+ parent::__construct( $name );
+
+ // Since we don't control the constructor parameters, we can't inject services that way.
+ // Instead, we initialize services in the execute() method, and allow them to be overridden
+ // using the setServices() method.
+ }
+
+ function isCacheable() {
+ return false;
+ }
+
+ public function execute( $par ) {
+ $this->setHeaders();
+ $this->outputHeader();
+
+ $out = $this->getOutput();
+ $out->allowClickjacking();
+
+ $request = $this->getRequest();
+ $target = $request->getVal( 'target', $par );
+ $namespace = $request->getIntOrNull( 'namespace' );
+
+ $protocols_list = [];
+ foreach ( $this->getConfig()->get( 'UrlProtocols' ) as $prot ) {
+ if ( $prot !== '//' ) {
+ $protocols_list[] = $prot;
+ }
+ }
+
+ $target2 = $target;
+ // Get protocol, default is http://
+ $protocol = 'http://';
+ $bits = wfParseUrl( $target );
+ if ( isset( $bits['scheme'] ) && isset( $bits['delimiter'] ) ) {
+ $protocol = $bits['scheme'] . $bits['delimiter'];
+ // Make sure wfParseUrl() didn't make some well-intended correction in the
+ // protocol
+ if ( strcasecmp( $protocol, substr( $target, 0, strlen( $protocol ) ) ) === 0 ) {
+ $target2 = substr( $target, strlen( $protocol ) );
+ } else {
+ // If it did, let LinkFilter::makeLikeArray() handle this
+ $protocol = '';
+ }
+ }
+
+ $out->addWikiMsg(
+ 'linksearch-text',
+ '<nowiki>' . $this->getLanguage()->commaList( $protocols_list ) . '</nowiki>',
+ count( $protocols_list )
+ );
+ $fields = [
+ 'target' => [
+ 'type' => 'text',
+ 'name' => 'target',
+ 'id' => 'target',
+ 'size' => 50,
+ 'label-message' => 'linksearch-pat',
+ 'default' => $target,
+ 'dir' => 'ltr',
+ ]
+ ];
+ if ( !$this->getConfig()->get( 'MiserMode' ) ) {
+ $fields += [
+ 'namespace' => [
+ 'type' => 'namespaceselect',
+ 'name' => 'namespace',
+ 'label-message' => 'linksearch-ns',
+ 'default' => $namespace,
+ 'id' => 'namespace',
+ 'all' => '',
+ 'cssclass' => 'namespaceselector',
+ ],
+ ];
+ }
+ $hiddenFields = [
+ 'title' => $this->getPageTitle()->getPrefixedDBkey(),
+ ];
+ $htmlForm = HTMLForm::factory( 'ooui', $fields, $this->getContext() );
+ $htmlForm->addHiddenFields( $hiddenFields );
+ $htmlForm->setSubmitTextMsg( 'linksearch-ok' );
+ $htmlForm->setWrapperLegendMsg( 'linksearch' );
+ $htmlForm->setAction( wfScript() );
+ $htmlForm->setMethod( 'get' );
+ $htmlForm->prepareForm()->displayForm( false );
+ $this->addHelpLink( 'Help:Linksearch' );
+
+ if ( $target != '' ) {
+ $this->setParams( [
+ 'query' => Parser::normalizeLinkUrl( $target2 ),
+ 'namespace' => $namespace,
+ 'protocol' => $protocol ] );
+ parent::execute( $par );
+ if ( $this->mungedQuery === false ) {
+ $out->addWikiMsg( 'linksearch-error' );
+ }
+ }