MediaWiki  REL1_21
SpecialNewimages.php
Go to the documentation of this file.
00001 <?php
00023 class SpecialNewFiles extends IncludableSpecialPage {
00024 
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                 $this->getOutput()->addHTML( $pager->getBody() );
00041                 if ( !$this->including() ) {
00042                         $this->getOutput()->addHTML( $pager->getNavigationBar() );
00043                 }
00044         }
00045 
00046         protected function getGroupName() {
00047                 return 'changes';
00048         }
00049 }
00050 
00054 class NewFilesPager extends ReverseChronologicalPager {
00055 
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                         if( count( $groupsWithBotPermission ) ) {
00079                                 $tables[] = 'user_groups';
00080                                 $conds[] = 'ug_group IS NULL';
00081                                 $jconds['user_groups'] = array(
00082                                         'LEFT JOIN',
00083                                         array(
00084                                                 'ug_group' => $groupsWithBotPermission,
00085                                                 'ug_user = img_user'
00086                                         )
00087                                 );
00088                         }
00089                 }
00090 
00091                 if( !$wgMiserMode && $this->like !== null ) {
00092                         $dbr = wfGetDB( DB_SLAVE );
00093                         $likeObj = Title::newFromURL( $this->like );
00094                         if( $likeObj instanceof Title ) {
00095                                 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
00096                                 $conds[] = "LOWER(img_name) $like";
00097                         }
00098                 }
00099 
00100                 $query = array(
00101                         'tables' => $tables,
00102                         'fields' => '*',
00103                         'join_conds' => $jconds,
00104                         'conds' => $conds
00105                 );
00106 
00107                 return $query;
00108         }
00109 
00110         function getIndexField() {
00111                 return 'img_timestamp';
00112         }
00113 
00114         function getStartBody() {
00115                 if ( !$this->gallery ) {
00116                         $this->gallery = new ImageGallery();
00117                 }
00118                 return '';
00119         }
00120 
00121         function getEndBody() {
00122                 return $this->gallery->toHTML();
00123         }
00124 
00125         function formatRow( $row ) {
00126                 $name = $row->img_name;
00127                 $user = User::newFromId( $row->img_user );
00128 
00129                 $title = Title::makeTitle( NS_FILE, $name );
00130                 $ul = Linker::link( $user->getUserpage(), $user->getName() );
00131 
00132                 $this->gallery->add(
00133                         $title,
00134                         "$ul<br />\n<i>"
00135                                 . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
00136                                 . "</i><br />\n"
00137                 );
00138         }
00139 
00140         function getForm() {
00141                 global $wgMiserMode;
00142 
00143                 $fields = array(
00144                         'like' => array(
00145                                 'type' => 'text',
00146                                 'label-message' => 'newimages-label',
00147                                 'name' => 'like',
00148                         ),
00149                         'showbots' => array(
00150                                 'type' => 'check',
00151                                 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
00152                                 'name' => 'showbots',
00153                         #       'default' => $this->getRequest()->getBool( 'showbots', 0 ),
00154                         ),
00155                         'limit' => array(
00156                                 'type' => 'hidden',
00157                                 'default' => $this->mLimit,
00158                                 'name' => 'limit',
00159                         ),
00160                         'offset' => array(
00161                                 'type' => 'hidden',
00162                                 'default' => $this->getRequest()->getText( 'offset' ),
00163                                 'name' => 'offset',
00164                         ),
00165                 );
00166 
00167                 if( $wgMiserMode ) {
00168                         unset( $fields['like'] );
00169                 }
00170 
00171                 $form = new HTMLForm( $fields, $this->getContext() );
00172                 $form->setTitle( $this->getTitle() );
00173                 $form->setSubmitTextMsg( 'ilsubmit' );
00174                 $form->setMethod( 'get' );
00175                 $form->setWrapperLegendMsg( 'newimages-legend' );
00176 
00177                 return $form;
00178         }
00179 }