MediaWiki  1.28.0
AllMessagesTablePager.php
Go to the documentation of this file.
1 <?php
29 
31 
32  public $mLimitsShown;
33 
37  public $lang;
38 
42  public $custom;
43 
44  function __construct( $page, $conds, $langObj = null ) {
45  parent::__construct( $page->getContext() );
46  $this->mIndexField = 'am_title';
47  $this->mPage = $page;
48  $this->mConds = $conds;
49  // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
50  $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
51  $this->mLimitsShown = [ 20, 50, 100, 250, 500, 5000 ];
52 
54 
55  $this->talk = $this->msg( 'talkpagelinktext' )->escaped();
56 
57  $this->lang = ( $langObj ? $langObj : $wgContLang );
58  $this->langcode = $this->lang->getCode();
59  $this->foreign = !$this->lang->equals( $wgContLang );
60 
61  $request = $this->getRequest();
62 
63  $this->filter = $request->getVal( 'filter', 'all' );
64  if ( $this->filter === 'all' ) {
65  $this->custom = null; // So won't match in either case
66  } else {
67  $this->custom = ( $this->filter === 'unmodified' );
68  }
69 
70  $prefix = $this->getLanguage()->ucfirst( $request->getVal( 'prefix', '' ) );
71  $prefix = $prefix !== '' ?
72  Title::makeTitleSafe( NS_MEDIAWIKI, $request->getVal( 'prefix', null ) ) :
73  null;
74 
75  if ( $prefix !== null ) {
76  $this->displayPrefix = $prefix->getDBkey();
77  $this->prefix = '/^' . preg_quote( $this->displayPrefix, '/' ) . '/i';
78  } else {
79  $this->displayPrefix = false;
80  $this->prefix = false;
81  }
82 
83  // The suffix that may be needed for message names if we're in a
84  // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
85  if ( $this->foreign ) {
86  $this->suffix = '/' . $this->langcode;
87  } else {
88  $this->suffix = '';
89  }
90  }
91 
92  function buildForm() {
93  $attrs = [ 'id' => 'mw-allmessages-form-lang', 'name' => 'lang' ];
94  $msg = wfMessage( 'allmessages-language' );
95  $langSelect = Xml::languageSelector( $this->langcode, false, null, $attrs, $msg );
96 
97  $out = Xml::openElement( 'form', [
98  'method' => 'get',
99  'action' => $this->getConfig()->get( 'Script' ),
100  'id' => 'mw-allmessages-form'
101  ] ) .
102  Xml::fieldset( $this->msg( 'allmessages-filter-legend' )->text() ) .
103  Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
104  Xml::openElement( 'table', [ 'class' => 'mw-allmessages-table' ] ) . "\n" .
105  '<tr>
106  <td class="mw-label">' .
107  Xml::label( $this->msg( 'allmessages-prefix' )->text(), 'mw-allmessages-form-prefix' ) .
108  "</td>\n
109  <td class=\"mw-input\">" .
110  Xml::input(
111  'prefix',
112  20,
113  str_replace( '_', ' ', $this->displayPrefix ),
114  [ 'id' => 'mw-allmessages-form-prefix' ]
115  ) .
116  "</td>\n
117  </tr>
118  <tr>\n
119  <td class='mw-label'>" .
120  $this->msg( 'allmessages-filter' )->escaped() .
121  "</td>\n
122  <td class='mw-input'>" .
123  Xml::radioLabel( $this->msg( 'allmessages-filter-unmodified' )->text(),
124  'filter',
125  'unmodified',
126  'mw-allmessages-form-filter-unmodified',
127  ( $this->filter === 'unmodified' )
128  ) .
129  Xml::radioLabel( $this->msg( 'allmessages-filter-all' )->text(),
130  'filter',
131  'all',
132  'mw-allmessages-form-filter-all',
133  ( $this->filter === 'all' )
134  ) .
135  Xml::radioLabel( $this->msg( 'allmessages-filter-modified' )->text(),
136  'filter',
137  'modified',
138  'mw-allmessages-form-filter-modified',
139  ( $this->filter === 'modified' )
140  ) .
141  "</td>\n
142  </tr>
143  <tr>\n
144  <td class=\"mw-label\">" . $langSelect[0] . "</td>\n
145  <td class=\"mw-input\">" . $langSelect[1] . "</td>\n
146  </tr>" .
147 
148  '<tr>
149  <td class="mw-label">' .
150  Xml::label( $this->msg( 'table_pager_limit_label' )->text(), 'mw-table_pager_limit_label' ) .
151  '</td>
152  <td class="mw-input">' .
153  $this->getLimitSelect( [ 'id' => 'mw-table_pager_limit_label' ] ) .
154  '</td>
155  <tr>
156  <td></td>
157  <td>' .
158  Xml::submitButton( $this->msg( 'allmessages-filter-submit' )->text() ) .
159  "</td>\n
160  </tr>" .
161 
162  Xml::closeElement( 'table' ) .
163  $this->getHiddenFields( [ 'title', 'prefix', 'filter', 'lang', 'limit' ] ) .
164  Xml::closeElement( 'fieldset' ) .
165  Xml::closeElement( 'form' );
166 
167  return $out;
168  }
169 
170  function getAllMessages( $descending ) {
171  $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
172 
173  // Normalise message names so they look like page titles and sort correctly - T86139
174  $messageNames = array_map( [ $this->lang, 'ucfirst' ], $messageNames );
175 
176  if ( $descending ) {
177  rsort( $messageNames );
178  } else {
179  asort( $messageNames );
180  }
181 
182  return $messageNames;
183  }
184 
196  public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
197  // FIXME: This function should be moved to Language:: or something.
198 
199  $dbr = wfGetDB( DB_REPLICA );
200  $res = $dbr->select( 'page',
201  [ 'page_namespace', 'page_title' ],
202  [ 'page_namespace' => [ NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ] ],
203  __METHOD__,
204  [ 'USE INDEX' => 'name_title' ]
205  );
206  $xNames = array_flip( $messageNames );
207 
208  $pageFlags = $talkFlags = [];
209 
210  foreach ( $res as $s ) {
211  $exists = false;
212 
213  if ( $foreign ) {
214  $titleParts = explode( '/', $s->page_title );
215  if ( count( $titleParts ) === 2 &&
216  $langcode === $titleParts[1] &&
217  isset( $xNames[$titleParts[0]] )
218  ) {
219  $exists = $titleParts[0];
220  }
221  } elseif ( isset( $xNames[$s->page_title] ) ) {
222  $exists = $s->page_title;
223  }
224 
225  $title = Title::newFromRow( $s );
226  if ( $exists && $title->inNamespace( NS_MEDIAWIKI ) ) {
227  $pageFlags[$exists] = true;
228  } elseif ( $exists && $title->inNamespace( NS_MEDIAWIKI_TALK ) ) {
229  $talkFlags[$exists] = true;
230  }
231  }
232 
233  return [ 'pages' => $pageFlags, 'talks' => $talkFlags ];
234  }
235 
244  function reallyDoQuery( $offset, $limit, $descending ) {
245  $result = new FakeResultWrapper( [] );
246 
247  $messageNames = $this->getAllMessages( $descending );
248  $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign );
249 
250  $count = 0;
251  foreach ( $messageNames as $key ) {
252  $customised = isset( $statuses['pages'][$key] );
253  if ( $customised !== $this->custom &&
254  ( $descending && ( $key < $offset || !$offset ) || !$descending && $key > $offset ) &&
255  ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false )
256  ) {
257  $actual = wfMessage( $key )->inLanguage( $this->langcode )->plain();
258  $default = wfMessage( $key )->inLanguage( $this->langcode )->useDatabase( false )->plain();
259  $result->result[] = [
260  'am_title' => $key,
261  'am_actual' => $actual,
262  'am_default' => $default,
263  'am_customised' => $customised,
264  'am_talk_exists' => isset( $statuses['talks'][$key] )
265  ];
266  $count++;
267  }
268 
269  if ( $count === $limit ) {
270  break;
271  }
272  }
273 
274  return $result;
275  }
276 
277  function getStartBody() {
278  $tableClass = $this->getTableClass();
279  return Xml::openElement( 'table', [
280  'class' => "mw-datatable $tableClass",
281  'id' => 'mw-allmessagestable'
282  ] ) .
283  "\n" .
284  "<thead><tr>
285  <th rowspan=\"2\">" .
286  $this->msg( 'allmessagesname' )->escaped() . "
287  </th>
288  <th>" .
289  $this->msg( 'allmessagesdefault' )->escaped() .
290  "</th>
291  </tr>\n
292  <tr>
293  <th>" .
294  $this->msg( 'allmessagescurrent' )->escaped() .
295  "</th>
296  </tr></thead><tbody>\n";
297  }
298 
299  function formatValue( $field, $value ) {
300  switch ( $field ) {
301  case 'am_title' :
302  $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix );
303  $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix );
304  $translation = Linker::makeExternalLink(
305  'https://translatewiki.net/w/i.php?' . wfArrayToCgi( [
306  'title' => 'Special:SearchTranslations',
307  'group' => 'mediawiki',
308  'grouppath' => 'mediawiki',
309  'language' => $this->getLanguage()->getCode(),
310  'query' => $value . ' ' . $this->msg( $value )->plain()
311  ] ),
312  $this->msg( 'allmessages-filter-translate' )->text()
313  );
314 
315  if ( $this->mCurrentRow->am_customised ) {
316  $title = Linker::linkKnown( $title, $this->getLanguage()->lcfirst( $value ) );
317  } else {
319  $title,
320  $this->getLanguage()->lcfirst( $value ),
321  [],
322  [],
323  [ 'broken' ]
324  );
325  }
326  if ( $this->mCurrentRow->am_talk_exists ) {
327  $talk = Linker::linkKnown( $talk, $this->talk );
328  } else {
329  $talk = Linker::link(
330  $talk,
331  $this->talk,
332  [],
333  [],
334  [ 'broken' ]
335  );
336  }
337 
338  return $title . ' ' .
339  $this->msg( 'parentheses' )->rawParams( $talk )->escaped() .
340  ' ' .
341  $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
342 
343  case 'am_default' :
344  case 'am_actual' :
346  }
347 
348  return '';
349  }
350 
351  function formatRow( $row ) {
352  // Do all the normal stuff
353  $s = parent::formatRow( $row );
354 
355  // But if there's a customised message, add that too.
356  if ( $row->am_customised ) {
357  $s .= Xml::openElement( 'tr', $this->getRowAttrs( $row, true ) );
358  $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) );
359 
360  if ( $formatted === '' ) {
361  $formatted = '&#160;';
362  }
363 
364  $s .= Xml::tags( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
365  . "</tr>\n";
366  }
367 
368  return $s;
369  }
370 
371  function getRowAttrs( $row, $isSecond = false ) {
372  $arr = [];
373 
374  if ( $row->am_customised ) {
375  $arr['class'] = 'allmessages-customised';
376  }
377 
378  if ( !$isSecond ) {
379  $arr['id'] = Sanitizer::escapeId( 'msg_' . $this->getLanguage()->lcfirst( $row->am_title ) );
380  }
381 
382  return $arr;
383  }
384 
385  function getCellAttrs( $field, $value ) {
386  if ( $this->mCurrentRow->am_customised && $field === 'am_title' ) {
387  return [ 'rowspan' => '2', 'class' => $field ];
388  } elseif ( $field === 'am_title' ) {
389  return [ 'class' => $field ];
390  } else {
391  return [
392  'lang' => $this->lang->getHtmlCode(),
393  'dir' => $this->lang->getDir(),
394  'class' => $field
395  ];
396  }
397  }
398 
399  // This is not actually used, as getStartBody is overridden above
400  function getFieldNames() {
401  return [
402  'am_title' => $this->msg( 'allmessagesname' )->text(),
403  'am_default' => $this->msg( 'allmessagesdefault' )->text()
404  ];
405  }
406 
407  function getTitle() {
408  return SpecialPage::getTitleFor( 'Allmessages', false );
409  }
410 
411  function isFieldSortable( $x ) {
412  return false;
413  }
414 
415  function getDefaultSort() {
416  return '';
417  }
418 
419  function getQueryInfo() {
420  return '';
421  }
422 
423 }
const DIR_DESCENDING
Definition: IndexPager.php:73
static newFromRow($row)
Make a Title object from a DB row.
Definition: Title.php:450
getTitle()
Get the Title object.
Table-based display with a user-selectable sort order.
Definition: TablePager.php:28
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:404
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:802
getLanguage()
Get the Language object.
either a plain
Definition: hooks.txt:1987
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name If you don't need a full Title object...
Definition: SpecialPage.php:82
static radioLabel($label, $name, $value, $id, $checked=false, $attribs=[])
Convenience function to build an HTML radio button with a label.
Definition: Xml.php:445
getLimitSelect($attribs=[])
Get a " elements for use in a method="get" form.
Definition: TablePager.php:390
msg()
Get a Message object with context set Parameters are the same as wfMessage()
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"&lt
const NS_MEDIAWIKI_TALK
Definition: Defines.php:65
static escapeHtmlAllowEntities($html)
Given HTML input, escape with htmlspecialchars but un-escape entities.
Definition: Sanitizer.php:1262
$res
Definition: database.txt:21
getConfig()
Get the Config object.
static languageSelector($selected, $customisedOnly=true, $inLanguage=null, $overrideAttrs=[], Message $msg=null)
Construct a language selector appropriate for use in a form or preferences.
Definition: Xml.php:204
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
static makeTitleSafe($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:535
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:953
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
reallyDoQuery($offset, $limit, $descending)
This function normally does a database query to get the results; we need to make a pretend result usi...
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
const NS_MEDIAWIKI
Definition: Defines.php:64
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:203
static escapeId($id, $options=[])
Given a value, escape it so that it can be used in an id attribute and return it. ...
Definition: Sanitizer.php:1170
static makeExternalLink($url, $text, $escape=true, $linktype= '', $attribs=[], $title=null)
Make an external link.
Definition: Linker.php:934
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static tags($element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2573
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
wfArrayToCgi($array1, $array2=null, $prefix= '')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
static getCustomisedStatuses($messageNames, $langcode= 'en', $foreign=false)
Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1046
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition: design.txt:56
__construct($page, $conds, $langObj=null)
$count
const DB_REPLICA
Definition: defines.php:22
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2491
Use TablePager for prettified output.