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 $this->mQueryConds = array( 'LOWER(img_name)' . $dbr->buildLike( $dbr->anyString(),
00041 strtolower( $nt->getDBkey() ), $dbr->anyString() ) );
00042 }
00043 }
00044
00045 parent::__construct();
00046 }
00047
00048 function getFieldNames() {
00049 if ( !$this->mFieldNames ) {
00050 global $wgMiserMode;
00051 $this->mFieldNames = array(
00052 'img_timestamp' => wfMsg( 'listfiles_date' ),
00053 'img_name' => wfMsg( 'listfiles_name' ),
00054 'img_user_text' => wfMsg( 'listfiles_user' ),
00055 'img_size' => wfMsg( 'listfiles_size' ),
00056 'img_description' => wfMsg( 'listfiles_description' ),
00057 );
00058 if( !$wgMiserMode ) {
00059 $this->mFieldNames['count'] = wfMsg( 'listfiles_count' );
00060 }
00061 }
00062 return $this->mFieldNames;
00063 }
00064
00065 function isFieldSortable( $field ) {
00066 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
00067 return in_array( $field, $sortable );
00068 }
00069
00070 function getQueryInfo() {
00071 $tables = array( 'image' );
00072 $fields = array_keys( $this->getFieldNames() );
00073 $fields[] = 'img_user';
00074 $options = $join_conds = array();
00075
00076 # Depends on $wgMiserMode
00077 if( isset( $this->mFieldNames['count'] ) ) {
00078 $tables[] = 'oldimage';
00079
00080 # Need to rewrite this one
00081 foreach ( $fields as &$field )
00082 if ( $field == 'count' )
00083 $field = 'COUNT(oi_archive_name) as count';
00084 unset( $field );
00085
00086 $dbr = wfGetDB( DB_SLAVE );
00087 if( $dbr->implicitGroupby() ) {
00088 $options = array( 'GROUP BY' => 'img_name' );
00089 } else {
00090 $columnlist = implode( ',', preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) );
00091 $options = array( 'GROUP BY' => "img_user, $columnlist" );
00092 }
00093 $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) );
00094 }
00095 return array(
00096 'tables' => $tables,
00097 'fields' => $fields,
00098 'conds' => $this->mQueryConds,
00099 'options' => $options,
00100 'join_conds' => $join_conds
00101 );
00102 }
00103
00104 function getDefaultSort() {
00105 return 'img_timestamp';
00106 }
00107
00108 function getStartBody() {
00109 # Do a link batch query for user pages
00110 if ( $this->mResult->numRows() ) {
00111 $lb = new LinkBatch;
00112 $this->mResult->seek( 0 );
00113 while ( $row = $this->mResult->fetchObject() ) {
00114 if ( $row->img_user ) {
00115 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
00116 }
00117 }
00118 $lb->execute();
00119 }
00120
00121 return parent::getStartBody();
00122 }
00123
00124 function formatValue( $field, $value ) {
00125 global $wgLang;
00126 switch ( $field ) {
00127 case 'img_timestamp':
00128 return htmlspecialchars( $wgLang->timeanddate( $value, true ) );
00129 case 'img_name':
00130 static $imgfile = null;
00131 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
00132
00133 $name = $this->mCurrentRow->img_name;
00134 $link = $this->getSkin()->linkKnown( Title::makeTitle( NS_FILE, $name ), $value );
00135 $image = wfLocalFile( $value );
00136 $url = $image->getURL();
00137 $download = Xml::element('a', array( 'href' => $url ), $imgfile );
00138 return "$link ($download)";
00139 case 'img_user_text':
00140 if ( $this->mCurrentRow->img_user ) {
00141 $link = $this->getSkin()->link(
00142 Title::makeTitle( NS_USER, $value ),
00143 htmlspecialchars( $value )
00144 );
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, $wgScript, $wgMiserMode;
00160 $search = $wgRequest->getText( 'ilsearch' );
00161
00162 $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, '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 }