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 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
41 $m = str_replace( "%", "\\%", $m );
42 $m = str_replace( "_", "\\_", $m );
43 $this->mQueryConds
= array( "LOWER(img_name) LIKE '%{$m}%'" );
47 parent
::__construct();
50 function getFieldNames() {
51 if ( !$this->mFieldNames
) {
53 $this->mFieldNames
= array(
54 'img_timestamp' => wfMsg( 'listfiles_date' ),
55 'img_name' => wfMsg( 'listfiles_name' ),
56 'img_user_text' => wfMsg( 'listfiles_user' ),
57 'img_size' => wfMsg( 'listfiles_size' ),
58 'img_description' => wfMsg( 'listfiles_description' ),
61 $this->mFieldNames
['COUNT(oi_archive_name)'] = wfMsg( 'listfiles_count' );
64 return $this->mFieldNames
;
67 function isFieldSortable( $field ) {
68 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
69 return in_array( $field, $sortable );
72 function getQueryInfo() {
73 $tables = array( 'image' );
74 $fields = array_keys( $this->getFieldNames() );
75 $fields[] = 'img_user';
76 $options = $join_conds = array();
77 # Depends on $wgMiserMode
78 if( isset($this->mFieldNames
['COUNT(oi_archive_name)']) ) {
79 $tables[] = 'oldimage';
80 $options = array('GROUP BY' => 'img_name');
81 $join_conds = array('oldimage' => array('LEFT JOIN','oi_name = img_name') );
86 'conds' => $this->mQueryConds
,
87 'options' => $options,
88 'join_conds' => $join_conds
92 function getDefaultSort() {
93 return 'img_timestamp';
96 function getStartBody() {
97 # Do a link batch query for user pages
98 if ( $this->mResult
->numRows() ) {
100 $this->mResult
->seek( 0 );
101 while ( $row = $this->mResult
->fetchObject() ) {
102 if ( $row->img_user
) {
103 $lb->add( NS_USER
, str_replace( ' ', '_', $row->img_user_text
) );
109 return parent
::getStartBody();
112 function formatValue( $field, $value ) {
115 case 'img_timestamp':
116 return $wgLang->timeanddate( $value, true );
118 static $imgfile = null;
119 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
121 $name = $this->mCurrentRow
->img_name
;
122 $link = $this->getSkin()->makeKnownLinkObj( Title
::makeTitle( NS_FILE
, $name ), $value );
123 $image = wfLocalFile( $value );
124 $url = $image->getURL();
125 $download = Xml
::element('a', array( 'href' => $url ), $imgfile );
126 return "$link ($download)";
127 case 'img_user_text':
128 if ( $this->mCurrentRow
->img_user
) {
129 $link = $this->getSkin()->makeLinkObj( Title
::makeTitle( NS_USER
, $value ),
130 htmlspecialchars( $value ) );
132 $link = htmlspecialchars( $value );
136 return $this->getSkin()->formatSize( $value );
137 case 'img_description':
138 return $this->getSkin()->commentBlock( $value );
139 case 'COUNT(oi_archive_name)':
140 return intval($value)+
1;
145 global $wgRequest, $wgMiserMode;
146 $search = $wgRequest->getText( 'ilsearch' );
148 $s = Xml
::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-listfiles-form' ) ) .
149 Xml
::openElement( 'fieldset' ) .
150 Xml
::element( 'legend', null, wfMsg( 'listfiles' ) ) .
151 Xml
::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
153 if ( !$wgMiserMode ) {
155 Xml
::inputLabel( wfMsg( 'listfiles_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
158 Xml
::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
159 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
160 Xml
::closeElement( 'fieldset' ) .
161 Xml
::closeElement( 'form' ) . "\n";
165 function getTableClass() {
166 return 'listfiles ' . parent
::getTableClass();
169 function getNavClass() {
170 return 'listfiles_nav ' . parent
::getNavClass();
173 function getSortHeaderClass() {
174 return 'listfiles_sort ' . parent
::getSortHeaderClass();