227adaa37e1f8c88be47775de51b3b5f74d6fd93
10 function wfSpecialListfiles( $par = null ) {
13 $pager = new ImageListPager( $par );
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( $par = null ) {
29 global $wgRequest, $wgMiserMode;
30 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
31 $this->mDefaultDirection
= true;
33 $this->mDefaultDirection
= false;
36 $userName = $wgRequest->getText( 'username', $par );
38 $nt = Title
::newFromText( $userName, NS_USER
);
39 if ( !is_null( $nt ) ) {
40 $this->mQueryConds
['img_user_text'] = $nt->getText();
44 $search = $wgRequest->getText( 'ilsearch' );
45 if ( $search != '' && !$wgMiserMode ) {
46 $nt = Title
::newFromURL( $search );
48 $dbr = wfGetDB( DB_SLAVE
);
49 $this->mQueryConds
[] = 'LOWER(img_name)' . $dbr->buildLike( $dbr->anyString(),
50 strtolower( $nt->getDBkey() ), $dbr->anyString() );
54 parent
::__construct();
57 function getFieldNames() {
58 if ( !$this->mFieldNames
) {
60 $this->mFieldNames
= array(
61 'img_timestamp' => wfMsg( 'listfiles_date' ),
62 'img_name' => wfMsg( 'listfiles_name' ),
63 'img_user_text' => wfMsg( 'listfiles_user' ),
64 'img_size' => wfMsg( 'listfiles_size' ),
65 'img_description' => wfMsg( 'listfiles_description' ),
68 $this->mFieldNames
['count'] = wfMsg( 'listfiles_count' );
71 return $this->mFieldNames
;
74 function isFieldSortable( $field ) {
75 static $sortable = array( 'img_timestamp', 'img_name' );
76 if ( $field == 'img_size' ) {
77 # No index for both img_size and img_user_text
78 return !isset( $this->mQueryConds
['img_user_text'] );
80 return in_array( $field, $sortable );
83 function getQueryInfo() {
84 $tables = array( 'image' );
85 $fields = array_keys( $this->getFieldNames() );
86 $fields[] = 'img_user';
87 $options = $join_conds = array();
89 # Depends on $wgMiserMode
90 if( isset( $this->mFieldNames
['count'] ) ) {
91 $tables[] = 'oldimage';
93 # Need to rewrite this one
94 foreach ( $fields as &$field )
95 if ( $field == 'count' )
96 $field = 'COUNT(oi_archive_name) as count';
99 $dbr = wfGetDB( DB_SLAVE
);
100 if( $dbr->implicitGroupby() ) {
101 $options = array( 'GROUP BY' => 'img_name' );
103 $columnlist = implode( ',', preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) );
104 $options = array( 'GROUP BY' => "img_user, $columnlist" );
106 $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) );
111 'conds' => $this->mQueryConds
,
112 'options' => $options,
113 'join_conds' => $join_conds
117 function getDefaultSort() {
118 return 'img_timestamp';
121 function getStartBody() {
122 # Do a link batch query for user pages
123 if ( $this->mResult
->numRows() ) {
125 $this->mResult
->seek( 0 );
126 while ( $row = $this->mResult
->fetchObject() ) {
127 if ( $row->img_user
) {
128 $lb->add( NS_USER
, str_replace( ' ', '_', $row->img_user_text
) );
134 return parent
::getStartBody();
137 function formatValue( $field, $value ) {
140 case 'img_timestamp':
141 return htmlspecialchars( $wgLang->timeanddate( $value, true ) );
143 static $imgfile = null;
144 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
146 $name = $this->mCurrentRow
->img_name
;
147 $link = $this->getSkin()->linkKnown( Title
::makeTitle( NS_FILE
, $name ), htmlspecialchars( $value ) );
148 $image = wfLocalFile( $value );
149 $url = $image->getURL();
150 $download = Xml
::element('a', array( 'href' => $url ), $imgfile );
151 return "$link ($download)";
152 case 'img_user_text':
153 if ( $this->mCurrentRow
->img_user
) {
154 $link = $this->getSkin()->link(
155 Title
::makeTitle( NS_USER
, $value ),
156 htmlspecialchars( $value )
159 $link = htmlspecialchars( $value );
163 return $this->getSkin()->formatSize( $value );
164 case 'img_description':
165 return $this->getSkin()->commentBlock( $value );
167 return intval($value)+
1;
172 global $wgRequest, $wgScript, $wgMiserMode;
173 $search = $wgRequest->getText( 'ilsearch' );
175 $s = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' ) ) .
176 Xml
::openElement( 'fieldset' ) .
177 Xml
::element( 'legend', null, wfMsg( 'listfiles' ) ) .
178 Xml
::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
180 if ( !$wgMiserMode ) {
182 Xml
::inputLabel( wfMsg( 'listfiles_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
185 Xml
::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
186 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
187 Xml
::closeElement( 'fieldset' ) .
188 Xml
::closeElement( 'form' ) . "\n";
192 function getTableClass() {
193 return 'listfiles ' . parent
::getTableClass();
196 function getNavClass() {
197 return 'listfiles_nav ' . parent
::getNavClass();
200 function getSortHeaderClass() {
201 return 'listfiles_sort ' . parent
::getSortHeaderClass();