* (bug 1938) Fix normalization of character references in link text and
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
index 459b362..b889cf7 100644 (file)
@@ -1,64 +1,73 @@
-<?
-
-function wfSpecialImagelist()
-{
-       global $wgUser, $wgOut, $wgLang, $sort, $limit;
-       global $wpIlMatch, $wpIlSubmit;
-
-       $fields = array( 'wpIlMatch' );
-       wfCleanFormFields( $fields );
-
+<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ *
+ */
+function wfSpecialImagelist() {
+       global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest;
+       
+       $sort = $wgRequest->getVal( 'sort' );
+       $wpIlMatch = $wgRequest->getText( 'wpIlMatch' );
+       $dbr =& wfGetDB( DB_SLAVE );
+       $image = $dbr->tableName( 'image' );
        $sql = "SELECT img_size,img_name,img_user,img_user_text," .
-         "img_description,img_timestamp FROM image";
+         "img_description,img_timestamp FROM $image";
 
        $byname = wfMsg( "byname" );
        $bydate = wfMsg( "bydate" );
        $bysize = wfMsg( "bysize" );
 
-       if ( "bysize" == $sort ) {
-               $sql .= " ORDER BY img_size DESC";
-               $st = $bysize;
-       } else if ( "byname" == $sort ) {
-               if ( $wpIlMatch ) {
-                       $nt = Title::newFromUrl( $wpIlMatch );
-                       $m = wfStrencode( strtolower( $nt->getDBkey() ) );
+       if ( !empty( $wpIlMatch ) ) {
+               $nt = Title::newFromUrl( $wpIlMatch );
+               if($nt ) {
+                       $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
                        $m = str_replace( "%", "\\%", $m );
                        $m = str_replace( "_", "\\_", $m );
                        $sql .= " WHERE LCASE(img_name) LIKE '%{$m}%'";
                }
+       }
+       if ( "bysize" == $sort ) {
+               $sql .= " ORDER BY img_size DESC";
+               $st = $bysize;
+       } else if ( "byname" == $sort ) {
                $sql .= " ORDER BY img_name";
                $st = $byname;
        } else {
+               $sort = "bydate";
                $sql .= " ORDER BY img_timestamp DESC";
                $st = $bydate;
        }
-       if ( ! isset( $limit ) ) { $limit = 50; }
+       list( $limit, $offset ) = wfCheckLimits( 50 );
        if ( 0 == $limit ) {
-               $lt = wfMsg( "all" );
+               $lt = wfMsg( 'imagelistall' );
        } else {
-               $lt = "${limit}";
+               $lt = $wgLang->formatNum( "${limit}" );
                $sql .= " LIMIT {$limit}";
        }
-       $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "\n" );
+       $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\n" );
 
-       $text = str_replace( "$1", "<strong>{$lt}</strong>",
-         wfMsg( "imagelisttext" ) );
-       $text = str_replace( "$2", "<strong>{$st}</strong>", $text );
-       $wgOut->addHTML( "<p>{$text}\n<p>" );
+       $text = wfMsg( "imagelisttext",
+               "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
+       $wgOut->addHTML( "<p>{$text}\n</p>" );
 
        $sk = $wgUser->getSkin();
        $cap = wfMsg( "ilshowmatch" );
        $sub = wfMsg( "ilsubmit" );
-       $action = wfLocalUrlE( $wgLang->specialPage( "Imagelist" ),
-         "sort=byname&limit={$limit}" );
+       $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
+       $action = $titleObj->escapeLocalURL(  "sort={$sort}&limit={$limit}" );
 
        $wgOut->addHTML( "<form id=\"imagesearch\" method=\"post\" action=\"" .
          "{$action}\">" .
-         "{$cap}: <input type=text size=8 name=\"wpIlMatch\" value=\"\"> " .
-         "<input type=submit name=\"wpIlSubmit\" value=\"{$sub}\"></form>" );
-
+         "{$cap}: <input type='text' size='8' name=\"wpIlMatch\" value=\"" .
+         htmlspecialchars( $wpIlMatch ) . "\" /> " .
+         "<input type='submit' name=\"wpIlSubmit\" value=\"{$sub}\" /></form>" );
        $nums = array( 50, 100, 250, 500 );
-       $here = $wgLang->specialPage( "Imagelist" );
+       $here = Title::makeTitle( NS_SPECIAL, 'Imagelist' );
 
        $fill = "";
        $first = true;
@@ -66,12 +75,11 @@ function wfSpecialImagelist()
                if ( ! $first ) { $fill .= " | "; }
                $first = false;
 
-               $fill .= $sk->makeKnownLink( $here, "{$num}",
-                 "sort=bysize&limit={$num}" );
+               $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
+                 "sort=byname&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
        }
-       $text = str_replace( "$1", $fill, wfMsg( "showlast" ) );
-       $text = str_replace( "$2", $bysize, $text );
-       $wgOut->addHTML( "{$text}<br>\n" );
+       $text = wfMsg( "showlast", $fill, $byname );
+       $wgOut->addHTML( "<p>{$text}<br />\n" );
 
        $fill = "";
        $first = true;
@@ -79,37 +87,49 @@ function wfSpecialImagelist()
                if ( ! $first ) { $fill .= " | "; }
                $first = false;
 
-               $fill .= $sk->makeKnownLink( $here, $num,
-                 "sort=bydate&limit={$num}" );
+               $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
+                 "sort=bysize&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
        }
-       $text = str_replace( "$1", $fill, wfMsg( "showlast" ) );
-       $text = str_replace( "$2", $bydate, $text );
-       $wgOut->addHTML( "{$text}<br>\n<p>" );
+       $text = wfMsg( "showlast", $fill, $bysize );
+       $wgOut->addHTML( "{$text}<br />\n" );
 
-       $res = wfQuery( $sql, "wfSpecialImagelist" );
-       while ( $s = wfFetchObject( $res ) ) {
+       $fill = "";
+       $first = true;
+       foreach ( $nums as $num ) {
+               if ( ! $first ) { $fill .= " | "; }
+               $first = false;
+
+               $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
+                 "sort=bydate&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
+       }
+       $text = wfMsg( "showlast", $fill, $bydate );
+       $wgOut->addHTML( "{$text}</p>\n<p>" );
+
+       $res = $dbr->query( $sql, "wfSpecialImagelist" );
+       while ( $s = $dbr->fetchObject( $res ) ) {
                $name = $s->img_name;
                $ut = $s->img_user_text;
-               if ( 0 == $s->img_user ) { $ul = $ut; }
-               else { $ul = $sk->makeLink( $wgLang->getNsText(
-                 Namespace::getUser() ) . ":{$ut}", $ut ); }
+               if ( 0 == $s->img_user ) {
+                       $ul = $ut;
+               } else {
+                       $ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
+               }
 
-               $ilink = "<a href=\"" . wfImageUrl( $name ) .
-                 "\">{$name}</a>";
+               $ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
+                 "\">" . htmlspecialchars( $name ) . "</a>";
 
-               $nb = str_replace( "$1", $s->img_size, wfMsg( "nbytes" ) );
+               $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
                $l = "(" .
-                 $sk->makeKnownLink( $wgLang->getNsText(
-                 Namespace::getImage() ) . ":{$name}", wfMsg( "imgdesc" ) ) .
+                 $sk->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ),
+                 wfMsg( "imgdesc" ) ) .
                  ") {$ilink} . . {$nb} . . {$ul} . . " .
                  $wgLang->timeanddate( $s->img_timestamp, true );
 
-               if ( "" != $s->img_description ) {
-                       $l .= " <em>({$s->img_description})</em>";
-               }
-               $wgOut->addHTML( "{$l}<br>\n" );
+               $l .= $sk->commentBlock( $s->img_description );
+               $wgOut->addHTML( "{$l}<br />\n" );
        }
-       wfFreeResult( $res );
+       $wgOut->addHTML( "</p>" );
+       $dbr->freeResult( $res );
 }
 
 ?>