Added placeholders for text injection by hooks to EditPage.php
[lhc/web/wiklou.git] / includes / SpecialNewimages.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialNewimages( $par, $specialPage ) {
12 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgGroupPermissions;
13
14 $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
15 $dbr =& wfGetDB( DB_SLAVE );
16 $sk = $wgUser->getSkin();
17 $shownav = !$specialPage->including();
18 $hidebots = $wgRequest->getBool('hidebots',1);
19
20 $hidebotsql = '';
21 if ($hidebots) {
22
23 /** Make a list of group names which have the 'bot' flag
24 set.
25 */
26 $botconds=array();
27 foreach ($wgGroupPermissions as $groupname=>$perms) {
28 if(array_key_exists('bot',$perms) && $perms['bot']) {
29 $botconds[]="ug_group='$groupname'";
30 }
31 }
32
33 /* If not bot groups, do not set $hidebotsql */
34 if ($botconds) {
35 $isbotmember=$dbr->makeList($botconds, LIST_OR);
36
37 /** This join, in conjunction with WHERE ug_group
38 IS NULL, returns only those rows from IMAGE
39 where the uploading user is not a member of
40 a group which has the 'bot' permission set.
41 */
42 $ug = $dbr->tableName('user_groups');
43 $hidebotsql = " LEFT OUTER JOIN $ug ON img_user=ug_user AND ($isbotmember)";
44 }
45 }
46
47 $image = $dbr->tableName('image');
48
49 $sql="SELECT img_timestamp from $image";
50 if ($hidebotsql) {
51 $sql .= "$hidebotsql WHERE ug_group IS NULL";
52 }
53 $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
54 $res = $dbr->query($sql, 'wfSpecialNewImages');
55 $row = $dbr->fetchRow($res);
56 if($row!==false) {
57 $ts=$row[0];
58 } else {
59 $ts=false;
60 }
61 $dbr->freeResult($res);
62 $sql='';
63
64 /** If we were clever, we'd use this to cache. */
65 $latestTimestamp = wfTimestamp( TS_MW, $ts);
66
67 /** Hardcode this for now. */
68 $limit = 48;
69
70 if ( $parval = intval( $par ) )
71 if ( $parval <= $limit && $parval > 0 )
72 $limit = $parval;
73
74 $where = array();
75 $searchpar = '';
76 if ( $wpIlMatch != '' ) {
77 $nt = Title::newFromUrl( $wpIlMatch );
78 if($nt ) {
79 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
80 $m = str_replace( '%', "\\%", $m );
81 $m = str_replace( '_', "\\_", $m );
82 $where[] = "LCASE(img_name) LIKE '%{$m}%'";
83 $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
84 }
85 }
86
87 $invertSort = false;
88 if( $until = $wgRequest->getVal( 'until' ) ) {
89 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
90 }
91 if( $from = $wgRequest->getVal( 'from' ) ) {
92 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
93 $invertSort = true;
94 }
95 $sql='SELECT img_size, img_name, img_user, img_user_text,'.
96 "img_description,img_timestamp FROM $image";
97
98 if($hidebotsql) {
99 $sql .= $hidebotsql;
100 $where[]='ug_group IS NULL';
101 }
102 if(count($where)) {
103 $sql.=' WHERE '.$dbr->makeList($where, LIST_AND);
104 }
105 $sql.=' ORDER BY img_timestamp '. ( $invertSort ? '' : ' DESC' );
106 $sql.=' LIMIT '.($limit+1);
107 $res = $dbr->query($sql, 'wfSpecialNewImages');
108
109 /**
110 * We have to flip things around to get the last N after a certain date
111 */
112 $images = array();
113 while ( $s = $dbr->fetchObject( $res ) ) {
114 if( $invertSort ) {
115 array_unshift( $images, $s );
116 } else {
117 array_push( $images, $s );
118 }
119 }
120 $dbr->freeResult( $res );
121
122 $gallery = new ImageGallery();
123 $firstTimestamp = null;
124 $lastTimestamp = null;
125 $shownImages = 0;
126 foreach( $images as $s ) {
127 if( ++$shownImages > $limit ) {
128 # One extra just to test for whether to show a page link;
129 # don't actually show it.
130 break;
131 }
132
133 $name = $s->img_name;
134 $ut = $s->img_user_text;
135
136 $nt = Title::newFromText( $name, NS_IMAGE );
137 $img = new Image( $nt );
138 $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
139
140 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp, true )."</i><br />\n" );
141
142 $timestamp = wfTimestamp( TS_MW, $s->img_timestamp );
143 if( empty( $firstTimestamp ) ) {
144 $firstTimestamp = $timestamp;
145 }
146 $lastTimestamp = $timestamp;
147 }
148
149 $bydate = wfMsg( 'bydate' );
150 $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
151 if ($shownav) {
152 $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
153 $wgOut->addHTML( $text . "\n" );
154 }
155
156 $sub = wfMsg( 'ilsubmit' );
157 $titleObj = SpecialPage::getTitleFor( 'Newimages' );
158 $action = $titleObj->escapeLocalURL( $hidebots ? '' : 'hidebots=0' );
159 if ($shownav) {
160 $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
161 "{$action}\">" .
162 "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
163 htmlspecialchars( $wpIlMatch ) . "\" /> " .
164 "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
165 }
166 $here = $wgContLang->specialPage( 'Newimages' );
167
168 /**
169 * Paging controls...
170 */
171
172 # If we change bot visibility, this needs to be carried along.
173 if(!$hidebots) {
174 $botpar='&hidebots=0';
175 } else {
176 $botpar='';
177 }
178 $now = wfTimestampNow();
179 $date = $wgLang->timeanddate( $now, true );
180 $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'sp-newimages-showfrom', $date ), 'from='.$now.$botpar.$searchpar );
181
182 $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ? wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ? '0' : '1').$searchpar);
183
184 $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
185 if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
186 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
187 }
188
189 $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
190 if( $shownImages > $limit && $lastTimestamp ) {
191 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
192 }
193
194 $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
195
196 if ($shownav)
197 $wgOut->addHTML( $prevnext );
198
199 if( count( $images ) ) {
200 $wgOut->addHTML( $gallery->toHTML() );
201 if ($shownav)
202 $wgOut->addHTML( $prevnext );
203 } else {
204 $wgOut->addWikiText( wfMsg( 'noimages' ) );
205 }
206 }
207
208 ?>