Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / includes / specials / SpecialNewimages.php
index 7dceb24..350aac6 100644 (file)
@@ -27,17 +27,20 @@ class SpecialNewFiles extends IncludableSpecialPage {
        }
 
        public function execute( $par ){
-               global $wgOut;
-
                $this->setHeaders();
                $this->outputHeader();
 
-               $pager = new NewFilesPager( $par );
+               $pager = new NewFilesPager( $this->getContext(), $par );
 
-               $form = $pager->getForm();
-               $form->prepareForm();
-               $form->displayForm( '' );
-               $wgOut->addHTML( $pager->getBody() . $pager->getNavigationBar() );
+               if ( !$this->including() ) {
+                       $form = $pager->getForm();
+                       $form->prepareForm();
+                       $form->displayForm( '' );
+               }
+               $this->getOutput()->addHTML( $pager->getBody() );
+               if ( !$this->including() ) {
+                       $this->getOutput()->addHTML( $pager->getNavigationBar() );
+               }
        }
 }
 
@@ -47,14 +50,19 @@ class SpecialNewFiles extends IncludableSpecialPage {
  */
 class NewFilesPager extends ReverseChronologicalPager {
 
-       function __construct( $par = null ) {
-               global $wgRequest, $wgUser;
+       /**
+        * @var ImageGallery
+        */
+       var $gallery;
 
-               $this->like = $wgRequest->getText( 'like' );
-               $this->showbots = $wgRequest->getBool( 'showbots' , 0 );
-               $this->skin = $wgUser->getSkin();
+       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();
+               parent::__construct( $context );
        }
 
        function getQueryInfo() {
@@ -63,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 ){
@@ -98,7 +109,10 @@ class NewFilesPager extends ReverseChronologicalPager {
        }
 
        function getStartBody(){
-               $this->gallery = new ImageGallery();
+               if ( !$this->gallery ) {
+                       $this->gallery = new ImageGallery();
+               }
+               return '';
        }
 
        function getEndBody(){
@@ -106,24 +120,22 @@ class NewFilesPager extends ReverseChronologicalPager {
        }
 
        function formatRow( $row ) {
-               global $wgLang;
-
                $name = $row->img_name;
                $user = User::newFromId( $row->img_user );
 
-               $title = Title::newFromText( $name, NS_FILE );
-               $ul = $this->skin->link( $user->getUserpage(), $user->getName() );
+               $title = Title::makeTitle( NS_FILE, $name );
+               $ul = Linker::link( $user->getUserpage(), $user->getName() );
 
                $this->gallery->add(
                        $title,
                        "$ul<br />\n<i>"
-                               . htmlspecialchars( $wgLang->timeanddate( $row->img_timestamp, true ) )
+                               . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
                                . "</i><br />\n"
                );
        }
 
        function getForm() {
-               global $wgRequest, $wgMiserMode;
+               global $wgMiserMode;
 
                $fields = array(
                        'like' => array(
@@ -133,18 +145,18 @@ 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' => $wgRequest->getBool( 'showbots', 0 ),
+                       #       'default' => $this->getRequest()->getBool( 'showbots', 0 ),
                        ),
                        'limit' => array(
                                'type' => 'hidden',
-                               'default' => $wgRequest->getText( 'limit' ),
+                               'default' => $this->mLimit,
                                'name' => 'limit',
                        ),
                        'offset' => array(
                                'type' => 'hidden',
-                               'default' => $wgRequest->getText( 'offset' ),
+                               'default' => $this->getRequest()->getText( 'offset' ),
                                'name' => 'offset',
                        ),
                );
@@ -153,11 +165,11 @@ class NewFilesPager extends ReverseChronologicalPager {
                        unset( $fields['like'] );
                }
 
-               $form = new HTMLForm( $fields );
+               $form = new HTMLForm( $fields, $this->getContext() );
                $form->setTitle( $this->getTitle() );
-               $form->setSubmitText( wfMsg( 'ilsubmit' ) );
+               $form->setSubmitTextMsg( 'ilsubmit' );
                $form->setMethod( 'get' );
-               $form->setWrapperLegend( wfMsg( 'newimages-legend' ) );
+               $form->setWrapperLegendMsg( 'newimages-legend' );
 
                return $form;
        }