10 function wfSpecialListfiles() {
13 $pager = new ImageListPager;
15 $limit = $pager->getForm();
16 $body = $pager->getBody();
17 $nav = $pager->getNavigationBar();
18 $wgOut->addHTML( "$limit<br />\n$body<br />\n$nav" );
22 * @ingroup SpecialPage Pager
24 class ImageListPager extends TablePager {
25 var $mFieldNames = null;
26 var $mQueryConds = array();
28 function __construct() {
29 global $wgRequest, $wgMiserMode;
30 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
31 $this->mDefaultDirection = true;
33 $this->mDefaultDirection = false;
35 $search = $wgRequest->getText( 'ilsearch' );
36 if ( $search != '' && !$wgMiserMode ) {
37 $nt = Title::newFromURL( $search );
39 $dbr = wfGetDB( DB_SLAVE );
40 $this->mQueryConds = array( 'LOWER(img_name)' . $dbr->buildLike( $dbr->anyString(),
41 strtolower( $nt->getDBkey() ), $dbr->anyString() ) );
45 parent::__construct();
48 function getFieldNames() {
49 if ( !$this->mFieldNames ) {
51 $this->mFieldNames = array(
52 'img_timestamp' => wfMsg( 'listfiles_date' ),
53 'img_name' => wfMsg( 'listfiles_name' ),
54 'img_user_text' => wfMsg( 'listfiles_user' ),
55 'img_size' => wfMsg( 'listfiles_size' ),
56 'img_description' => wfMsg( 'listfiles_description' ),
59 $this->mFieldNames['count'] = wfMsg( 'listfiles_count' );
62 return $this->mFieldNames;
65 function isFieldSortable( $field ) {
66 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
67 return in_array( $field, $sortable );
70 function getQueryInfo() {
71 $tables = array( 'image' );
72 $fields = array_keys( $this->getFieldNames() );
73 $fields[] = 'img_user';
74 $options = $join_conds = array();
76 # Depends on $wgMiserMode
77 if( isset( $this->mFieldNames['count'] ) ) {
78 $tables[] = 'oldimage';
80 # Need to rewrite this one
81 foreach ( $fields as &$field )
82 if ( $field == 'count' )
83 $field = 'COUNT(oi_archive_name) as count';
86 $dbr = wfGetDB( DB_SLAVE );
87 if( $dbr->implicitGroupby() ) {
88 $options = array( 'GROUP BY' => 'img_name' );
90 $columnlist = implode( ',', preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) );
91 $options = array( 'GROUP BY' => "img_user, $columnlist" );
93 $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) );
98 'conds' => $this->mQueryConds,
99 'options' => $options,
100 'join_conds' => $join_conds
104 function getDefaultSort() {
105 return 'img_timestamp';
108 function getStartBody() {
109 # Do a link batch query for user pages
110 if ( $this->mResult->numRows() ) {
112 $this->mResult->seek( 0 );
113 while ( $row = $this->mResult->fetchObject() ) {
114 if ( $row->img_user ) {
115 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
121 return parent::getStartBody();
124 function formatValue( $field, $value ) {
127 case 'img_timestamp':
128 return htmlspecialchars( $wgLang->timeanddate( $value, true ) );
130 static $imgfile = null;
131 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
133 $name = $this->mCurrentRow->img_name;
134 $link = $this->getSkin()->linkKnown( Title::makeTitle( NS_FILE, $name ), $value );
135 $image = wfLocalFile( $value );
136 $url = $image->getURL();
137 $download = Xml::element('a', array( 'href' => $url ), $imgfile );
138 return "$link ($download)";
139 case 'img_user_text':
140 if ( $this->mCurrentRow->img_user ) {
141 $link = $this->getSkin()->link(
142 Title::makeTitle( NS_USER, $value ),
143 htmlspecialchars( $value )
146 $link = htmlspecialchars( $value );
150 return $this->getSkin()->formatSize( $value );
151 case 'img_description':
152 return $this->getSkin()->commentBlock( $value );
154 return intval($value)+1;
159 global $wgRequest, $wgScript, $wgMiserMode;
160 $search = $wgRequest->getText( 'ilsearch' );
162 $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' ) ) .
163 Xml::openElement( 'fieldset' ) .
164 Xml::element( 'legend', null, wfMsg( 'listfiles' ) ) .
165 Xml::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
167 if ( !$wgMiserMode ) {
169 Xml::inputLabel( wfMsg( 'listfiles_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
172 Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
173 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
174 Xml::closeElement( 'fieldset' ) .
175 Xml::closeElement( 'form' ) . "\n";
179 function getTableClass() {
180 return 'listfiles ' . parent::getTableClass();
183 function getNavClass() {
184 return 'listfiles_nav ' . parent::getNavClass();
187 function getSortHeaderClass() {
188 return 'listfiles_sort ' . parent::getSortHeaderClass();