MediaWiki  1.23.8
ApiQueryExtLinksUsage.php
Go to the documentation of this file.
1 <?php
31 
32  public function __construct( $query, $moduleName ) {
33  parent::__construct( $query, $moduleName, 'eu' );
34  }
35 
36  public function execute() {
37  $this->run();
38  }
39 
40  public function getCacheMode( $params ) {
41  return 'public';
42  }
43 
44  public function executeGenerator( $resultPageSet ) {
45  $this->run( $resultPageSet );
46  }
47 
52  private function run( $resultPageSet = null ) {
53  $params = $this->extractRequestParams();
54 
55  $query = $params['query'];
56  $protocol = self::getProtocolPrefix( $params['protocol'] );
57 
58  $this->addTables( array( 'page', 'externallinks' ) ); // must be in this order for 'USE INDEX'
59  $this->addOption( 'USE INDEX', 'el_index' );
60  $this->addWhere( 'page_id=el_from' );
61 
62  global $wgMiserMode;
63  $miser_ns = array();
64  if ( $wgMiserMode ) {
65  $miser_ns = $params['namespace'];
66  } else {
67  $this->addWhereFld( 'page_namespace', $params['namespace'] );
68  }
69 
70  $whereQuery = $this->prepareUrlQuerySearchString( $query, $protocol );
71 
72  if ( $whereQuery !== null ) {
73  $this->addWhere( $whereQuery );
74  }
75 
76  $prop = array_flip( $params['prop'] );
77  $fld_ids = isset( $prop['ids'] );
78  $fld_title = isset( $prop['title'] );
79  $fld_url = isset( $prop['url'] );
80 
81  if ( is_null( $resultPageSet ) ) {
82  $this->addFields( array(
83  'page_id',
84  'page_namespace',
85  'page_title'
86  ) );
87  $this->addFieldsIf( 'el_to', $fld_url );
88  } else {
89  $this->addFields( $resultPageSet->getPageTableFields() );
90  }
91 
92  $limit = $params['limit'];
93  $offset = $params['offset'];
94  $this->addOption( 'LIMIT', $limit + 1 );
95  if ( isset( $offset ) ) {
96  $this->addOption( 'OFFSET', $offset );
97  }
98 
99  $res = $this->select( __METHOD__ );
100 
101  $result = $this->getResult();
102  $count = 0;
103  foreach ( $res as $row ) {
104  if ( ++$count > $limit ) {
105  // We've reached the one extra which shows that there are
106  // additional pages to be had. Stop here...
107  $this->setContinueEnumParameter( 'offset', $offset + $limit );
108  break;
109  }
110 
111  if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
112  continue;
113  }
114 
115  if ( is_null( $resultPageSet ) ) {
116  $vals = array();
117  if ( $fld_ids ) {
118  $vals['pageid'] = intval( $row->page_id );
119  }
120  if ( $fld_title ) {
121  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
123  }
124  if ( $fld_url ) {
125  $to = $row->el_to;
126  // expand protocol-relative urls
127  if ( $params['expandurl'] ) {
128  $to = wfExpandUrl( $to, PROTO_CANONICAL );
129  }
130  $vals['url'] = $to;
131  }
132  $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
133  if ( !$fit ) {
134  $this->setContinueEnumParameter( 'offset', $offset + $count - 1 );
135  break;
136  }
137  } else {
138  $resultPageSet->processDbRow( $row );
139  }
140  }
141 
142  if ( is_null( $resultPageSet ) ) {
143  $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ),
144  $this->getModulePrefix() );
145  }
146  }
147 
148  public function getAllowedParams() {
149  return array(
150  'prop' => array(
151  ApiBase::PARAM_ISMULTI => true,
152  ApiBase::PARAM_DFLT => 'ids|title|url',
154  'ids',
155  'title',
156  'url'
157  )
158  ),
159  'offset' => array(
160  ApiBase::PARAM_TYPE => 'integer'
161  ),
162  'protocol' => array(
163  ApiBase::PARAM_TYPE => self::prepareProtocols(),
164  ApiBase::PARAM_DFLT => '',
165  ),
166  'query' => null,
167  'namespace' => array(
168  ApiBase::PARAM_ISMULTI => true,
169  ApiBase::PARAM_TYPE => 'namespace'
170  ),
171  'limit' => array(
172  ApiBase::PARAM_DFLT => 10,
173  ApiBase::PARAM_TYPE => 'limit',
174  ApiBase::PARAM_MIN => 1,
177  ),
178  'expandurl' => false,
179  );
180  }
181 
182  public static function prepareProtocols() {
183  global $wgUrlProtocols;
184  $protocols = array( '' );
185  foreach ( $wgUrlProtocols as $p ) {
186  if ( $p !== '//' ) {
187  $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
188  }
189  }
190 
191  return $protocols;
192  }
193 
194  public static function getProtocolPrefix( $protocol ) {
195  // Find the right prefix
196  global $wgUrlProtocols;
197  if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) {
198  foreach ( $wgUrlProtocols as $p ) {
199  if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
200  $protocol = $p;
201  break;
202  }
203  }
204 
205  return $protocol;
206  } else {
207  return null;
208  }
209  }
210 
211  public function getParamDescription() {
212  global $wgMiserMode;
213  $p = $this->getModulePrefix();
214  $desc = array(
215  'prop' => array(
216  'What pieces of information to include',
217  ' ids - Adds the ID of page',
218  ' title - Adds the title and namespace ID of the page',
219  ' url - Adds the URL used in the page',
220  ),
221  'offset' => 'Used for paging. Use the value returned for "continue"',
222  'protocol' => array(
223  "Protocol of the URL. If empty and {$p}query set, the protocol is http.",
224  "Leave both this and {$p}query empty to list all external links"
225  ),
226  'query' => 'Search string without protocol. See [[Special:LinkSearch]]. ' .
227  'Leave empty to list all external links',
228  'namespace' => 'The page namespace(s) to enumerate.',
229  'limit' => 'How many pages to return.',
230  'expandurl' => 'Expand protocol-relative URLs with the canonical protocol',
231  );
232 
233  if ( $wgMiserMode ) {
234  $desc['namespace'] = array(
235  $desc['namespace'],
236  "NOTE: Due to \$wgMiserMode, using this may result in fewer than \"{$p}limit\" results",
237  'returned before continuing; in extreme cases, zero results may be returned',
238  );
239  }
240 
241  return $desc;
242  }
243 
244  public function getResultProperties() {
245  return array(
246  'ids' => array(
247  'pageid' => 'integer'
248  ),
249  'title' => array(
250  'ns' => 'namespace',
251  'title' => 'string'
252  ),
253  'url' => array(
254  'url' => 'string'
255  )
256  );
257  }
258 
259  public function getDescription() {
260  return 'Enumerate pages that contain a given URL.';
261  }
262 
263  public function getPossibleErrors() {
264  return array_merge( parent::getPossibleErrors(), array(
265  array( 'code' => 'bad_query', 'info' => 'Invalid query' ),
266  ) );
267  }
268 
269  public function getExamples() {
270  return array(
271  'api.php?action=query&list=exturlusage&euquery=www.mediawiki.org'
272  );
273  }
274 
275  public function getHelpUrls() {
276  return 'https://www.mediawiki.org/wiki/API:Exturlusage';
277  }
278 }
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
ApiQueryExtLinksUsage\getCacheMode
getCacheMode( $params)
Get the cache mode for the data generated by this module.
Definition: ApiQueryExtLinksUsage.php:40
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:117
PROTO_CANONICAL
const PROTO_CANONICAL
Definition: Defines.php:271
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiQueryExtLinksUsage\getHelpUrls
getHelpUrls()
Definition: ApiQueryExtLinksUsage.php:275
ApiQueryExtLinksUsage\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiQueryExtLinksUsage.php:269
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
ApiQueryBase\select
select( $method, $extraQuery=array())
Execute a SELECT query based on the values in the internal arrays.
Definition: ApiQueryBase.php:274
$params
$params
Definition: styleTest.css.php:40
$limit
if( $sleep) $limit
Definition: importImages.php:99
ApiQueryExtLinksUsage
Definition: ApiQueryExtLinksUsage.php:30
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:252
ApiQueryExtLinksUsage\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiQueryExtLinksUsage.php:36
ApiQueryBase\addFieldsIf
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
Definition: ApiQueryBase.php:131
ApiQueryGeneratorBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Overrides base in case of generator & smart continue to notify ApiQueryMain instead of adding them to...
Definition: ApiQueryBase.php:676
ApiQueryExtLinksUsage\prepareProtocols
static prepareProtocols()
Definition: ApiQueryExtLinksUsage.php:182
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:56
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Definition: ApiBase.php:78
ApiBase\PARAM_MAX
const PARAM_MAX
Definition: ApiBase.php:52
ApiQueryBase\addTables
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
Definition: ApiQueryBase.php:82
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiQueryExtLinksUsage\run
run( $resultPageSet=null)
Definition: ApiQueryExtLinksUsage.php:52
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ApiQueryExtLinksUsage\getPossibleErrors
getPossibleErrors()
Definition: ApiQueryExtLinksUsage.php:263
ApiBase\getModulePrefix
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
Definition: ApiBase.php:165
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ApiQueryExtLinksUsage\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiQueryExtLinksUsage.php:244
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:185
ApiQueryExtLinksUsage\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiQueryExtLinksUsage.php:148
$count
$count
Definition: UtfNormalTest2.php:96
ApiQueryGeneratorBase
Definition: ApiQueryBase.php:626
ApiBase\LIMIT_BIG2
const LIMIT_BIG2
Definition: ApiBase.php:79
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:148
ApiQueryExtLinksUsage\__construct
__construct( $query, $moduleName)
Definition: ApiQueryExtLinksUsage.php:32
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
ApiQueryExtLinksUsage\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiQueryExtLinksUsage.php:259
ApiBase\PARAM_MAX2
const PARAM_MAX2
Definition: ApiBase.php:54
ApiQueryBase\addWhere
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Definition: ApiQueryBase.php:152
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
ApiQueryBase\prepareUrlQuerySearchString
prepareUrlQuerySearchString( $query=null, $protocol=null)
Definition: ApiQueryBase.php:537
$res
$res
Definition: database.txt:21
ApiQueryExtLinksUsage\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiQueryExtLinksUsage.php:211
ApiQueryExtLinksUsage\executeGenerator
executeGenerator( $resultPageSet)
Execute this module as a generator.
Definition: ApiQueryExtLinksUsage.php:44
ApiQueryBase\addTitleInfo
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
Definition: ApiQueryBase.php:339
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:497
ApiQueryExtLinksUsage\getProtocolPrefix
static getProtocolPrefix( $protocol)
Definition: ApiQueryExtLinksUsage.php:194