Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / includes / specials / SpecialNewimages.php
index f95748a..350aac6 100644 (file)
@@ -30,15 +30,16 @@ class SpecialNewFiles extends IncludableSpecialPage {
                $this->setHeaders();
                $this->outputHeader();
 
-               $out = $this->getOutput();
                $pager = new NewFilesPager( $this->getContext(), $par );
 
                if ( !$this->including() ) {
-                       $out->addHTML( $pager->buildHTMLForm() );
+                       $form = $pager->getForm();
+                       $form->prepareForm();
+                       $form->displayForm( '' );
                }
-               $out->addHTML( $pager->getBody() );
+               $this->getOutput()->addHTML( $pager->getBody() );
                if ( !$this->including() ) {
-                       $out->addHTML( $pager->getNavigationBar() );
+                       $this->getOutput()->addHTML( $pager->getNavigationBar() );
                }
        }
 }
@@ -57,6 +58,9 @@ class NewFilesPager extends ReverseChronologicalPager {
        function __construct( IContextSource $context, $par = null ) {
                $this->like = $context->getRequest()->getText( 'like' );
                $this->showbots = $context->getRequest()->getBool( 'showbots' , 0 );
+               if ( is_numeric( $par ) ) {
+                       $this->setLimit( $par );
+               }
 
                parent::__construct( $context );
        }
@@ -67,15 +71,18 @@ class NewFilesPager extends ReverseChronologicalPager {
                $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'
-                               )
-                       );
+                       $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
+                       if( count( $groupsWithBotPermission ) ) {
+                               $tables[] = 'user_groups';
+                               $conds[] = 'ug_group IS NULL';
+                               $jconds['user_groups'] = array(
+                                       'LEFT JOIN',
+                                       array(
+                                               'ug_group' => $groupsWithBotPermission,
+                                               'ug_user = img_user'
+                                       )
+                               );
+                       }
                }
 
                if( !$wgMiserMode && $this->like !== null ){
@@ -102,7 +109,10 @@ class NewFilesPager extends ReverseChronologicalPager {
        }
 
        function getStartBody(){
-               $this->gallery = new ImageGallery();
+               if ( !$this->gallery ) {
+                       $this->gallery = new ImageGallery();
+               }
+               return '';
        }
 
        function getEndBody(){
@@ -119,12 +129,12 @@ class NewFilesPager extends ReverseChronologicalPager {
                $this->gallery->add(
                        $title,
                        "$ul<br />\n<i>"
-                               . htmlspecialchars( $this->getLanguage()->timeanddate( $row->img_timestamp, true ) )
+                               . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
                                . "</i><br />\n"
                );
        }
 
-       protected function getHTMLFormFields() {
+       function getForm() {
                global $wgMiserMode;
 
                $fields = array(
@@ -135,8 +145,19 @@ class NewFilesPager extends ReverseChronologicalPager {
                        ),
                        'showbots' => array(
                                'type' => 'check',
-                               'label' => wfMessage( 'showhidebots', wfMsg( 'show' ) ),
+                               'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
                                'name' => 'showbots',
+                       #       'default' => $this->getRequest()->getBool( 'showbots', 0 ),
+                       ),
+                       'limit' => array(
+                               'type' => 'hidden',
+                               'default' => $this->mLimit,
+                               'name' => 'limit',
+                       ),
+                       'offset' => array(
+                               'type' => 'hidden',
+                               'default' => $this->getRequest()->getText( 'offset' ),
+                               'name' => 'offset',
                        ),
                );
 
@@ -144,14 +165,12 @@ class NewFilesPager extends ReverseChronologicalPager {
                        unset( $fields['like'] );
                }
 
-               return $fields;
-       }
-
-       protected function getHTMLFormLegend() {
-               return 'newimages-legend';
-       }
+               $form = new HTMLForm( $fields, $this->getContext() );
+               $form->setTitle( $this->getTitle() );
+               $form->setSubmitTextMsg( 'ilsubmit' );
+               $form->setMethod( 'get' );
+               $form->setWrapperLegendMsg( 'newimages-legend' );
 
-       protected function getHTMLFormSubmit() {
-               return 'ilsubmit';
+               return $form;
        }
 }