This is giving me a syntax error. It looks gross this way, but I can't think of any...
[lhc/web/wiklou.git] / includes / SpecialNewimages.php
index 37a487b..f81a70f 100644 (file)
@@ -1,51 +1,55 @@
 <?php
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 
-/** */
-require_once( 'ImageGallery.php' );
-
 /**
  *
  */
-function wfSpecialNewimages() {
-       global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest,
-              $wgGroupPermissions;
-       
+function wfSpecialNewimages( $par, $specialPage ) {
+       global $wgUser, $wgOut, $wgLang, $wgRequest, $wgGroupPermissions, $wgMiserMode;
+
        $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
-       $dbr =& wfGetDB( DB_SLAVE );
+       $dbr = wfGetDB( DB_SLAVE );
        $sk = $wgUser->getSkin();
+       $shownav = !$specialPage->including();
        $hidebots = $wgRequest->getBool('hidebots',1);
 
-       if($hidebots) { 
-               
+       $hidebotsql = '';
+       if ($hidebots) {
+
                /** Make a list of group names which have the 'bot' flag
-                   set. 
+                   set.
                */
                $botconds=array();
                foreach ($wgGroupPermissions as $groupname=>$perms) {
                        if(array_key_exists('bot',$perms) && $perms['bot']) {
                                $botconds[]="ug_group='$groupname'";
                        }
-               }               
-               $isbotmember=$dbr->makeList($botconds, LIST_OR);
-               
-               /** This join, in conjunction with WHERE ug_group
-                   IS NULL, returns only those rows from IMAGE 
-                   where the uploading user is not a member of
-                   a group which has the 'bot' permission set. 
-               */
-               $joinsql=' LEFT OUTER JOIN user_groups ON img_user=ug_user AND ('
-                 . $isbotmember.')';           
+               }
+
+               /* If not bot groups, do not set $hidebotsql */
+               if ($botconds) {
+                       $isbotmember=$dbr->makeList($botconds, LIST_OR);
+
+                       /** This join, in conjunction with WHERE ug_group
+                           IS NULL, returns only those rows from IMAGE
+                       where the uploading user is not a member of
+                       a group which has the 'bot' permission set.
+                       */
+                       $ug = $dbr->tableName('user_groups');
+                       $hidebotsql = " LEFT OUTER JOIN $ug ON img_user=ug_user AND ($isbotmember)";
+               }
        }
-       $sql='SELECT img_timestamp from image';
-       if($hidebots) {
-               $sql.=$joinsql.' WHERE ug_group IS NULL';
+
+       $image = $dbr->tableName('image');
+
+       $sql="SELECT img_timestamp from $image";
+       if ($hidebotsql) {
+               $sql .= "$hidebotsql WHERE ug_group IS NULL";
        }
-       $sql.=' ORDER BY img_timestamp DESC LIMIT 1';   
+       $sql.=' ORDER BY img_timestamp DESC LIMIT 1';
        $res = $dbr->query($sql, 'wfSpecialNewImages');
        $row = $dbr->fetchRow($res);
        if($row!==false) {
@@ -61,40 +65,48 @@ function wfSpecialNewimages() {
 
        /** Hardcode this for now. */
        $limit = 48;
-       
+
+       if ( $parval = intval( $par ) ) {
+               if ( $parval <= $limit && $parval > 0 ) {
+                       $limit = $parval;
+               }
+       }
+
        $where = array();
-       if ( $wpIlMatch != '' ) {
+       $searchpar = '';
+       if ( $wpIlMatch != '' && !$wgMiserMode) {
                $nt = Title::newFromUrl( $wpIlMatch );
                if($nt ) {
                        $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
                        $m = str_replace( '%', "\\%", $m );
                        $m = str_replace( '_', "\\_", $m );
-                       $where[] = "LCASE(img_name) LIKE '%{$m}%'";
+                       $where[] = "LOWER(img_name) LIKE '%{$m}%'";
+                       $searchpar = '&wpIlMatch=' . urlencode( $wpIlMatch );
                }
-       }       
-       
+       }
+
        $invertSort = false;
        if( $until = $wgRequest->getVal( 'until' ) ) {
-               $where[] = 'img_timestamp < ' . $dbr->timestamp( $until );
+               $where[] = "img_timestamp < '" . $dbr->timestamp( $until ) . "'";
        }
        if( $from = $wgRequest->getVal( 'from' ) ) {
-               $where[] = 'img_timestamp >= ' . $dbr->timestamp( $from );
+               $where[] = "img_timestamp >= '" . $dbr->timestamp( $from ) . "'";
                $invertSort = true;
        }
        $sql='SELECT img_size, img_name, img_user, img_user_text,'.
-            'img_description,img_timestamp FROM image';
+            "img_description,img_timestamp FROM $image";
 
-       if($hidebots) {
-               $sql.=$joinsql;
+       if($hidebotsql) {
+               $sql .= $hidebotsql;
                $where[]='ug_group IS NULL';
-       }       
+       }
        if(count($where)) {
-               $sql.=' WHERE '.$dbr->makeList($where, LIST_AND);       
+               $sql.=' WHERE '.$dbr->makeList($where, LIST_AND);
        }
        $sql.=' ORDER BY img_timestamp '. ( $invertSort ? '' : ' DESC' );
        $sql.=' LIMIT '.($limit+1);
        $res = $dbr->query($sql, 'wfSpecialNewImages');
+
        /**
         * We have to flip things around to get the last N after a certain date
         */
@@ -107,7 +119,7 @@ function wfSpecialNewimages() {
                }
        }
        $dbr->freeResult( $res );
-       
+
        $gallery = new ImageGallery();
        $firstTimestamp = null;
        $lastTimestamp = null;
@@ -118,41 +130,39 @@ function wfSpecialNewimages() {
                        # don't actually show it.
                        break;
                }
-               
+
                $name = $s->img_name;
                $ut = $s->img_user_text;
 
                $nt = Title::newFromText( $name, NS_IMAGE );
-               $img = Image::newFromTitle( $nt );
                $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
 
-               $gallery->add( $img, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp, true )."</i><br />\n" );
-               
+               $gallery->add( $nt, "$ul<br />\n<i>".$wgLang->timeanddate( $s->img_timestamp, true )."</i><br />\n" );
+
                $timestamp = wfTimestamp( TS_MW, $s->img_timestamp );
                if( empty( $firstTimestamp ) ) {
                        $firstTimestamp = $timestamp;
                }
                $lastTimestamp = $timestamp;
        }
-       
+
        $bydate = wfMsg( 'bydate' );
        $lt = $wgLang->formatNum( min( $shownImages, $limit ) );
-       $text = wfMsg( "imagelisttext",
-               "<strong>{$lt}</strong>", "<strong>{$bydate}</strong>" );
-       $wgOut->addHTML( "<p>{$text}\n</p>" );
+       if ($shownav) {
+               $text = wfMsgExt( 'imagelisttext', array('parse'), $lt, $bydate );
+               $wgOut->addHTML( $text . "\n" );
+       }
 
        $sub = wfMsg( 'ilsubmit' );
-       $titleObj = Title::makeTitle( NS_SPECIAL, 'Newimages' );
-       $action = $titleObj->escapeLocalURL(  "limit={$limit}" );
-       if(!$hidebots) {
-               $action.='&hidebots=0';
+       $titleObj = SpecialPage::getTitleFor( 'Newimages' );
+       $action = $titleObj->escapeLocalURL( $hidebots ? '' : 'hidebots=0' );
+       if ($shownav && !$wgMiserMode) {
+               $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
+                 "{$action}\">" .
+                       Xml::input( 'wpIlMatch', 20, $wpIlMatch ) . ' ' .
+                 Xml::submitButton( $sub, array( 'name' => 'wpIlSubmit' ) ) .
+                 "</form>" );
        }
-       $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
-         "{$action}\">" .
-         "<input type='text' size='20' name=\"wpIlMatch\" value=\"" .
-         htmlspecialchars( $wpIlMatch ) . "\" /> " .
-         "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
-       $here = $wgContLang->specialPage( 'Newimages' );
 
        /**
         * Paging controls...
@@ -165,31 +175,33 @@ function wfSpecialNewimages() {
                $botpar='';
        }
        $now = wfTimestampNow();
-       $date = $wgLang->timeanddate( $now );
-       $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsg( 'rclistfrom', $date ), 'from='.$now.$botpar );
-       
-       $botLink = $sk->makeKnownLinkObj($titleObj, wfMsg( 'showhidebots', ($hidebots ? wfMsg('show') : wfMsg('hide'))),'hidebots='.($hidebots ? '0' : '1'));
-       
-       $prevLink = wfMsg( 'prevn', $wgLang->formatNum( $limit ) );
+       $date = $wgLang->timeanddate( $now, true );
+       $dateLink = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml( 'sp-newimages-showfrom', $date ), 'from='.$now.$botpar.$searchpar );
+
+       $botLink = $sk->makeKnownLinkObj($titleObj, wfMsgHtml( 'showhidebots', ($hidebots ? wfMsgHtml('show') : wfMsgHtml('hide'))),'hidebots='.($hidebots ? '0' : '1').$searchpar);
+
+       $prevLink = wfMsgHtml( 'prevn', $wgLang->formatNum( $limit ) );
        if( $firstTimestamp && $firstTimestamp != $latestTimestamp ) {
-               $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar );
+               $prevLink = $sk->makeKnownLinkObj( $titleObj, $prevLink, 'from=' . $firstTimestamp . $botpar . $searchpar );
        }
-       
-       $nextLink = wfMsg( 'nextn', $wgLang->formatNum( $limit ) );
+
+       $nextLink = wfMsgHtml( 'nextn', $wgLang->formatNum( $limit ) );
        if( $shownImages > $limit && $lastTimestamp ) {
-               $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar );
+               $nextLink = $sk->makeKnownLinkObj( $titleObj, $nextLink, 'until=' . $lastTimestamp.$botpar.$searchpar );
        }
-       
-       $prevnext = '<p>' . $botLink . ' '. wfMsg( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
-       
-       $wgOut->addHTML( $prevnext );
-       
+
+       $prevnext = '<p>' . $botLink . ' '. wfMsgHtml( 'viewprevnext', $prevLink, $nextLink, $dateLink ) .'</p>';
+
+       if ($shownav)
+               $wgOut->addHTML( $prevnext );
+
        if( count( $images ) ) {
                $wgOut->addHTML( $gallery->toHTML() );
-               $wgOut->addHTML( $prevnext );
+               if ($shownav)
+                       $wgOut->addHTML( $prevnext );
        } else {
                $wgOut->addWikiText( wfMsg( 'noimages' ) );
        }
 }
 
-?>
+