Index: trunk/phase3/includes/QueryPage.php |
— | — | @@ -172,18 +172,6 @@ |
173 | 173 | function formatResult( $skin, $result ) { |
174 | 174 | return ''; |
175 | 175 | } |
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 | | - } |
188 | 176 | |
189 | 177 | /** |
190 | 178 | * The content returned by this function will be output before any result |
— | — | @@ -290,94 +278,21 @@ |
291 | 279 | function doQuery( $offset, $limit, $shownavigation=true ) { |
292 | 280 | global $wgUser, $wgOut, $wgLang, $wgContLang; |
293 | 281 | |
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 | | - |
368 | 282 | $this->offset = $offset; |
369 | 283 | $this->limit = $limit; |
370 | 284 | |
371 | | - $fname = get_class($this) . '::reallyDoQuery'; |
| 285 | + $sname = $this->getName(); |
| 286 | + $fname = get_class($this) . '::doQuery'; |
372 | 287 | $dbr = wfGetDB( DB_SLAVE ); |
373 | 288 | |
| 289 | + $wgOut->setSyndicated( $this->isSyndicated() ); |
374 | 290 | |
375 | 291 | if ( !$this->isCached() ) { |
376 | 292 | $sql = $this->getSQL(); |
377 | | - $result['cached'] = false; |
378 | 293 | } else { |
379 | 294 | # Get the cached result |
380 | 295 | $querycache = $dbr->tableName( 'querycache' ); |
381 | | - $type = $dbr->strencode( $this->getName() ); |
| 296 | + $type = $dbr->strencode( $sname ); |
382 | 297 | $sql = |
383 | 298 | "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value |
384 | 299 | FROM $querycache WHERE qc_type='$type'"; |
— | — | @@ -389,17 +304,21 @@ |
390 | 305 | $tRow = $dbr->fetchObject( $tRes ); |
391 | 306 | |
392 | 307 | 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 ); |
394 | 312 | } else { |
395 | | - $result['cached'] = true; |
| 313 | + $wgOut->addWikiMsg( 'perfcached' ); |
396 | 314 | } |
397 | 315 | |
398 | 316 | # If updates on this page have been disabled, let the user know |
399 | 317 | # that the data set won't be refreshed for now |
400 | 318 | global $wgDisableQueryPageUpdate; |
401 | 319 | if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) { |
402 | | - $result['disabled'] = true; |
| 320 | + $wgOut->addWikiMsg( 'querypage-no-updates' ); |
403 | 321 | } |
| 322 | + |
404 | 323 | } |
405 | 324 | |
406 | 325 | } |
— | — | @@ -410,11 +329,45 @@ |
411 | 330 | $num = $dbr->numRows($res); |
412 | 331 | |
413 | 332 | $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; |
419 | 372 | } |
420 | 373 | |
421 | 374 | /** |
— | — | @@ -438,7 +391,7 @@ |
439 | 392 | |
440 | 393 | # $res might contain the whole 1,000 rows, so we read up to |
441 | 394 | # $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++ ) { |
443 | 396 | $line = $this->formatResult( $skin, $row ); |
444 | 397 | if( $line ) { |
445 | 398 | $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 ) |
— | — | @@ -475,7 +428,6 @@ |
476 | 429 | } |
477 | 430 | } |
478 | 431 | |
479 | | - |
480 | 432 | function openList( $offset ) { |
481 | 433 | return "\n<ol start='" . ( $offset + 1 ) . "' class='special'>\n"; |
482 | 434 | } |