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