]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/SpecialImagelist.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / SpecialImagelist.php
index 1ac3384680a12eb1c1d49c40ca0bca21b71446f6..1688fe7c61ef73336a8b3c0145d96001ea720917 100644 (file)
 <?php
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 
 /**
  *
  */
 function wfSpecialImagelist() {
-       global $wgUser, $wgOut, $wgLang, $wgContLang, $wgRequest, $wgMiserMode;
-       
-       $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";
-
-       $byname = wfMsg( "byname" );
-       $bydate = wfMsg( "bydate" );
-       $bysize = wfMsg( "bysize" );
-
-       if ( !$wgMiserMode && !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}%'";
+       global $wgOut;
+
+       $pager = new ImageListPager;
+
+       $limit = $pager->getForm();
+       $body = $pager->getBody();
+       $nav = $pager->getNavigationBar();
+       $wgOut->addHTML(
+               $limit
+               . '<br/>'
+               . $body
+               . '<br/>'
+               . $nav );
+}
+
+/**
+ * @addtogroup SpecialPage
+ * @addtogroup Pager
+ */
+class ImageListPager extends TablePager {
+       var $mFieldNames = null;
+       var $mMessages = array();
+       var $mQueryConds = array();
+
+       function __construct() {
+               global $wgRequest, $wgMiserMode;
+               if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
+                       $this->mDefaultDirection = true;
+               } else {
+                       $this->mDefaultDirection = false;
                }
+               $search = $wgRequest->getText( 'ilsearch' );
+               if ( $search != '' && !$wgMiserMode ) {
+                       $nt = Title::newFromUrl( $search );
+                       if( $nt ) {
+                               $dbr = wfGetDB( DB_SLAVE );
+                               $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
+                               $m = str_replace( "%", "\\%", $m );
+                               $m = str_replace( "_", "\\_", $m );
+                               $this->mQueryConds = array( "LOWER(img_name) LIKE '%{$m}%'" );
+                       }
+               }
+
+               parent::__construct();
        }
-       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;
-       }
-       list( $limit, $offset ) = wfCheckLimits( 50 );
-       if ( 0 == $limit ) {
-               $lt = wfMsg( 'imagelistall' );
-       } else {
-               $lt = $wgLang->formatNum( "${limit}" );
-               $sql .= " LIMIT {$limit}";
+
+       function getFieldNames() {
+               if ( !$this->mFieldNames ) {
+                       $this->mFieldNames = array(
+                               'img_timestamp' => wfMsg( 'imagelist_date' ),
+                               'img_name' => wfMsg( 'imagelist_name' ),
+                               'img_user_text' => wfMsg( 'imagelist_user' ),
+                               'img_size' => wfMsg( 'imagelist_size' ),
+                               'img_description' => wfMsg( 'imagelist_description' ),
+                       );
+               }
+               return $this->mFieldNames;
        }
-       $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "</p>\n" );
-
-       $text = wfMsg( "imagelisttext",
-               "<strong>{$lt}</strong>", "<strong>{$st}</strong>" );
-       $wgOut->addHTML( "<p>{$text}\n</p>" );
-
-       $sk = $wgUser->getSkin();
-       $sub = wfMsg( "ilsubmit" );
-       $titleObj = Title::makeTitle( NS_SPECIAL, "Imagelist" );
-       $action = $titleObj->escapeLocalURL(  "sort={$sort}&limit={$limit}" );
-
-       if ( !$wgMiserMode ) {
-               $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>" );
+
+       function isFieldSortable( $field ) {
+               static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
+               return in_array( $field, $sortable );
        }
-       $nums = array( 50, 100, 250, 500 );
-       $here = Title::makeTitle( NS_SPECIAL, 'Imagelist' );
 
-       $fill = "";
-       $first = true;
-       foreach ( $nums as $num ) {
-               if ( ! $first ) { $fill .= " | "; }
-               $first = false;
+       function getQueryInfo() {
+               $fields = $this->getFieldNames();
+               $fields = array_keys( $fields );
+               $fields[] = 'img_user';
+               return array(
+                       'tables' => 'image',
+                       'fields' => $fields,
+                       'conds' => $this->mQueryConds
+               );
+       }
 
-               $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
-                 "sort=byname&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
+       function getDefaultSort() {
+               return 'img_timestamp';
        }
-       $text = wfMsg( "showlast", $fill, $byname );
-       $wgOut->addHTML( "<p>{$text}<br />\n" );
 
-       $fill = "";
-       $first = true;
-       foreach ( $nums as $num ) {
-               if ( ! $first ) { $fill .= " | "; }
-               $first = false;
+       function getStartBody() {
+               # Do a link batch query for user pages
+               if ( $this->mResult->numRows() ) {
+                       $lb = new LinkBatch;
+                       $this->mResult->seek( 0 );
+                       while ( $row = $this->mResult->fetchObject() ) {
+                               if ( $row->img_user ) {
+                                       $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
+                               }
+                       }
+                       $lb->execute();
+               }
 
-               $fill .= $sk->makeKnownLinkObj( $here, $wgLang->formatNum( $num ),
-                 "sort=bysize&limit={$num}&wpIlMatch=" . urlencode( $wpIlMatch ) );
+               # Cache messages used in each row
+               $this->mMessages['imgdesc'] = wfMsgHtml( 'imgdesc' );
+               $this->mMessages['imgfile'] = wfMsgHtml( 'imgfile' );
+               
+               return parent::getStartBody();
        }
-       $text = wfMsg( "showlast", $fill, $bysize );
-       $wgOut->addHTML( "{$text}<br />\n" );
-
-       $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 ) );
+       function formatValue( $field, $value ) {
+               global $wgLang;
+               switch ( $field ) {
+                       case 'img_timestamp':
+                               return $wgLang->timeanddate( $value, true );
+                       case 'img_name':
+                               $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 ), $this->mMessages['imgfile'] );
+                               return "$link ($download)";
+                       case 'img_user_text':
+                               if ( $this->mCurrentRow->img_user ) {
+                                       $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ), 
+                                               htmlspecialchars( $value ) );
+                               } else {
+                                       $link = htmlspecialchars( $value );
+                               }
+                               return $link;
+                       case 'img_size':
+                               return $this->getSkin()->formatSize( $value );
+                       case 'img_description':
+                               return $this->getSkin()->commentBlock( $value );
+               }
        }
-       $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->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
+
+       function getForm() {
+               global $wgRequest, $wgMiserMode;
+               $url = $this->getTitle()->escapeLocalURL();
+               $search = $wgRequest->getText( 'ilsearch' );
+               $s = "<form method=\"get\" action=\"$url\">\n" .
+                       wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() );
+               if ( !$wgMiserMode ) {
+                       $s .= "<br/>\n" .
+                       Xml::inputLabel( wfMsg( 'imagelist_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
                }
+               $s .= " " . Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ." \n" .
+                       $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
+                       "</form>\n";
+               return $s;
+       }
 
-               $ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
-                 "\">" . strtr(htmlspecialchars( $name ), '_', ' ') . "</a>";
+       function getTableClass() {
+               return 'imagelist ' . parent::getTableClass();
+       }
 
-               $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
-               $l = "(" .
-                 $sk->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ),
-                 wfMsg( "imgdesc" ) ) .
-                 ") {$ilink} . . {$nb} . . {$ul} . . " .
-                 $wgLang->timeanddate( $s->img_timestamp, true );
+       function getNavClass() {
+               return 'imagelist_nav ' . parent::getNavClass();
+       }
 
-               $l .= $sk->commentBlock( $s->img_description );
-               $wgOut->addHTML( "{$l}<br />\n" );
+       function getSortHeaderClass() {
+               return 'imagelist_sort ' . parent::getSortHeaderClass();
        }
-       $wgOut->addHTML( "</p>" );
-       $dbr->freeResult( $res );
 }
 
-?>
+