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