]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/SpecialNewimages.php
MediaWiki 1.5.8 (initial commit)
[autoinstallsdev/mediawiki.git] / includes / SpecialNewimages.php
1 <?php
2 /**
3  *
4  * @package MediaWiki
5  * @subpackage SpecialPage
6  */
7
8 /** */
9 require_once( 'ImageGallery.php' );
10
11 /**
12  *
13  */
14 function wfSpecialNewimages() {
15         global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
16         
17         $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
18         $dbr =& wfGetDB( DB_SLAVE );
19         $sk = $wgUser->getSkin();
20
21         /** If we were clever, we'd use this to cache. */
22         $latestTimestamp = wfTimestamp( TS_MW, $dbr->selectField(
23                 'image', 'img_timestamp',
24                 '', 'wfSpecialNewimages',
25                 array( 'ORDER BY' => 'img_timestamp DESC',
26                        'LIMIT' => 1 ) ) );
27         
28         /** Hardcode this for now. */
29         $limit = 48;
30         
31         $where = array();
32         if ( $wpIlMatch != '' ) {
33                 $nt = Title::newFromUrl( $wpIlMatch );
34                 if($nt ) {
35                         $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
36                         $m = str_replace( '%', "\\%", $m );
37                         $m = str_replace( '_', "\\_", $m );
38                         $where[] = "LCASE(img_name) LIKE '%{$m}%'";
39                 }
40         }       
41         
42         $invertSort = false;
43         if( $until = $wgRequest->getVal( 'until' ) ) {
44                 $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
45         }
46         if( $from = $wgRequest->getVal( 'from' ) ) {
47                 $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
48                 $invertSort = true;
49         }
50         
51         $res = $dbr->select( 'image',
52                 array( 'img_size', 'img_name', 'img_user', 'img_user_text',
53                        'img_description', 'img_timestamp' ),
54                 $where,
55                 'wfSpecialNewimages',
56                 array( 'LIMIT' => $limit + 1,
57                        'ORDER BY' => 'img_timestamp' . ( $invertSort ? '' : ' DESC' ) )
58         );
59
60         /**
61          * We have to flip things around to get the last N after a certain date
62          */
63         $images = array();
64         while ( $s = $dbr->fetchObject( $res ) ) {
65                 if( $invertSort ) {
66                         array_unshift( $images, $s );
67                 } else {
68                         array_push( $images, $s );
69                 }
70         }
71         $dbr->freeResult( $res );
72         
73         $gallery = new ImageGallery();
74         $firstTimestamp = null;
75         $lastTimestamp = null;
76         $shownImages = 0;
77         foreach( $images as $s ) {
78                 if( ++$shownImages > $limit ) {
79                         # One extra just to test for whether to show a page link;
80                         # don't actually show it.
81                         break;
82                 }
83                 
84                 $name = $s->img_name;
85                 $ut = $s->img_user_text;
86
87                 $nt = Title::newFromText( $name, NS_IMAGE );
88                 $img = Image::newFromTitle( $nt );
89                 $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
90
91                 $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp, true )."</i><br />\n" );
92                 
93                 $timestamp = wfTimestamp( TS_MW, $s->img_timestamp );
94                 if( empty( $firstTimestamp ) ) {
95                         $firstTimestamp = $timestamp;
96                 }
97                 $lastTimestamp = $timestamp;
98         }
99         
100         $bydate = wfMsg( 'bydate' );
101         $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
102         $text = wfMsg( "imagelisttext",
103                 "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>" );
104         $wgOut->addHTML( "<p>{$text}\n</p>" );
105
106         $sub = wfMsg( 'ilsubmit' );
107         $titleObj = Title::makeTitle( NS_SPECIAL, 'Newimages' );
108         $action = $titleObj->escapeLocalURL(  "limit={$limit}" );
109
110         $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
111           "{$action}\">" .
112           "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
113           htmlspecialchars( $wpIlMatch ) . "\" /> " .
114           "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
115         $here = $wgContLang->specialPage( 'Newimages' );
116
117         /**
118          * Paging controls...
119          */
120         $now = wfTimestampNow();
121         $date = $wgLang->timeanddate( $now );
122         $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from=' . $now );
123         
124         $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
125         if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
126                 $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp );
127         }
128         
129         $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
130         if( $shownImages > $limit && $lastTimestamp ) {
131                 $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp );
132         }
133         
134         $prevnext = '<p>' . wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) . '</p>';
135         $wgOut->addHTML( $prevnext );
136         
137         if( count( $images ) ) {
138                 $wgOut->addHTML( $gallery->toHTML() );
139                 $wgOut->addHTML( $prevnext );
140         } else {
141                 $wgOut->addWikiText( wfMsg( 'noimages' ) );
142         }
143 }
144
145 ?>