Use prefixedText(), rather than IRC clean text for replace call on comment to make...
[mediawiki.git] / includes / SpecialImagelist.php
blobc0c9db89613b1317692f1fafc63a9284c766d0d7
1 <?php
2 /**
4 * @addtogroup SpecialPage
5 */
7 /**
9 */
10 function wfSpecialImagelist() {
11 global $wgOut;
13 $pager = new ImageListPager;
15 $limit = $pager->getForm();
16 $body = $pager->getBody();
17 $nav = $pager->getNavigationBar();
18 $wgOut->addHTML( "$limit<br />\n$body<br />\n$nav" );
21 /**
22 * @addtogroup SpecialPage
23 * @addtogroup Pager
25 class ImageListPager extends TablePager {
26 var $mFieldNames = null;
27 var $mQueryConds = array();
29 function __construct() {
30 global $wgRequest, $wgMiserMode;
31 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
32 $this->mDefaultDirection = true;
33 } else {
34 $this->mDefaultDirection = false;
36 $search = $wgRequest->getText( 'ilsearch' );
37 if ( $search != '' && !$wgMiserMode ) {
38 $nt = Title::newFromUrl( $search );
39 if( $nt ) {
40 $dbr = wfGetDB( DB_SLAVE );
41 $m = $dbr->strencode( strtolower( $nt->getDBkey() ) );
42 $m = str_replace( "%", "\\%", $m );
43 $m = str_replace( "_", "\\_", $m );
44 $this->mQueryConds = array( "LOWER(img_name) LIKE '%{$m}%'" );
48 parent::__construct();
51 function getFieldNames() {
52 if ( !$this->mFieldNames ) {
53 $this->mFieldNames = array(
54 'img_timestamp' => wfMsg( 'imagelist_date' ),
55 'img_name' => wfMsg( 'imagelist_name' ),
56 'img_user_text' => wfMsg( 'imagelist_user' ),
57 'img_size' => wfMsg( 'imagelist_size' ),
58 'img_description' => wfMsg( 'imagelist_description' ),
61 return $this->mFieldNames;
64 function isFieldSortable( $field ) {
65 static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
66 return in_array( $field, $sortable );
69 function getQueryInfo() {
70 $fields = $this->getFieldNames();
71 $fields = array_keys( $fields );
72 $fields[] = 'img_user';
73 return array(
74 'tables' => 'image',
75 'fields' => $fields,
76 'conds' => $this->mQueryConds
80 function getDefaultSort() {
81 return 'img_timestamp';
84 function getStartBody() {
85 # Do a link batch query for user pages
86 if ( $this->mResult->numRows() ) {
87 $lb = new LinkBatch;
88 $this->mResult->seek( 0 );
89 while ( $row = $this->mResult->fetchObject() ) {
90 if ( $row->img_user ) {
91 $lb->add( NS_USER, str_replace( ' ', '_', $row->img_user_text ) );
94 $lb->execute();
97 return parent::getStartBody();
100 function formatValue( $field, $value ) {
101 global $wgLang;
102 switch ( $field ) {
103 case 'img_timestamp':
104 return $wgLang->timeanddate( $value, true );
105 case 'img_name':
106 static $imgfile = null;
107 if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
109 $name = $this->mCurrentRow->img_name;
110 $link = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_IMAGE, $name ), $value );
111 $image = wfLocalFile( $value );
112 $url = $image->getURL();
113 $download = Xml::element('a', array( 'href' => $url ), $imgfile );
114 return "$link ($download)";
115 case 'img_user_text':
116 if ( $this->mCurrentRow->img_user ) {
117 $link = $this->getSkin()->makeLinkObj( Title::makeTitle( NS_USER, $value ),
118 htmlspecialchars( $value ) );
119 } else {
120 $link = htmlspecialchars( $value );
122 return $link;
123 case 'img_size':
124 return $this->getSkin()->formatSize( $value );
125 case 'img_description':
126 return $this->getSkin()->commentBlock( $value );
130 function getForm() {
131 global $wgRequest, $wgMiserMode;
132 $search = $wgRequest->getText( 'ilsearch' );
134 $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-imagelist-form' ) ) .
135 Xml::openElement( 'fieldset' ) .
136 Xml::element( 'legend', null, wfMsg( 'imagelist' ) ) .
137 Xml::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
139 if ( !$wgMiserMode ) {
140 $s .= "<br />\n" .
141 Xml::inputLabel( wfMsg( 'imagelist_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
143 $s .= ' ' .
144 Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
145 $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
146 Xml::closeElement( 'fieldset' ) .
147 Xml::closeElement( 'form' ) . "\n";
148 return $s;
151 function getTableClass() {
152 return 'imagelist ' . parent::getTableClass();
155 function getNavClass() {
156 return 'imagelist_nav ' . parent::getNavClass();
159 function getSortHeaderClass() {
160 return 'imagelist_sort ' . parent::getSortHeaderClass();