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