MediaWiki  REL1_23
SpecialNewimages.php
Go to the documentation of this file.
00001 <?php
00024 class SpecialNewFiles extends IncludableSpecialPage {
00025     public function __construct() {
00026         parent::__construct( 'Newimages' );
00027     }
00028 
00029     public function execute( $par ) {
00030         $this->setHeaders();
00031         $this->outputHeader();
00032 
00033         $pager = new NewFilesPager( $this->getContext(), $par );
00034 
00035         if ( !$this->including() ) {
00036             $form = $pager->getForm();
00037             $form->prepareForm();
00038             $form->displayForm( '' );
00039         }
00040 
00041         $this->getOutput()->addHTML( $pager->getBody() );
00042         if ( !$this->including() ) {
00043             $this->getOutput()->addHTML( $pager->getNavigationBar() );
00044         }
00045     }
00046 
00047     protected function getGroupName() {
00048         return 'changes';
00049     }
00050 }
00051 
00055 class NewFilesPager extends ReverseChronologicalPager {
00059     var $gallery;
00060 
00061     function __construct( IContextSource $context, $par = null ) {
00062         $this->like = $context->getRequest()->getText( 'like' );
00063         $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
00064         if ( is_numeric( $par ) ) {
00065             $this->setLimit( $par );
00066         }
00067 
00068         parent::__construct( $context );
00069     }
00070 
00071     function getQueryInfo() {
00072         global $wgMiserMode;
00073         $conds = $jconds = array();
00074         $tables = array( 'image' );
00075 
00076         if ( !$this->showbots ) {
00077             $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
00078 
00079             if ( count( $groupsWithBotPermission ) ) {
00080                 $tables[] = 'user_groups';
00081                 $conds[] = 'ug_group IS NULL';
00082                 $jconds['user_groups'] = array(
00083                     'LEFT JOIN',
00084                     array(
00085                         'ug_group' => $groupsWithBotPermission,
00086                         'ug_user = img_user'
00087                     )
00088                 );
00089             }
00090         }
00091 
00092         if ( !$wgMiserMode && $this->like !== null ) {
00093             $dbr = wfGetDB( DB_SLAVE );
00094             $likeObj = Title::newFromURL( $this->like );
00095             if ( $likeObj instanceof Title ) {
00096                 $like = $dbr->buildLike(
00097                     $dbr->anyString(),
00098                     strtolower( $likeObj->getDBkey() ),
00099                     $dbr->anyString()
00100                 );
00101                 $conds[] = "LOWER(img_name) $like";
00102             }
00103         }
00104 
00105         $query = array(
00106             'tables' => $tables,
00107             'fields' => '*',
00108             'join_conds' => $jconds,
00109             'conds' => $conds
00110         );
00111 
00112         return $query;
00113     }
00114 
00115     function getIndexField() {
00116         return 'img_timestamp';
00117     }
00118 
00119     function getStartBody() {
00120         if ( !$this->gallery ) {
00121             // Note that null for mode is taken to mean use default.
00122             $mode = $this->getRequest()->getVal( 'gallerymode', null );
00123             try {
00124                 $this->gallery = ImageGalleryBase::factory( $mode );
00125             } catch ( MWException $e ) {
00126                 // User specified something invalid, fallback to default.
00127                 $this->gallery = ImageGalleryBase::factory();
00128             }
00129             $this->gallery->setContext( $this->getContext() );
00130         }
00131 
00132         return '';
00133     }
00134 
00135     function getEndBody() {
00136         return $this->gallery->toHTML();
00137     }
00138 
00139     function formatRow( $row ) {
00140         $name = $row->img_name;
00141         $user = User::newFromId( $row->img_user );
00142 
00143         $title = Title::makeTitle( NS_FILE, $name );
00144         $ul = Linker::link( $user->getUserpage(), $user->getName() );
00145         $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
00146 
00147         $this->gallery->add(
00148             $title,
00149             "$ul<br />\n<i>"
00150                 . htmlspecialchars( $time )
00151                 . "</i><br />\n"
00152         );
00153     }
00154 
00155     function getForm() {
00156         global $wgMiserMode;
00157 
00158         $fields = array(
00159             'like' => array(
00160                 'type' => 'text',
00161                 'label-message' => 'newimages-label',
00162                 'name' => 'like',
00163             ),
00164             'showbots' => array(
00165                 'type' => 'check',
00166                 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
00167                 'name' => 'showbots',
00168             ),
00169             'limit' => array(
00170                 'type' => 'hidden',
00171                 'default' => $this->mLimit,
00172                 'name' => 'limit',
00173             ),
00174             'offset' => array(
00175                 'type' => 'hidden',
00176                 'default' => $this->getRequest()->getText( 'offset' ),
00177                 'name' => 'offset',
00178             ),
00179         );
00180 
00181         if ( $wgMiserMode ) {
00182             unset( $fields['like'] );
00183         }
00184 
00185         $context = new DerivativeContext( $this->getContext() );
00186         $context->setTitle( $this->getTitle() ); // Remove subpage
00187         $form = new HTMLForm( $fields, $context );
00188         $form->setSubmitTextMsg( 'ilsubmit' );
00189         $form->setMethod( 'get' );
00190         $form->setWrapperLegendMsg( 'newimages-legend' );
00191 
00192         return $form;
00193     }
00194 }