X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fspecialpage%2FQueryPage.php;h=16a6d303d8938c77c2859957ffb1c4c5c48ef45e;hb=a38af7ba26579bb3004f673e44d39710887763aa;hp=655b495e771bdc9cba937d911890cc0830c5c440;hpb=485f66f1744fea056e20a5bef619989bf1749202;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specialpage/QueryPage.php b/includes/specialpage/QueryPage.php index 655b495e77..46873b169a 100644 --- a/includes/specialpage/QueryPage.php +++ b/includes/specialpage/QueryPage.php @@ -21,6 +21,7 @@ * @ingroup SpecialPage */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\IDatabase; use Wikimedia\Rdbms\DBError; @@ -45,13 +46,18 @@ abstract class QueryPage extends SpecialPage { * The number of rows returned by the query. Reading this variable * only makes sense in functions that are run after the query has been * done, such as preprocessResults() and formatRow(). + * + * @var int */ protected $numRows; + /** + * @var string|null + */ protected $cachedTimestamp = null; /** - * Whether to show prev/next links + * @var bool Whether to show prev/next links */ protected $shownavigation = true; @@ -61,7 +67,8 @@ abstract class QueryPage extends SpecialPage { * * DO NOT CHANGE THIS LIST without testing that * maintenance/updateSpecialPages.php still works. - * @return array + * + * @return string[][] */ public static function getPages() { static $qp = null; @@ -165,7 +172,7 @@ abstract class QueryPage extends SpecialPage { * Subclasses return an array of fields to order by here. Don't append * DESC to the field names, that'll be done automatically if * sortDescending() returns true. - * @return array + * @return string[] * @since 1.18 */ function getOrderFields() { @@ -377,7 +384,7 @@ abstract class QueryPage extends SpecialPage { /** * Get a DB connection to be used for slow recache queries - * @return IDatabase + * @return \Wikimedia\Rdbms\Database */ function getRecacheDB() { return wfGetDB( DB_REPLICA, [ $this->getName(), 'QueryPage::recache', 'vslow' ] ); @@ -499,6 +506,9 @@ abstract class QueryPage extends SpecialPage { return [ 'value' ]; } + /** + * @return string + */ public function getCachedTimestamp() { if ( is_null( $this->cachedTimestamp ) ) { $dbr = wfGetDB( DB_REPLICA ); @@ -568,7 +578,7 @@ abstract class QueryPage extends SpecialPage { /** * This is the actual workhorse. It does everything needed to make a * real, honest-to-gosh query page. - * @param string $par + * @param string|null $par */ public function execute( $par ) { $user = $this->getUser(); @@ -648,8 +658,8 @@ abstract class QueryPage extends SpecialPage { $miserMaxResults = $this->getConfig()->get( 'MiserMode' ) && ( $this->offset + $this->limit >= $this->getMaxResults() ); $atEnd = ( $this->numRows <= $this->limit ) || $miserMaxResults; - $paging = $this->getLanguage()->viewPrevNext( $this->getPageTitle( $par ), $this->offset, - $this->limit, $this->linkParameters(), $atEnd ); + $paging = $this->buildPrevNextNavigation( $this->offset, + $this->limit, $this->linkParameters(), $atEnd, $par ); $out->addHTML( '

' . $paging . '

' ); } else { # No results to show, so don't bother with "showing X of Y" etc. @@ -690,8 +700,6 @@ abstract class QueryPage extends SpecialPage { * @param int $offset Paging offset */ protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) { - global $wgContLang; - if ( $num > 0 ) { $html = []; if ( !$this->listoutput ) { @@ -700,7 +708,6 @@ abstract class QueryPage extends SpecialPage { # $res might contain the whole 1,000 rows, so we read up to # $num [should update this to use a Pager] - // phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall for ( $i = 0; $i < $num && $row = $res->fetchObject(); $i++ ) { $line = $this->formatResult( $skin, $row ); if ( $line ) { @@ -726,7 +733,7 @@ abstract class QueryPage extends SpecialPage { } $html = $this->listoutput - ? $wgContLang->listToText( $html ) + ? MediaWikiServices::getInstance()->getContentLanguage()->listToText( $html ) : implode( '', $html ); $out->addHTML( $html ); @@ -756,98 +763,6 @@ abstract class QueryPage extends SpecialPage { function preprocessResults( $db, $res ) { } - /** - * Similar to above, but packaging in a syndicated feed instead of a web page - * @param string $class - * @param int $limit - * @return bool - */ - function doFeed( $class = '', $limit = 50 ) { - if ( !$this->getConfig()->get( 'Feed' ) ) { - $this->getOutput()->addWikiMsg( 'feed-unavailable' ); - return false; - } - - $limit = min( $limit, $this->getConfig()->get( 'FeedLimit' ) ); - - $feedClasses = $this->getConfig()->get( 'FeedClasses' ); - if ( isset( $feedClasses[$class] ) ) { - /** @var RSSFeed|AtomFeed $feed */ - $feed = new $feedClasses[$class]( - $this->feedTitle(), - $this->feedDesc(), - $this->feedUrl() ); - $feed->outHeader(); - - $res = $this->reallyDoQuery( $limit, 0 ); - foreach ( $res as $obj ) { - $item = $this->feedResult( $obj ); - if ( $item ) { - $feed->outItem( $item ); - } - } - - $feed->outFooter(); - return true; - } else { - return false; - } - } - - /** - * Override for custom handling. If the titles/links are ok, just do - * feedItemDesc() - * @param object $row - * @return FeedItem|null - */ - function feedResult( $row ) { - if ( !isset( $row->title ) ) { - return null; - } - $title = Title::makeTitle( intval( $row->namespace ), $row->title ); - if ( $title ) { - $date = $row->timestamp ?? ''; - $comments = ''; - if ( $title ) { - $talkpage = $title->getTalkPage(); - $comments = $talkpage->getFullURL(); - } - - return new FeedItem( - $title->getPrefixedText(), - $this->feedItemDesc( $row ), - $title->getFullURL(), - $date, - $this->feedItemAuthor( $row ), - $comments ); - } else { - return null; - } - } - - function feedItemDesc( $row ) { - return isset( $row->comment ) ? htmlspecialchars( $row->comment ) : ''; - } - - function feedItemAuthor( $row ) { - return $row->user_text ?? ''; - } - - function feedTitle() { - $desc = $this->getDescription(); - $code = $this->getConfig()->get( 'LanguageCode' ); - $sitename = $this->getConfig()->get( 'Sitename' ); - return "$sitename - $desc [$code]"; - } - - function feedDesc() { - return $this->msg( 'tagline' )->text(); - } - - function feedUrl() { - return $this->getPageTitle()->getFullURL(); - } - /** * Creates a new LinkBatch object, adds all pages from the passed ResultWrapper (MUST include * title and optional the namespace field) and executes the batch. This operation will pre-cache @@ -865,7 +780,7 @@ abstract class QueryPage extends SpecialPage { $batch = new LinkBatch; foreach ( $res as $row ) { - $batch->add( $ns !== null ? $ns : $row->namespace, $row->title ); + $batch->add( $ns ?? $row->namespace, $row->title ); } $batch->execute();