*/
class AllMessagesTablePager extends TablePager {
- protected $filter, $prefix, $langcode, $displayPrefix;
+ /**
+ * @var string
+ */
+ protected $langcode;
- public $mLimitsShown;
+ /**
+ * @var bool
+ */
+ protected $foreign;
+
+ /**
+ * @var string
+ */
+ protected $prefix;
/**
* @var Language
*/
public $custom;
- function __construct( $page, $conds, Language $langObj = null ) {
- parent::__construct( $page->getContext() );
+ /**
+ * @param IContextSource|null $context
+ * @param FormOptions $opts
+ */
+ public function __construct( IContextSource $context = null, FormOptions $opts ) {
+ parent::__construct( $context );
+
$this->mIndexField = 'am_title';
- $this->mPage = $page;
- $this->mConds = $conds;
// FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
$this->mDefaultDirection = IndexPager::DIR_DESCENDING;
- $this->mLimitsShown = [ 20, 50, 100, 250, 500, 5000 ];
-
- $this->talk = $this->msg( 'talkpagelinktext' )->escaped();
+ $langObj = wfGetLangObj( $opts->getValue( 'lang' ) );
$contLang = MediaWikiServices::getInstance()->getContentLanguage();
$this->lang = $langObj ?? $contLang;
+
$this->langcode = $this->lang->getCode();
$this->foreign = !$this->lang->equals( $contLang );
- $request = $this->getRequest();
-
- $this->filter = $request->getVal( 'filter', 'all' );
- if ( $this->filter === 'all' ) {
+ $filter = $opts->getValue( 'filter' );
+ if ( $filter === 'all' ) {
$this->custom = null; // So won't match in either case
} else {
- $this->custom = ( $this->filter === 'unmodified' );
+ $this->custom = ( $filter === 'unmodified' );
}
- $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
+ $prefix = $this->getLanguage()->ucfirst( $opts->getValue( 'prefix' ) );
$prefix = $prefix !== '' ?
- Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'prefix', null ) ) :
+ Title::makeTitleSafe( NS_MEDIAWIKI, $opts->getValue( 'prefix' ) ) :
null;
if ( $prefix !== null ) {
- $this->displayPrefix = $prefix->getDBkey();
- $this->prefix = '/^' . preg_quote( $this->displayPrefix, '/' ) . '/i';
+ $displayPrefix = $prefix->getDBkey();
+ $this->prefix = '/^' . preg_quote( $displayPrefix, '/' ) . '/i';
} else {
- $this->displayPrefix = false;
$this->prefix = false;
}
}
}
- function buildForm() {
- $attrs = [ 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ];
- $msg = wfMessage( 'allmessages-language' );
- $langSelect = Xml::languageSelector( $this->langcode, false, null, $attrs, $msg );
-
- $out = Xml::openElement( 'form', [
- 'method' => 'get',
- 'action' => $this->getConfig()->get( 'Script' ),
- 'id' => 'mw-allmessages-form'
- ] ) .
- Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
- Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
- Xml::openElement( 'table', [ 'class' => 'mw-allmessages-table' ] ) . "\n" .
- '<tr>
- <td class="mw-label">' .
- Xml::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
- "</td>\n
- <td class=\"mw-input\">" .
- Xml::input(
- 'prefix',
- 20,
- str_replace( '_', ' ', $this->displayPrefix ),
- [ 'id' => 'mw-allmessages-form-prefix' ]
- ) .
- "</td>\n
- </tr>
- <tr>\n
- <td class='mw-label'>" .
- $this->msg( 'allmessages-filter' )->escaped() .
- "</td>\n
- <td class='mw-input'>" .
- Xml::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
- 'filter',
- 'unmodified',
- 'mw-allmessages-form-filter-unmodified',
- ( $this->filter === 'unmodified' )
- ) .
- Xml::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
- 'filter',
- 'all',
- 'mw-allmessages-form-filter-all',
- ( $this->filter === 'all' )
- ) .
- Xml::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
- 'filter',
- 'modified',
- 'mw-allmessages-form-filter-modified',
- ( $this->filter === 'modified' )
- ) .
- "</td>\n
- </tr>
- <tr>\n
- <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
- <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
- </tr>" .
-
- '<tr>
- <td class="mw-label">' .
- Xml::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
- '</td>
- <td class="mw-input">' .
- $this->getLimitSelect( [ 'id' => 'mw-table_pager_limit_label' ] ) .
- '</td>
- <tr>
- <td></td>
- <td>' .
- Xml::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
- "</td>\n
- </tr>" .
-
- Xml::closeElement( 'table' ) .
- $this->getHiddenFields( [ 'title', 'prefix', 'filter', 'lang', 'limit' ] ) .
- Xml::closeElement( 'fieldset' ) .
- Xml::closeElement( 'form' );
-
- return $out;
- }
-
function getAllMessages( $descending ) {
$messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
return $result;
}
- function getStartBody() {
+ protected function getStartBody() {
$tableClass = $this->getTableClass();
return Xml::openElement( 'table', [
'class' => "mw-datatable $tableClass",
<th>" .
$this->msg( 'allmessagescurrent' )->escaped() .
"</th>
- </tr></thead><tbody>\n";
+ </tr></thead>\n";
+ }
+
+ function getEndBody() {
+ return Html::closeElement( 'table' );
}
function formatValue( $field, $value ) {
] ),
$this->msg( 'allmessages-filter-translate' )->text()
);
+ $talkLink = $this->msg( 'talkpagelinktext' )->escaped();
if ( $this->mCurrentRow->am_customised ) {
$title = $linkRenderer->makeKnownLink( $title, $this->getLanguage()->lcfirst( $value ) );
);
}
if ( $this->mCurrentRow->am_talk_exists ) {
- $talk = $linkRenderer->makeKnownLink( $talk, $this->talk );
+ $talk = $linkRenderer->makeKnownLink( $talk, $talkLink );
} else {
$talk = $linkRenderer->makeBrokenLink(
$talk,
- $this->talk
+ $talkLink
);
}
return '';
}
+ /** @return string HTML */
function formatRow( $row ) {
// Do all the normal stuff
$s = parent::formatRow( $row );
// But if there's a customised message, add that too.
if ( $row->am_customised ) {
- $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) );
+ $s .= Html::openElement( 'tr', $this->getRowAttrs( $row, true ) );
$formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) );
if ( $formatted === '' ) {
$formatted = "\u{00A0}";
}
- $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
- . "</tr>\n";
+ $s .= Html::element( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
+ . Html::closeElement( 'tr' );
}
- return $s;
+ return Html::rawElement( 'tbody', [], $s );
}
- function getRowAttrs( $row, $isSecond = false ) {
- $arr = [];
-
- if ( $row->am_customised ) {
- $arr['class'] = 'allmessages-customised';
- }
-
- if ( !$isSecond ) {
- $arr['id'] = Sanitizer::escapeIdForAttribute(
- 'msg_' . $this->getLanguage()->lcfirst( $row->am_title )
- );
- }
-
- return $arr;
+ function getRowAttrs( $row ) {
+ return [];
}
+ /** @return array HTML attributes */
function getCellAttrs( $field, $value ) {
- if ( $this->mCurrentRow->am_customised && $field === 'am_title' ) {
- return [ 'rowspan' => '2', 'class' => $field ];
- } elseif ( $field === 'am_title' ) {
- return [ 'class' => $field ];
+ $attr = [];
+ if ( $field === 'am_title' ) {
+ if ( $this->mCurrentRow->am_customised ) {
+ $attr += [ 'rowspan' => '2' ];
+ }
} else {
- return [
+ $attr += [
'lang' => $this->lang->getHtmlCode(),
'dir' => $this->lang->getDir(),
- 'class' => $field
];
+ if ( $this->mCurrentRow->am_customised ) {
+ // CSS class: am_default, am_actual
+ $attr += [ 'class' => $field ];
+ }
}
+ return $attr;
}
// This is not actually used, as getStartBody is overridden above