]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialListfiles.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialListfiles.php
index e15b6959aca6903cf43acc229b9da4b0c5e6e6fe..e6e1048cd6a9277ff426a674e1f4f8ce4dcc0d4f 100644 (file)
 <?php
 /**
+ * Implements Special:Listfiles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
-/**
- *
- */
-function wfSpecialListfiles() {
-       global $wgOut;
-
-       $pager = new ImageListPager;
-
-       $limit = $pager->getForm();
-       $body = $pager->getBody();
-       $nav = $pager->getNavigationBar();
-       $wgOut->addHTML( "$limit<br />\n$body<br />\n$nav" );
-}
+class SpecialListFiles extends IncludableSpecialPage {
+       public function __construct() {
+               parent::__construct( 'Listfiles' );
+       }
 
-/**
- * @ingroup SpecialPage Pager
- */
-class ImageListPager extends TablePager {
-       var $mFieldNames = null;
-       var $mQueryConds = array();
+       public function execute( $par ) {
+               $this->setHeaders();
+               $this->outputHeader();
 
-       function __construct() {
-               global $wgRequest, $wgMiserMode;
-               if ( $wgRequest->getText( 'sort', 'img_date' ) == 'img_date' ) {
-                       $this->mDefaultDirection = true;
+               if ( $this->including() ) {
+                       $userName = $par;
+                       $search = '';
+                       $showAll = false;
                } 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();
-       }
-
-       function getFieldNames() {
-               if ( !$this->mFieldNames ) {
-                       global $wgMiserMode;
-                       $this->mFieldNames = array(
-                               'img_timestamp' => wfMsg( 'listfiles_date' ),
-                               'img_name' => wfMsg( 'listfiles_name' ),
-                               'img_user_text' => wfMsg( 'listfiles_user' ),
-                               'img_size' => wfMsg( 'listfiles_size' ),
-                               'img_description' => wfMsg( 'listfiles_description' ),
-                       );
-                       if( !$wgMiserMode ) {
-                               $this->mFieldNames['count'] = wfMsg( 'listfiles_count' );
-                       }
+                       $userName = $this->getRequest()->getText( 'user', $par );
+                       $search = $this->getRequest()->getText( 'ilsearch', '' );
+                       $showAll = $this->getRequest()->getBool( 'ilshowall', false );
                }
-               return $this->mFieldNames;
-       }
-
-       function isFieldSortable( $field ) {
-               static $sortable = array( 'img_timestamp', 'img_name', 'img_size' );
-               return in_array( $field, $sortable );
-       }
-
-       function getQueryInfo() {
-               $tables = array( 'image' );
-               $fields = array_keys( $this->getFieldNames() );
-               $fields[] = 'img_user';
-               $options = $join_conds = array();
-
-               # Depends on $wgMiserMode
-               if( isset( $this->mFieldNames['count'] ) ) {
-                       $tables[] = 'oldimage';
 
-                       # Need to rewrite this one
-                       foreach ( $fields as &$field )
-                               if ( $field == 'count' )
-                                       $field = 'COUNT(oi_archive_name) as count';
-                       unset( $field );
-
-                       $dbr = wfGetDB( DB_SLAVE );
-                       if( $dbr->implicitGroupby() ) {
-                               $options = array( 'GROUP BY' => 'img_name' );
-                       } else {
-                               $columnlist = implode( ',', preg_grep( '/^img/', array_keys( $this->getFieldNames() ) ) );
-                               $options = array( 'GROUP BY' => "img_user, $columnlist" );
-                       }
-                       $join_conds = array( 'oldimage' => array( 'LEFT JOIN', 'oi_name = img_name' ) );
-               }
-               return array(
-                       'tables'     => $tables,
-                       'fields'     => $fields,
-                       'conds'      => $this->mQueryConds,
-                       'options'    => $options,
-                       'join_conds' => $join_conds
+               $pager = new ImageListPager(
+                       $this->getContext(),
+                       $userName,
+                       $search,
+                       $this->including(),
+                       $showAll
                );
-       }
-
-       function getDefaultSort() {
-               return 'img_timestamp';
-       }
-
-       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();
-               }
 
-               return parent::getStartBody();
-       }
-
-       function formatValue( $field, $value ) {
-               global $wgLang;
-               switch ( $field ) {
-                       case 'img_timestamp':
-                               return $wgLang->timeanddate( $value, true );
-                       case 'img_name':
-                               static $imgfile = null;
-                               if ( $imgfile === null ) $imgfile = wfMsg( 'imgfile' );
-
-                               $name = $this->mCurrentRow->img_name;
-                               $link = $this->getSkin()->makeKnownLinkObj( Title::makeTitle( NS_FILE, $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 ),
-                                               htmlspecialchars( $value ) );
-                               } else {
-                                       $link = htmlspecialchars( $value );
-                               }
-                               return $link;
-                       case 'img_size':
-                               return $this->getSkin()->formatSize( $value );
-                       case 'img_description':
-                               return $this->getSkin()->commentBlock( $value );
-                       case 'count':
-                               return intval($value)+1;
+               $out = $this->getOutput();
+               if ( $this->including() ) {
+                       $out->addParserOutputContent( $pager->getBodyOutput() );
+               } else {
+                       $user = $pager->getRelevantUser();
+                       $this->getSkin()->setRelevantUser( $user );
+                       $pager->getForm();
+                       $out->addParserOutputContent( $pager->getFullOutput() );
                }
        }
 
-       function getForm() {
-               global $wgRequest, $wgMiserMode;
-               $search = $wgRequest->getText( 'ilsearch' );
-
-               $s = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $this->getTitle()->getLocalURL(), 'id' => 'mw-listfiles-form' ) ) .
-                       Xml::openElement( 'fieldset' ) .
-                       Xml::element( 'legend', null, wfMsg( 'listfiles' ) ) .
-                       Xml::tags( 'label', null, wfMsgHtml( 'table_pager_limit', $this->getLimitSelect() ) );
-
-               if ( !$wgMiserMode ) {
-                       $s .= "<br />\n" .
-                               Xml::inputLabel( wfMsg( 'listfiles_search_for' ), 'ilsearch', 'mw-ilsearch', 20, $search );
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return [];
                }
-               $s .= ' ' .
-                       Xml::submitButton( wfMsg( 'table_pager_limit_submit' ) ) ."\n" .
-                       $this->getHiddenFields( array( 'limit', 'ilsearch' ) ) .
-                       Xml::closeElement( 'fieldset' ) .
-                       Xml::closeElement( 'form' ) . "\n";
-               return $s;
-       }
-
-       function getTableClass() {
-               return 'listfiles ' . parent::getTableClass();
-       }
-
-       function getNavClass() {
-               return 'listfiles_nav ' . parent::getNavClass();
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
        }
 
-       function getSortHeaderClass() {
-               return 'listfiles_sort ' . parent::getSortHeaderClass();
+       protected function getGroupName() {
+               return 'media';
        }
 }