r14822 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r14821‎ | r14822 | r14823 >
Date:22:44, 19 June 2006
Author:brion
Status:old
Tags:
Comment:
Quickie special page to search the external-links table.
Currently only 'http' links are supported; LinkFilter needs to be changed to allow other pretties.
Modified paths:
  • /trunk/extensions/LinkSearch (added) (history)
  • /trunk/extensions/LinkSearch/LinkSearch.php (added) (history)

Diff [purge]

Index: trunk/extensions/LinkSearch/LinkSearch.php
@@ -0,0 +1,109 @@
 2+<?php
 3+
 4+/**
 5+ * Quickie special page to search the external-links table.
 6+ * Currently only 'http' links are supported; LinkFilter needs to be
 7+ * changed to allow other pretties.
 8+ */
 9+
 10+$wgExtensionFunctions[] = 'wfLinkSearchSetup';
 11+
 12+function wfLinkSearchSetup() {
 13+ $GLOBALS['wgMessageCache']->addMessages(
 14+ array(
 15+ 'linksearch' => 'Search web links',
 16+ 'linksearch-text' => 'Wildcards such as "*.wikipedia.org" may be used.',
 17+ 'linksearch-line' => '$1 linked from $2',
 18+ )
 19+ );
 20+
 21+ SpecialPage::addPage( new SpecialPage( 'Linksearch', /* permission */false,
 22+ /*listed*/ true, /*function*/ false, /*file*/ false ) );
 23+
 24+ class LinkSearchPage extends QueryPage {
 25+ function __construct( $query ) {
 26+ $this->mQuery = $query;
 27+ }
 28+
 29+ function getName() {
 30+ return 'Linksearch';
 31+ }
 32+
 33+ /**
 34+ * Return an appropriately formatted LIKE query
 35+ * @fixme Fix up LinkFilter to work with non-http links as well
 36+ */
 37+ static function mungeQuery( $query ) {
 38+ if( substr( $query, 0, 7 ) == 'http://' ) {
 39+ $query = substr( $query, 7 );
 40+ }
 41+ return LinkFilter::makeLike( $query );
 42+ }
 43+
 44+ function linkParameters() {
 45+ return array( 'target' => $this->mQuery );
 46+ }
 47+
 48+ function getSQL() {
 49+ $dbr = wfGetDB( DB_SLAVE );
 50+
 51+ $page = $dbr->tableName( 'page' );
 52+ $externallinks = $dbr->tableName( 'externallinks' );
 53+
 54+ $search = self::mungeQuery( $this->mQuery );
 55+ $encSearch = $dbr->addQuotes( $search );
 56+
 57+ return
 58+ "SELECT
 59+ page_namespace AS namespace,
 60+ page_title AS title,
 61+ el_index AS value,
 62+ el_to AS url
 63+ FROM
 64+ $page,
 65+ $externallinks
 66+ WHERE
 67+ page_id=el_from
 68+ AND el_index LIKE $encSearch";
 69+ }
 70+
 71+ function formatResult( $skin, $result ) {
 72+ $title = Title::makeTitle( $result->namespace, $result->title );
 73+ $url = $result->url;
 74+
 75+ $pageLink = $skin->makeKnownLinkObj( $title );
 76+ $urlLink = $skin->makeExternalLink( $url, $url );
 77+
 78+ return wfMsgHtml( 'linksearch-line', $urlLink, $pageLink );
 79+ }
 80+
 81+ }
 82+
 83+ function wfSpecialLinksearch( $par=null ) {
 84+ list( $limit, $offset ) = wfCheckLimits();
 85+ $target = $GLOBALS['wgRequest']->getVal( 'target', $par );
 86+
 87+ $self = Title::makeTitle( NS_SPECIAL, 'Linksearch' );
 88+
 89+ global $wgOut;
 90+ $wgOut->addWikiText( wfMsg( 'linksearch-text' ) );
 91+ $wgOut->addHtml(
 92+ wfOpenElement( 'form',
 93+ array( 'method' => 'get', 'action' => $GLOBALS['wgScript'] ) ) .
 94+ wfHidden( 'title', $self->getPrefixedUrl() ) .
 95+ wfInput( 'target', 50, $target ) .
 96+ wfSubmitButton( wfMsg( 'search' ) ) .
 97+ wfCloseElement( 'form' ) );
 98+
 99+ if( $target != '' ) {
 100+ // For debugging
 101+ $search = LinkSearchPage::mungeQuery( $target );
 102+ $wgOut->addHtml( "\n<!-- " . htmlspecialchars( $search ) . " -->\n" );
 103+
 104+ $searcher = new LinkSearchPage( $target );
 105+ $searcher->doQuery( $offset, $limit );
 106+ }
 107+ }
 108+}
 109+
 110+?>
Property changes on: trunk/extensions/LinkSearch/LinkSearch.php
___________________________________________________________________
Added: svn:eol-style
1111 + native

Status & tagging log