* Reorganised the includes directory, creating subdirectories db, parser and specials
[lhc/web/wiklou.git] / includes / specials / Imagelist.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 function wfSpecialImagelist() {
11 global $wgOut;
12
13 $pager = new ImageListPager;
14
15 $limit = $pager->getForm();
16 $body = $pager->getBody();
17 $nav = $pager->getNavigationBar();
18 $wgOut->addHTML( "$limit<br />\n$body<br />\n$nav" );
19 }
20
21 /**
22 * @ingroup SpecialPage Pager
23 */
24 class ImageListPager extends TablePager {
25 var $mFieldNames = null;
26 var $mQueryConds = array();
27
28 function __construct() {
29 global $wgRequest, $wgMiserMode;
30 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
31 $this->mDefaultDirection = true;
32 } else {
33 $this->mDefaultDirection = false;
34 }
35 $search = $wgRequest->getText( 'ilsearch' );
36 if ( $search != '' && !$wgMiserMode ) {
37 $nt = Title::newFromUrl( $search );
38 if( $nt ) {
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}%'" );
44 }
45 }
46
47 parent::__construct();
48 }
49
50 function getFieldNames() {
51 if ( !$this->mFieldNames ) {
52 $this->mFieldNames = array(
53 'img_timestamp' => wfMsg( 'imagelist_date' ),
54 'img_name' => wfMsg( 'imagelist_name' ),
55 'img_user_text' => wfMsg( 'imagelist_user' ),
56 'img_size' => wfMsg( 'imagelist_size' ),
57 'img_description' => wfMsg( 'imagelist_description' ),
58 );
59 }
60 return $this->mFieldNames;
61 }
62
63 function isFieldSortable( $field ) {
64 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
65 return in_array( $field, $sortable );
66 }
67
68 function getQueryInfo() {
69 $fields = $this->getFieldNames();
70 $fields = array_keys( $fields );
71 $fields[] = 'img_user';
72 return array(
73 'tables' => 'image',
74 'fields' => $fields,
75 'conds' => $this->mQueryConds
76 );
77 }
78
79 function getDefaultSort() {
80 return 'img_timestamp';
81 }
82
83 function getStartBody() {
84 # Do a link batch query for user pages
85 if ( $this->mResult->numRows() ) {
86 $lb = new LinkBatch;
87 $this->mResult->seek( 0 );
88 while ( $row = $this->mResult->fetchObject() ) {
89 if ( $row->img_user ) {
90 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
91 }
92 }
93 $lb->execute();
94 }
95
96 return parent::getStartBody();
97 }
98
99 function formatValue( $field, $value ) {
100 global $wgLang;
101 switch ( $field ) {
102 case 'img_timestamp':
103 return $wgLang->timeanddate( $value, true );
104 case 'img_name':
105 static $imgfile = null;
106 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
107
108 $name = $this->mCurrentRow->img_name;
109 $link = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ), $value );
110 $image = wfLocalFile( $value );
111 $url = $image->getURL();
112 $download = Xml::element('a', array( 'href' => $url ), $imgfile );
113 return "$link ($download)";
114 case 'img_user_text':
115 if ( $this->mCurrentRow->img_user ) {
116 $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ),
117 htmlspecialchars( $value ) );
118 } else {
119 $link = htmlspecialchars( $value );
120 }
121 return $link;
122 case 'img_size':
123 return $this->getSkin()->formatSize( $value );
124 case 'img_description':
125 return $this->getSkin()->commentBlock( $value );
126 }
127 }
128
129 function getForm() {
130 global $wgRequest, $wgMiserMode;
131 $search = $wgRequest->getText( 'ilsearch' );
132
133 $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-imagelist-form' ) ) .
134 Xml::openElement( 'fieldset' ) .
135 Xml::element( 'legend', null, wfMsg( 'imagelist' ) ) .
136 Xml::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
137
138 if ( !$wgMiserMode ) {
139 $s .= "<br />\n" .
140 Xml::inputLabel( wfMsg( 'imagelist_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
141 }
142 $s .= ' ' .
143 Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
144 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
145 Xml::closeElement( 'fieldset' ) .
146 Xml::closeElement( 'form' ) . "\n";
147 return $s;
148 }
149
150 function getTableClass() {
151 return 'imagelist ' . parent::getTableClass();
152 }
153
154 function getNavClass() {
155 return 'imagelist_nav ' . parent::getNavClass();
156 }
157
158 function getSortHeaderClass() {
159 return 'imagelist_sort ' . parent::getSortHeaderClass();
160 }
161 }