r90485 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90484‎ | r90485 | r90486 >
Date:21:13, 20 June 2011
Author:aaron
Status:ok
Tags:
Comment:
Code cleanups to ListFiles including r85548
Modified paths:
  • /trunk/phase3/includes/specials/SpecialListfiles.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialListfiles.php
@@ -28,19 +28,27 @@
2929 }
3030
3131 public function execute( $par ){
32 - global $wgOut;
 32+ global $wgOut, $wgRequest;
3333 $this->setHeaders();
3434 $this->outputHeader();
3535
36 - $pager = new ImageListPager( $par, $this->including() );
 36+ if ( $this->including() ) {
 37+ $userName = $par;
 38+ $search = '';
 39+ } else {
 40+ $userName = $wgRequest->getText( 'user', $par );
 41+ $search = $wgRequest->getText( 'ilsearch', '' );
 42+ }
3743
 44+ $pager = new ImageListPager( $userName, $search, $this->including() );
 45+
3846 if ( $this->including() ) {
3947 $html = $pager->getBody();
4048 } else {
41 - $limit = $pager->getForm();
 49+ $form = $pager->getForm();
4250 $body = $pager->getBody();
4351 $nav = $pager->getNavigationBar();
44 - $html = "$limit<br />\n$body<br />\n$nav";
 52+ $html = "$form<br />\n$body<br />\n$nav";
4553 }
4654 $wgOut->addHTML( $html );
4755 }
@@ -53,15 +61,14 @@
5462 var $mFieldNames = null;
5563 var $mQueryConds = array();
5664 var $mUserName = null;
 65+ var $mSearch = '';
5766 var $mIncluding = false;
5867
59 - function __construct( $par = null, $including = false ) {
 68+ function __construct( $userName = null, $search = '', $including = false ) {
6069 global $wgRequest, $wgMiserMode;
6170
6271 $this->mIncluding = $including;
6372
64 -
65 - $userName = $including ? $par : $wgRequest->getText( 'user', $par );
6673 if ( $userName ) {
6774 $nt = Title::newFromText( $userName, NS_USER );
6875 if ( !is_null( $nt ) ) {
@@ -70,22 +77,23 @@
7178 }
7279 }
7380
 81+ if ( $search != '' && !$wgMiserMode ) {
 82+ $this->mSearch = $search;
 83+ $nt = Title::newFromURL( $this->mSearch );
 84+ if ( $nt ) {
 85+ $dbr = wfGetDB( DB_SLAVE );
 86+ $this->mQueryConds[] = 'LOWER(img_name)' .
 87+ $dbr->buildLike( $dbr->anyString(),
 88+ strtolower( $nt->getDBkey() ), $dbr->anyString() );
 89+ }
 90+ }
 91+
7492 if ( !$including ) {
7593 if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
7694 $this->mDefaultDirection = true;
7795 } else {
7896 $this->mDefaultDirection = false;
7997 }
80 -
81 - $search = $wgRequest->getText( 'ilsearch' );
82 - if ( $search != '' && !$wgMiserMode ) {
83 - $nt = Title::newFromURL( $search );
84 - if ( $nt ) {
85 - $dbr = wfGetDB( DB_SLAVE );
86 - $this->mQueryConds[] = 'LOWER(img_name)' . $dbr->buildLike( $dbr->anyString(),
87 - strtolower( $nt->getDBkey() ), $dbr->anyString() );
88 - }
89 - }
9098 } else {
9199 $this->mDefaultDirection = true;
92100 }
@@ -149,7 +157,8 @@
150158 if( $dbr->implicitGroupby() ) {
151159 $options = array( 'GROUP BY' => 'img_name' );
152160 } else {
153 - $columnlist = implode( ',', preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) );
 161+ $columnlist = implode( ',',
 162+ preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) );
154163 $options = array( 'GROUP BY' => "img_user, $columnlist" );
155164 }
156165 $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) );
@@ -228,29 +237,29 @@
229238 }
230239
231240 function getForm() {
232 - global $wgRequest, $wgScript, $wgMiserMode;
233 - $search = $wgRequest->getText( 'ilsearch' );
 241+ global $wgScript, $wgMiserMode;
234242 $inputForm = array();
235243 $inputForm['table_pager_limit_label'] = $this->getLimitSelect();
236244 if ( !$wgMiserMode ) {
237 - $inputForm['listfiles_search_for'] = Html::input( 'ilsearch', $search, 'text', array(
238 - 'size' => '40',
239 - 'maxlength' => '255',
240 - 'id' => 'mw-ilsearch',
 245+ $inputForm['listfiles_search_for'] = Html::input( 'ilsearch', $this->mSearch, 'text',
 246+ array(
 247+ 'size' => '40',
 248+ 'maxlength' => '255',
 249+ 'id' => 'mw-ilsearch',
241250 ) );
242251 }
243252 $inputForm['username'] = Html::input( 'user', $this->mUserName, 'text', array(
244 - 'size' => '40',
245 - 'maxlength' => '255',
246 - 'id' => 'mw-listfiles-user',
 253+ 'size' => '40',
 254+ 'maxlength' => '255',
 255+ 'id' => 'mw-listfiles-user',
247256 ) );
248 - $s = Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' ) ) .
 257+ return Html::openElement( 'form',
 258+ array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-listfiles-form' ) ) .
249259 Xml::fieldset( wfMsg( 'listfiles' ) ) .
250260 Xml::buildForm( $inputForm, 'table_pager_limit_submit' ) .
251261 $this->getHiddenFields( array( 'limit', 'ilsearch', 'user' ) ) .
252262 Html::closeElement( 'fieldset' ) .
253263 Html::closeElement( 'form' ) . "\n";
254 - return $s;
255264 }
256265
257266 function getTableClass() {
@@ -278,9 +287,7 @@
279288
280289 function getDefaultQuery() {
281290 $queries = parent::getDefaultQuery();
282 - if ( !isset( $queries['user'] )
283 - && !is_null( $this->mUserName ) )
284 - {
 291+ if ( !isset( $queries['user'] ) && !is_null( $this->mUserName ) ) {
285292 $queries['user'] = $this->mUserName;
286293 }
287294 return $queries;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85548Made Special:ListFiles transcludablemaxsem16:45, 6 April 2011

Status & tagging log