r53216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53215‎ | r53216 | r53217 >
Date:08:44, 14 July 2009
Author:catrope
Status:ok
Tags:
Comment:
Revert r53147 properly; was supposed to be reverted in r53167, but I wasn't fully awake at the time.
Modified paths:
  • /trunk/phase3/includes/QueryPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/QueryPage.php
@@ -172,18 +172,6 @@
173173 function formatResult( $skin, $result ) {
174174 return '';
175175 }
176 - /**
177 - * Formats the result as something that can be understood by the API.
178 - * Defaults to setting id, ns and title
179 - */
180 - function formatApiResult( $result ) {
181 - $title = Title::makeTitle( $row->namespace, $row->title );
182 - return array(
183 - 'pageid' => intval( $row->id ),
184 - 'ns' => intval( $title->getNamespace() ),
185 - 'title' => $title->getPrefixedText(),
186 - );
187 - }
188176
189177 /**
190178 * The content returned by this function will be output before any result
@@ -290,94 +278,21 @@
291279 function doQuery( $offset, $limit, $shownavigation=true ) {
292280 global $wgUser, $wgOut, $wgLang, $wgContLang;
293281
294 - $wgOut->setSyndicated( $this->isSyndicated() );
295 -
296 - # Really really do the query now
297 - $result = $this->reallyDoQuery( $offset, $limit );
298 -
299 - # Tell about cachiness
300 - if ( $result['cached'] !== false ) {
301 - if ( $result['cached'] === true ) {
302 - $wgOut->addWikiMsg( 'perfcached' );
303 - } else {
304 - $updated = $wgLang->timeAndDate( $result['cached'], true, true );
305 - $wgOut->addMeta( 'Data-Cache-Time', $result['cached'] );
306 - $wgOut->addInlineScript( "var dataCacheTime = '{$result['cached']}';" );
307 - $wgOut->addWikiMsg( 'perfcachedts', $updated );
308 - }
309 - }
310 - if ( $result['disabled'] ) {
311 - # If updates on this page have been disabled, let the user know
312 - # that the data set won't be refreshed for now
313 -
314 - $wgOut->addWikiMsg( 'querypage-no-updates' );
315 - }
316 -
317 - $wgOut->addHTML( XML::openElement( 'div', array('class' => 'mw-spcontent') ) );
318 -
319 - # Top header and navigation
320 - if( $shownavigation ) {
321 - $wgOut->addHTML( $this->getPageHeader() );
322 - if( $result['count'] > 0 ) {
323 - $wgOut->addHTML( '<p>' . wfShowingResults( $offset, $result['count'] ) . '</p>' );
324 - # Disable the "next" link when we reach the end
325 - $paging = wfViewPrevNext( $offset, $limit, $wgContLang->specialPage( $this->getName() ),
326 - wfArrayToCGI( $this->linkParameters() ), ( $result['count'] < $limit ) );
327 - $wgOut->addHTML( '<p>' . $paging . '</p>' );
328 - } else {
329 - # No results to show, so don't bother with "showing X of Y" etc.
330 - # -- just let the user know and give up now
331 - $wgOut->addHTML( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
332 - $wgOut->addHTML( XML::closeElement( 'div' ) );
333 - return;
334 - }
335 - }
336 -
337 - # The actual results; specialist subclasses will want to handle this
338 - # with more than a straight list, so we hand them the info, plus
339 - # an OutputPage, and let them get on with it
340 - $this->outputResults( $wgOut,
341 - $wgUser->getSkin(),
342 - $result['dbr'], # Should use a ResultWrapper for this
343 - $result['result'],
344 - $result['count'],
345 - $offset );
346 -
347 - # Repeat the paging links at the bottom
348 - if( $shownavigation ) {
349 - $wgOut->addHTML( '<p>' . $paging . '</p>' );
350 - }
351 -
352 - $wgOut->addHTML( XML::closeElement( 'div' ) );
353 -
354 - return $result['count'];
355 - }
356 -
357 - /**
358 - * Really really do the query. Returns an array with:
359 - * 'disabled' => true if the data will not be further refreshed,
360 - * 'cached' => false if uncached, the timestamp of the last cache if known, else simply true,
361 - * 'result' => the real result object,
362 - * 'count' => number of results,
363 - * 'dbr' => the database used for fetching the data
364 - */
365 - protected function reallyDoQuery( $offset, $limit ) {
366 - $result = array( 'disabled' => false );
367 -
368282 $this->offset = $offset;
369283 $this->limit = $limit;
370284
371 - $fname = get_class($this) . '::reallyDoQuery';
 285+ $sname = $this->getName();
 286+ $fname = get_class($this) . '::doQuery';
372287 $dbr = wfGetDB( DB_SLAVE );
373288
 289+ $wgOut->setSyndicated( $this->isSyndicated() );
374290
375291 if ( !$this->isCached() ) {
376292 $sql = $this->getSQL();
377 - $result['cached'] = false;
378293 } else {
379294 # Get the cached result
380295 $querycache = $dbr->tableName( 'querycache' );
381 - $type = $dbr->strencode( $this->getName() );
 296+ $type = $dbr->strencode( $sname );
382297 $sql =
383298 "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value
384299 FROM $querycache WHERE qc_type='$type'";
@@ -389,17 +304,21 @@
390305 $tRow = $dbr->fetchObject( $tRes );
391306
392307 if( $tRow ) {
393 - $result['cached'] = $tRow->qci_timestamp;
 308+ $updated = $wgLang->timeAndDate( $tRow->qci_timestamp, true, true );
 309+ $wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp );
 310+ $wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" );
 311+ $wgOut->addWikiMsg( 'perfcachedts', $updated );
394312 } else {
395 - $result['cached'] = true;
 313+ $wgOut->addWikiMsg( 'perfcached' );
396314 }
397315
398316 # If updates on this page have been disabled, let the user know
399317 # that the data set won't be refreshed for now
400318 global $wgDisableQueryPageUpdate;
401319 if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) {
402 - $result['disabled'] = true;
 320+ $wgOut->addWikiMsg( 'querypage-no-updates' );
403321 }
 322+
404323 }
405324
406325 }
@@ -410,11 +329,45 @@
411330 $num = $dbr->numRows($res);
412331
413332 $this->preprocessResults( $dbr, $res );
414 -
415 - $result['result'] = $res;
416 - $result['count'] = $num;
417 - $result['dbr'] = $dbr;
418 - return $result;
 333+
 334+ $wgOut->addHTML( XML::openElement( 'div', array('class' => 'mw-spcontent') ) );
 335+
 336+ # Top header and navigation
 337+ if( $shownavigation ) {
 338+ $wgOut->addHTML( $this->getPageHeader() );
 339+ if( $num > 0 ) {
 340+ $wgOut->addHTML( '<p>' . wfShowingResults( $offset, $num ) . '</p>' );
 341+ # Disable the "next" link when we reach the end
 342+ $paging = wfViewPrevNext( $offset, $limit, $wgContLang->specialPage( $sname ),
 343+ wfArrayToCGI( $this->linkParameters() ), ( $num < $limit ) );
 344+ $wgOut->addHTML( '<p>' . $paging . '</p>' );
 345+ } else {
 346+ # No results to show, so don't bother with "showing X of Y" etc.
 347+ # -- just let the user know and give up now
 348+ $wgOut->addHTML( '<p>' . wfMsgHtml( 'specialpage-empty' ) . '</p>' );
 349+ $wgOut->addHTML( XML::closeElement( 'div' ) );
 350+ return;
 351+ }
 352+ }
 353+
 354+ # The actual results; specialist subclasses will want to handle this
 355+ # with more than a straight list, so we hand them the info, plus
 356+ # an OutputPage, and let them get on with it
 357+ $this->outputResults( $wgOut,
 358+ $wgUser->getSkin(),
 359+ $dbr, # Should use a ResultWrapper for this
 360+ $res,
 361+ $dbr->numRows( $res ),
 362+ $offset );
 363+
 364+ # Repeat the paging links at the bottom
 365+ if( $shownavigation ) {
 366+ $wgOut->addHTML( '<p>' . $paging . '</p>' );
 367+ }
 368+
 369+ $wgOut->addHTML( XML::closeElement( 'div' ) );
 370+
 371+ return $num;
419372 }
420373
421374 /**
@@ -438,7 +391,7 @@
439392
440393 # $res might contain the whole 1,000 rows, so we read up to
441394 # $num [should update this to use a Pager]
442 - for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
 395+ for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) {
443396 $line = $this->formatResult( $skin, $row );
444397 if( $line ) {
445398 $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 )
@@ -475,7 +428,6 @@
476429 }
477430 }
478431
479 -
480432 function openList( $offset ) {
481433 return "\n<ol start='" . ( $offset + 1 ) . "' class='special'>\n";
482434 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r53147Refactored the querying code out of the display code, to allow a future API m...btongminh21:16, 12 July 2009
r53167Revert r53147, r53149 and r53163 ("Add API module for QueryPage-based special...catrope12:40, 13 July 2009

Status & tagging log