Some styling for Special:Imagelist courtesy of Splarka
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialImagelist() {
12 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgMiserMode;
13
14 $pager = new ImageListPager;
15
16 $limit = $pager->getForm();
17 $body = $pager->getBody();
18 $nav = $pager->getNavigationBar();
19 $wgOut->addHTML( "
20 $limit
21 <br/>
22 $body
23 $nav" );
24 }
25
26 class ImageListPager extends TablePager {
27 var $mFieldNames = null;
28 var $mMessages = array();
29 var $mQueryConds = array();
30
31 function __construct() {
32 global $wgRequest, $wgMiserMode;
33 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
34 $this->mDefaultDirection = true;
35 } else {
36 $this->mDefaultDirection = false;
37 }
38 $search = $wgRequest->getText( 'ilsearch' );
39 if ( $search != '' && !$wgMiserMode ) {
40 $nt = Title::newFromUrl( $search );
41 if( $nt ) {
42 $dbr =& wfGetDB( DB_SLAVE );
43 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
44 $m = str_replace( "%", "\\%", $m );
45 $m = str_replace( "_", "\\_", $m );
46 $this->mQueryConds = array( "LCASE(img_name) LIKE '%{$m}%'" );
47 }
48 }
49
50 parent::__construct();
51 }
52
53 function getFieldNames() {
54 if ( !$this->mFieldNames ) {
55 $this->mFieldNames = array(
56 'links' => '',
57 'img_timestamp' => wfMsg( 'imagelist_date' ),
58 'img_name' => wfMsg( 'imagelist_name' ),
59 'img_user_text' => wfMsg( 'imagelist_user' ),
60 'img_size' => wfMsg( 'imagelist_size' ),
61 'img_description' => wfMsg( 'imagelist_description' ),
62 );
63 }
64 return $this->mFieldNames;
65 }
66
67 function isFieldSortable( $field ) {
68 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
69 return in_array( $field, $sortable );
70 }
71
72 function getQueryInfo() {
73 $fields = $this->getFieldNames();
74 unset( $fields['links'] );
75 $fields = array_keys( $fields );
76 $fields[] = 'img_user';
77 return array(
78 'tables' => 'image',
79 'fields' => $fields,
80 'conds' => $this->mQueryConds
81 );
82 }
83
84 function getDefaultSort() {
85 return 'img_timestamp';
86 }
87
88 function getStartBody() {
89 # Do a link batch query for user pages
90 if ( $this->mResult->numRows() ) {
91 $lb = new LinkBatch;
92 $this->mResult->seek( 0 );
93 while ( $row = $this->mResult->fetchObject() ) {
94 if ( $row->img_user ) {
95 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
96 }
97 }
98 $lb->execute();
99 }
100
101 # Cache messages used in each row
102 $this->mMessages['imgdesc'] = wfMsgHtml( 'imgdesc' );
103 $this->mMessages['imgfile'] = wfMsgHtml( 'imgfile' );
104
105 return parent::getStartBody();
106 }
107
108 function formatValue( $field, $value ) {
109 global $wgLang;
110 switch ( $field ) {
111 case 'links':
112 $name = $this->mCurrentRow->img_name;
113 $ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
114 "\">" . $this->mMessages['imgfile'] . "</a>";
115 $desc = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ),
116 $this->mMessages['imgdesc'] );
117 return "$desc | $ilink";
118 case 'img_timestamp':
119 return $wgLang->timeanddate( $value, true );
120 case 'img_name':
121 return htmlspecialchars( $value );
122 case 'img_user_text':
123 if ( $this->mCurrentRow->img_user ) {
124 $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ),
125 htmlspecialchars( $value ) );
126 } else {
127 $link = htmlspecialchars( $value );
128 }
129 return $link;
130 case 'img_size':
131 return $wgLang->formatNum( $value );
132 case 'img_description':
133 return $this->getSkin()->commentBlock( $value );
134 }
135 }
136
137 function getForm() {
138 global $wgRequest, $wgMiserMode;
139 $url = $this->getTitle()->escapeLocalURL();
140 $msgSubmit = wfMsgHtml( 'table_pager_limit_submit' );
141 $msgSearch = wfMsgHtml( 'imagelist_search_for' );
142 $search = $wgRequest->getText( 'ilsearch' );
143 $encSearch = htmlspecialchars( $search );
144 $s = "<form method=\"get\" action=\"$url\">\n" .
145 wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() );
146 if ( !$wgMiserMode ) {
147 $s .= "<br/>\n" . $msgSearch .
148 " <input type=\"text\" size=\"20\" name=\"ilsearch\" value=\"$encSearch\"/><br/>\n";
149 }
150 $s .= " <input type=\"submit\" value=\"$msgSubmit\"/>\n" .
151 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
152 "</form>\n";
153 return $s;
154 }
155
156 function getTableClass() {
157 return 'imagelist ' . parent::getTableClass();
158 }
159
160 function getNavClass() {
161 return 'imagelist_nav ' . parent::getNavClass();
162 }
163
164 function getSortHeaderClass() {
165 return 'imagelist_sort ' . parent::getSortHeaderClass();
166 }
167 }
168
169 ?>