Fix #7989 : RSS feed sets white background color and may be unreadable
[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 'img_timestamp' => wfMsg( 'imagelist_date' ),
61 'img_name' => wfMsg( 'imagelist_name' ),
62 'img_user_text' => wfMsg( 'imagelist_user' ),
63 'img_size' => wfMsg( 'imagelist_size' ),
64 'img_description' => wfMsg( 'imagelist_description' ),
65 );
66 }
67 return $this->mFieldNames;
68 }
69
70 function isFieldSortable( $field ) {
71 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
72 return in_array( $field, $sortable );
73 }
74
75 function getQueryInfo() {
76 $fields = $this->getFieldNames();
77 $fields = array_keys( $fields );
78 $fields[] = 'img_user';
79 return array(
80 'tables' => 'image',
81 'fields' => $fields,
82 'conds' => $this->mQueryConds
83 );
84 }
85
86 function getDefaultSort() {
87 return 'img_timestamp';
88 }
89
90 function getStartBody() {
91 # Do a link batch query for user pages
92 if ( $this->mResult->numRows() ) {
93 $lb = new LinkBatch;
94 $this->mResult->seek( 0 );
95 while ( $row = $this->mResult->fetchObject() ) {
96 if ( $row->img_user ) {
97 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
98 }
99 }
100 $lb->execute();
101 }
102
103 # Cache messages used in each row
104 $this->mMessages['imgdesc'] = wfMsgHtml( 'imgdesc' );
105 $this->mMessages['imgfile'] = wfMsgHtml( 'imgfile' );
106
107 return parent::getStartBody();
108 }
109
110 function formatValue( $field, $value ) {
111 global $wgLang;
112 switch ( $field ) {
113 case 'img_timestamp':
114 return $wgLang->timeanddate( $value, true );
115 case 'img_name':
116 $name = $this->mCurrentRow->img_name;
117 $link = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ), $value );
118 $download = Xml::element('a', array( "href" => Image::imageUrl( $name ) ), $this->mMessages['imgfile'] );
119 return "$link ($download)";
120 case 'img_user_text':
121 if ( $this->mCurrentRow->img_user ) {
122 $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ),
123 htmlspecialchars( $value ) );
124 } else {
125 $link = htmlspecialchars( $value );
126 }
127 return $link;
128 case 'img_size':
129 return $this->getSkin()->formatSize( $value );
130 case 'img_description':
131 return $this->getSkin()->commentBlock( $value );
132 }
133 }
134
135 function getForm() {
136 global $wgRequest, $wgMiserMode;
137 $url = $this->getTitle()->escapeLocalURL();
138 $search = $wgRequest->getText( 'ilsearch' );
139 $s = "<form method=\"get\" action=\"$url\">\n" .
140 wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() );
141 if ( !$wgMiserMode ) {
142 $s .= "<br/>\n" .
143 Xml::inputLabel( wfMsg( 'imagelist_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
144 }
145 $s .= " " . Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ." \n" .
146 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
147 "</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 }
163
164 ?>