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