MediaWiki  1.23.2
ApiQueryIWLinks.php
Go to the documentation of this file.
1 <?php
34 
35  public function __construct( $query, $moduleName ) {
36  parent::__construct( $query, $moduleName, 'iw' );
37  }
38 
39  public function execute() {
40  if ( $this->getPageSet()->getGoodTitleCount() == 0 ) {
41  return;
42  }
43 
44  $params = $this->extractRequestParams();
45 
46  if ( isset( $params['title'] ) && !isset( $params['prefix'] ) ) {
47  $this->dieUsageMsg( array( 'missingparam', 'prefix' ) );
48  }
49 
50  $this->addFields( array(
51  'iwl_from',
52  'iwl_prefix',
53  'iwl_title'
54  ) );
55 
56  $this->addTables( 'iwlinks' );
57  $this->addWhereFld( 'iwl_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
58 
59  if ( !is_null( $params['continue'] ) ) {
60  $cont = explode( '|', $params['continue'] );
61  $this->dieContinueUsageIf( count( $cont ) != 3 );
62  $op = $params['dir'] == 'descending' ? '<' : '>';
63  $db = $this->getDB();
64  $iwlfrom = intval( $cont[0] );
65  $iwlprefix = $db->addQuotes( $cont[1] );
66  $iwltitle = $db->addQuotes( $cont[2] );
67  $this->addWhere(
68  "iwl_from $op $iwlfrom OR " .
69  "(iwl_from = $iwlfrom AND " .
70  "(iwl_prefix $op $iwlprefix OR " .
71  "(iwl_prefix = $iwlprefix AND " .
72  "iwl_title $op= $iwltitle)))"
73  );
74  }
75 
76  $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
77  if ( isset( $params['prefix'] ) ) {
78  $this->addWhereFld( 'iwl_prefix', $params['prefix'] );
79  if ( isset( $params['title'] ) ) {
80  $this->addWhereFld( 'iwl_title', $params['title'] );
81  $this->addOption( 'ORDER BY', 'iwl_from' . $sort );
82  } else {
83  $this->addOption( 'ORDER BY', array(
84  'iwl_from' . $sort,
85  'iwl_title' . $sort
86  ) );
87  }
88  } else {
89  // Don't order by iwl_from if it's constant in the WHERE clause
90  if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
91  $this->addOption( 'ORDER BY', 'iwl_prefix' . $sort );
92  } else {
93  $this->addOption( 'ORDER BY', array(
94  'iwl_from' . $sort,
95  'iwl_prefix' . $sort,
96  'iwl_title' . $sort
97  ) );
98  }
99  }
100 
101  $this->addOption( 'LIMIT', $params['limit'] + 1 );
102  $res = $this->select( __METHOD__ );
103 
104  $count = 0;
105  foreach ( $res as $row ) {
106  if ( ++$count > $params['limit'] ) {
107  // We've reached the one extra which shows that
108  // there are additional pages to be had. Stop here...
110  'continue',
111  "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}"
112  );
113  break;
114  }
115  $entry = array( 'prefix' => $row->iwl_prefix );
116 
117  if ( $params['url'] ) {
118  $title = Title::newFromText( "{$row->iwl_prefix}:{$row->iwl_title}" );
119  if ( $title ) {
120  $entry['url'] = wfExpandUrl( $title->getFullURL(), PROTO_CURRENT );
121  }
122  }
123 
124  ApiResult::setContent( $entry, $row->iwl_title );
125  $fit = $this->addPageSubItem( $row->iwl_from, $entry );
126  if ( !$fit ) {
128  'continue',
129  "{$row->iwl_from}|{$row->iwl_prefix}|{$row->iwl_title}"
130  );
131  break;
132  }
133  }
134  }
135 
136  public function getCacheMode( $params ) {
137  return 'public';
138  }
139 
140  public function getAllowedParams() {
141  return array(
142  'url' => false,
143  'limit' => array(
144  ApiBase::PARAM_DFLT => 10,
145  ApiBase::PARAM_TYPE => 'limit',
146  ApiBase::PARAM_MIN => 1,
149  ),
150  'continue' => null,
151  'prefix' => null,
152  'title' => null,
153  'dir' => array(
154  ApiBase::PARAM_DFLT => 'ascending',
156  'ascending',
157  'descending'
158  )
159  ),
160  );
161  }
162 
163  public function getParamDescription() {
164  return array(
165  'url' => 'Whether to get the full URL',
166  'limit' => 'How many interwiki links to return',
167  'continue' => 'When more results are available, use this to continue',
168  'prefix' => 'Prefix for the interwiki',
169  'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix",
170  'dir' => 'The direction in which to list',
171  );
172  }
173 
174  public function getResultProperties() {
175  return array(
176  '' => array(
177  'prefix' => 'string',
178  'url' => array(
179  ApiBase::PROP_TYPE => 'string',
180  ApiBase::PROP_NULLABLE => true
181  ),
182  '*' => 'string'
183  )
184  );
185  }
186 
187  public function getDescription() {
188  return 'Returns all interwiki links from the given page(s).';
189  }
190 
191  public function getPossibleErrors() {
192  return array_merge( parent::getPossibleErrors(), array(
193  array( 'missingparam', 'prefix' ),
194  ) );
195  }
196 
197  public function getExamples() {
198  return array(
199  'api.php?action=query&prop=iwlinks&titles=Main%20Page'
200  => 'Get interwiki links from the [[Main Page]]',
201  );
202  }
203 
204  public function getHelpUrls() {
205  return 'https://www.mediawiki.org/wiki/API:Iwlinks';
206  }
207 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
ApiQueryBase\addFields
addFields( $value)
Add a set of fields to select to the internal array.
Definition: ApiQueryBase.php:117
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
ApiResult\setContent
static setContent(&$arr, $value, $subElemName=null)
Adds a content element to an array.
Definition: ApiResult.php:201
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1929
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
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
ApiQueryBase\addOption
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
Definition: ApiQueryBase.php:252
ApiBase\PARAM_MIN
const PARAM_MIN
Definition: ApiBase.php:56
ApiQueryBase
This is a base class for all Query modules.
Definition: ApiQueryBase.php:34
ApiBase\LIMIT_BIG1
const LIMIT_BIG1
Definition: ApiBase.php:78
ApiQueryBase\getDB
getDB()
Get the Query database connection (read-only)
Definition: ApiQueryBase.php:417
PROTO_CURRENT
const PROTO_CURRENT
Definition: Defines.php:270
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.
ApiBase\PROP_TYPE
const PROP_TYPE
Definition: ApiBase.php:74
$sort
$sort
Definition: profileinfo.php:301
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
ApiBase\dieContinueUsageIf
dieContinueUsageIf( $condition)
Die with the $prefix.
Definition: ApiBase.php:1965
ApiBase\PROP_NULLABLE
const PROP_NULLABLE
Definition: ApiBase.php:76
ApiQueryBase\addWhereFld
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
Definition: ApiQueryBase.php:185
ApiQueryBase\getPageSet
getPageSet()
Get the PageSet object to work on.
Definition: ApiQueryBase.php:441
$count
$count
Definition: UtfNormalTest2.php:96
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\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
ApiQueryBase\setContinueEnumParameter
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
Definition: ApiQueryBase.php:404
$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
$res
$res
Definition: database.txt:21
ApiQueryBase\addPageSubItem
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
Definition: ApiQueryBase.php:383
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:497