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