[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/specials/ -> SpecialNewimages.php (source)

   1  <?php
   2  /**
   3   * Implements Special:Newimages
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @ingroup SpecialPage
  22   */
  23  
  24  class SpecialNewFiles extends IncludableSpecialPage {
  25  	public function __construct() {
  26          parent::__construct( 'Newimages' );
  27      }
  28  
  29  	public function execute( $par ) {
  30          $this->setHeaders();
  31          $this->outputHeader();
  32  
  33          $pager = new NewFilesPager( $this->getContext(), $par );
  34  
  35          if ( !$this->including() ) {
  36              $this->setTopText();
  37              $form = $pager->getForm();
  38              $form->prepareForm();
  39              $form->displayForm( '' );
  40          }
  41  
  42          $this->getOutput()->addHTML( $pager->getBody() );
  43          if ( !$this->including() ) {
  44              $this->getOutput()->addHTML( $pager->getNavigationBar() );
  45          }
  46      }
  47  
  48  	protected function getGroupName() {
  49          return 'changes';
  50      }
  51  
  52      /**
  53       * Send the text to be displayed above the options
  54       */
  55  	function setTopText() {
  56          global $wgContLang;
  57  
  58          $message = $this->msg( 'newimagestext' )->inContentLanguage();
  59          if ( !$message->isDisabled() ) {
  60              $this->getOutput()->addWikiText(
  61                  Html::rawElement( 'p',
  62                      array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ),
  63                      "\n" . $message->plain() . "\n"
  64                  ),
  65                  /* $lineStart */ false,
  66                  /* $interface */ false
  67              );
  68          }
  69      }
  70  }
  71  
  72  /**
  73   * @ingroup SpecialPage Pager
  74   */
  75  class NewFilesPager extends ReverseChronologicalPager {
  76      /**
  77       * @var ImageGallery
  78       */
  79      protected $gallery;
  80  
  81  	function __construct( IContextSource $context, $par = null ) {
  82          $this->like = $context->getRequest()->getText( 'like' );
  83          $this->showbots = $context->getRequest()->getBool( 'showbots', 0 );
  84          if ( is_numeric( $par ) ) {
  85              $this->setLimit( $par );
  86          }
  87  
  88          parent::__construct( $context );
  89      }
  90  
  91  	function getQueryInfo() {
  92          $conds = $jconds = array();
  93          $tables = array( 'image' );
  94  
  95          if ( !$this->showbots ) {
  96              $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' );
  97  
  98              if ( count( $groupsWithBotPermission ) ) {
  99                  $tables[] = 'user_groups';
 100                  $conds[] = 'ug_group IS NULL';
 101                  $jconds['user_groups'] = array(
 102                      'LEFT JOIN',
 103                      array(
 104                          'ug_group' => $groupsWithBotPermission,
 105                          'ug_user = img_user'
 106                      )
 107                  );
 108              }
 109          }
 110  
 111          if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) {
 112              $dbr = wfGetDB( DB_SLAVE );
 113              $likeObj = Title::newFromURL( $this->like );
 114              if ( $likeObj instanceof Title ) {
 115                  $like = $dbr->buildLike(
 116                      $dbr->anyString(),
 117                      strtolower( $likeObj->getDBkey() ),
 118                      $dbr->anyString()
 119                  );
 120                  $conds[] = "LOWER(img_name) $like";
 121              }
 122          }
 123  
 124          $query = array(
 125              'tables' => $tables,
 126              'fields' => '*',
 127              'join_conds' => $jconds,
 128              'conds' => $conds
 129          );
 130  
 131          return $query;
 132      }
 133  
 134  	function getIndexField() {
 135          return 'img_timestamp';
 136      }
 137  
 138  	function getStartBody() {
 139          if ( !$this->gallery ) {
 140              // Note that null for mode is taken to mean use default.
 141              $mode = $this->getRequest()->getVal( 'gallerymode', null );
 142              try {
 143                  $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
 144              } catch ( MWException $e ) {
 145                  // User specified something invalid, fallback to default.
 146                  $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
 147              }
 148          }
 149  
 150          return '';
 151      }
 152  
 153  	function getEndBody() {
 154          return $this->gallery->toHTML();
 155      }
 156  
 157  	function formatRow( $row ) {
 158          $name = $row->img_name;
 159          $user = User::newFromId( $row->img_user );
 160  
 161          $title = Title::makeTitle( NS_FILE, $name );
 162          $ul = Linker::link( $user->getUserpage(), $user->getName() );
 163          $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() );
 164  
 165          $this->gallery->add(
 166              $title,
 167              "$ul<br />\n<i>"
 168                  . htmlspecialchars( $time )
 169                  . "</i><br />\n"
 170          );
 171      }
 172  
 173  	function getForm() {
 174          $fields = array(
 175              'like' => array(
 176                  'type' => 'text',
 177                  'label-message' => 'newimages-label',
 178                  'name' => 'like',
 179              ),
 180              'showbots' => array(
 181                  'type' => 'check',
 182                  'label-message' => 'newimages-showbots',
 183                  'name' => 'showbots',
 184              ),
 185              'limit' => array(
 186                  'type' => 'hidden',
 187                  'default' => $this->mLimit,
 188                  'name' => 'limit',
 189              ),
 190              'offset' => array(
 191                  'type' => 'hidden',
 192                  'default' => $this->getRequest()->getText( 'offset' ),
 193                  'name' => 'offset',
 194              ),
 195          );
 196  
 197          if ( $this->getConfig()->get( 'MiserMode' ) ) {
 198              unset( $fields['like'] );
 199          }
 200  
 201          $context = new DerivativeContext( $this->getContext() );
 202          $context->setTitle( $this->getTitle() ); // Remove subpage
 203          $form = new HTMLForm( $fields, $context );
 204          $form->setSubmitTextMsg( 'ilsubmit' );
 205          $form->setMethod( 'get' );
 206          $form->setWrapperLegendMsg( 'newimages-legend' );
 207  
 208          return $form;
 209      }
 210  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1