]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialLinkSearch.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialLinkSearch.php
index 267ef690d3d150b77bd595924b17c4cb7da32a85..9dee9d5a2fbf530d4023400cd2400352f1137c5e 100644 (file)
@@ -1,21 +1,35 @@
 <?php
 /**
+ * Implements Special:LinkSearch
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
- *
  * @author Brion Vibber
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
 
 /**
  * Special:LinkSearch to search the external-links table.
- * @ingroup SpecialPage
  */
-
 function wfSpecialLinkSearch( $par ) {
 
        list( $limit, $offset ) = wfCheckLimits();
-       global $wgOut, $wgRequest, $wgUrlProtocols, $wgMiserMode, $wgLang;
+       global $wgOut, $wgUrlProtocols, $wgMiserMode, $wgLang;
        $target = $GLOBALS['wgRequest']->getVal( 'target', $par );
        $namespace = $GLOBALS['wgRequest']->getIntorNull( 'namespace', null );
 
@@ -48,15 +62,16 @@ function wfSpecialLinkSearch( $par ) {
 
        $self = Title::makeTitle( NS_SPECIAL, 'Linksearch' );
 
-       $wgOut->addWikiText( wfMsg( 'linksearch-text', '<nowiki>' . $wgLang->commaList( $wgUrlProtocols) . '</nowiki>' ) );
-       $s =    Xml::openElement( 'form', array( 'id' => 'mw-linksearch-form', 'method' => 'get', 'action' => $GLOBALS['wgScript'] ) ) .
-               Xml::hidden( 'title', $self->getPrefixedDbKey() ) .
+       $wgOut->allowClickjacking();
+       $wgOut->addWikiMsg( 'linksearch-text', '<nowiki>' . $wgLang->commaList( $wgUrlProtocols ) . '</nowiki>' );
+       $s = Xml::openElement( 'form', array( 'id' => 'mw-linksearch-form', 'method' => 'get', 'action' => $GLOBALS['wgScript'] ) ) .
+               Html::hidden( 'title', $self->getPrefixedDbKey() ) .
                '<fieldset>' .
                Xml::element( 'legend', array(), wfMsg( 'linksearch' ) ) .
                Xml::inputLabel( wfMsg( 'linksearch-pat' ), 'target', 'target', 50, $target ) . ' ';
        if ( !$wgMiserMode ) {
                $s .= Xml::label( wfMsg( 'linksearch-ns' ), 'namespace' ) . ' ' .
-                       XML::namespaceSelector( $namespace, '' );
+                       Xml::namespaceSelector( $namespace, '' );
        }
        $s .=   Xml::submitButton( wfMsg( 'linksearch-ok' ) ) .
                '</fieldset>' .
@@ -73,6 +88,9 @@ function wfSpecialLinkSearch( $par ) {
        }
 }
 
+/**
+ * @ingroup SpecialPage
+ */
 class LinkSearchPage extends QueryPage {
        function setParams( $params ) {
                $this->mQuery = $params['query'];
@@ -96,11 +114,12 @@ class LinkSearchPage extends QueryPage {
         */
        static function mungeQuery( $query , $prot ) {
                $field = 'el_index';
-               $rv = LinkFilter::makeLike( $query , $prot );
+               $rv = LinkFilter::makeLikeArray( $query , $prot );
                if ($rv === false) {
-                       //makeLike doesn't handle wildcard in IP, so we'll have to munge here.
+                       // 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';
                        }
                }
@@ -125,8 +144,8 @@ class LinkSearchPage extends QueryPage {
 
                /* strip everything past first wildcard, so that index-based-only lookup would be done */
                list( $munged, $clause ) = self::mungeQuery( $this->mQuery, $this->mProt );
-               $stripped = substr($munged,0,strpos($munged,'%')+1);
-               $encSearch = $dbr->addQuotes( $stripped );
+               $stripped = LinkFilter::keepOneWildcard( $munged );
+               $like = $dbr->buildLike( $stripped );
 
                $encSQL = '';
                if ( isset ($this->mNs) && !$wgMiserMode )
@@ -144,14 +163,14 @@ class LinkSearchPage extends QueryPage {
                                $externallinks $use_index
                        WHERE
                                page_id=el_from
-                               AND $clause LIKE $encSearch
+                               AND $clause $like
                                $encSQL";
        }
 
        function formatResult( $skin, $result ) {
                $title = Title::makeTitle( $result->namespace, $result->title );
                $url = $result->url;
-               $pageLink = $skin->makeKnownLinkObj( $title );
+               $pageLink = $skin->linkKnown( $title );
                $urlLink = $skin->makeExternalLink( $url, $url );
 
                return wfMsgHtml( 'linksearch-line', $urlLink, $pageLink );
@@ -162,9 +181,9 @@ class LinkSearchPage extends QueryPage {
         */
        function doQuery( $offset, $limit, $shownavigation=true ) {
                global $wgOut;
-               list( $this->mMungedQuery, $clause ) = LinkSearchPage::mungeQuery( $this->mQuery, $this->mProt );
+               list( $this->mMungedQuery,  ) = LinkSearchPage::mungeQuery( $this->mQuery, $this->mProt );
                if( $this->mMungedQuery === false ) {
-                       $wgOut->addWikiText( wfMsg( 'linksearch-error' ) );
+                       $wgOut->addWikiMsg( 'linksearch-error' );
                } else {
                        // For debugging
                        // Generates invalid xhtml with patterns that contain --