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