r37642 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37641‎ | r37642 | r37643 >
Date:12:04, 14 July 2008
Author:catrope
Status:old
Tags:
Comment:
API list=exturlusage: Added possibility to filter by protocol in "list all links" mode. euprotocol now accepts an empty string too, which is interpreted as "list all links" if euquery is empty, and silently interpreted as 'http' if euquery is not empty, to preserve backwards compatibility.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryExtLinksUsage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php
@@ -54,7 +54,7 @@
5555
5656 // Find the right prefix
5757 global $wgUrlProtocols;
58 - if(!is_null($protocol) && $protocol != '' && !in_array($protocol, $wgUrlProtocols))
 58+ if(!is_null($protocol) && !empty($protocol) && !in_array($protocol, $wgUrlProtocols))
5959 {
6060 foreach ($wgUrlProtocols as $p) {
6161 if( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
@@ -63,6 +63,8 @@
6464 }
6565 }
6666 }
 67+ else
 68+ $protocol = null;
6769
6870 $db = $this->getDb();
6971 $this->addTables(array('page','externallinks')); // must be in this order for 'USE INDEX'
@@ -72,12 +74,17 @@
7375
7476 if(!is_null($query) || $query != '')
7577 {
76 - $likeQuery = LinkFilter::makeLike($query , $protocol);
 78+ if(is_null($protocol))
 79+ $protocol = 'http';
 80+
 81+ $likeQuery = LinkFilter::makeLike($query, $protocol);
7782 if (!$likeQuery)
7883 $this->dieUsage('Invalid query', 'bad_query');
7984 $likeQuery = substr($likeQuery, 0, strpos($likeQuery,'%')+1);
8085 $this->addWhere('el_index LIKE ' . $db->addQuotes( $likeQuery ));
8186 }
 87+ else if(!is_null($protocol))
 88+ $this->addWhere('el_index LIKE ' . $db->addQuotes( "$protocol%" ));
8289
8390 $prop = array_flip($params['prop']);
8491 $fld_ids = isset($prop['ids']);
@@ -139,7 +146,7 @@
140147
141148 public function getAllowedParams() {
142149 global $wgUrlProtocols;
143 - $protocols = array();
 150+ $protocols = array('');
144151 foreach ($wgUrlProtocols as $p) {
145152 $protocols[] = substr($p, 0, strpos($p,':'));
146153 }
@@ -159,7 +166,7 @@
160167 ),
161168 'protocol' => array (
162169 ApiBase :: PARAM_TYPE => $protocols,
163 - ApiBase :: PARAM_DFLT => 'http',
 170+ ApiBase :: PARAM_DFLT => '',
164171 ),
165172 'query' => null,
166173 'namespace' => array (
@@ -180,8 +187,9 @@
181188 return array (
182189 'prop' => 'What pieces of information to include',
183190 'offset' => 'Used for paging. Use the value returned for "continue"',
184 - 'protocol' => 'Protocol of the url',
185 - 'query' => 'Search string without protocol. See [[Special:LinkSearch]]. Leave empty to list all external links (euprotocol will be ignored)',
 191+ 'protocol' => array( 'Protocol of the url. If empty and euquery set, the protocol is http.',
 192+ 'Leave both this and euquery empty to list all external links'),
 193+ 'query' => 'Search string without protocol. See [[Special:LinkSearch]]. Leave empty to list all external links',
186194 'namespace' => 'The page namespace(s) to enumerate.',
187195 'limit' => 'How many entries to return.'
188196 );
Index: trunk/phase3/RELEASE-NOTES
@@ -526,6 +526,7 @@
527527 prop={links,templatelinks,langlinks,extlinks,categories,images}
528528 * Added flag "top" to list=usercontribs if the user is the last contributor to
529529 the page
 530+* list=exturlusage in "list all links" mode can now filter by protocol
530531
531532 === Languages updated in 1.13 ===
532533

Follow-up revisions

RevisionCommit summaryAuthorDate
r37712Revert r37642 for now ('Added possibility to filter by protocol in "list all ...brion20:51, 15 July 2008
r37717Revert r37712 which was itself a revert of r37642 (filter by protocol in list...catrope21:29, 15 July 2008
r37725Redoing r37642 ('Added possibility to filter by protocol in "list all links" ...catrope22:03, 15 July 2008

Status & tagging log