Merge "make rebuildtextindex script aware of content models."
[lhc/web/wiklou.git] / includes / specials / SpecialLinkSearch.php
index 623504d..5de6076 100644 (file)
@@ -43,16 +43,23 @@ class LinkSearchPage extends QueryPage {
        }
 
        function execute( $par ) {
-               global $wgOut, $wgRequest, $wgUrlProtocols, $wgMiserMode, $wgLang;
+               global $wgUrlProtocols, $wgMiserMode;
+
                $this->setHeaders();
-               $wgOut->allowClickjacking();
+               $this->outputHeader();
+
+               $out = $this->getOutput();
+               $out->allowClickjacking();
 
-               $target = $wgRequest->getVal( 'target', $par );
-               $namespace = $wgRequest->getIntorNull( 'namespace', null );
+               $request = $this->getRequest();
+               $target = $request->getVal( 'target', $par );
+               $namespace = $request->getIntorNull( 'namespace', null );
 
-               $protocols_list[] = '';
+               $protocols_list = array();
                foreach( $wgUrlProtocols as $prot ) {
-                       $protocols_list[] = $prot;
+                       if ( $prot !== '//' ) {
+                               $protocols_list[] = $prot;
+                       }
                }
 
                $target2 = $target;
@@ -71,28 +78,35 @@ 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(
@@ -101,12 +115,13 @@ class LinkSearchPage extends QueryPage {
                                'protocol' => $protocol ) );
                        parent::execute( $par );
                        if( $this->mMungedQuery === false )
-                               $wgOut->addWikiMsg( 'linksearch-error' );
+                               $out->addWikiMsg( 'linksearch-error' );
                }
        }
 
        /**
         * Disable RSS/Atom feeds
+        * @return bool
         */
        function isSyndicated() {
                return false;
@@ -114,6 +129,8 @@ class LinkSearchPage extends QueryPage {
 
        /**
         * Return an appropriately formatted LIKE query and the clause
+        *
+        * @return array
         */
        static function mungeQuery( $query, $prot ) {
                $field = 'el_index';
@@ -154,9 +171,9 @@ class LinkSearchPage extends QueryPage {
                $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" ),
                        'options' => array( 'USE INDEX' => $clause )
@@ -170,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 = false, $limit = false ) {
-               global $wgOut;
                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 );
                }
        }
@@ -197,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();