MediaWiki  REL1_20
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 
00047 
00051 class NewFilesPager extends ReverseChronologicalPager {
00052 
00056         var $gallery;
00057 
00058         function __construct( IContextSource $context, $par = null ) {
00059                 $this->like = $context->getRequest()->getText( 'like' );
00060                 $this->showbots = $context->getRequest()->getBool( 'showbots' , 0 );
00061                 if ( is_numeric( $par ) ) {
00062                         $this->setLimit( $par );
00063                 }
00064 
00065                 parent::__construct( $context );
00066         }
00067 
00068         function getQueryInfo() {
00069                 global $wgMiserMode;
00070                 $conds = $jconds = array();
00071                 $tables = array( 'image' );
00072 
00073                 if( !$this->showbots ) {
00074                         $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
00075                         if( count( $groupsWithBotPermission ) ) {
00076                                 $tables[] = 'user_groups';
00077                                 $conds[] = 'ug_group IS NULL';
00078                                 $jconds['user_groups'] = array(
00079                                         'LEFT JOIN',
00080                                         array(
00081                                                 'ug_group' => $groupsWithBotPermission,
00082                                                 'ug_user = img_user'
00083                                         )
00084                                 );
00085                         }
00086                 }
00087 
00088                 if( !$wgMiserMode && $this->like !== null ){
00089                         $dbr = wfGetDB( DB_SLAVE );
00090                         $likeObj = Title::newFromURL( $this->like );
00091                         if( $likeObj instanceof Title ){
00092                                 $like = $dbr->buildLike( $dbr->anyString(), strtolower( $likeObj->getDBkey() ), $dbr->anyString() );
00093                                 $conds[] = "LOWER(img_name) $like";
00094                         }
00095                 }
00096 
00097                 $query = array(
00098                         'tables' => $tables,
00099                         'fields' => '*',
00100                         'join_conds' => $jconds,
00101                         'conds' => $conds
00102                 );
00103 
00104                 return $query;
00105         }
00106 
00107         function getIndexField(){
00108                 return 'img_timestamp';
00109         }
00110 
00111         function getStartBody(){
00112                 if ( !$this->gallery ) {
00113                         $this->gallery = new ImageGallery();
00114                 }
00115                 return '';
00116         }
00117 
00118         function getEndBody(){
00119                 return $this->gallery->toHTML();
00120         }
00121 
00122         function formatRow( $row ) {
00123                 $name = $row->img_name;
00124                 $user = User::newFromId( $row->img_user );
00125 
00126                 $title = Title::makeTitle( NS_FILE, $name );
00127                 $ul = Linker::link( $user->getUserpage(), $user->getName() );
00128 
00129                 $this->gallery->add(
00130                         $title,
00131                         "$ul<br />\n<i>"
00132                                 . htmlspecialchars( $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ) )
00133                                 . "</i><br />\n"
00134                 );
00135         }
00136 
00137         function getForm() {
00138                 global $wgMiserMode;
00139 
00140                 $fields = array(
00141                         'like' => array(
00142                                 'type' => 'text',
00143                                 'label-message' => 'newimages-label',
00144                                 'name' => 'like',
00145                         ),
00146                         'showbots' => array(
00147                                 'type' => 'check',
00148                                 'label' => $this->msg( 'showhidebots', $this->msg( 'show' )->plain() )->escaped(),
00149                                 'name' => 'showbots',
00150                         #       'default' => $this->getRequest()->getBool( 'showbots', 0 ),
00151                         ),
00152                         'limit' => array(
00153                                 'type' => 'hidden',
00154                                 'default' => $this->mLimit,
00155                                 'name' => 'limit',
00156                         ),
00157                         'offset' => array(
00158                                 'type' => 'hidden',
00159                                 'default' => $this->getRequest()->getText( 'offset' ),
00160                                 'name' => 'offset',
00161                         ),
00162                 );
00163 
00164                 if( $wgMiserMode ){
00165                         unset( $fields['like'] );
00166                 }
00167 
00168                 $form = new HTMLForm( $fields, $this->getContext() );
00169                 $form->setTitle( $this->getTitle() );
00170                 $form->setSubmitTextMsg( 'ilsubmit' );
00171                 $form->setMethod( 'get' );
00172                 $form->setWrapperLegendMsg( 'newimages-legend' );
00173 
00174                 return $form;
00175         }
00176 }