X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FQueryPage.php;h=ef675c0e53c473f14a6d45082e2034cb8ae52193;hb=5b72053fb957556fc65d67191366eb917829734a;hp=f656949b9bd69d42cc60d6549cc9c90f7a2527a9;hpb=4cd08cba20f1a2135816a5a5998fa937a8289c49;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/QueryPage.php b/includes/QueryPage.php index f656949b9b..ef675c0e53 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -130,7 +130,7 @@ abstract class QueryPage extends SpecialPage { function getQueryInfo() { return null; } - + /** * For back-compat, subclasses may return a raw SQL query here, as a string. * This is stronly deprecated; getQueryInfo() should be overridden instead. @@ -274,7 +274,7 @@ abstract class QueryPage extends SpecialPage { if ( !$this->isCacheable() ) { return 0; } - + $fname = get_class( $this ) . '::recache'; $dbw = wfGetDB( DB_MASTER ); $dbr = wfGetDB( DB_SLAVE, array( $this->getName(), __METHOD__, 'vslow' ) ); @@ -381,9 +381,9 @@ abstract class QueryPage extends SpecialPage { } /** - * Parameters and order changed in 1.18 + * Somewhat deprecated, you probably want to be using execute() */ - function doQuery( $limit, $offset = false ) { + function doQuery( $offset = false, $limit = false ) { if ( $this->isCached() && $this->isCacheable() ) { return $this->fetchFromCache( $limit, $offset ); } else { @@ -407,6 +407,11 @@ abstract class QueryPage extends SpecialPage { if ( $offset !== false ) { $options['OFFSET'] = intval( $offset ); } + if ( $this->sortDescending() ) { + $options['ORDER BY'] = 'qc_value DESC'; + } else { + $options['ORDER BY'] = 'qc_value ASC'; + } $res = $dbr->select( 'querycache', array( 'qc_type', 'qc_namespace AS namespace', 'qc_title AS title', @@ -416,9 +421,9 @@ abstract class QueryPage extends SpecialPage { ); return $dbr->resultObject( $res ); } - + public function getCachedTimestamp() { - if ( !is_null( $this->cachedTimestamp ) ) { + if ( is_null( $this->cachedTimestamp ) ) { $dbr = wfGetDB( DB_SLAVE ); $fname = get_class( $this ) . '::getCachedTimestamp'; $this->cachedTimestamp = $dbr->selectField( 'querycache_info', 'qci_timestamp', @@ -432,23 +437,23 @@ abstract class QueryPage extends SpecialPage { * real, honest-to-gosh query page. */ function execute( $par ) { - global $wgUser, $wgOut, $wgLang; - - if ( !$this->userCanExecute( $wgUser ) ) { + if ( !$this->userCanExecute( $this->getUser() ) ) { $this->displayRestrictionError(); return; } - if ( $this->limit == 0 && $this->offset == 0 ) - list( $this->limit, $this->offset ) = wfCheckLimits(); + if ( $this->limit == 0 && $this->offset == 0 ) { + list( $this->limit, $this->offset ) = $this->getRequest()->getLimitOffset(); + } $dbr = wfGetDB( DB_SLAVE ); $this->setHeaders(); - $wgOut->setSyndicated( $this->isSyndicated() ); + $out = $this->getOutput(); + $out->setSyndicated( $this->isSyndicated() ); if ( $this->isCached() && !$this->isCacheable() ) { - $wgOut->setSyndicated( false ); - $wgOut->addWikiMsg( 'querypage-disabled' ); + $out->setSyndicated( false ); + $out->addWikiMsg( 'querypage-disabled' ); return 0; } @@ -465,21 +470,22 @@ abstract class QueryPage extends SpecialPage { $ts = $this->getCachedTimestamp(); if ( $ts ) { - $updated = $wgLang->timeanddate( $ts, true, true ); - $updateddate = $wgLang->date( $ts, true, true ); - $updatedtime = $wgLang->time( $ts, true, true ); - $wgOut->addMeta( 'Data-Cache-Time', $ts ); - $wgOut->addInlineScript( "var dataCacheTime = '$ts';" ); - $wgOut->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime ); + $lang = $this->getLanguage(); + $updated = $lang->timeanddate( $ts, true, true ); + $updateddate = $lang->date( $ts, true, true ); + $updatedtime = $lang->time( $ts, true, true ); + $out->addMeta( 'Data-Cache-Time', $ts ); + $out->addInlineScript( "var dataCacheTime = '$ts';" ); + $out->addWikiMsg( 'perfcachedts', $updated, $updateddate, $updatedtime ); } else { - $wgOut->addWikiMsg( 'perfcached' ); + $out->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 ) ) { - $wgOut->addWikiMsg( 'querypage-no-updates' ); + $out->addWikiMsg( 'querypage-no-updates' ); } } @@ -490,23 +496,23 @@ abstract class QueryPage extends SpecialPage { $this->preprocessResults( $dbr, $res ); - $wgOut->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) ); + $out->addHTML( Xml::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) ); # Top header and navigation if ( $this->shownavigation ) { - $wgOut->addHTML( $this->getPageHeader() ); + $out->addHTML( $this->getPageHeader() ); if ( $this->numRows > 0 ) { - $wgOut->addHTML( '

' . wfShowingResults( $this->offset, $this->numRows ) . '

' ); + $out->addHTML( $this->msg( 'showingresults' )->numParams( + $this->numRows, $this->offset + 1 )->parseAsBlock() ); # Disable the "next" link when we reach the end - $paging = wfViewPrevNext( $this->offset, $this->limit, - $this->getTitle( $par ), - wfArrayToCGI( $this->linkParameters() ), ( $this->numRows < $this->limit ) ); - $wgOut->addHTML( '

' . $paging . '

' ); + $paging = $this->getLanguage()->viewPrevNext( $this->getTitle( $par ), $this->offset, + $this->limit, $this->linkParameters(), ( $this->numRows < $this->limit ) ); + $out->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' ) ); + $out->addWikiMsg( 'specialpage-empty' ); + $out->addHTML( Xml::closeElement( 'div' ) ); return; } } @@ -514,8 +520,8 @@ abstract class QueryPage extends SpecialPage { # 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(), + $this->outputResults( $out, + $this->getSkin(), $dbr, # Should use a ResultWrapper for this $res, $this->numRows, @@ -523,10 +529,10 @@ abstract class QueryPage extends SpecialPage { # Repeat the paging links at the bottom if ( $this->shownavigation ) { - $wgOut->addHTML( '

' . $paging . '

' ); + $out->addHTML( '

' . $paging . '

' ); } - $wgOut->addHTML( Xml::closeElement( 'div' ) ); + $out->addHTML( Xml::closeElement( 'div' ) ); return $this->numRows; } @@ -547,8 +553,9 @@ abstract class QueryPage extends SpecialPage { if ( $num > 0 ) { $html = array(); - if ( !$this->listoutput ) + if ( !$this->listoutput ) { $html[] = $this->openList( $offset ); + } # $res might contain the whole 1,000 rows, so we read up to # $num [should update this to use a Pager] @@ -578,8 +585,9 @@ abstract class QueryPage extends SpecialPage { } } - if ( !$this->listoutput ) + if ( !$this->listoutput ) { $html[] = $this->closeList(); + } $html = $this->listoutput ? $wgContLang->listToText( $html ) @@ -589,10 +597,17 @@ abstract class QueryPage extends SpecialPage { } } + /** + * @param $offset + * @return string + */ function openList( $offset ) { return "\n
    \n"; } + /** + * @return string + */ function closeList() { return "
\n"; } @@ -609,8 +624,7 @@ abstract class QueryPage extends SpecialPage { global $wgFeed, $wgFeedClasses; if ( !$wgFeed ) { - global $wgOut; - $wgOut->addWikiMsg( 'feed-unavailable' ); + $this->getOutput()->addWikiMsg( 'feed-unavailable' ); return; } @@ -626,7 +640,6 @@ abstract class QueryPage extends SpecialPage { $this->feedUrl() ); $feed->outHeader(); - $dbr = wfGetDB( DB_SLAVE ); $res = $this->reallyDoQuery( $limit, 0 ); foreach ( $res as $obj ) { $item = $this->feedResult( $obj ); @@ -681,18 +694,16 @@ abstract class QueryPage extends SpecialPage { function feedTitle() { global $wgLanguageCode, $wgSitename; - $page = SpecialPage::getPage( $this->getName() ); - $desc = $page->getDescription(); + $desc = $this->getDescription(); return "$wgSitename - $desc [$wgLanguageCode]"; } function feedDesc() { - return wfMsgExt( 'tagline', 'parsemag' ); + return $this->msg( 'tagline' )->text(); } function feedUrl() { - $title = SpecialPage::getTitleFor( $this->getName() ); - return $title->getFullURL(); + return $this->getTitle()->getFullURL(); } } @@ -749,8 +760,8 @@ abstract class WantedQueryPage extends QueryPage { if ( $title instanceof Title ) { if ( $this->isCached() || $this->forceExistenceCheck() ) { $pageLink = $title->isKnown() - ? '' . $skin->link( $title ) . '' - : $skin->link( + ? '' . Linker::link( $title ) . '' + : Linker::link( $title, null, array(), @@ -758,7 +769,7 @@ abstract class WantedQueryPage extends QueryPage { array( 'broken' ) ); } else { - $pageLink = $skin->link( + $pageLink = Linker::link( $title, null, array(), @@ -766,10 +777,9 @@ abstract class WantedQueryPage extends QueryPage { array( 'broken' ) ); } - return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) ); + return $this->getLanguage()->specialList( $pageLink, $this->makeWlhLink( $title, $result ) ); } else { - $tsafe = htmlspecialchars( $result->title ); - return wfMsgHtml( 'wantedpages-badtitle', $tsafe ); + return $this->msg( 'wantedpages-badtitle', $result->title )->escaped(); } } @@ -777,15 +787,12 @@ abstract class WantedQueryPage extends QueryPage { * Make a "what links here" link for a given title * * @param $title Title to make the link for - * @param $skin Skin object to use * @param $result Object: result row * @return string */ - private function makeWlhLink( $title, $skin, $result ) { - global $wgLang; - $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' ); - $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ), - $wgLang->formatNum( $result->value ) ); - return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) ); + private function makeWlhLink( $title, $result ) { + $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); + $label = $this->msg( 'nlinks' )->numParams( $result->value )->escaped(); + return Linker::link( $wlh, $label ); } }