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