MediaWiki
REL1_20
|
00001 <?php 00030 class SpecialAllmessages extends SpecialPage { 00031 00035 protected $table; 00036 00040 public function __construct() { 00041 parent::__construct( 'Allmessages' ); 00042 } 00043 00049 public function execute( $par ) { 00050 $request = $this->getRequest(); 00051 $out = $this->getOutput(); 00052 00053 $this->setHeaders(); 00054 00055 global $wgUseDatabaseMessages; 00056 if( !$wgUseDatabaseMessages ) { 00057 $out->addWikiMsg( 'allmessagesnotsupportedDB' ); 00058 return; 00059 } else { 00060 $this->outputHeader( 'allmessagestext' ); 00061 } 00062 00063 $out->addModuleStyles( 'mediawiki.special' ); 00064 00065 $this->table = new AllmessagesTablePager( 00066 $this, 00067 array(), 00068 wfGetLangObj( $request->getVal( 'lang', $par ) ) 00069 ); 00070 00071 $this->langcode = $this->table->lang->getCode(); 00072 00073 $out->addHTML( $this->table->buildForm() . 00074 $this->table->getNavigationBar() . 00075 $this->table->getBody() . 00076 $this->table->getNavigationBar() ); 00077 00078 } 00079 00080 } 00081 00086 class AllmessagesTablePager extends TablePager { 00087 00088 protected $filter, $prefix, $langcode, $displayPrefix; 00089 00090 public $mLimitsShown; 00091 00095 public $lang; 00096 00100 public $custom; 00101 00102 function __construct( $page, $conds, $langObj = null ) { 00103 parent::__construct( $page->getContext() ); 00104 $this->mIndexField = 'am_title'; 00105 $this->mPage = $page; 00106 $this->mConds = $conds; 00107 $this->mDefaultDirection = true; // always sort ascending 00108 $this->mLimitsShown = array( 20, 50, 100, 250, 500, 5000 ); 00109 00110 global $wgContLang; 00111 00112 $this->talk = $this->msg( 'talkpagelinktext' )->escaped(); 00113 00114 $this->lang = ( $langObj ? $langObj : $wgContLang ); 00115 $this->langcode = $this->lang->getCode(); 00116 $this->foreign = $this->langcode != $wgContLang->getCode(); 00117 00118 $request = $this->getRequest(); 00119 00120 $this->filter = $request->getVal( 'filter', 'all' ); 00121 if( $this->filter === 'all' ){ 00122 $this->custom = null; // So won't match in either case 00123 } else { 00124 $this->custom = ($this->filter == 'unmodified'); 00125 } 00126 00127 $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) ); 00128 $prefix = $prefix != '' ? Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'prefix', null ) ) : null; 00129 if( $prefix !== null ){ 00130 $this->displayPrefix = $prefix->getDBkey(); 00131 $this->prefix = '/^' . preg_quote( $this->displayPrefix ) . '/i'; 00132 } else { 00133 $this->displayPrefix = false; 00134 $this->prefix = false; 00135 } 00136 00137 // The suffix that may be needed for message names if we're in a 00138 // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr' 00139 if( $this->foreign ) { 00140 $this->suffix = '/' . $this->langcode; 00141 } else { 00142 $this->suffix = ''; 00143 } 00144 } 00145 00146 function buildForm() { 00147 global $wgScript; 00148 00149 $attrs = array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ); 00150 $msg = wfMessage( 'allmessages-language' ); 00151 $langSelect = Xml::languageSelector( $this->langcode, false, null, $attrs, $msg ); 00152 00153 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) . 00154 Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) . 00155 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . 00156 Xml::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" . 00157 '<tr> 00158 <td class="mw-label">' . 00159 Xml::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) . 00160 "</td>\n 00161 <td class=\"mw-input\">" . 00162 Xml::input( 'prefix', 20, str_replace( '_', ' ', $this->displayPrefix ), array( 'id' => 'mw-allmessages-form-prefix' ) ) . 00163 "</td>\n 00164 </tr> 00165 <tr>\n 00166 <td class='mw-label'>" . 00167 $this->msg( 'allmessages-filter' )->escaped() . 00168 "</td>\n 00169 <td class='mw-input'>" . 00170 Xml::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(), 00171 'filter', 00172 'unmodified', 00173 'mw-allmessages-form-filter-unmodified', 00174 ( $this->filter == 'unmodified' ) 00175 ) . 00176 Xml::radioLabel( $this->msg( 'allmessages-filter-all' )->text(), 00177 'filter', 00178 'all', 00179 'mw-allmessages-form-filter-all', 00180 ( $this->filter == 'all' ) 00181 ) . 00182 Xml::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(), 00183 'filter', 00184 'modified', 00185 'mw-allmessages-form-filter-modified', 00186 ( $this->filter == 'modified' ) 00187 ) . 00188 "</td>\n 00189 </tr> 00190 <tr>\n 00191 <td class=\"mw-label\">" . $langSelect[0] . "</td>\n 00192 <td class=\"mw-input\">" . $langSelect[1] . "</td>\n 00193 </tr>" . 00194 00195 '<tr> 00196 <td class="mw-label">' . 00197 Xml::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) . 00198 '</td> 00199 <td class="mw-input">' . 00200 $this->getLimitSelect() . 00201 '</td> 00202 <tr> 00203 <td></td> 00204 <td>' . 00205 Xml::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) . 00206 "</td>\n 00207 </tr>" . 00208 00209 Xml::closeElement( 'table' ) . 00210 $this->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang', 'limit' ) ) . 00211 Xml::closeElement( 'fieldset' ) . 00212 Xml::closeElement( 'form' ); 00213 return $out; 00214 } 00215 00216 function getAllMessages( $descending ) { 00217 wfProfileIn( __METHOD__ ); 00218 $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' ); 00219 if( $descending ){ 00220 rsort( $messageNames ); 00221 } else { 00222 asort( $messageNames ); 00223 } 00224 00225 // Normalise message names so they look like page titles 00226 $messageNames = array_map( array( $this->lang, 'ucfirst' ), $messageNames ); 00227 00228 wfProfileOut( __METHOD__ ); 00229 return $messageNames; 00230 } 00231 00243 public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) { 00244 // FIXME: This function should be moved to Language:: or something. 00245 wfProfileIn( __METHOD__ . '-db' ); 00246 00247 $dbr = wfGetDB( DB_SLAVE ); 00248 $res = $dbr->select( 'page', 00249 array( 'page_namespace', 'page_title' ), 00250 array( 'page_namespace' => array( NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ) ), 00251 __METHOD__, 00252 array( 'USE INDEX' => 'name_title' ) 00253 ); 00254 $xNames = array_flip( $messageNames ); 00255 00256 $pageFlags = $talkFlags = array(); 00257 00258 foreach ( $res as $s ) { 00259 $exists = false; 00260 if( $foreign ) { 00261 $title = explode( '/', $s->page_title ); 00262 if( count( $title ) === 2 && $langcode == $title[1] 00263 && isset( $xNames[$title[0]] ) ) { 00264 $exists = $title[0]; 00265 } 00266 } elseif( isset( $xNames[$s->page_title] ) ) { 00267 $exists = $s->page_title; 00268 } 00269 if( $exists && $s->page_namespace == NS_MEDIAWIKI ) { 00270 $pageFlags[$exists] = true; 00271 } elseif( $exists && $s->page_namespace == NS_MEDIAWIKI_TALK ) { 00272 $talkFlags[$exists] = true; 00273 } 00274 } 00275 00276 wfProfileOut( __METHOD__ . '-db' ); 00277 00278 return array( 'pages' => $pageFlags, 'talks' => $talkFlags ); 00279 } 00280 00286 function reallyDoQuery( $offset, $limit, $descending ) { 00287 $result = new FakeResultWrapper( array() ); 00288 00289 $messageNames = $this->getAllMessages( $descending ); 00290 $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign ); 00291 00292 $count = 0; 00293 foreach( $messageNames as $key ) { 00294 $customised = isset( $statuses['pages'][$key] ); 00295 if( $customised !== $this->custom && 00296 ( $descending && ( $key < $offset || !$offset ) || !$descending && $key > $offset ) && 00297 ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false ) 00298 ) { 00299 $actual = wfMessage( $key )->inLanguage( $this->langcode )->plain(); 00300 $default = wfMessage( $key )->inLanguage( $this->langcode )->useDatabase( false )->plain(); 00301 $result->result[] = array( 00302 'am_title' => $key, 00303 'am_actual' => $actual, 00304 'am_default' => $default, 00305 'am_customised' => $customised, 00306 'am_talk_exists' => isset( $statuses['talks'][$key] ) 00307 ); 00308 $count++; 00309 } 00310 if( $count == $limit ) { 00311 break; 00312 } 00313 } 00314 return $result; 00315 } 00316 00317 function getStartBody() { 00318 return Xml::openElement( 'table', array( 'class' => 'mw-datatable TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" . 00319 "<thead><tr> 00320 <th rowspan=\"2\">" . 00321 $this->msg( 'allmessagesname' )->escaped() . " 00322 </th> 00323 <th>" . 00324 $this->msg( 'allmessagesdefault' )->escaped() . 00325 "</th> 00326 </tr>\n 00327 <tr> 00328 <th>" . 00329 $this->msg( 'allmessagescurrent' )->escaped() . 00330 "</th> 00331 </tr></thead><tbody>\n"; 00332 } 00333 00334 function formatValue( $field, $value ){ 00335 switch( $field ){ 00336 00337 case 'am_title' : 00338 00339 $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix ); 00340 $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix ); 00341 00342 if( $this->mCurrentRow->am_customised ){ 00343 $title = Linker::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) ); 00344 } else { 00345 $title = Linker::link( 00346 $title, 00347 $this->getLanguage()->lcfirst( $value ), 00348 array(), 00349 array(), 00350 array( 'broken' ) 00351 ); 00352 } 00353 if ( $this->mCurrentRow->am_talk_exists ) { 00354 $talk = Linker::linkKnown( $talk , $this->talk ); 00355 } else { 00356 $talk = Linker::link( 00357 $talk, 00358 $this->talk, 00359 array(), 00360 array(), 00361 array( 'broken' ) 00362 ); 00363 } 00364 return $title . ' ' . $this->msg( 'parentheses' )->rawParams( $talk )->escaped(); 00365 00366 case 'am_default' : 00367 case 'am_actual' : 00368 return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES ); 00369 } 00370 return ''; 00371 } 00372 00373 function formatRow( $row ){ 00374 // Do all the normal stuff 00375 $s = parent::formatRow( $row ); 00376 00377 // But if there's a customised message, add that too. 00378 if( $row->am_customised ){ 00379 $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) ); 00380 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) ); 00381 if ( $formatted == '' ) { 00382 $formatted = ' '; 00383 } 00384 $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted ) 00385 . "</tr>\n"; 00386 } 00387 return $s; 00388 } 00389 00390 function getRowAttrs( $row, $isSecond = false ){ 00391 $arr = array(); 00392 if( $row->am_customised ){ 00393 $arr['class'] = 'allmessages-customised'; 00394 } 00395 if( !$isSecond ){ 00396 $arr['id'] = Sanitizer::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title ) ); 00397 } 00398 return $arr; 00399 } 00400 00401 function getCellAttrs( $field, $value ){ 00402 if( $this->mCurrentRow->am_customised && $field == 'am_title' ){ 00403 return array( 'rowspan' => '2', 'class' => $field ); 00404 } elseif( $field == 'am_title' ) { 00405 return array( 'class' => $field ); 00406 } else { 00407 return array( 'lang' => $this->langcode, 'dir' => $this->lang->getDir(), 'class' => $field ); 00408 } 00409 } 00410 00411 // This is not actually used, as getStartBody is overridden above 00412 function getFieldNames() { 00413 return array( 00414 'am_title' => $this->msg( 'allmessagesname' )->text(), 00415 'am_default' => $this->msg( 'allmessagesdefault' )->text() 00416 ); 00417 } 00418 00419 function getTitle() { 00420 return SpecialPage::getTitleFor( 'Allmessages', false ); 00421 } 00422 00423 function isFieldSortable( $x ){ 00424 return false; 00425 } 00426 00427 function getDefaultSort(){ 00428 return ''; 00429 } 00430 00431 function getQueryInfo(){ 00432 return ''; 00433 } 00434 } 00435