r69753 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69752‎ | r69753 | r69754 >
Date:21:03, 22 July 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 24485) Make iwbacklinks a generator, display iwprefix and iwtitle optional

Second part, make ApiQueryIWBacklinks a Generator
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryIWBacklinks.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryIWBacklinks.php
@@ -33,13 +33,21 @@
3434 * This gives links pointing to the given interwiki
3535 * @ingroup API
3636 */
37 -class ApiQueryIWBacklinks extends ApiQueryBase {
 37+class ApiQueryIWBacklinks extends ApiQueryGeneratorBase {
3838
3939 public function __construct( $query, $moduleName ) {
4040 parent::__construct( $query, $moduleName, 'iwbl' );
4141 }
 42+
 43+ public function execute() {
 44+ $this->run();
 45+ }
4246
43 - public function execute() {
 47+ public function executeGenerator( $resultPageSet ) {
 48+ $this->run( $resultPageSet );
 49+ }
 50+
 51+ public function run( $resultPageSet = null ) {
4452 $params = $this->extractRequestParams();
4553
4654 if ( isset( $params['title'] ) && !isset( $params['prefix'] ) ) {
@@ -91,6 +99,8 @@
92100
93101 $db = $this->getDB();
94102 $res = $this->select( __METHOD__ );
 103+
 104+ $pages = array();
95105
96106 $count = 0;
97107 $result = $this->getResult();
@@ -102,35 +112,40 @@
103113 break;
104114 }
105115
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 - if ( $iwprefix ) {
117 - $entry['iwprefix'] = $row->iwl_prefix;
118 - }
119 -
120 - if ( $iwtitle ) {
121 - $entry['iwtitle'] = $row->iwl_title;
122 - }
 116+ if ( !is_null( $resultPageSet ) ) {
 117+ $pages[] = Title::makeTitle( $row->page_namespace, $row->page_title )->getPrefixedText();
 118+ } else {
 119+ $entry = array();
 120+
 121+ $entry['pageid'] = intval( $row->page_id );
 122+ $entry['ns'] = $row->page_namespace;
 123+ $entry['title'] = $row->page_title;
 124+
 125+ if ( $row->page_is_redirect ) {
 126+ $entry['redirect'] = '';
 127+ }
 128+
 129+ if ( $iwprefix ) {
 130+ $entry['iwprefix'] = $row->iwl_prefix;
 131+ }
 132+
 133+ if ( $iwtitle ) {
 134+ $entry['iwtitle'] = $row->iwl_title;
 135+ }
123136
124 - $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
125 - if ( !$fit ) {
126 - $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
127 - break;
 137+ $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $entry );
 138+ if ( !$fit ) {
 139+ $this->setContinueEnumParameter( 'continue', "{$row->iwl_prefix}|{$row->iwl_title}|{$row->iwl_from}" );
 140+ break;
 141+ }
128142 }
129143 }
130 -
131 - $this->getResult()->setIndexedTagName_internal(
132 - array( 'query', $this->getModuleName() ),
133 - 'iw'
134 - );
 144+
 145+ if ( is_null( $resultPageSet ) ) {
 146+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'iw' );
 147+ } else {
 148+ $resultPageSet->populateFromTitles( $pages );
 149+ }
135150 }
136151
137152 public function getAllowedParams() {
@@ -188,7 +203,7 @@
189204 protected function getExamples() {
190205 return array(
191206 'api.php?action=query&list=iwbacklinks&iwbltitle=Test&iwblprefix=wikibooks',
192 - //'api.php?action=query&generator=iwbacklinks&giwbltitle=Test&iwblprefix=wikibooks&prop=info'
 207+ 'api.php?action=query&generator=iwbacklinks&giwbltitle=Test&iwblprefix=wikibooks&prop=info'
193208 );
194209 }
195210
Index: trunk/phase3/RELEASE-NOTES
@@ -282,7 +282,8 @@
283283 * (bug 24296) Added converttitles parameter to convert titles to their
284284 canonical language variant.
285285 * Fixed "link" parameter in image links with "thumb" parameter.
286 -* (bug 23936) - Add "displaytitle" to query/info API
 286+* (bug 23936) Add "displaytitle" to query/info API
 287+* (bug 24485) Make iwbacklinks a generator, display iwprefix and iwtitle optional
287288
288289 === Languages updated in 1.17 ===
289290

Follow-up revisions

RevisionCommit summaryAuthorDate
r69777Stylize API up to date...reedy07:33, 23 July 2010
r69799Fixup code from r69753, create title from row and use that in the pageset...reedy16:59, 23 July 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69749Part of bug 24485 - Make iwbacklinks a generator, display iwprefix and iwtit...reedy20:21, 22 July 2010

Comments

#Comment by Catrope (talk | contribs)   07:18, 23 July 2010
+				$pages[] = Title::makeTitle( $row->page_namespace, $row->page_title )->getPrefixedText();

It's better to pass Title objects to ApiPageSet rather than incurring the overhead of first doing getPrefixedText() then newFromText() (the latter is slowish because it has to parse the title for the namespace prefix and all that). It also saves an existence check query in case you happen to have the full page row with page_id and all that (which you do) and create the Title object with Title::newFromRow() (which you don't do).

+				$entry['pageid'] = intval( $row->page_id );
+				$entry['ns'] = $row->page_namespace;

I must have missed this before when I added intval() (I think I was the one that did), but for consistency we should do intval( $row->page_namespace ) as well.

+* ([https://bugzilla.wikimedia.org/show_bug.cgi?id=24485 bug 24485]) Make iwbacklinks a generator, display iwprefix and iwtitle optional

Gramatically, something like "optionally display iwprefix and iwtitle" would probably be better.

NOTE: The last pre block above also highlights yet another bug in the CodeReview parser

Status & tagging log