MediaWiki
REL1_24
|
00001 <?php 00024 class SpecialNewFiles extends IncludableSpecialPage { 00025 public function __construct() { 00026 parent::__construct( 'Newimages' ); 00027 } 00028 00029 public function execute( $par ) { 00030 $this->setHeaders(); 00031 $this->outputHeader(); 00032 00033 $pager = new NewFilesPager( $this->getContext(), $par ); 00034 00035 if ( !$this->including() ) { 00036 $this->setTopText(); 00037 $form = $pager->getForm(); 00038 $form->prepareForm(); 00039 $form->displayForm( '' ); 00040 } 00041 00042 $this->getOutput()->addHTML( $pager->getBody() ); 00043 if ( !$this->including() ) { 00044 $this->getOutput()->addHTML( $pager->getNavigationBar() ); 00045 } 00046 } 00047 00048 protected function getGroupName() { 00049 return 'changes'; 00050 } 00051 00055 function setTopText() { 00056 global $wgContLang; 00057 00058 $message = $this->msg( 'newimagestext' )->inContentLanguage(); 00059 if ( !$message->isDisabled() ) { 00060 $this->getOutput()->addWikiText( 00061 Html::rawElement( 'p', 00062 array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() ), 00063 "\n" . $message->plain() . "\n" 00064 ), 00065 /* $lineStart */ false, 00066 /* $interface */ false 00067 ); 00068 } 00069 } 00070 } 00071 00075 class NewFilesPager extends ReverseChronologicalPager { 00079 protected $gallery; 00080 00081 function __construct( IContextSource $context, $par = null ) { 00082 $this->like = $context->getRequest()->getText( 'like' ); 00083 $this->showbots = $context->getRequest()->getBool( 'showbots', 0 ); 00084 if ( is_numeric( $par ) ) { 00085 $this->setLimit( $par ); 00086 } 00087 00088 parent::__construct( $context ); 00089 } 00090 00091 function getQueryInfo() { 00092 $conds = $jconds = array(); 00093 $tables = array( 'image' ); 00094 00095 if ( !$this->showbots ) { 00096 $groupsWithBotPermission = User::getGroupsWithPermission( 'bot' ); 00097 00098 if ( count( $groupsWithBotPermission ) ) { 00099 $tables[] = 'user_groups'; 00100 $conds[] = 'ug_group IS NULL'; 00101 $jconds['user_groups'] = array( 00102 'LEFT JOIN', 00103 array( 00104 'ug_group' => $groupsWithBotPermission, 00105 'ug_user = img_user' 00106 ) 00107 ); 00108 } 00109 } 00110 00111 if ( !$this->getConfig()->get( 'MiserMode' ) && $this->like !== null ) { 00112 $dbr = wfGetDB( DB_SLAVE ); 00113 $likeObj = Title::newFromURL( $this->like ); 00114 if ( $likeObj instanceof Title ) { 00115 $like = $dbr->buildLike( 00116 $dbr->anyString(), 00117 strtolower( $likeObj->getDBkey() ), 00118 $dbr->anyString() 00119 ); 00120 $conds[] = "LOWER(img_name) $like"; 00121 } 00122 } 00123 00124 $query = array( 00125 'tables' => $tables, 00126 'fields' => '*', 00127 'join_conds' => $jconds, 00128 'conds' => $conds 00129 ); 00130 00131 return $query; 00132 } 00133 00134 function getIndexField() { 00135 return 'img_timestamp'; 00136 } 00137 00138 function getStartBody() { 00139 if ( !$this->gallery ) { 00140 // Note that null for mode is taken to mean use default. 00141 $mode = $this->getRequest()->getVal( 'gallerymode', null ); 00142 try { 00143 $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() ); 00144 } catch ( MWException $e ) { 00145 // User specified something invalid, fallback to default. 00146 $this->gallery = ImageGalleryBase::factory( false, $this->getContext() ); 00147 } 00148 } 00149 00150 return ''; 00151 } 00152 00153 function getEndBody() { 00154 return $this->gallery->toHTML(); 00155 } 00156 00157 function formatRow( $row ) { 00158 $name = $row->img_name; 00159 $user = User::newFromId( $row->img_user ); 00160 00161 $title = Title::makeTitle( NS_FILE, $name ); 00162 $ul = Linker::link( $user->getUserpage(), $user->getName() ); 00163 $time = $this->getLanguage()->userTimeAndDate( $row->img_timestamp, $this->getUser() ); 00164 00165 $this->gallery->add( 00166 $title, 00167 "$ul<br />\n<i>" 00168 . htmlspecialchars( $time ) 00169 . "</i><br />\n" 00170 ); 00171 } 00172 00173 function getForm() { 00174 $fields = array( 00175 'like' => array( 00176 'type' => 'text', 00177 'label-message' => 'newimages-label', 00178 'name' => 'like', 00179 ), 00180 'showbots' => array( 00181 'type' => 'check', 00182 'label-message' => 'newimages-showbots', 00183 'name' => 'showbots', 00184 ), 00185 'limit' => array( 00186 'type' => 'hidden', 00187 'default' => $this->mLimit, 00188 'name' => 'limit', 00189 ), 00190 'offset' => array( 00191 'type' => 'hidden', 00192 'default' => $this->getRequest()->getText( 'offset' ), 00193 'name' => 'offset', 00194 ), 00195 ); 00196 00197 if ( $this->getConfig()->get( 'MiserMode' ) ) { 00198 unset( $fields['like'] ); 00199 } 00200 00201 $context = new DerivativeContext( $this->getContext() ); 00202 $context->setTitle( $this->getTitle() ); // Remove subpage 00203 $form = new HTMLForm( $fields, $context ); 00204 $form->setSubmitTextMsg( 'ilsubmit' ); 00205 $form->setMethod( 'get' ); 00206 $form->setWrapperLegendMsg( 'newimages-legend' ); 00207 00208 return $form; 00209 } 00210 }