From f6fcd73591ca5257bbf0d7001600f0b3272eae7b Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 14 Jul 2009 08:44:58 +0000 Subject: [PATCH] Revert r53147 properly; was supposed to be reverted in r53167, but I wasn't fully awake at the time. --- includes/QueryPage.php | 150 ++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 99 deletions(-) diff --git a/includes/QueryPage.php b/includes/QueryPage.php index a8abee3385..86a988e987 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -172,18 +172,6 @@ class QueryPage { function formatResult( $skin, $result ) { return ''; } - /** - * Formats the result as something that can be understood by the API. - * Defaults to setting id, ns and title - */ - function formatApiResult( $result ) { - $title = Title::makeTitle( $row->namespace, $row->title ); - return array( - 'pageid' => intval( $row->id ), - 'ns' => intval( $title->getNamespace() ), - 'title' => $title->getPrefixedText(), - ); - } /** * The content returned by this function will be output before any result @@ -290,94 +278,21 @@ class QueryPage { function doQuery( $offset, $limit, $shownavigation=true ) { global $wgUser, $wgOut, $wgLang, $wgContLang; - $wgOut->setSyndicated( $this->isSyndicated() ); - - # Really really do the query now - $result = $this->reallyDoQuery( $offset, $limit ); - - # Tell about cachiness - if ( $result['cached'] !== false ) { - if ( $result['cached'] === true ) { - $wgOut->addWikiMsg( 'perfcached' ); - } else { - $updated = $wgLang->timeAndDate( $result['cached'], true, true ); - $wgOut->addMeta( 'Data-Cache-Time', $result['cached'] ); - $wgOut->addInlineScript( "var dataCacheTime = '{$result['cached']}';" ); - $wgOut->addWikiMsg( 'perfcachedts', $updated ); - } - } - if ( $result['disabled'] ) { - # If updates on this page have been disabled, let the user know - # that the data set won't be refreshed for now - - $wgOut->addWikiMsg( 'querypage-no-updates' ); - } - - $wgOut->addHTML( XML::openElement( 'div', array('class' => 'mw-spcontent') ) ); - - # Top header and navigation - if( $shownavigation ) { - $wgOut->addHTML( $this->getPageHeader() ); - if( $result['count'] > 0 ) { - $wgOut->addHTML( '

' . wfShowingResults( $offset, $result['count'] ) . '

' ); - # Disable the "next" link when we reach the end - $paging = wfViewPrevNext( $offset, $limit, $wgContLang->specialPage( $this->getName() ), - wfArrayToCGI( $this->linkParameters() ), ( $result['count'] < $limit ) ); - $wgOut->addHTML( '

' . $paging . '

' ); - } else { - # No results to show, so don't bother with "showing X of Y" etc. - # -- just let the user know and give up now - $wgOut->addHTML( '

' . wfMsgHtml( 'specialpage-empty' ) . '

' ); - $wgOut->addHTML( XML::closeElement( 'div' ) ); - return; - } - } - - # The actual results; specialist subclasses will want to handle this - # with more than a straight list, so we hand them the info, plus - # an OutputPage, and let them get on with it - $this->outputResults( $wgOut, - $wgUser->getSkin(), - $result['dbr'], # Should use a ResultWrapper for this - $result['result'], - $result['count'], - $offset ); - - # Repeat the paging links at the bottom - if( $shownavigation ) { - $wgOut->addHTML( '

' . $paging . '

' ); - } - - $wgOut->addHTML( XML::closeElement( 'div' ) ); - - return $result['count']; - } - - /** - * Really really do the query. Returns an array with: - * 'disabled' => true if the data will not be further refreshed, - * 'cached' => false if uncached, the timestamp of the last cache if known, else simply true, - * 'result' => the real result object, - * 'count' => number of results, - * 'dbr' => the database used for fetching the data - */ - protected function reallyDoQuery( $offset, $limit ) { - $result = array( 'disabled' => false ); - $this->offset = $offset; $this->limit = $limit; - $fname = get_class($this) . '::reallyDoQuery'; + $sname = $this->getName(); + $fname = get_class($this) . '::doQuery'; $dbr = wfGetDB( DB_SLAVE ); + $wgOut->setSyndicated( $this->isSyndicated() ); if ( !$this->isCached() ) { $sql = $this->getSQL(); - $result['cached'] = false; } else { # Get the cached result $querycache = $dbr->tableName( 'querycache' ); - $type = $dbr->strencode( $this->getName() ); + $type = $dbr->strencode( $sname ); $sql = "SELECT qc_type as type, qc_namespace as namespace,qc_title as title, qc_value as value FROM $querycache WHERE qc_type='$type'"; @@ -389,17 +304,21 @@ class QueryPage { $tRow = $dbr->fetchObject( $tRes ); if( $tRow ) { - $result['cached'] = $tRow->qci_timestamp; + $updated = $wgLang->timeAndDate( $tRow->qci_timestamp, true, true ); + $wgOut->addMeta( 'Data-Cache-Time', $tRow->qci_timestamp ); + $wgOut->addInlineScript( "var dataCacheTime = '{$tRow->qci_timestamp}';" ); + $wgOut->addWikiMsg( 'perfcachedts', $updated ); } else { - $result['cached'] = true; + $wgOut->addWikiMsg( 'perfcached' ); } # If updates on this page have been disabled, let the user know # that the data set won't be refreshed for now global $wgDisableQueryPageUpdate; if( is_array( $wgDisableQueryPageUpdate ) && in_array( $this->getName(), $wgDisableQueryPageUpdate ) ) { - $result['disabled'] = true; + $wgOut->addWikiMsg( 'querypage-no-updates' ); } + } } @@ -410,11 +329,45 @@ class QueryPage { $num = $dbr->numRows($res); $this->preprocessResults( $dbr, $res ); - - $result['result'] = $res; - $result['count'] = $num; - $result['dbr'] = $dbr; - return $result; + + $wgOut->addHTML( XML::openElement( 'div', array('class' => 'mw-spcontent') ) ); + + # Top header and navigation + if( $shownavigation ) { + $wgOut->addHTML( $this->getPageHeader() ); + if( $num > 0 ) { + $wgOut->addHTML( '

' . wfShowingResults( $offset, $num ) . '

' ); + # Disable the "next" link when we reach the end + $paging = wfViewPrevNext( $offset, $limit, $wgContLang->specialPage( $sname ), + wfArrayToCGI( $this->linkParameters() ), ( $num < $limit ) ); + $wgOut->addHTML( '

' . $paging . '

' ); + } else { + # No results to show, so don't bother with "showing X of Y" etc. + # -- just let the user know and give up now + $wgOut->addHTML( '

' . wfMsgHtml( 'specialpage-empty' ) . '

' ); + $wgOut->addHTML( XML::closeElement( 'div' ) ); + return; + } + } + + # The actual results; specialist subclasses will want to handle this + # with more than a straight list, so we hand them the info, plus + # an OutputPage, and let them get on with it + $this->outputResults( $wgOut, + $wgUser->getSkin(), + $dbr, # Should use a ResultWrapper for this + $res, + $dbr->numRows( $res ), + $offset ); + + # Repeat the paging links at the bottom + if( $shownavigation ) { + $wgOut->addHTML( '

' . $paging . '

' ); + } + + $wgOut->addHTML( XML::closeElement( 'div' ) ); + + return $num; } /** @@ -438,7 +391,7 @@ class QueryPage { # $res might contain the whole 1,000 rows, so we read up to # $num [should update this to use a Pager] - for ( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) { + for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) { $line = $this->formatResult( $skin, $row ); if( $line ) { $attr = ( isset( $row->usepatrol ) && $row->usepatrol && $row->patrolled == 0 ) @@ -475,7 +428,6 @@ class QueryPage { } } - function openList( $offset ) { return "\n
    \n"; } -- 2.20.1