X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialNewimages.php;h=dbf354d5f6fe4e766824181271f9be086c1498cf;hb=0800a2fe7ffeba966120a78e856ed286f926c5e4;hp=61f5230c33b0bb9570528599a2f513eed65dd360;hpb=ae57ab1eec9f9051fc0e6786e8eff9d01988be19;p=lhc%2Fweb%2Fwiklou.git
diff --git a/includes/specials/SpecialNewimages.php b/includes/specials/SpecialNewimages.php
index 61f5230c33..dbf354d5f6 100644
--- a/includes/specials/SpecialNewimages.php
+++ b/includes/specials/SpecialNewimages.php
@@ -1,245 +1,167 @@
getText( 'wpIlMatch' );
- $dbr = wfGetDB( DB_SLAVE );
- $sk = $wgUser->getSkin();
- $shownav = !$specialPage->including();
- $hidebots = $wgRequest->getBool( 'hidebots' , 1 );
-
- $hidebotsql = '';
- if ( $hidebots ) {
- # Make a list of group names which have the 'bot' flag set.
- $botconds = array();
- foreach ( User::getGroupsWithPermission('bot') as $groupname ) {
- $botconds[] = 'ug_group = ' . $dbr->addQuotes( $groupname );
- }
-
- # If not bot groups, do not set $hidebotsql
- if ( $botconds ) {
- $isbotmember = $dbr->makeList( $botconds, LIST_OR );
-
- # This join, in conjunction with WHERE ug_group IS NULL, returns
- # only those rows from IMAGE where the uploading user is not a mem-
- # ber of a group which has the 'bot' permission set.
- $ug = $dbr->tableName( 'user_groups' );
- $hidebotsql = " LEFT JOIN $ug ON img_user=ug_user AND ($isbotmember)";
- }
- }
-
- $image = $dbr->tableName( 'image' );
-
- $sql = "SELECT img_timestamp from $image";
- if ($hidebotsql) {
- $sql .= "$hidebotsql WHERE ug_group IS NULL";
- }
- $sql .= ' ORDER BY img_timestamp DESC';
- $sql = $dbr->limitResult($sql, 1, false);
- $res = $dbr->query( $sql, __FUNCTION__ );
- $row = $dbr->fetchRow( $res );
- if( $row !== false ) {
- $ts = $row[0];
- } else {
- $ts = false;
+ public function __construct(){
+ parent::__construct( 'Newimages' );
}
- $dbr->freeResult( $res );
- $sql = '';
- # If we were clever, we'd use this to cache.
- $latestTimestamp = wfTimestamp( TS_MW, $ts );
+ public function execute( $par ){
+ $this->setHeaders();
+ $this->outputHeader();
- # Hardcode this for now.
- $limit = 48;
+ $pager = new NewFilesPager( $this->getContext(), $par );
- if ( $parval = intval( $par ) ) {
- if ( $parval <= $limit && $parval > 0 ) {
- $limit = $parval;
+ if ( !$this->including() ) {
+ $form = $pager->getForm();
+ $form->prepareForm();
+ $form->displayForm( '' );
}
- }
-
- $where = array();
- $searchpar = array();
- if ( $wpIlMatch != '' && !$wgMiserMode) {
- $nt = Title::newFromUrl( $wpIlMatch );
- if( $nt ) {
- $where[] = 'LOWER(img_name) ' . $dbr->buildLike( $dbr->anyString(), strtolower( $nt->getDBkey() ), $dbr->anyString() );
- $searchpar['wpIlMatch'] = $wpIlMatch;
+ $this->getOutput()->addHTML( $pager->getBody() );
+ if ( !$this->including() ) {
+ $this->getOutput()->addHTML( $pager->getNavigationBar() );
}
}
+}
- $invertSort = false;
- if( $until = $wgRequest->getVal( 'until' ) ) {
- $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
- }
- if( $from = $wgRequest->getVal( 'from' ) ) {
- $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
- $invertSort = true;
- }
- $sql='SELECT img_size, img_name, img_user, img_user_text,'.
- "img_description,img_timestamp FROM $image";
- if( $hidebotsql ) {
- $sql .= $hidebotsql;
- $where[] = 'ug_group IS NULL';
- }
- if( count( $where ) ) {
- $sql .= ' WHERE ' . $dbr->makeList( $where, LIST_AND );
- }
- $sql.=' ORDER BY img_timestamp '. ( $invertSort ? '' : ' DESC' );
- $sql = $dbr->limitResult($sql, ( $limit + 1 ), false);
- $res = $dbr->query( $sql, __FUNCTION__ );
+/**
+ * @ingroup SpecialPage Pager
+ */
+class NewFilesPager extends ReverseChronologicalPager {
/**
- * We have to flip things around to get the last N after a certain date
+ * @var ImageGallery
*/
- $images = array();
- while ( $s = $dbr->fetchObject( $res ) ) {
- if( $invertSort ) {
- array_unshift( $images, $s );
- } else {
- array_push( $images, $s );
- }
- }
- $dbr->freeResult( $res );
-
- $gallery = new ImageGallery();
- $firstTimestamp = null;
- $lastTimestamp = null;
- $shownImages = 0;
- foreach( $images as $s ) {
- $shownImages++;
- if( $shownImages > $limit ) {
- # One extra just to test for whether to show a page link;
- # don't actually show it.
- break;
+ var $gallery;
+
+ function __construct( IContextSource $context, $par = null ) {
+ $this->like = $context->getRequest()->getText( 'like' );
+ $this->showbots = $context->getRequest()->getBool( 'showbots' , 0 );
+
+ parent::__construct( $context );
+ }
+
+ function getQueryInfo() {
+ global $wgMiserMode;
+ $conds = $jconds = array();
+ $tables = array( 'image' );
+
+ if( !$this->showbots ) {
+ $tables[] = 'user_groups';
+ $conds[] = 'ug_group IS NULL';
+ $jconds['user_groups'] = array(
+ 'LEFT JOIN',
+ array(
+ 'ug_group' => User::getGroupsWithPermission( 'bot' ),
+ 'ug_user = img_user'
+ )
+ );
}
- $name = $s->img_name;
- $ut = $s->img_user_text;
+ if( !$wgMiserMode && $this->like !== null ){
+ $dbr = wfGetDB( DB_SLAVE );
+ $likeObj = Title::newFromURL( $this->like );
+ if( $likeObj instanceof Title ){
+ $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
+ $conds[] = "LOWER(img_name) $like";
+ }
+ }
- $nt = Title::newFromText( $name, NS_FILE );
- $ul = $sk->link( Title::makeTitle( NS_USER, $ut ), $ut );
+ $query = array(
+ 'tables' => $tables,
+ 'fields' => '*',
+ 'join_conds' => $jconds,
+ 'conds' => $conds
+ );
- $gallery->add( $nt, "$ul
\n".htmlspecialchars($wgLang->timeanddate( $s->img_timestamp, true ))."
\n" );
+ return $query;
+ }
- $timestamp = wfTimestamp( TS_MW, $s->img_timestamp );
- if( empty( $firstTimestamp ) ) {
- $firstTimestamp = $timestamp;
- }
- $lastTimestamp = $timestamp;
+ function getIndexField(){
+ return 'img_timestamp';
}
- $titleObj = SpecialPage::getTitleFor( 'Newimages' );
- $action = $titleObj->getLocalURL( $hidebots ? '' : 'hidebots=0' );
- if ( $shownav && !$wgMiserMode ) {
- $wgOut->addHTML(
- Xml::openElement( 'form', array( 'action' => $action, 'method' => 'post', 'id' => 'imagesearch' ) ) .
- Xml::fieldset( wfMsg( 'newimages-legend' ) ) .
- Xml::inputLabel( wfMsg( 'newimages-label' ), 'wpIlMatch', 'wpIlMatch', 20, $wpIlMatch ) . ' ' .
- Xml::submitButton( wfMsg( 'ilsubmit' ), array( 'name' => 'wpIlSubmit' ) ) .
- Xml::closeElement( 'fieldset' ) .
- Xml::closeElement( 'form' )
- );
+ function getStartBody(){
+ $this->gallery = new ImageGallery();
}
- $bydate = wfMsg( 'bydate' );
- $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
- if ( $shownav ) {
- $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
- $wgOut->addHTML( $text . "\n" );
+ function getEndBody(){
+ return $this->gallery->toHTML();
}
- /**
- * Paging controls...
- */
+ function formatRow( $row ) {
+ $name = $row->img_name;
+ $user = User::newFromId( $row->img_user );
- # If we change bot visibility, this needs to be carried along.
- if( !$hidebots ) {
- $botpar = array( 'hidebots' => 0 );
- } else {
- $botpar = array();
- }
- $now = wfTimestampNow();
- $d = $wgLang->date( $now, true );
- $t = $wgLang->time( $now, true );
- $query = array_merge(
- array( 'from' => $now ),
- $botpar,
- $searchpar
- );
-
- $dateLink = $sk->linkKnown(
- $titleObj,
- htmlspecialchars( wfMsg( 'sp-newimages-showfrom', $d, $t ) ),
- array(),
- $query
- );
-
- $query = array_merge(
- array( 'hidebots' => ( $hidebots ? 0 : 1 ) ),
- $searchpar
- );
-
- $showhide = $hidebots ? wfMsg( 'show' ) : wfMsg( 'hide' );
-
- $botLink = $sk->linkKnown(
- $titleObj,
- htmlspecialchars( wfMsg( 'showhidebots', $showhide ) ),
- array(),
- $query
- );
-
- $opts = array( 'parsemag', 'escapenoentities' );
- $prevLink = wfMsgExt( 'pager-newer-n', $opts, $wgLang->formatNum( $limit ) );
- if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
- $query = array_merge(
- array( 'from' => $firstTimestamp ),
- $botpar,
- $searchpar
- );
+ $title = Title::makeTitle( NS_FILE, $name );
+ $ul = Linker::link( $user->getUserpage(), $user->getName() );
- $prevLink = $sk->linkKnown(
- $titleObj,
- $prevLink,
- array(),
- $query
+ $this->gallery->add(
+ $title,
+ "$ul
\n"
+ . htmlspecialchars( $this->getLanguage()->timeanddate( $row->img_timestamp, true ) )
+ . "
\n"
);
}
- $nextLink = wfMsgExt( 'pager-older-n', $opts, $wgLang->formatNum( $limit ) );
- if( $shownImages > $limit && $lastTimestamp ) {
- $query = array_merge(
- array( 'until' => $lastTimestamp ),
- $botpar,
- $searchpar
- );
-
- $nextLink = $sk->linkKnown(
- $titleObj,
- $nextLink,
- array(),
- $query
+ function getForm() {
+ global $wgMiserMode;
+
+ $fields = array(
+ 'like' => array(
+ 'type' => 'text',
+ 'label-message' => 'newimages-label',
+ 'name' => 'like',
+ ),
+ 'showbots' => array(
+ 'type' => 'check',
+ 'label' => wfMessage( 'showhidebots', wfMsg( 'show' ) ),
+ 'name' => 'showbots',
+ # 'default' => $this->getRequest()->getBool( 'showbots', 0 ),
+ ),
+ 'limit' => array(
+ 'type' => 'hidden',
+ 'default' => $this->getRequest()->getText( 'limit' ),
+ 'name' => 'limit',
+ ),
+ 'offset' => array(
+ 'type' => 'hidden',
+ 'default' => $this->getRequest()->getText( 'offset' ),
+ 'name' => 'offset',
+ ),
);
- }
-
- $prevnext = '
' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'
'; + if( $wgMiserMode ){ + unset( $fields['like'] ); + } - if ($shownav) - $wgOut->addHTML( $prevnext ); + $form = new HTMLForm( $fields, $this->getContext() ); + $form->setTitle( $this->getTitle() ); + $form->setSubmitText( wfMsg( 'ilsubmit' ) ); + $form->setMethod( 'get' ); + $form->setWrapperLegend( wfMsg( 'newimages-legend' ) ); - if( count( $images ) ) { - $wgOut->addHTML( $gallery->toHTML() ); - if ($shownav) - $wgOut->addHTML( $prevnext ); - } else { - $wgOut->addWikiMsg( 'noimages' ); + return $form; } }