MediaWiki
REL1_21
|
00001 <?php 00024 class SpecialListFiles extends IncludableSpecialPage { 00025 00026 public function __construct() { 00027 parent::__construct( 'Listfiles' ); 00028 } 00029 00030 public function execute( $par ) { 00031 $this->setHeaders(); 00032 $this->outputHeader(); 00033 00034 if ( $this->including() ) { 00035 $userName = $par; 00036 $search = ''; 00037 } else { 00038 $userName = $this->getRequest()->getText( 'user', $par ); 00039 $search = $this->getRequest()->getText( 'ilsearch', '' ); 00040 } 00041 00042 $pager = new ImageListPager( $this->getContext(), $userName, $search, $this->including() ); 00043 00044 if ( $this->including() ) { 00045 $html = $pager->getBody(); 00046 } else { 00047 $form = $pager->getForm(); 00048 $body = $pager->getBody(); 00049 $nav = $pager->getNavigationBar(); 00050 $html = "$form<br />\n$body<br />\n$nav"; 00051 } 00052 $this->getOutput()->addHTML( $html ); 00053 } 00054 00055 protected function getGroupName() { 00056 return 'media'; 00057 } 00058 } 00059 00063 class ImageListPager extends TablePager { 00064 var $mFieldNames = null; 00065 var $mQueryConds = array(); 00066 var $mUserName = null; 00067 var $mSearch = ''; 00068 var $mIncluding = false; 00069 00070 function __construct( IContextSource $context, $userName = null, $search = '', $including = false ) { 00071 global $wgMiserMode; 00072 00073 $this->mIncluding = $including; 00074 00075 if ( $userName ) { 00076 $nt = Title::newFromText( $userName, NS_USER ); 00077 if ( !is_null( $nt ) ) { 00078 $this->mUserName = $nt->getText(); 00079 $this->mQueryConds['img_user_text'] = $this->mUserName; 00080 } 00081 } 00082 00083 if ( $search != '' && !$wgMiserMode ) { 00084 $this->mSearch = $search; 00085 $nt = Title::newFromURL( $this->mSearch ); 00086 if ( $nt ) { 00087 $dbr = wfGetDB( DB_SLAVE ); 00088 $this->mQueryConds[] = 'LOWER(img_name)' . 00089 $dbr->buildLike( $dbr->anyString(), 00090 strtolower( $nt->getDBkey() ), $dbr->anyString() ); 00091 } 00092 } 00093 00094 if ( !$including ) { 00095 if ( $context->getRequest()->getText( 'sort', 'img_date' ) == 'img_date' ) { 00096 $this->mDefaultDirection = true; 00097 } else { 00098 $this->mDefaultDirection = false; 00099 } 00100 } else { 00101 $this->mDefaultDirection = true; 00102 } 00103 00104 parent::__construct( $context ); 00105 } 00106 00110 function getFieldNames() { 00111 if ( !$this->mFieldNames ) { 00112 global $wgMiserMode; 00113 $this->mFieldNames = array( 00114 'img_timestamp' => $this->msg( 'listfiles_date' )->text(), 00115 'img_name' => $this->msg( 'listfiles_name' )->text(), 00116 'thumb' => $this->msg( 'listfiles_thumb' )->text(), 00117 'img_size' => $this->msg( 'listfiles_size' )->text(), 00118 'img_user_text' => $this->msg( 'listfiles_user' )->text(), 00119 'img_description' => $this->msg( 'listfiles_description' )->text(), 00120 ); 00121 if( !$wgMiserMode ) { 00122 $this->mFieldNames['count'] = $this->msg( 'listfiles_count' )->text(); 00123 } 00124 } 00125 return $this->mFieldNames; 00126 } 00127 00128 function isFieldSortable( $field ) { 00129 if ( $this->mIncluding ) { 00130 return false; 00131 } 00132 static $sortable = array( 'img_timestamp', 'img_name' ); 00133 if ( $field == 'img_size' ) { 00134 # No index for both img_size and img_user_text 00135 return !isset( $this->mQueryConds['img_user_text'] ); 00136 } 00137 return in_array( $field, $sortable ); 00138 } 00139 00140 function getQueryInfo() { 00141 $tables = array( 'image' ); 00142 $fields = array_keys( $this->getFieldNames() ); 00143 $fields[] = 'img_user'; 00144 $fields[array_search( 'thumb', $fields )] = 'img_name AS thumb'; 00145 $options = $join_conds = array(); 00146 00147 # Depends on $wgMiserMode 00148 if( isset( $this->mFieldNames['count'] ) ) { 00149 $tables[] = 'oldimage'; 00150 00151 # Need to rewrite this one 00152 foreach ( $fields as &$field ) { 00153 if ( $field == 'count' ) { 00154 $field = 'COUNT(oi_archive_name) AS count'; 00155 } 00156 } 00157 unset( $field ); 00158 00159 $dbr = wfGetDB( DB_SLAVE ); 00160 if( $dbr->implicitGroupby() ) { 00161 $options = array( 'GROUP BY' => 'img_name' ); 00162 } else { 00163 $columnlist = preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ); 00164 $options = array( 'GROUP BY' => array_merge( array( 'img_user' ), $columnlist ) ); 00165 } 00166 $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) ); 00167 } 00168 return array( 00169 'tables' => $tables, 00170 'fields' => $fields, 00171 'conds' => $this->mQueryConds, 00172 'options' => $options, 00173 'join_conds' => $join_conds 00174 ); 00175 } 00176 00177 function getDefaultSort() { 00178 return 'img_timestamp'; 00179 } 00180 00181 function doBatchLookups() { 00182 $userIds = array(); 00183 $this->mResult->seek( 0 ); 00184 foreach ( $this->mResult as $row ) { 00185 $userIds[] = $row->img_user; 00186 } 00187 # Do a link batch query for names and userpages 00188 UserCache::singleton()->doQuery( $userIds, array( 'userpage' ), __METHOD__ ); 00189 } 00190 00191 function formatValue( $field, $value ) { 00192 switch ( $field ) { 00193 case 'thumb': 00194 $file = wfLocalFile( $value ); 00195 $thumb = $file->transform( array( 'width' => 180, 'height' => 360 ) ); 00196 return $thumb->toHtml( array( 'desc-link' => true ) ); 00197 case 'img_timestamp': 00198 return htmlspecialchars( $this->getLanguage()->userTimeAndDate( $value, $this->getUser() ) ); 00199 case 'img_name': 00200 static $imgfile = null; 00201 if ( $imgfile === null ) $imgfile = $this->msg( 'imgfile' )->text(); 00202 00203 // Weird files can maybe exist? Bug 22227 00204 $filePage = Title::makeTitleSafe( NS_FILE, $value ); 00205 if( $filePage ) { 00206 $link = Linker::linkKnown( $filePage, htmlspecialchars( $filePage->getText() ) ); 00207 $download = Xml::element( 'a', 00208 array( 'href' => wfLocalFile( $filePage )->getURL() ), 00209 $imgfile 00210 ); 00211 $download = $this->msg( 'parentheses' )->rawParams( $download )->escaped(); 00212 return "$link $download"; 00213 } else { 00214 return htmlspecialchars( $value ); 00215 } 00216 case 'img_user_text': 00217 if ( $this->mCurrentRow->img_user ) { 00218 $name = User::whoIs( $this->mCurrentRow->img_user ); 00219 $link = Linker::link( 00220 Title::makeTitle( NS_USER, $name ), 00221 htmlspecialchars( $name ) 00222 ); 00223 } else { 00224 $link = htmlspecialchars( $value ); 00225 } 00226 return $link; 00227 case 'img_size': 00228 return htmlspecialchars( $this->getLanguage()->formatSize( $value ) ); 00229 case 'img_description': 00230 return Linker::formatComment( $value ); 00231 case 'count': 00232 return intval( $value ) + 1; 00233 } 00234 } 00235 00236 function getForm() { 00237 global $wgScript, $wgMiserMode; 00238 $inputForm = array(); 00239 $inputForm['table_pager_limit_label'] = $this->getLimitSelect(); 00240 if ( !$wgMiserMode ) { 00241 $inputForm['listfiles_search_for'] = Html::input( 'ilsearch', $this->mSearch, 'text', 00242 array( 00243 'size' => '40', 00244 'maxlength' => '255', 00245 'id' => 'mw-ilsearch', 00246 ) ); 00247 } 00248 $inputForm['username'] = Html::input( 'user', $this->mUserName, 'text', array( 00249 'size' => '40', 00250 'maxlength' => '255', 00251 'id' => 'mw-listfiles-user', 00252 ) ); 00253 return Html::openElement( 'form', 00254 array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' ) ) . 00255 Xml::fieldset( $this->msg( 'listfiles' )->text() ) . 00256 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . 00257 Xml::buildForm( $inputForm, 'table_pager_limit_submit' ) . 00258 $this->getHiddenFields( array( 'limit', 'ilsearch', 'user', 'title' ) ) . 00259 Html::closeElement( 'fieldset' ) . 00260 Html::closeElement( 'form' ) . "\n"; 00261 } 00262 00263 function getTableClass() { 00264 return 'listfiles ' . parent::getTableClass(); 00265 } 00266 00267 function getNavClass() { 00268 return 'listfiles_nav ' . parent::getNavClass(); 00269 } 00270 00271 function getSortHeaderClass() { 00272 return 'listfiles_sort ' . parent::getSortHeaderClass(); 00273 } 00274 00275 function getPagingQueries() { 00276 $queries = parent::getPagingQueries(); 00277 if ( !is_null( $this->mUserName ) ) { 00278 # Append the username to the query string 00279 foreach ( $queries as &$query ) { 00280 $query['user'] = $this->mUserName; 00281 } 00282 } 00283 return $queries; 00284 } 00285 00286 function getDefaultQuery() { 00287 $queries = parent::getDefaultQuery(); 00288 if ( !isset( $queries['user'] ) && !is_null( $this->mUserName ) ) { 00289 $queries['user'] = $this->mUserName; 00290 } 00291 return $queries; 00292 } 00293 00294 function getTitle() { 00295 return SpecialPage::getTitleFor( 'Listfiles' ); 00296 } 00297 }