r67450 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r67449‎ | r67450 | r67451 >
Date:10:17, 6 June 2010
Author:catrope
Status:ok (Comments)
Tags:
Comment:
API: Add pltitles and tltemplates to prop=links and prop=templates respectively, similar to prop=categories's clcategories
Modified paths:
  • /trunk/phase3/includes/api/ApiQueryLinks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryLinks.php
@@ -46,11 +46,13 @@
4747 $this->table = 'pagelinks';
4848 $this->prefix = 'pl';
4949 $this->description = 'link';
 50+ $this->titlesParam = 'titles';
5051 break;
5152 case self::TEMPLATES:
5253 $this->table = 'templatelinks';
5354 $this->prefix = 'tl';
5455 $this->description = 'template';
 56+ $this->titlesParam = 'templates';
5557 break;
5658 default:
5759 ApiBase::dieDebug( __METHOD__, 'Unknown module name' );
@@ -83,6 +85,22 @@
8486 $this->addTables( $this->table );
8587 $this->addWhereFld( $this->prefix . '_from', array_keys( $this->getPageSet()->getGoodTitles() ) );
8688 $this->addWhereFld( $this->prefix . '_namespace', $params['namespace'] );
 89+
 90+ if ( !is_null( $params[$this->titlesParam] ) ) {
 91+ $lb = new LinkBatch;
 92+ foreach ( $params[$this->titlesParam] as $t ) {
 93+ $title = Title::newFromText( $t );
 94+ if ( !$title ) {
 95+ $this->setWarning( "``$t'' is not a valid title" );
 96+ } else {
 97+ $lb->addObj( $title );
 98+ }
 99+ }
 100+ $cond = $lb->constructSet( $this->prefix, $this->getDB() );
 101+ if ( $cond ) {
 102+ $this->addWhere( $cond );
 103+ }
 104+ }
87105
88106 if ( !is_null( $params['continue'] ) ) {
89107 $cont = explode( '|', $params['continue'] );
@@ -178,16 +196,25 @@
179197 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
180198 ),
181199 'continue' => null,
 200+ $this->titlesParam => array(
 201+ ApiBase::PARAM_ISMULTI => true,
 202+ ),
182203 );
183204 }
184205
185206 public function getParamDescription() {
186 - $desc = $this->description;
187 - return array(
 207+ $desc = $this->description;
 208+ $arr = array(
188209 'namespace' => "Show {$desc}s in this namespace(s) only",
189210 'limit' => "How many {$desc}s to return",
190211 'continue' => 'When more results are available, use this to continue',
191212 );
 213+ if ( $this->getModuleName() == self::LINKS ) {
 214+ $arr[$this->titlesParam] = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.';
 215+ } else if ( $this->getModuleName() == self::TEMPLATES ) {
 216+ $arr[$this->titlesParam] = 'Only list these templates. Useful for checking whether a certain page uses a certain template.';
 217+ }
 218+ return $arr;
192219 }
193220
194221 public function getDescription() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r67612RELEASE-NOTES for r67450reedy12:23, 8 June 2010

Comments

#Comment by Reedy (talk | contribs)   12:18, 6 June 2010

Roan, doing API stuff? :o ;)

#Comment by Catrope (talk | contribs)   12:30, 6 June 2010

Special request from DannyB IIRC. But yes, I should start doing API work very soon now.

Status & tagging log