00001 <?php 00010 function wfSpecialListfiles() { 00011 global $wgOut; 00012 00013 $pager = new ImageListPager; 00014 00015 $limit = $pager->getForm(); 00016 $body = $pager->getBody(); 00017 $nav = $pager->getNavigationBar(); 00018 $wgOut->addHTML( "$limit<br />\n$body<br />\n$nav" ); 00019 } 00020 00024 class ImageListPager extends TablePager { 00025 var $mFieldNames = null; 00026 var $mQueryConds = array(); 00027 00028 function __construct() { 00029 global $wgRequest, $wgMiserMode; 00030 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) { 00031 $this->mDefaultDirection = true; 00032 } else { 00033 $this->mDefaultDirection = false; 00034 } 00035 $search = $wgRequest->getText( 'ilsearch' ); 00036 if ( $search != '' && !$wgMiserMode ) { 00037 $nt = Title::newFromUrl( $search ); 00038 if( $nt ) { 00039 $dbr = wfGetDB( DB_SLAVE ); 00040 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) ); 00041 $m = str_replace( "%", "\\%", $m ); 00042 $m = str_replace( "_", "\\_", $m ); 00043 $this->mQueryConds = array( "LOWER(img_name) LIKE '%{$m}%'" ); 00044 } 00045 } 00046 00047 parent::__construct(); 00048 } 00049 00050 function getFieldNames() { 00051 if ( !$this->mFieldNames ) { 00052 global $wgMiserMode; 00053 $this->mFieldNames = array( 00054 'img_timestamp' => wfMsg( 'listfiles_date' ), 00055 'img_name' => wfMsg( 'listfiles_name' ), 00056 'img_user_text' => wfMsg( 'listfiles_user' ), 00057 'img_size' => wfMsg( 'listfiles_size' ), 00058 'img_description' => wfMsg( 'listfiles_description' ), 00059 ); 00060 if( !$wgMiserMode ) { 00061 $this->mFieldNames['count'] = wfMsg( 'listfiles_count' ); 00062 } 00063 } 00064 return $this->mFieldNames; 00065 } 00066 00067 function isFieldSortable( $field ) { 00068 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' ); 00069 return in_array( $field, $sortable ); 00070 } 00071 00072 function getQueryInfo() { 00073 $tables = array( 'image' ); 00074 $fields = array_keys( $this->getFieldNames() ); 00075 $fields[] = 'img_user'; 00076 $options = $join_conds = array(); 00077 00078 # Depends on $wgMiserMode 00079 if( isset( $this->mFieldNames['count'] ) ) { 00080 $tables[] = 'oldimage'; 00081 00082 # Need to rewrite this one 00083 foreach ( $fields as &$field ) 00084 if ( $field == 'count' ) 00085 $field = 'COUNT(oi_archive_name) as count'; 00086 unset( $field ); 00087 00088 $dbr = wfGetDB( DB_SLAVE ); 00089 if( $dbr->implicitGroupby() ) { 00090 $options = array( 'GROUP BY' => 'img_name' ); 00091 } else { 00092 $columnlist = implode( ',', preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) ); 00093 $options = array( 'GROUP BY' => "img_user, $columnlist" ); 00094 } 00095 $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) ); 00096 } 00097 return array( 00098 'tables' => $tables, 00099 'fields' => $fields, 00100 'conds' => $this->mQueryConds, 00101 'options' => $options, 00102 'join_conds' => $join_conds 00103 ); 00104 } 00105 00106 function getDefaultSort() { 00107 return 'img_timestamp'; 00108 } 00109 00110 function getStartBody() { 00111 # Do a link batch query for user pages 00112 if ( $this->mResult->numRows() ) { 00113 $lb = new LinkBatch; 00114 $this->mResult->seek( 0 ); 00115 while ( $row = $this->mResult->fetchObject() ) { 00116 if ( $row->img_user ) { 00117 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) ); 00118 } 00119 } 00120 $lb->execute(); 00121 } 00122 00123 return parent::getStartBody(); 00124 } 00125 00126 function formatValue( $field, $value ) { 00127 global $wgLang; 00128 switch ( $field ) { 00129 case 'img_timestamp': 00130 return $wgLang->timeanddate( $value, true ); 00131 case 'img_name': 00132 static $imgfile = null; 00133 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' ); 00134 00135 $name = $this->mCurrentRow->img_name; 00136 $link = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_FILE, $name ), $value ); 00137 $image = wfLocalFile( $value ); 00138 $url = $image->getURL(); 00139 $download = Xml::element('a', array( 'href' => $url ), $imgfile ); 00140 return "$link ($download)"; 00141 case 'img_user_text': 00142 if ( $this->mCurrentRow->img_user ) { 00143 $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ), 00144 htmlspecialchars( $value ) ); 00145 } else { 00146 $link = htmlspecialchars( $value ); 00147 } 00148 return $link; 00149 case 'img_size': 00150 return $this->getSkin()->formatSize( $value ); 00151 case 'img_description': 00152 return $this->getSkin()->commentBlock( $value ); 00153 case 'count': 00154 return intval($value)+1; 00155 } 00156 } 00157 00158 function getForm() { 00159 global $wgRequest, $wgMiserMode; 00160 $search = $wgRequest->getText( 'ilsearch' ); 00161 00162 $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-listfiles-form' ) ) . 00163 Xml::openElement( 'fieldset' ) . 00164 Xml::element( 'legend', null, wfMsg( 'listfiles' ) ) . 00165 Xml::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) ); 00166 00167 if ( !$wgMiserMode ) { 00168 $s .= "<br />\n" . 00169 Xml::inputLabel( wfMsg( 'listfiles_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search ); 00170 } 00171 $s .= ' ' . 00172 Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" . 00173 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) . 00174 Xml::closeElement( 'fieldset' ) . 00175 Xml::closeElement( 'form' ) . "\n"; 00176 return $s; 00177 } 00178 00179 function getTableClass() { 00180 return 'listfiles ' . parent::getTableClass(); 00181 } 00182 00183 function getNavClass() { 00184 return 'listfiles_nav ' . parent::getNavClass(); 00185 } 00186 00187 function getSortHeaderClass() { 00188 return 'listfiles_sort ' . parent::getSortHeaderClass(); 00189 } 00190 }