00001 <?php
00007 class SpecialAllmessages extends SpecialPage {
00008
00012 public function __construct() {
00013 parent::__construct( 'Allmessages' );
00014 }
00015
00021 public function execute( $par ) {
00022 global $wgOut, $wgRequest;
00023
00024 $this->setHeaders();
00025
00026 global $wgUseDatabaseMessages;
00027 if( !$wgUseDatabaseMessages ) {
00028 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
00029 return;
00030 } else {
00031 $this->outputHeader( 'allmessagestext' );
00032 }
00033
00034 $this->filter = $wgRequest->getVal( 'filter', 'all' );
00035 $this->prefix = $wgRequest->getVal( 'prefix', '' );
00036
00037 $this->table = new AllmessagesTablePager(
00038 $this,
00039 $conds = array(),
00040 wfGetLangObj( $wgRequest->getVal( 'lang', $par ) )
00041 );
00042
00043 $this->langCode = $this->table->lang->getCode();
00044
00045 $wgOut->addHTML( $this->buildForm() .
00046 $this->table->getNavigationBar() .
00047 $this->table->getLimitForm() .
00048 $this->table->getBody() .
00049 $this->table->getNavigationBar() );
00050
00051 }
00052
00053 function buildForm() {
00054 global $wgScript;
00055
00056 $languages = Language::getLanguageNames( false );
00057 ksort( $languages );
00058
00059 $out = Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'mw-allmessages-form' ) ) .
00060 Xml::fieldset( wfMsg( 'allmessages-filter-legend' ) ) .
00061 Xml::hidden( 'title', $this->getTitle() ) .
00062 Xml::openElement( 'table', array( 'class' => 'mw-allmessages-table' ) ) . "\n" .
00063 '<tr>
00064 <td class="mw-label">' .
00065 Xml::label( wfMsg( 'allmessages-prefix' ), 'mw-allmessages-form-prefix' ) .
00066 "</td>\n
00067 <td class=\"mw-input\">" .
00068 Xml::input( 'prefix', 20, str_replace( '_', ' ', $this->prefix ), array( 'id' => 'mw-allmessages-form-prefix' ) ) .
00069 "</td>\n
00070 </tr>
00071 <tr>\n
00072 <td class='mw-label'>" .
00073 wfMsg( 'allmessages-filter' ) .
00074 "</td>\n
00075 <td class='mw-input'>" .
00076 Xml::radioLabel( wfMsg( 'allmessages-filter-unmodified' ),
00077 'filter',
00078 'unmodified',
00079 'mw-allmessages-form-filter-unmodified',
00080 ( $this->filter == 'unmodified' ? true : false )
00081 ) .
00082 Xml::radioLabel( wfMsg( 'allmessages-filter-all' ),
00083 'filter',
00084 'all',
00085 'mw-allmessages-form-filter-all',
00086 ( $this->filter == 'all' ? true : false )
00087 ) .
00088 Xml::radioLabel( wfMsg( 'allmessages-filter-modified' ),
00089 'filter',
00090 'modified',
00091 'mw-allmessages-form-filter-modified',
00092 ( $this->filter == 'modified' ? true : false )
00093 ) .
00094 "</td>\n
00095 </tr>
00096 <tr>\n
00097 <td class=\"mw-label\">" .
00098 Xml::label( wfMsg( 'allmessages-language' ), 'mw-allmessages-form-lang' ) .
00099 "</td>\n
00100 <td class=\"mw-input\">" .
00101 Xml::openElement( 'select', array( 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ) );
00102
00103 foreach( $languages as $lang => $name ) {
00104 $selected = $lang == $this->langCode ? true : false;
00105 $out .= Xml::option( $lang . ' - ' . $name, $lang, $selected ) . "\n";
00106 }
00107 $out .= Xml::closeElement( 'select' ) .
00108 "</td>\n
00109 </tr>
00110 <tr>\n
00111 <td></td>
00112 <td>" .
00113 Xml::submitButton( wfMsg( 'allmessages-filter-submit' ) ) .
00114 "</td>\n
00115 </tr>" .
00116 Xml::closeElement( 'table' ) .
00117 $this->table->getHiddenFields( array( 'title', 'prefix', 'filter', 'lang' ) ) .
00118 Xml::closeElement( 'fieldset' ) .
00119 Xml::closeElement( 'form' );
00120 return $out;
00121 }
00122 }
00123
00124
00125
00126
00127 class AllmessagesTablePager extends TablePager {
00128
00129 public $mLimitsShown;
00130
00131 function __construct( $page, $conds, $langObj = null ) {
00132 parent::__construct();
00133 $this->mIndexField = 'am_title';
00134 $this->mPage = $page;
00135 $this->mConds = $conds;
00136 $this->mDefaultDirection = true;
00137
00138
00139
00140 $this->mLimitsShown = array( 20, 50, 100, 250, 500, 5000 => wfMsg('limitall') );
00141
00142 global $wgLang, $wgContLang, $wgRequest;
00143
00144 $this->talk = htmlspecialchars( wfMsg( 'talkpagelinktext' ) );
00145
00146 $this->lang = ( $langObj ? $langObj : $wgContLang );
00147 $this->langcode = $this->lang->getCode();
00148 $this->foreign = $this->langcode != $wgContLang->getCode();
00149
00150 if( $wgRequest->getVal( 'filter', 'all' ) === 'all' ){
00151 $this->custom = null;
00152 } else {
00153 $this->custom = ($wgRequest->getVal( 'filter' ) == 'unmodified');
00154 }
00155
00156 $prefix = $wgLang->ucfirst( $wgRequest->getVal( 'prefix', '' ) );
00157 $prefix = $prefix != '' ? Title::makeTitleSafe( NS_MEDIAWIKI, $wgRequest->getVal( 'prefix', null ) ) : null;
00158 if( $prefix !== null ){
00159 $this->prefix = '/^' . preg_quote( $prefix->getDBkey() ) . '/i';
00160 } else {
00161 $this->prefix = false;
00162 }
00163 $this->getSkin();
00164
00165
00166
00167 if( $this->foreign ) {
00168 $this->suffix = '/' . $this->langcode;
00169 } else {
00170 $this->suffix = '';
00171 }
00172 }
00173
00174 function getAllMessages( $descending ) {
00175 wfProfileIn( __METHOD__ );
00176 $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
00177 if( $descending ){
00178 rsort( $messageNames );
00179 } else {
00180 asort( $messageNames );
00181 }
00182
00183
00184 $messageNames = array_map( array( $this->lang, 'ucfirst' ), $messageNames );
00185 wfProfileIn( __METHOD__ );
00186
00187 return $messageNames;
00188 }
00189
00196 function getCustomisedStatuses( $messageNames ) {
00197 wfProfileIn( __METHOD__ . '-db' );
00198
00199 $dbr = wfGetDB( DB_SLAVE );
00200 $res = $dbr->select( 'page',
00201 array( 'page_namespace', 'page_title' ),
00202 array( 'page_namespace' => array( NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ) ),
00203 __METHOD__,
00204 array( 'USE INDEX' => 'name_title' )
00205 );
00206 $xNames = array_flip( $messageNames );
00207
00208 $pageFlags = $talkFlags = array();
00209
00210 while( $s = $dbr->fetchObject( $res ) ) {
00211 if( $s->page_namespace == NS_MEDIAWIKI ) {
00212 if( $this->foreign ) {
00213 $title = explode( '/', $s->page_title );
00214 if( count( $title ) === 2 && $this->langcode == $title[1]
00215 && isset( $xNames[$title[0]] ) )
00216 {
00217 $pageFlags["{$title[0]}"] = true;
00218 }
00219 } elseif( isset( $xNames[$s->page_title] ) ) {
00220 $pageFlags[$s->page_title] = true;
00221 }
00222 } else if( $s->page_namespace == NS_MEDIAWIKI_TALK ){
00223 $talkFlags[$s->page_title] = true;
00224 }
00225 }
00226 $dbr->freeResult( $res );
00227
00228 wfProfileOut( __METHOD__ . '-db' );
00229
00230 return array( 'pages' => $pageFlags, 'talks' => $talkFlags );
00231 }
00232
00233
00234
00235
00236 function reallyDoQuery( $offset, $limit, $descending ) {
00237 $result = new FakeResultWrapper( array() );
00238
00239 $messageNames = $this->getAllMessages( $descending );
00240 $statuses = $this->getCustomisedStatuses( $messageNames );
00241
00242 $count = 0;
00243 foreach( $messageNames as $key ) {
00244 $customised = isset( $statuses['pages'][$key] );
00245 if( $customised !== $this->custom &&
00246 ( $descending && ( $key < $offset || !$offset ) || !$descending && $key > $offset ) &&
00247 ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false )
00248 ){
00249 $result->result[] = array(
00250 'am_title' => $key,
00251 'am_actual' => wfMsgGetKey( $key, true, $this->langcode, false ),
00252 'am_default' => wfMsgGetKey( $key, false, $this->langcode, false ),
00253 'am_customised' => $customised,
00254 'am_talk_exists' => isset( $statuses['talks'][$key] )
00255 );
00256 $count++;
00257 }
00258 if( $count == $limit ) break;
00259 }
00260 return $result;
00261 }
00262
00263 function getStartBody() {
00264 return Xml::openElement( 'table', array( 'class' => 'TablePager', 'id' => 'mw-allmessagestable' ) ) . "\n" .
00265 "<thead><tr>
00266 <th rowspan=\"2\">" .
00267 wfMsg( 'allmessagesname' ) . "
00268 </th>
00269 <th>" .
00270 wfMsg( 'allmessagesdefault' ) .
00271 "</th>
00272 </tr>\n
00273 <tr>
00274 <th>" .
00275 wfMsg( 'allmessagescurrent' ) .
00276 "</th>
00277 </tr></thead><tbody>\n";
00278 }
00279
00280 function formatValue( $field, $value ){
00281 global $wgLang;
00282 switch( $field ){
00283
00284 case 'am_title' :
00285
00286 $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix );
00287 $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix );
00288
00289 if( $this->mCurrentRow->am_customised ){
00290 $title = $this->mSkin->linkKnown( $title, $wgLang->lcfirst( $value ) );
00291 } else {
00292 $title = $this->mSkin->link(
00293 $title,
00294 $wgLang->lcfirst( $value ),
00295 array(),
00296 array(),
00297 array( 'broken' )
00298 );
00299 }
00300 if ( $this->mCurrentRow->am_talk_exists ) {
00301 $talk = $this->mSkin->linkKnown( $talk , $this->talk );
00302 } else {
00303 $talk = $this->mSkin->link(
00304 $talk,
00305 $this->talk,
00306 array(),
00307 array(),
00308 array( 'broken' )
00309 );
00310 }
00311 return $title . ' (' . $talk . ')';
00312
00313 case 'am_default' :
00314 return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES );
00315 case 'am_actual' :
00316 return Sanitizer::escapeHtmlAllowEntities( $value, ENT_QUOTES );
00317 }
00318 return '';
00319 }
00320
00321 function formatRow( $row ){
00322
00323 $s = parent::formatRow( $row );
00324
00325
00326 if( $row->am_customised ){
00327 $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) );
00328 $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) );
00329 if ( $formatted == '' ) {
00330 $formatted = ' ';
00331 }
00332 $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
00333 . "</tr>\n";
00334 }
00335 return $s;
00336 }
00337
00338 function getRowAttrs( $row, $isSecond = false ){
00339 $arr = array();
00340 global $wgLang;
00341 if( $row->am_customised ){
00342 $arr['class'] = 'allmessages-customised';
00343 }
00344 if( !$isSecond ){
00345 $arr['id'] = Sanitizer::escapeId( 'msg_' . $wgLang->lcfirst( $row->am_title ) );
00346 }
00347 return $arr;
00348 }
00349
00350 function getCellAttrs( $field, $value ){
00351 if( $this->mCurrentRow->am_customised && $field == 'am_title' ){
00352 return array( 'rowspan' => '2', 'class' => $field );
00353 } else {
00354 return array( 'class' => $field );
00355 }
00356 }
00357
00358
00359 function getFieldNames() {
00360 return array(
00361 'am_title' => wfMsg( 'allmessagesname' ),
00362 'am_default' => wfMsg( 'allmessagesdefault' )
00363 );
00364 }
00365 function getTitle() {
00366 return SpecialPage::getTitleFor( 'Allmessages', false );
00367 }
00368 function isFieldSortable( $x ){
00369 return false;
00370 }
00371 function getDefaultSort(){
00372 return '';
00373 }
00374 function getQueryInfo(){
00375 return '';
00376 }
00377 }
00378
00379
00380
00381 class FakeResultWrapper extends ResultWrapper {
00382
00383 var $result = array();
00384 var $db = null;
00385 var $pos = 0;
00386 var $currentRow = null;
00387
00388 function __construct( $array ){
00389 $this->result = $array;
00390 }
00391
00392 function numRows() {
00393 return count( $this->result );
00394 }
00395
00396 function fetchRow() {
00397 $this->currentRow = $this->result[$this->pos++];
00398 return $this->currentRow;
00399 }
00400
00401 function seek( $row ) {
00402 $this->pos = $row;
00403 }
00404
00405 function free() {}
00406
00407
00408 function fetchObject(){
00409 $this->currentRow = $this->result[$this->pos++];
00410 return (object)$this->currentRow;
00411 }
00412
00413 function rewind() {
00414 $this->pos = 0;
00415 $this->currentRow = null;
00416 }
00417 }