Merge "(bug 40585) Don't drop 'step="any"' in HTML input fields."
[lhc/web/wiklou.git] / includes / specials / SpecialLinkSearch.php
index a54c738..5de6076 100644 (file)
@@ -21,7 +21,7 @@
  * @ingroup SpecialPage
  * @author Brion Vibber
  */
+
 
 /**
  * Special:LinkSearch to search the external-links table.
@@ -37,15 +37,29 @@ class LinkSearchPage extends QueryPage {
        function __construct( $name = 'LinkSearch' ) {
                parent::__construct( $name );
        }
-       
+
+       function isCacheable() {
+               return false;
+       }
+
        function execute( $par ) {
-               global $wgOut, $wgRequest, $wgUrlProtocols, $wgMiserMode, $wgLang, $wgScript;
-               $target = $wgRequest->getVal( 'target', $par );
-               $namespace = $wgRequest->getIntorNull( 'namespace', null );
+               global $wgUrlProtocols, $wgMiserMode;
+
+               $this->setHeaders();
+               $this->outputHeader();
 
-               $protocols_list[] = '';
+               $out = $this->getOutput();
+               $out->allowClickjacking();
+
+               $request = $this->getRequest();
+               $target = $request->getVal( 'target', $par );
+               $namespace = $request->getIntorNull( 'namespace', null );
+
+               $protocols_list = array();
                foreach( $wgUrlProtocols as $prot ) {
-                       $protocols_list[] = $prot;
+                       if ( $prot !== '//' ) {
+                               $protocols_list[] = $prot;
+                       }
                }
 
                $target2 = $target;
@@ -64,42 +78,50 @@ class LinkSearchPage extends QueryPage {
                        // default
                        $protocol = 'http://';
                }
-               if ( !in_array( $protocol, $protocols_list ) ) {
+               if ( $protocol != '' && !in_array( $protocol, $protocols_list ) ) {
                        // unsupported protocol, show original search request
                        $target2 = $target;
                        $protocol = '';
                }
 
-               $self = $this->getTitle();
-
-               $wgOut->addWikiMsg( 'linksearch-text', '<nowiki>' . $wgLang->commaList( $wgUrlProtocols ) . '</nowiki>' );
+               $out->addWikiMsg( 'linksearch-text', '<nowiki>' . $this->getLanguage()->commaList( $protocols_list ) . '</nowiki>' );
                $s = Xml::openElement( 'form', array( 'id' => 'mw-linksearch-form', 'method' => 'get', 'action' => $GLOBALS['wgScript'] ) ) .
-                       Html::hidden( 'title', $self->getPrefixedDbKey() ) .
+                       Html::hidden( 'title', $this->getTitle()->getPrefixedDbKey() ) .
                        '<fieldset>' .
-                       Xml::element( 'legend', array(), wfMsg( 'linksearch' ) ) .
-                       Xml::inputLabel( wfMsg( 'linksearch-pat' ), 'target', 'target', 50, $target ) . ' ';
+                       Xml::element( 'legend', array(), $this->msg( 'linksearch' )->text() ) .
+                       Xml::inputLabel( $this->msg( 'linksearch-pat' )->text(), 'target', 'target', 50, $target ) . ' ';
                if ( !$wgMiserMode ) {
-                       $s .= Xml::label( wfMsg( 'linksearch-ns' ), 'namespace' ) . ' ' .
-                               Xml::namespaceSelector( $namespace, '' );
+                       $s .= Html::namespaceSelector(
+                               array(
+                                       'selected' => $namespace,
+                                       'all' => '',
+                                       'label' => $this->msg( 'linksearch-ns' )->text()
+                               ), array(
+                                       'name'  => 'namespace',
+                                       'id'    => 'namespace',
+                                       'class' => 'namespaceselector',
+                               )
+                       );
                }
-               $s .=   Xml::submitButton( wfMsg( 'linksearch-ok' ) ) .
+               $s .= Xml::submitButton( $this->msg( 'linksearch-ok' )->text() ) .
                        '</fieldset>' .
                        Xml::closeElement( 'form' );
-               $wgOut->addHTML( $s );
+               $out->addHTML( $s );
 
                if( $target != '' ) {
-                       $this->setParams( array( 
+                       $this->setParams( array(
                                'query' => $target2,
                                'namespace' => $namespace,
                                'protocol' => $protocol ) );
                        parent::execute( $par );
                        if( $this->mMungedQuery === false )
-                               $wgOut->addWikiText( wfMsg( 'linksearch-error' ) );
+                               $out->addWikiMsg( 'linksearch-error' );
                }
        }
 
        /**
         * Disable RSS/Atom feeds
+        * @return bool
         */
        function isSyndicated() {
                return false;
@@ -107,14 +129,17 @@ class LinkSearchPage extends QueryPage {
 
        /**
         * Return an appropriately formatted LIKE query and the clause
+        *
+        * @return array
         */
-       static function mungeQuery( $query , $prot ) {
+       static function mungeQuery( $query, $prot ) {
                $field = 'el_index';
-               $rv = LinkFilter::makeLike( $query , $prot );
+               $rv = LinkFilter::makeLikeArray( $query , $prot );
                if ( $rv === false ) {
                        // LinkFilter doesn't handle wildcard in IP, so we'll have to munge here.
                        if (preg_match('/^(:?[0-9]{1,3}\.)+\*\s*$|^(:?[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]*\*\s*$/', $query)) {
-                               $rv = $prot . rtrim($query, " \t*") . '%';
+                               $dbr = wfGetDB( DB_SLAVE );
+                               $rv = array( $prot . rtrim( $query, " \t*" ), $dbr->anyString() );
                                $field = 'el_to';
                        }
                }
@@ -141,16 +166,16 @@ class LinkSearchPage extends QueryPage {
                if( $this->mMungedQuery === false )
                        // Invalid query; return no results
                        return array( 'tables' => 'page', 'fields' => 'page_id', 'conds' => '0=1' );
-               
-               $stripped = substr( $this->mMungedQuery, 0, strpos( $this->mMungedQuery, '%' ) + 1 );
-               $encSearch = $dbr->addQuotes( $stripped );
+
+               $stripped = LinkFilter::keepOneWildcard( $this->mMungedQuery );
+               $like = $dbr->buildLike( $stripped );
                $retval = array (
                        'tables' => array ( 'page', 'externallinks' ),
-                       'fields' => array ( 'page_namespace AS namespace',
-                                       'page_title AS title',
-                                       'el_index AS value', 'el_to AS url' ),
+                       'fields' => array ( 'namespace' => 'page_namespace',
+                                       'title' => 'page_title',
+                                       'value' => 'el_index', 'url' => 'el_to' ),
                        'conds' => array ( 'page_id = el_from',
-                                       "$clause LIKE $encSearch" ),
+                                       "$clause $like" ),
                        'options' => array( 'USE INDEX' => $clause )
                );
                if ( isset( $this->mNs ) && !$wgMiserMode ) {
@@ -162,24 +187,23 @@ class LinkSearchPage extends QueryPage {
        function formatResult( $skin, $result ) {
                $title = Title::makeTitle( $result->namespace, $result->title );
                $url = $result->url;
-               $pageLink = $skin->linkKnown( $title );
-               $urlLink = $skin->makeExternalLink( $url, $url );
+               $pageLink = Linker::linkKnown( $title );
+               $urlLink = Linker::makeExternalLink( $url, $url );
 
-               return wfMsgHtml( 'linksearch-line', $urlLink, $pageLink );
+               return $this->msg( 'linksearch-line' )->rawParams( $urlLink, $pageLink )->escaped();
        }
 
        /**
         * Override to check query validity.
         */
-       function doQuery( $offset, $limit = false ) {
-               global $wgOut;
+       function doQuery( $offset = false, $limit = false ) {
                list( $this->mMungedQuery,  ) = LinkSearchPage::mungeQuery( $this->mQuery, $this->mProt );
                if( $this->mMungedQuery === false ) {
-                       $wgOut->addWikiMsg( 'linksearch-error' );
+                       $this->getOutput()->addWikiMsg( 'linksearch-error' );
                } else {
                        // For debugging
                        // Generates invalid xhtml with patterns that contain --
-                       //$wgOut->addHTML( "\n<!-- " . htmlspecialchars( $this->mMungedQuery ) . " -->\n" );
+                       //$this->getOutput()->addHTML( "\n<!-- " . htmlspecialchars( $this->mMungedQuery ) . " -->\n" );
                        parent::doQuery( $offset, $limit );
                }
        }
@@ -189,6 +213,7 @@ class LinkSearchPage extends QueryPage {
         * We do a truncated index search, so the optimizer won't trust
         * it as good enough for optimizing sort. The implicit ordering
         * from the scan will usually do well enough for our needs.
+        * @return array
         */
        function getOrderFields() {
                return array();