Index: trunk/phase3/includes/api/ApiQuery.php |
— | — | @@ -73,6 +73,7 @@ |
74 | 74 | 'embeddedin' => 'ApiQueryBacklinks', |
75 | 75 | 'filearchive' => 'ApiQueryFilearchive', |
76 | 76 | 'imageusage' => 'ApiQueryBacklinks', |
| 77 | + 'iwbacklinks' => 'ApiQueryIWBacklinks', |
77 | 78 | 'logevents' => 'ApiQueryLogEvents', |
78 | 79 | 'recentchanges' => 'ApiQueryRecentChanges', |
79 | 80 | 'search' => 'ApiQuerySearch', |
Index: trunk/phase3/includes/api/ApiQueryIWBacklinks.php |
— | — | @@ -0,0 +1,180 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on May 14, 2010 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.17+ |
| 8 | + * |
| 9 | + * Copyright (C) 2010 Sam Reed |
| 10 | + * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com |
| 11 | + * |
| 12 | + * This program is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License as published by |
| 14 | + * the Free Software Foundation; either version 2 of the License, or |
| 15 | + * (at your option) any later version. |
| 16 | + * |
| 17 | + * This program is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License along |
| 23 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 25 | + * http://www.gnu.org/copyleft/gpl.html |
| 26 | + */ |
| 27 | + |
| 28 | +if ( !defined( 'MEDIAWIKI' ) ) { |
| 29 | + // Eclipse helper - will be ignored in production |
| 30 | + require_once( "ApiQueryBase.php" ); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * This gives links pointing to the given interwiki |
| 35 | + * @ingroup API |
| 36 | + */ |
| 37 | +class ApiQueryIWBacklinks extends ApiQueryBase { |
| 38 | + |
| 39 | + public function __construct( $query, $moduleName ) { |
| 40 | + parent::__construct( $query, $moduleName, 'iwbl' ); |
| 41 | + } |
| 42 | + |
| 43 | + public function execute() { |
| 44 | + $params = $this->extractRequestParams( false ); |
| 45 | + |
| 46 | + $userMax = ( $this->redirect ? ApiBase::LIMIT_BIG1 / 2 : ApiBase::LIMIT_BIG1 ); |
| 47 | + $botMax = ( $this->redirect ? ApiBase::LIMIT_BIG2 / 2 : ApiBase::LIMIT_BIG2 ); |
| 48 | + |
| 49 | + if ( $params['limit'] == 'max' ) { |
| 50 | + $params['limit'] = $this->getMain()->canApiHighLimits() ? $botMax : $userMax; |
| 51 | + $this->getResult()->addValue( 'limits', $this->getModuleName(), $params['limit'] ); |
| 52 | + } |
| 53 | + |
| 54 | + if ( !is_null( $params['continue'] ) ) { |
| 55 | + $cont = explode( '|', $params['continue'] ); |
| 56 | + if ( count( $cont ) != 3 ) { |
| 57 | + $this->dieUsage( 'Invalid continue param. You should pass the ' . |
| 58 | + 'original value returned by the previous query', '_badcontinue' ); |
| 59 | + } |
| 60 | + |
| 61 | + $from = intval( $cont[0] ); |
| 62 | + $prefix = $this->getDB()->strencode( $cont[1] ); |
| 63 | + $title = $this->getDB()->strencode( $this->titleToKey( $cont[2] ) ); |
| 64 | + $this->addWhere( |
| 65 | + "iwl_from > $from OR " . |
| 66 | + "(iwl_from = $from AND " . |
| 67 | + "(iwl_prefix > '$prefix' OR " . |
| 68 | + "(iwl_prefix = '$prefix' AND " . |
| 69 | + "iwl_title >= '$title')))" |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + $this->addTables( array( 'iwlinks', 'page' ) ); |
| 74 | + $this->addWhere( 'iwl_from = page_id' ); |
| 75 | + |
| 76 | + $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect', |
| 77 | + 'iwl_from', 'iwl_prefix', 'iwl_title' ) ); |
| 78 | + |
| 79 | + if ( $params['prefix'] !== '' ) { |
| 80 | + $this->addWhereFld( 'iwl_prefix', $params['prefix'] ); |
| 81 | + } |
| 82 | + |
| 83 | + if ( $params['title'] !== '' ) { |
| 84 | + $this->addWhereFld( 'iwl_title', $params['title'] ); |
| 85 | + } |
| 86 | + |
| 87 | + $this->addWhereFld( 'page_namespace', $params['namespace'] ); |
| 88 | + |
| 89 | + $this->addOption( 'LIMIT', $params['limit'] + 1 ); |
| 90 | + $this->addOption( 'ORDER BY', 'iwl_from' ); |
| 91 | + $this->addOption( 'STRAIGHT_JOIN' ); |
| 92 | + |
| 93 | + $db = $this->getDB(); |
| 94 | + $res = $this->select( __METHOD__ . '::firstQuery' ); |
| 95 | + |
| 96 | + $count = 0; |
| 97 | + $result = $this->getResult(); |
| 98 | + while ( $row = $db->fetchObject( $res ) ) { |
| 99 | + if ( ++ $count > $params['limit'] ) { |
| 100 | + // We've reached the one extra which shows that there are additional pages to be had. Stop here... |
| 101 | + // Continue string preserved in case the redirect query doesn't pass the limit |
| 102 | + $this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" ); |
| 103 | + break; |
| 104 | + } |
| 105 | + |
| 106 | + $entry = array(); |
| 107 | + |
| 108 | + $entry['pageid'] = intval( $row->page_id ); |
| 109 | + $entry['ns'] = $row->page_namespace; |
| 110 | + $entry['title'] = $row->page_title; |
| 111 | + |
| 112 | + if ( $row->page_is_redirect ) { |
| 113 | + $entry['redirect'] = ''; |
| 114 | + } |
| 115 | + |
| 116 | + $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry ); |
| 117 | + if ( !$fit ) { |
| 118 | + $this->setContinueEnumParameter( 'continue', "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}" ); |
| 119 | + break; |
| 120 | + } |
| 121 | + } |
| 122 | + $db->freeResult( $res ); |
| 123 | + |
| 124 | + $this->getResult()->setIndexedTagName_internal( |
| 125 | + array( 'query', $this->getModuleName() ), |
| 126 | + 'iw' |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + public function getAllowedParams() { |
| 131 | + return array( |
| 132 | + 'prefix' => null, |
| 133 | + 'title' => null, |
| 134 | + 'continue' => null, |
| 135 | + 'namespace' => array( |
| 136 | + ApiBase::PARAM_ISMULTI => true, |
| 137 | + ApiBase::PARAM_TYPE => 'namespace' |
| 138 | + ), |
| 139 | + 'limit' => array( |
| 140 | + ApiBase::PARAM_DFLT => 10, |
| 141 | + ApiBase::PARAM_TYPE => 'limit', |
| 142 | + ApiBase::PARAM_MIN => 1, |
| 143 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 144 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 145 | + ) |
| 146 | + ); |
| 147 | + } |
| 148 | + |
| 149 | + public function getParamDescription() { |
| 150 | + return array( |
| 151 | + 'prefix' => 'Prefix for the interwiki', |
| 152 | + 'title' => 'Interwiki link to search for', |
| 153 | + 'continue' => 'When more results are available, use this to continue', |
| 154 | + 'namespace' => 'The namespace to enumerate', |
| 155 | + 'limit' => 'How many total pages to return', |
| 156 | + ); |
| 157 | + } |
| 158 | + |
| 159 | + public function getDescription() { |
| 160 | + return 'Find all pages that link to the given interwiki link'; |
| 161 | + } |
| 162 | + |
| 163 | + public function getPossibleErrors() { |
| 164 | + return array_merge( parent::getPossibleErrors(), array( |
| 165 | + array( 'invalidtitle', 'title' ), |
| 166 | + array( 'missingparam', 'title' ), |
| 167 | + array( 'code' => '_badcontinue', 'info' => 'Invalid continue param. You should pass the original value returned by the previous query' ), |
| 168 | + ) ); |
| 169 | + } |
| 170 | + |
| 171 | + protected function getExamples() { |
| 172 | + return array( |
| 173 | + 'api.php?action=query&list=iwbacklinks&iwbltitle=Test&iwblprefix=wikibooks', |
| 174 | + 'api.php?action=query&generator=iwbacklinks&giwbltitle=Test&iwblprefix=wikibooks&prop=info' |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + public function getVersion() { |
| 179 | + return __CLASS__ . ': $Id$'; |
| 180 | + } |
| 181 | +} |
Property changes on: trunk/phase3/includes/api/ApiQueryIWBacklinks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 182 | + native |
Added: svn:keywords |
2 | 183 | + Id |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -322,6 +322,7 @@ |
323 | 323 | 'ApiQueryImages' => 'includes/api/ApiQueryImages.php', |
324 | 324 | 'ApiQueryInfo' => 'includes/api/ApiQueryInfo.php', |
325 | 325 | 'ApiQueryIWLinks' => 'includes/api/ApiQueryIWLinks.php', |
| 326 | + 'ApiQueryIWBacklinks' => 'includes/api/ApiQueryIWBacklinks.php', |
326 | 327 | 'ApiQueryLangLinks' => 'includes/api/ApiQueryLangLinks.php', |
327 | 328 | 'ApiQueryLinks' => 'includes/api/ApiQueryLinks.php', |
328 | 329 | 'ApiQueryLogEvents' => 'includes/api/ApiQueryLogEvents.php', |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -187,6 +187,7 @@ |
188 | 188 | * (bug 21346) Make deleted images searchable by hash |
189 | 189 | * (bug 23461) Normalise usage of parameter names in parameter descriptions |
190 | 190 | * (bug 23548) Allow access of another users watchlist through watchlistraw using token and username |
| 191 | +* (bug 23524) Api Modules as followup to bug 14473 (Add iwlinks table to track inline interwiki link usage |
191 | 192 | |
192 | 193 | === Languages updated in 1.17 === |
193 | 194 | |