* Add exception hooks to output pretty messages
[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 $image = wfLocalFile( $value );
119 $url = $image->getURL();
120 $download = Xml::element('a', array( "href" => $url ), $this->mMessages['imgfile'] );
121 return "$link ($download)";
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 $this->getSkin()->formatSize( $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 $search = $wgRequest->getText( 'ilsearch' );
141 $s = "<form method=\"get\" action=\"$url\">\n" .
142 wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() );
143 if ( !$wgMiserMode ) {
144 $s .= "<br/>\n" .
145 Xml::inputLabel( wfMsg( 'imagelist_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
146 }
147 $s .= " " . Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ." \n" .
148 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
149 "</form>\n";
150 return $s;
151 }
152
153 function getTableClass() {
154 return 'imagelist ' . parent::getTableClass();
155 }
156
157 function getNavClass() {
158 return 'imagelist_nav ' . parent::getNavClass();
159 }
160
161 function getSortHeaderClass() {
162 return 'imagelist_sort ' . parent::getSortHeaderClass();
163 }
164 }
165
166