From c640837eacd279bb1ea678790dccf1b23e398fc8 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Wed, 28 Mar 2007 21:01:58 +0000 Subject: [PATCH] * Split most of the result output code from QueryPage::doQuery() into QueryPage::outputResults(), leaving paging and other logic behind * Introduce ImageQueryPage class which uses galleries instead of boring old lists * (bug 9069) Use galleries in query pages dedicated to images [uncategorised images, most linked-to images and unused files at the moment] --- RELEASE-NOTES | 1 + includes/AutoLoader.php | 1 + includes/ImageQueryPage.php | 66 ++++++++++++ includes/QueryPage.php | 136 +++++++++++++++--------- includes/SpecialMostimages.php | 20 ++-- includes/SpecialUncategorizedimages.php | 8 +- includes/SpecialUnusedimages.php | 30 +----- 7 files changed, 161 insertions(+), 101 deletions(-) create mode 100644 includes/ImageQueryPage.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index fd08cb5fb7..ed3b994e44 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -106,6 +106,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 9397) Introduce "sp-contributions-footer" and "sp-contributions-footer-anon" messages, shown at the end of Special:Contributions as appropriate for the target * (bug 8421) Expose current action in JavaScript globals (as 'wgAction') +* (bug 9069) Use galleries in query pages dedicated to images == Bugfixes since 1.9 == * (bug 7292) Fix site statistics when moving pages in/out of content namespaces diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 6ec55ed4cb..153cc3046d 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -135,6 +135,7 @@ function __autoload($className) { 'ProtectionForm' => 'includes/ProtectionForm.php', 'QueryPage' => 'includes/QueryPage.php', 'PageQueryPage' => 'includes/QueryPage.php', + 'ImageQueryPage' => 'includes/ImageQueryPage.php', 'RawPage' => 'includes/RawPage.php', 'RecentChange' => 'includes/RecentChange.php', 'Revision' => 'includes/Revision.php', diff --git a/includes/ImageQueryPage.php b/includes/ImageQueryPage.php new file mode 100644 index 0000000000..65a50a4d9b --- /dev/null +++ b/includes/ImageQueryPage.php @@ -0,0 +1,66 @@ + + */ +class ImageQueryPage extends QueryPage { + + /** + * Format and output report results using the given information plus + * OutputPage + * + * @param OutputPage $out OutputPage to print to + * @param Skin $skin User skin to use + * @param Database $dbr Database (read) connection to use + * @param int $res Result pointer + * @param int $num Number of available result rows + * @param int $offset Paging offset + */ + protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) { + if( $num > 0 ) { + $gallery = new ImageGallery(); + $gallery->useSkin( $skin ); + + # $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++ ) { + $image = $this->prepareImage( $row ); + if( $image instanceof Image ) + $gallery->add( $image, $this->getCellHtml( $row ) ); + } + + $out->addHtml( $gallery->toHtml() ); + } + } + + /** + * Prepare an image object given a result row + * + * @param object $row Result row + * @return Image + */ + private function prepareImage( $row ) { + $namespace = isset( $row->namespace ) ? $row->namespace : NS_IMAGE; + $title = Title::makeTitleSafe( $namespace, $row->title ); + return ( $title instanceof Title && $title->getNamespace() == NS_IMAGE ) + ? new Image( $title ) + : null; + } + + /** + * Get additional HTML to be shown in a results' cell + * + * @param object $row Result row + * @return string + */ + protected function getCellHtml( $row ) { + return ''; + } + +} + +?> \ No newline at end of file diff --git a/includes/QueryPage.php b/includes/QueryPage.php index d386d1295b..781a482720 100644 --- a/includes/QueryPage.php +++ b/includes/QueryPage.php @@ -330,65 +330,99 @@ class QueryPage { $num = $dbr->numRows($res); $this->preprocessResults( $dbr, $res ); - - $sk = $wgUser->getSkin( ); - - if($shownavigation) { - $wgOut->addHTML( $this->getPageHeader() ); - - # if list is empty, show it - if( $num == 0 ) { - $wgOut->addHTML( '

' . wfMsgHTML('specialpage-empty') . '

' ); + $sk = $wgUser->getSkin(); + + # 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' ) . '

' ); return; } - - $top = wfShowingResults( $offset, $num); - $wgOut->addHTML( "

{$top}\n" ); - - # often disable 'next' link when we reach the end - $atend = $num < $limit; - - $sl = wfViewPrevNext( $offset, $limit , - $wgContLang->specialPage( $sname ), - wfArrayToCGI( $this->linkParameters() ), $atend ); - $wgOut->addHTML( "
{$sl}

\n" ); } - if ( $num > 0 ) { - $s = array(); - if ( ! $this->listoutput ) - $s[] = $this->openList( $offset ); - - # Only read at most $num rows, because $res may contain the whole 1000 - for ( $i = 0; $i < $num && $obj = $dbr->fetchObject( $res ); $i++ ) { - $format = $this->formatResult( $sk, $obj ); - if ( $format ) { - $attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol && - $obj->patrolled == 0 ) ? ' class="not-patrolled"' : ''; - $s[] = $this->listoutput ? $format : "{$format}\n"; + + # 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 . '

' ); + } + + return $num; + } + + /** + * Format and output report results using the given information plus + * OutputPage + * + * @param OutputPage $out OutputPage to print to + * @param Skin $skin User skin to use + * @param Database $dbr Database (read) connection to use + * @param int $res Result pointer + * @param int $num Number of available result rows + * @param int $offset Paging offset + */ + protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) { + global $wgContLang; + + if( $num > 0 ) { + $html = array(); + 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] + for( $i = 0; $i < $num && $row = $dbr->fetchObject( $res ); $i++ ) { + $line = $this->formatResult( $skin, $row ); + if( $line ) { + $attr = ( isset( $obj->usepatrol ) && $obj->usepatrol && $obj->patrolled == 0 ) + ? ' class="not-patrolled"' + : ''; + $html[] = $this->listoutput + ? $format + : "{$line}\n"; } } - - if($this->tryLastResult()) { - // flush the very last result - $obj = null; - $format = $this->formatResult( $sk, $obj ); - if( $format ) { - $attr = ( isset ( $obj->usepatrol ) && $obj->usepatrol && - $obj->patrolled == 0 ) ? ' class="not-patrolled"' : ''; - $s[] = "{$format}\n"; + + # Flush the final result + if( $this->tryLastResult() ) { + $row = null; + $line = $this->formatResult( $skin, $row ); + if( $line ) { + $attr = ( isset( $obj->usepatrol ) && $obj->usepatrol && $obj->patrolled == 0 ) + ? ' class="not-patrolled"' + : ''; + $html[] = $this->listoutput + ? $format + : "{$line}\n"; } } - - $dbr->freeResult( $res ); - if ( ! $this->listoutput ) - $s[] = $this->closeList(); - $str = $this->listoutput ? $wgContLang->listToText( $s ) : implode( '', $s ); - $wgOut->addHTML( $str ); + + if( !$this->listoutput ) + $html[] = $this->closeList(); + + $html = $this->listoutput + ? $wgContLang->listToText( $html ) + : implode( '', $html ); + + $out->addHtml( $html ); } - if($shownavigation) { - $wgOut->addHTML( "

{$sl}

\n" ); - } - return $num; } function openList( $offset ) { diff --git a/includes/SpecialMostimages.php b/includes/SpecialMostimages.php index 6a6d8c5f68..6b01d7d5ba 100644 --- a/includes/SpecialMostimages.php +++ b/includes/SpecialMostimages.php @@ -10,7 +10,7 @@ /** * @addtogroup SpecialPage */ -class MostimagesPage extends QueryPage { +class MostimagesPage extends ImageQueryPage { function getName() { return 'Mostimages'; } function isExpensive() { return true; } @@ -32,20 +32,12 @@ class MostimagesPage extends QueryPage { "; } - function formatResult( $skin, $result ) { - global $wgLang, $wgContLang; - - $nt = Title::makeTitle( $result->namespace, $result->title ); - $text = $wgContLang->convert( $nt->getPrefixedText() ); - - $plink = $skin->makeKnownLink( $nt->getPrefixedText(), $text ); - - $nl = wfMsgExt( 'nlinks', array( 'parsemag', 'escape'), - $wgLang->formatNum ( $result->value ) ); - $nlink = $skin->makeKnownLink( $nt->getPrefixedText() . '#filelinks', $nl ); - - return wfSpecialList($plink, $nlink); + function getCellHtml( $row ) { + global $wgLang; + return wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ), + $wgLang->formatNum( $row->value ) ) . '
'; } + } /** diff --git a/includes/SpecialUncategorizedimages.php b/includes/SpecialUncategorizedimages.php index f91b25c112..7c916770a1 100644 --- a/includes/SpecialUncategorizedimages.php +++ b/includes/SpecialUncategorizedimages.php @@ -7,7 +7,7 @@ * @author Rob Church */ -class UncategorizedImagesPage extends QueryPage { +class UncategorizedImagesPage extends ImageQueryPage { function getName() { return 'Uncategorizedimages'; @@ -36,12 +36,6 @@ class UncategorizedImagesPage extends QueryPage { WHERE cl_from IS NULL AND page_namespace = {$ns} AND page_is_redirect = 0"; } - function formatResult( $skin, $row ) { - global $wgContLang; - $title = Title::makeTitleSafe( NS_IMAGE, $row->title ); - $label = htmlspecialchars( $wgContLang->convert( $title->getText() ) ); - return $skin->makeKnownLinkObj( $title, $label ); - } } function wfSpecialUncategorizedimages() { diff --git a/includes/SpecialUnusedimages.php b/includes/SpecialUnusedimages.php index 35e9ca94fb..b4fb403db8 100644 --- a/includes/SpecialUnusedimages.php +++ b/includes/SpecialUnusedimages.php @@ -7,7 +7,7 @@ /** * @addtogroup SpecialPage */ -class UnusedimagesPage extends QueryPage { +class UnusedimagesPage extends ImageQueryPage { function getName() { return 'Unusedimages'; @@ -38,34 +38,6 @@ class UnusedimagesPage extends QueryPage { } } - function formatResult( $skin, $result ) { - global $wgLang, $wgContLang; - $title = Title::makeTitle( NS_IMAGE, $result->title ); - - $imageUrl = htmlspecialchars( Image::imageUrl( $result->title ) ); - $dirmark = $wgContLang->getDirMark(); // To keep text in correct order - - $return = - # The 'desc' linking to the image page - '('.$skin->makeKnownLinkObj( $title, wfMsg('imgdesc') ).') ' . $dirmark . - - # Link to the image itself - '' . htmlspecialchars( $title->getText() ) . - ' . . ' . $dirmark . - - # Last modified date - $wgLang->timeanddate($result->value) . ' . . ' . $dirmark . - - # Link to username - $skin->makeLinkObj( Title::makeTitle( NS_USER, $result->img_user_text ), - $result->img_user_text) . $dirmark . - - # If there is a description, show it - $skin->commentBlock( $wgContLang->convert( $result->img_description ) ); - - return $return; - } - function getPageHeader() { return wfMsg( "unusedimagestext" ); } -- 2.20.1