API: Requesting a token you aren't allowed to request no longer dies with an error...
[lhc/web/wiklou.git] / includes / SpecialImagelist.php
index 69004be..3d449b5 100644 (file)
@@ -1,8 +1,7 @@
 <?php
 /**
- *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @file
+ * @ingroup SpecialPage
  */
 
 /**
@@ -16,16 +15,14 @@ function wfSpecialImagelist() {
        $limit = $pager->getForm();
        $body = $pager->getBody();
        $nav = $pager->getNavigationBar();
-       $wgOut->addHTML( "
-               $limit
-               <br/>
-               $body
-               $nav" );
+       $wgOut->addHTML( "$limit<br />\n$body<br />\n$nav" );
 }
 
+/**
+ * @ingroup SpecialPage Pager
+ */
 class ImageListPager extends TablePager {
        var $mFieldNames = null;
-       var $mMessages = array();
        var $mQueryConds = array();
 
        function __construct() {
@@ -39,11 +36,11 @@ class ImageListPager extends TablePager {
                if ( $search != '' && !$wgMiserMode ) {
                        $nt = Title::newFromUrl( $search );
                        if( $nt ) {
-                               $dbr =& wfGetDB( DB_SLAVE );
+                               $dbr = wfGetDB( DB_SLAVE );
                                $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
                                $m = str_replace( "%", "\\%", $m );
                                $m = str_replace( "_", "\\_", $m );
-                               $this->mQueryConds = array( "LCASE(img_name) LIKE '%{$m}%'" );
+                               $this->mQueryConds = array( "LOWER(img_name) LIKE '%{$m}%'" );
                        }
                }
 
@@ -53,7 +50,6 @@ class ImageListPager extends TablePager {
        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' ),
@@ -71,7 +67,6 @@ class ImageListPager extends TablePager {
 
        function getQueryInfo() {
                $fields = $this->getFieldNames();
-               unset( $fields['links'] );
                $fields = array_keys( $fields );
                $fields[] = 'img_user';
                return array(
@@ -98,37 +93,34 @@ class ImageListPager extends TablePager {
                        $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 );
+                               static $imgfile = null;
+                               if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
+
+                               $name = $this->mCurrentRow->img_name;
+                               $link = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ), $value );
+                               $image = wfLocalFile( $value );
+                               $url = $image->getURL();
+                               $download = Xml::element('a', array( 'href' => $url ), $imgfile );
+                               return "$link ($download)";
                        case 'img_user_text':
                                if ( $this->mCurrentRow->img_user ) {
-                                       $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ), 
+                                       $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ),
                                                htmlspecialchars( $value ) );
                                } else {
                                        $link = htmlspecialchars( $value );
                                }
                                return $link;
                        case 'img_size':
-                               return $wgLang->formatNum( $value );
+                               return $this->getSkin()->formatSize( $value );
                        case 'img_description':
                                return $this->getSkin()->commentBlock( $value );
                }
@@ -136,20 +128,22 @@ class ImageListPager extends TablePager {
 
        function getForm() {
                global $wgRequest, $wgMiserMode;
-               $url = $this->getTitle()->escapeLocalURL();
-               $msgSubmit = wfMsgHtml( 'table_pager_limit_submit' );
-               $msgSearch = wfMsgHtml( 'imagelist_search_for' );
                $search = $wgRequest->getText( 'ilsearch' );
-               $encSearch = htmlspecialchars( $search );
-               $s = "<form method=\"get\" action=\"$url\">\n" . 
-                       wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() );
+
+               $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-imagelist-form' ) ) .
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'imagelist' ) ) .
+                       Xml::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
+
                if ( !$wgMiserMode ) {
-                       $s .= "<br/>\n" . $msgSearch .
-                               " <input type=\"text\" size=\"20\" name=\"ilsearch\" value=\"$encSearch\"/><br/>\n";
+                       $s .= "<br />\n" .
+                               Xml::inputLabel( wfMsg( 'imagelist_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
                }
-               $s .= " <input type=\"submit\" value=\"$msgSubmit\"/>\n" .
+               $s .= ' ' .
+                       Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
                        $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
-                       "</form>\n";
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::closeElement( 'form' ) . "\n";
                return $s;
        }
 
@@ -165,5 +159,3 @@ class ImageListPager extends TablePager {
                return 'imagelist_sort ' . parent::getSortHeaderClass();
        }
 }
-
-?>