r40830 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r40829‎ | r40830 | r40831 >
Date:19:51, 14 September 2008
Author:siebrand
Status:old
Tags:
Comment:
* Add functionality of extension LinkSearch to core
* Update release notes for adding of Special:Log/newusers
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/QueryPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLinkSearch.php (added) (history)
  • /trunk/phase3/includes/specials/SpecialLinkSearch.php (added) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1377,6 +1377,15 @@
13781378 'special-categories-sort-count',
13791379 'special-categories-sort-abc',
13801380 ),
 1381+ 'linksearch' => array(
 1382+ 'linksearch',
 1383+ 'linksearch-pat',
 1384+ 'linksearch-ns',
 1385+ 'linksearch-ok',
 1386+ 'linksearch-text',
 1387+ 'linksearch-line',
 1388+ 'linksearch-error',
 1389+ ),
13811390 'listusers' => array(
13821391 'listusersfrom',
13831392 'listusers-submit',
@@ -2805,6 +2814,7 @@
28062815 'logpages' => 'Special:Log',
28072816 'allpages' => 'Special:AllPages',
28082817 'categories' => 'Special:Categories',
 2818+ 'linksearch' => 'Special:LinkSearch',
28092819 'listusers' => 'Special:ListUsers',
28102820 'newuserlog' => 'Special:Log/newusers',
28112821 'listgrouprights' => 'Special:ListGroupRights',
Index: trunk/phase3/includes/AutoLoader.php
@@ -8,7 +8,7 @@
99 # Extension classes are specified with $wgAutoloadClasses
1010 # This array is a global instead of a static member of AutoLoader to work around a bug in APC
1111 global $wgAutoloadLocalClasses;
12 -$wgAutoloadLocalClasses = array(
 12+$wgAutoloadLocalClasses = array(
1313 # Includes
1414 'AjaxDispatcher' => 'includes/AjaxDispatcher.php',
1515 'AjaxResponse' => 'includes/AjaxResponse.php',
@@ -356,7 +356,7 @@
357357 'WhiteSpaceNode' => 'includes/diff/Nodes.php',
358358 'WikiDiff3' => 'includes/diff/Diff.php',
359359 'WordLevelDiff' => 'includes/diff/DifferenceEngine.php',
360 -
 360+
361361 # includes/filerepo
362362 'ArchivedFile' => 'includes/filerepo/ArchivedFile.php',
363363 'File' => 'includes/filerepo/File.php',
@@ -446,6 +446,7 @@
447447 'ImportReporter' => 'includes/specials/SpecialImport.php',
448448 'ImportStreamSource' => 'includes/specials/SpecialImport.php',
449449 'ImportStringSource' => 'includes/specials/SpecialImport.php',
 450+ 'LinkSearchPage' => 'includes/specials/SpecialLinkSearch.php',
450451 'ListredirectsPage' => 'includes/specials/SpecialListredirects.php',
451452 'LoginForm' => 'includes/specials/SpecialUserlogin.php',
452453 'LonelyPagesPage' => 'includes/specials/SpecialLonelypages.php',
@@ -517,11 +518,11 @@
518519 class AutoLoader {
519520 /**
520521 * autoload - take a class name and attempt to load it
521 - *
 522+ *
522523 * @param string $className Name of class we're looking for.
523524 * @return bool Returning false is important on failure as
524525 * it allows Zend to try and look in other registered autoloaders
525 - * as well.
 526+ * as well.
526527 */
527528 static function autoload( $className ) {
528529 global $wgAutoloadClasses, $wgAutoloadLocalClasses;
@@ -580,4 +581,3 @@
581582 AutoLoader::autoload( $class );
582583 }
583584 }
584 -
Index: trunk/phase3/includes/DefaultSettings.php
@@ -2828,6 +2828,7 @@
28292829 'Mytalk' => 'redirects',
28302830 'Mycontributions' => 'redirects',
28312831 'Search' => 'redirects',
 2832+ 'LinkSearch' => 'redirects',
28322833
28332834 'Movepage' => 'pagetools',
28342835 'MergeHistory' => 'pagetools',
Index: trunk/phase3/includes/specials/SpecialLinkSearch.php
@@ -0,0 +1,182 @@
 2+<?php
 3+/**
 4+ * @file
 5+ * @ingroup SpecialPage
 6+ *
 7+ * @author Brion Vibber
 8+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 9+ */
 10+
 11+/**
 12+ * Special:LinkSearch to search the external-links table.
 13+ * @ingroup SpecialPage
 14+ */
 15+
 16+function wfSpecialLinkSearch( $par ) {
 17+
 18+ list( $limit, $offset ) = wfCheckLimits();
 19+ global $wgOut, $wgRequest, $wgUrlProtocols, $wgMiserMode;
 20+ $target = $GLOBALS['wgRequest']->getVal( 'target', $par );
 21+ $namespace = $GLOBALS['wgRequest']->getIntorNull( 'namespace', null );
 22+
 23+ $protocols_list[] = '';
 24+ foreach( $wgUrlProtocols as $prot ) {
 25+ $protocols_list[] = $prot;
 26+ }
 27+
 28+ $target2 = $target;
 29+ $protocol = '';
 30+ $pr_sl = strpos($target2, '//' );
 31+ $pr_cl = strpos($target2, ':' );
 32+ if ( $pr_sl ) {
 33+ // For protocols with '//'
 34+ $protocol = substr( $target2, 0 , $pr_sl+2 );
 35+ $target2 = substr( $target2, $pr_sl+2 );
 36+ } elseif ( !$pr_sl && $pr_cl ) {
 37+ // For protocols without '//' like 'mailto:'
 38+ $protocol = substr( $target2, 0 , $pr_cl+1 );
 39+ $target2 = substr( $target2, $pr_cl+1 );
 40+ } elseif ( $protocol == '' && $target2 != '' ) {
 41+ // default
 42+ $protocol = 'http://';
 43+ }
 44+ if ( !in_array( $protocol, $protocols_list ) ) {
 45+ // unsupported protocol, show original search request
 46+ $target2 = $target;
 47+ $protocol = '';
 48+ }
 49+
 50+ $self = Title::makeTitle( NS_SPECIAL, 'Linksearch' );
 51+
 52+ $wgOut->addWikiText( wfMsg( 'linksearch-text', '<nowiki>' . implode( ', ', $wgUrlProtocols) . '</nowiki>' ) );
 53+ $s = Xml::openElement( 'form', array( 'id' => 'mw-linksearch-form', 'method' => 'get', 'action' => $GLOBALS['wgScript'] ) ) .
 54+ Xml::hidden( 'title', $self->getPrefixedDbKey() ) .
 55+ '<fieldset>' .
 56+ Xml::element( 'legend', array(), wfMsg( 'linksearch' ) ) .
 57+ Xml::inputLabel( wfMsg( 'linksearch-pat' ), 'target', 'target', 50, $target ) . ' ';
 58+ if ( !$wgMiserMode ) {
 59+ $s .= Xml::label( wfMsg( 'linksearch-ns' ), 'namespace' ) . ' ' .
 60+ XML::namespaceSelector( $namespace, '' );
 61+ }
 62+ $s .= Xml::submitButton( wfMsg( 'linksearch-ok' ) ) .
 63+ '</fieldset>' .
 64+ Xml::closeElement( 'form' );
 65+ $wgOut->addHtml( $s );
 66+
 67+ if( $target != '' ) {
 68+ $searcher = new LinkSearchPage( $target2, $namespace, $protocol );
 69+ $searcher->doQuery( $offset, $limit );
 70+ }
 71+}
 72+
 73+class LinkSearchPage extends QueryPage {
 74+
 75+ function __construct( $query, $ns, $prot ) {
 76+ $this->mQuery = $query;
 77+ $this->mNs = $ns;
 78+ $this->mProt = $prot;
 79+ }
 80+
 81+ function getName() {
 82+ return 'LinkSearch';
 83+ }
 84+
 85+ /**
 86+ * Disable RSS/Atom feeds
 87+ */
 88+ function isSyndicated() {
 89+ return false;
 90+ }
 91+
 92+ /**
 93+ * Return an appropriately formatted LIKE query and the clause
 94+ */
 95+ static function mungeQuery( $query , $prot ) {
 96+ $field = 'el_index';
 97+ $rv = LinkFilter::makeLike( $query , $prot );
 98+ if ($rv === false) {
 99+ //makeLike doesn't handle wildcard in IP, so we'll have to munge here.
 100+ if (preg_match('/^(:?[0-9]{1,3}\.)+\*\s*$|^(:?[0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]*\*\s*$/', $query)) {
 101+ $rv = $prot . rtrim($query, " \t*") . '%';
 102+ $field = 'el_to';
 103+ }
 104+ }
 105+ return array( $rv, $field );
 106+ }
 107+
 108+ function linkParameters() {
 109+ global $wgMiserMode;
 110+ $params = array();
 111+ $params['target'] = $this->mProt . $this->mQuery;
 112+ if( isset( $this->mNs ) && !$wgMiserMode ) {
 113+ $params['namespace'] = $this->mNs;
 114+ }
 115+ return $params;
 116+ }
 117+
 118+ function getSQL() {
 119+ global $wgMiserMode;
 120+ $dbr = wfGetDB( DB_SLAVE );
 121+ $page = $dbr->tableName( 'page' );
 122+ $externallinks = $dbr->tableName( 'externallinks' );
 123+
 124+ /* strip everything past first wildcard, so that index-based-only lookup would be done */
 125+ list( $munged, $clause ) = self::mungeQuery( $this->mQuery, $this->mProt );
 126+ $stripped = substr($munged,0,strpos($munged,'%')+1);
 127+ $encSearch = $dbr->addQuotes( $stripped );
 128+
 129+ $encSQL = '';
 130+ if ( isset ($this->mNs) && !$wgMiserMode )
 131+ $encSQL = 'AND page_namespace=' . $dbr->addQuotes( $this->mNs );
 132+
 133+ $use_index = $dbr->useIndexClause( $clause );
 134+ return
 135+ "SELECT
 136+ page_namespace AS namespace,
 137+ page_title AS title,
 138+ el_index AS value,
 139+ el_to AS url
 140+ FROM
 141+ $page,
 142+ $externallinks $use_index
 143+ WHERE
 144+ page_id=el_from
 145+ AND $clause LIKE $encSearch
 146+ $encSQL";
 147+ }
 148+
 149+ function formatResult( $skin, $result ) {
 150+ $title = Title::makeTitle( $result->namespace, $result->title );
 151+ $url = $result->url;
 152+ $pageLink = $skin->makeKnownLinkObj( $title );
 153+ $urlLink = $skin->makeExternalLink( $url, $url );
 154+
 155+ return wfMsgHtml( 'linksearch-line', $urlLink, $pageLink );
 156+ }
 157+
 158+ /**
 159+ * Override to check query validity.
 160+ */
 161+ function doQuery( $offset, $limit, $shownavigation=true ) {
 162+ global $wgOut;
 163+ list( $this->mMungedQuery, $clause ) = LinkSearchPage::mungeQuery( $this->mQuery, $this->mProt );
 164+ if( $this->mMungedQuery === false ) {
 165+ $wgOut->addWikiText( wfMsg( 'linksearch-error' ) );
 166+ } else {
 167+ // For debugging
 168+ // Generates invalid xhtml with patterns that contain --
 169+ //$wgOut->addHtml( "\n<!-- " . htmlspecialchars( $this->mMungedQuery ) . " -->\n" );
 170+ parent::doQuery( $offset, $limit, $shownavigation );
 171+ }
 172+ }
 173+
 174+ /**
 175+ * Override to squash the ORDER BY.
 176+ * We do a truncated index search, so the optimizer won't trust
 177+ * it as good enough for optimizing sort. The implicit ordering
 178+ * from the scan will usually do well enough for our needs.
 179+ */
 180+ function getOrder() {
 181+ return '';
 182+ }
 183+}
Property changes on: trunk/phase3/includes/specials/SpecialLinkSearch.php
___________________________________________________________________
Name: svn:mergeinfo
1184 +
Name: svn:eol-style
2185 + native
Index: trunk/phase3/includes/QueryPage.php
@@ -21,6 +21,7 @@
2222 array( 'DeadendPagesPage', 'Deadendpages' ),
2323 array( 'DisambiguationsPage', 'Disambiguations' ),
2424 array( 'DoubleRedirectsPage', 'DoubleRedirects' ),
 25+ array( 'LinkSearchPage', 'LinkSearch' ),
2526 array( 'ListredirectsPage', 'Listredirects' ),
2627 array( 'LonelyPagesPage', 'Lonelypages' ),
2728 array( 'LongPagesPage', 'Longpages' ),
Index: trunk/phase3/includes/SpecialPage.php
@@ -129,6 +129,7 @@
130130 'Contributions' => array( 'SpecialPage', 'Contributions' ),
131131 'Emailuser' => array( 'UnlistedSpecialPage', 'Emailuser' ),
132132 'Whatlinkshere' => array( 'SpecialPage', 'Whatlinkshere' ),
 133+ 'LinkSearch' => array( 'SpecialPage', 'LinkSearch' ),
133134 'Recentchangeslinked' => 'SpecialRecentchangeslinked',
134135 'Movepage' => array( 'UnlistedSpecialPage', 'Movepage' ),
135136 'Blockme' => array( 'UnlistedSpecialPage', 'Blockme' ),
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2104,6 +2104,16 @@
21052105 'special-categories-sort-count' => 'sort by count',
21062106 'special-categories-sort-abc' => 'sort alphabetically',
21072107
 2108+# Special:LinkSearch
 2109+'linksearch' => 'Search web links',
 2110+'linksearch-pat' => 'Search pattern:',
 2111+'linksearch-ns' => 'Namespace:',
 2112+'linksearch-ok' => 'Search',
 2113+'linksearch-text' => 'Wildcards such as "*.wikipedia.org" may be used.<br />
 2114+Supported protocols: <tt>$1</tt>',
 2115+'linksearch-line' => '$1 linked from $2',
 2116+'linksearch-error' => 'Wildcards may appear only at the start of the hostname.',
 2117+
21082118 # Special:ListUsers
21092119 'listusersfrom' => 'Display users starting at:',
21102120 'listusers-submit' => 'Show',
Index: trunk/phase3/RELEASE-NOTES
@@ -126,6 +126,9 @@
127127 * Added Wantedfiles special pages, allowing users to find image links with no image.
128128 * (bug 12650) It is now possible to set different expiration times for different
129129 restriction types on the protection form.
 130+* Special:Log/newusers recording new users.was added (was extension Newuserlog)
 131+* Special:LinkSearch to search for external links was added (was extension
 132+ LinkSearch)
130133
131134 === Bug fixes in 1.14 ===
132135

Follow-up revisions

RevisionCommit summaryAuthorDate
r40833Add special page names for LinkSearch (follow up for r40830).siebrand20:06, 14 September 2008
r40835Add OBSOLETE message as this functionality was added to core in r40830.siebrand20:07, 14 September 2008
r40836Localisation updates for core messages from Betawiki...siebrand20:19, 14 September 2008
r40866Cleanup for r40830. Don't die for sites that still have the extension on.aaron18:53, 15 September 2008