r92375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92374‎ | r92375 | r92376 >
Date:18:38, 16 July 2011
Author:btongminh
Status:ok
Tags:
Comment:
Per IRC request, conditionally add namespace, page id and url
Modified paths:
  • /trunk/extensions/GlobalUsage/ApiQueryGlobalUsage.php (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageQuery.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/GlobalUsageQuery.php
@@ -169,6 +169,7 @@
170170 'gil_to',
171171 'gil_wiki',
172172 'gil_page',
 173+ 'gil_page_namespace_id',
173174 'gil_page_namespace',
174175 'gil_page_title'
175176 ),
@@ -211,6 +212,7 @@
212213 $this->result[$row->gil_to][$row->gil_wiki][] = array(
213214 'image' => $row->gil_to,
214215 'id' => $row->gil_page,
 216+ 'namespace_id' => $row->gil_page_namespace_id,
215217 'namespace' => $row->gil_page_namespace,
216218 'title' => $row->gil_page_title,
217219 'wiki' => $row->gil_wiki,
Index: trunk/extensions/GlobalUsage/ApiQueryGlobalUsage.php
@@ -29,6 +29,7 @@
3030
3131 public function execute() {
3232 $params = $this->extractRequestParams();
 33+ $prop = array_flip( $params['prop'] );
3334
3435 $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
3536 if ( !empty( $pageIds[NS_FILE] ) ) {
@@ -51,18 +52,29 @@
5253 $pageId = intval( $pageIds[$image] );
5354 foreach ( $wikis as $wiki => $result ) {
5455 foreach ( $result as $item ) {
55 - if ( $item['namespace'] )
 56+ if ( $item['namespace'] ) {
5657 $title = "{$item['namespace']}:{$item['title']}";
57 - else
 58+ } else {
5859 $title = $item['title'];
59 - $url = WikiMap::getForeignUrl( $item['wiki'], $title );
 60+ }
 61+ $result = array(
 62+ 'title' => $title,
 63+ 'wiki' => WikiMap::getWikiName( $wiki )
 64+ );
 65+ if ( isset( $prop['url'] ) ) {
 66+ $result['url'] = wfExpandUrl(
 67+ WikiMap::getForeignUrl( $item['wiki'], $title ) );
 68+ }
 69+ if ( isset( $prop['pageid'] ) ) {
 70+ $result['pageid'] = $item['id'];
 71+ }
 72+ if ( isset( $prop['namespace'] ) ) {
 73+ $result['ns'] = $item['namespace_id'];
 74+ }
 75+
6076 $fit = $apiResult->addValue( array(
6177 'query', 'pages', $pageId, 'globalusage'
62 - ), null, array(
63 - 'title' => $title,
64 - 'url' => $url,
65 - 'wiki' => WikiMap::getWikiName( $wiki )
66 - ) );
 78+ ), null, $result );
6779
6880 if ( !$fit ) {
6981 $continue = "{$item['image']}|{$item['wiki']}|{$item['id']}";
@@ -94,6 +106,15 @@
95107
96108 public function getAllowedParams() {
97109 return array(
 110+ 'prop' => array(
 111+ ApiBase::PARAM_DFLT => 'url',
 112+ ApiBase::PARAM_TYPE => array(
 113+ 'url',
 114+ 'pageid',
 115+ 'namespace',
 116+ ),
 117+ ApiBase::PARAM_ISMULTI => true,
 118+ ),
98119 'limit' => array(
99120 ApiBase :: PARAM_DFLT => 10,
100121 ApiBase :: PARAM_TYPE => 'limit',
@@ -108,6 +129,12 @@
109130
110131 public function getParamDescription () {
111132 return array(
 133+ 'prop' => array(
 134+ 'What properties to return',
 135+ ' url - Adds url ',
 136+ ' pageid - Adds page id',
 137+ ' namespace - Adds namespace id',
 138+ ),
112139 'limit' => 'How many links to return',
113140 'continue' => 'When more results are available, use this to continue',
114141 'filterlocal' => 'Filter local usage of the file',

Status & tagging log