Index: trunk/phase3/includes/api/ApiQueryExtLinksUsage.php |
— | — | @@ -50,25 +50,16 @@ |
51 | 51 | $this->run( $resultPageSet ); |
52 | 52 | } |
53 | 53 | |
| 54 | + /** |
| 55 | + * @para $resultPageSet ApiPageSet |
| 56 | + * @return void |
| 57 | + */ |
54 | 58 | private function run( $resultPageSet = null ) { |
55 | 59 | $params = $this->extractRequestParams(); |
56 | 60 | |
57 | | - $protocol = $params['protocol']; |
58 | 61 | $query = $params['query']; |
| 62 | + $protocol = self::getProtocolPrefix( $params['protocol'] ); |
59 | 63 | |
60 | | - // Find the right prefix |
61 | | - global $wgUrlProtocols; |
62 | | - if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) { |
63 | | - foreach ( $wgUrlProtocols as $p ) { |
64 | | - if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) { |
65 | | - $protocol = $p; |
66 | | - break; |
67 | | - } |
68 | | - } |
69 | | - } else { |
70 | | - $protocol = null; |
71 | | - } |
72 | | - |
73 | 64 | $db = $this->getDB(); |
74 | 65 | $this->addTables( array( 'page', 'externallinks' ) ); // must be in this order for 'USE INDEX' |
75 | 66 | $this->addOption( 'USE INDEX', 'el_index' ); |
— | — | @@ -195,6 +186,23 @@ |
196 | 187 | return $protocols; |
197 | 188 | } |
198 | 189 | |
| 190 | + public static function getProtocolPrefix( $protocol ) { |
| 191 | + // Find the right prefix |
| 192 | + global $wgUrlProtocols; |
| 193 | + if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) { |
| 194 | + foreach ( $wgUrlProtocols as $p ) { |
| 195 | + if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) { |
| 196 | + $protocol = $p; |
| 197 | + break; |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + return $protocol; |
| 202 | + } else { |
| 203 | + return null; |
| 204 | + } |
| 205 | + } |
| 206 | + |
199 | 207 | public function getParamDescription() { |
200 | 208 | $p = $this->getModulePrefix(); |
201 | 209 | return array( |
Index: trunk/phase3/includes/api/ApiQueryExternalLinks.php |
— | — | @@ -46,6 +46,11 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | $params = $this->extractRequestParams(); |
| 50 | + $db = $this->getDB(); |
| 51 | + |
| 52 | + $query = $params['query']; |
| 53 | + $protocol = ApiQueryExtLinksUsage::getProtocolPrefix( $params['protocol'] ); |
| 54 | + |
50 | 55 | $this->addFields( array( |
51 | 56 | 'el_from', |
52 | 57 | 'el_to' |
— | — | @@ -54,6 +59,23 @@ |
55 | 60 | $this->addTables( 'externallinks' ); |
56 | 61 | $this->addWhereFld( 'el_from', array_keys( $this->getPageSet()->getGoodTitles() ) ); |
57 | 62 | |
| 63 | + //TODO: Refactor out,duplicated from ApiQueryExtLinksUsage |
| 64 | + if ( !is_null( $query ) || $query != '' ) { |
| 65 | + if ( is_null( $protocol ) ) { |
| 66 | + $protocol = 'http://'; |
| 67 | + } |
| 68 | + |
| 69 | + $likeQuery = LinkFilter::makeLikeArray( $query, $protocol ); |
| 70 | + if ( !$likeQuery ) { |
| 71 | + $this->dieUsage( 'Invalid query', 'bad_query' ); |
| 72 | + } |
| 73 | + |
| 74 | + $likeQuery = LinkFilter::keepOneWildcard( $likeQuery ); |
| 75 | + $this->addWhere( 'el_index ' . $db->buildLike( $likeQuery ) ); |
| 76 | + } elseif ( !is_null( $protocol ) ) { |
| 77 | + $this->addWhere( 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ) ); |
| 78 | + } |
| 79 | + |
58 | 80 | // Don't order by el_from if it's constant in the WHERE clause |
59 | 81 | if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) { |
60 | 82 | $this->addOption( 'ORDER BY', 'el_from' ); |
— | — | @@ -98,13 +120,24 @@ |
99 | 121 | ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
100 | 122 | ), |
101 | 123 | 'offset' => null, |
| 124 | + 'protocol' => array( |
| 125 | + ApiBase::PARAM_TYPE => ApiQueryExtLinksUsage::prepareProtocols(), |
| 126 | + ApiBase::PARAM_DFLT => '', |
| 127 | + ), |
| 128 | + 'query' => null, |
102 | 129 | ); |
103 | 130 | } |
104 | 131 | |
105 | 132 | public function getParamDescription() { |
| 133 | + $p = $this->getModulePrefix(); |
106 | 134 | return array( |
107 | 135 | 'limit' => 'How many links to return', |
108 | 136 | 'offset' => 'When more results are available, use this to continue', |
| 137 | + 'protocol' => array( |
| 138 | + "Protocol of the url. If empty and {$p}query set, the protocol is http.", |
| 139 | + "Leave both this and {$p}query empty to list all external links" |
| 140 | + ), |
| 141 | + 'query' => 'Search string without protocol. Useful for checking whether a certain page contains a certain external url', |
109 | 142 | ); |
110 | 143 | } |
111 | 144 | |
— | — | @@ -112,6 +145,12 @@ |
113 | 146 | return 'Returns all external urls (not interwikies) from the given page(s)'; |
114 | 147 | } |
115 | 148 | |
| 149 | + public function getPossibleErrors() { |
| 150 | + return array_merge( parent::getPossibleErrors(), array( |
| 151 | + array( 'code' => 'bad_query', 'info' => 'Invalid query' ), |
| 152 | + ) ); |
| 153 | + } |
| 154 | + |
116 | 155 | protected function getExamples() { |
117 | 156 | return array( |
118 | 157 | 'Get a list of external links on the [[Main Page]]:', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -77,6 +77,7 @@ |
78 | 78 | * (bug 26460) Add support for listing category members by category pageid |
79 | 79 | * (bug 26482) add a imimages param to prop=images |
80 | 80 | * (bug 26498) allow LinksUpdate with API |
| 81 | +* (bug 26485) add a elextlinks param to prop=extlinks |
81 | 82 | |
82 | 83 | === Languages updated in 1.18 === |
83 | 84 | |