MediaWiki  1.33.0
AllMessagesTablePager.php
Go to the documentation of this file.
1 <?php
24 
32 
36  protected $langcode;
37 
41  protected $foreign;
42 
46  protected $prefix;
47 
51  public $lang;
52 
56  public $custom;
57 
62  public function __construct( IContextSource $context = null, FormOptions $opts ) {
63  parent::__construct( $context );
64 
65  $this->mIndexField = 'am_title';
66  // FIXME: Why does this need to be set to DIR_DESCENDING to produce ascending ordering?
67  $this->mDefaultDirection = IndexPager::DIR_DESCENDING;
68 
69  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
70  $this->lang = wfGetLangObj( $opts->getValue( 'lang' ) );
71 
72  $this->langcode = $this->lang->getCode();
73  $this->foreign = !$this->lang->equals( $contLang );
74 
75  $filter = $opts->getValue( 'filter' );
76  if ( $filter === 'all' ) {
77  $this->custom = null; // So won't match in either case
78  } else {
79  $this->custom = ( $filter === 'unmodified' );
80  }
81 
82  $prefix = $this->getLanguage()->ucfirst( $opts->getValue( 'prefix' ) );
83  $prefix = $prefix !== '' ?
84  Title::makeTitleSafe( NS_MEDIAWIKI, $opts->getValue( 'prefix' ) ) :
85  null;
86 
87  if ( $prefix !== null ) {
88  $displayPrefix = $prefix->getDBkey();
89  $this->prefix = '/^' . preg_quote( $displayPrefix, '/' ) . '/i';
90  } else {
91  $this->prefix = false;
92  }
93 
94  // The suffix that may be needed for message names if we're in a
95  // different language (eg [[MediaWiki:Foo/fr]]: $suffix = '/fr'
96  if ( $this->foreign ) {
97  $this->suffix = '/' . $this->langcode;
98  } else {
99  $this->suffix = '';
100  }
101  }
102 
103  function getAllMessages( $descending ) {
104  $messageNames = Language::getLocalisationCache()->getSubitemList( 'en', 'messages' );
105 
106  // Normalise message names so they look like page titles and sort correctly - T86139
107  $messageNames = array_map( [ $this->lang, 'ucfirst' ], $messageNames );
108 
109  if ( $descending ) {
110  rsort( $messageNames );
111  } else {
112  asort( $messageNames );
113  }
114 
115  return $messageNames;
116  }
117 
129  public static function getCustomisedStatuses( $messageNames, $langcode = 'en', $foreign = false ) {
130  // FIXME: This function should be moved to Language:: or something.
131 
132  $dbr = wfGetDB( DB_REPLICA );
133  $res = $dbr->select( 'page',
134  [ 'page_namespace', 'page_title' ],
135  [ 'page_namespace' => [ NS_MEDIAWIKI, NS_MEDIAWIKI_TALK ] ],
136  __METHOD__,
137  [ 'USE INDEX' => 'name_title' ]
138  );
139  $xNames = array_flip( $messageNames );
140 
141  $pageFlags = $talkFlags = [];
142 
143  foreach ( $res as $s ) {
144  $exists = false;
145 
146  if ( $foreign ) {
147  $titleParts = explode( '/', $s->page_title );
148  if ( count( $titleParts ) === 2 &&
149  $langcode === $titleParts[1] &&
150  isset( $xNames[$titleParts[0]] )
151  ) {
152  $exists = $titleParts[0];
153  }
154  } elseif ( isset( $xNames[$s->page_title] ) ) {
155  $exists = $s->page_title;
156  }
157 
159  if ( $exists && $title->inNamespace( NS_MEDIAWIKI ) ) {
160  $pageFlags[$exists] = true;
161  } elseif ( $exists && $title->inNamespace( NS_MEDIAWIKI_TALK ) ) {
162  $talkFlags[$exists] = true;
163  }
164  }
165 
166  return [ 'pages' => $pageFlags, 'talks' => $talkFlags ];
167  }
168 
177  function reallyDoQuery( $offset, $limit, $order ) {
178  $asc = ( $order === self::QUERY_ASCENDING );
179  $result = new FakeResultWrapper( [] );
180 
181  $messageNames = $this->getAllMessages( $order );
182  $statuses = self::getCustomisedStatuses( $messageNames, $this->langcode, $this->foreign );
183 
184  $count = 0;
185  foreach ( $messageNames as $key ) {
186  $customised = isset( $statuses['pages'][$key] );
187  if ( $customised !== $this->custom &&
188  ( $asc && ( $key < $offset || !$offset ) || !$asc && $key > $offset ) &&
189  ( ( $this->prefix && preg_match( $this->prefix, $key ) ) || $this->prefix === false )
190  ) {
191  $actual = wfMessage( $key )->inLanguage( $this->lang )->plain();
192  $default = wfMessage( $key )->inLanguage( $this->lang )->useDatabase( false )->plain();
193  $result->result[] = [
194  'am_title' => $key,
195  'am_actual' => $actual,
196  'am_default' => $default,
197  'am_customised' => $customised,
198  'am_talk_exists' => isset( $statuses['talks'][$key] )
199  ];
200  $count++;
201  }
202 
203  if ( $count === $limit ) {
204  break;
205  }
206  }
207 
208  return $result;
209  }
210 
211  protected function getStartBody() {
212  $tableClass = $this->getTableClass();
213  return Xml::openElement( 'table', [
214  'class' => "mw-datatable $tableClass",
215  'id' => 'mw-allmessagestable'
216  ] ) .
217  "\n" .
218  "<thead><tr>
219  <th rowspan=\"2\">" .
220  $this->msg( 'allmessagesname' )->escaped() . "
221  </th>
222  <th>" .
223  $this->msg( 'allmessagesdefault' )->escaped() .
224  "</th>
225  </tr>\n
226  <tr>
227  <th>" .
228  $this->msg( 'allmessagescurrent' )->escaped() .
229  "</th>
230  </tr></thead>\n";
231  }
232 
233  function getEndBody() {
234  return Html::closeElement( 'table' );
235  }
236 
237  function formatValue( $field, $value ) {
238  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
239  switch ( $field ) {
240  case 'am_title' :
241  $title = Title::makeTitle( NS_MEDIAWIKI, $value . $this->suffix );
242  $talk = Title::makeTitle( NS_MEDIAWIKI_TALK, $value . $this->suffix );
243  $translation = Linker::makeExternalLink(
244  'https://translatewiki.net/w/i.php?' . wfArrayToCgi( [
245  'title' => 'Special:SearchTranslations',
246  'group' => 'mediawiki',
247  'grouppath' => 'mediawiki',
248  'language' => $this->getLanguage()->getCode(),
249  'query' => $value . ' ' . $this->msg( $value )->plain()
250  ] ),
251  $this->msg( 'allmessages-filter-translate' )->text()
252  );
253  $talkLink = $this->msg( 'talkpagelinktext' )->escaped();
254 
255  if ( $this->mCurrentRow->am_customised ) {
256  $title = $linkRenderer->makeKnownLink( $title, $this->getLanguage()->lcfirst( $value ) );
257  } else {
258  $title = $linkRenderer->makeBrokenLink(
259  $title,
260  $this->getLanguage()->lcfirst( $value )
261  );
262  }
263  if ( $this->mCurrentRow->am_talk_exists ) {
264  $talk = $linkRenderer->makeKnownLink( $talk, $talkLink );
265  } else {
266  $talk = $linkRenderer->makeBrokenLink(
267  $talk,
268  $talkLink
269  );
270  }
271 
272  return $title . ' ' .
273  $this->msg( 'parentheses' )->rawParams( $talk )->escaped() .
274  ' ' .
275  $this->msg( 'parentheses' )->rawParams( $translation )->escaped();
276 
277  case 'am_default' :
278  case 'am_actual' :
279  return Sanitizer::escapeHtmlAllowEntities( $value );
280  }
281 
282  return '';
283  }
284 
289  function formatRow( $row ) {
290  // Do all the normal stuff
291  $s = parent::formatRow( $row );
292 
293  // But if there's a customised message, add that too.
294  if ( $row->am_customised ) {
295  $s .= Html::openElement( 'tr', $this->getRowAttrs( $row, true ) );
296  $formatted = strval( $this->formatValue( 'am_actual', $row->am_actual ) );
297 
298  if ( $formatted === '' ) {
299  $formatted = "\u{00A0}";
300  }
301 
302  $s .= Html::element( 'td', $this->getCellAttrs( 'am_actual', $row->am_actual ), $formatted )
303  . Html::closeElement( 'tr' );
304  }
305 
306  return Html::rawElement( 'tbody', [], $s );
307  }
308 
309  function getRowAttrs( $row ) {
310  return [];
311  }
312 
318  function getCellAttrs( $field, $value ) {
319  $attr = [];
320  if ( $field === 'am_title' ) {
321  if ( $this->mCurrentRow->am_customised ) {
322  $attr += [ 'rowspan' => '2' ];
323  }
324  } else {
325  $attr += [
326  'lang' => $this->lang->getHtmlCode(),
327  'dir' => $this->lang->getDir(),
328  ];
329  if ( $this->mCurrentRow->am_customised ) {
330  // CSS class: am_default, am_actual
331  $attr += [ 'class' => $field ];
332  }
333  }
334  return $attr;
335  }
336 
337  // This is not actually used, as getStartBody is overridden above
338  function getFieldNames() {
339  return [
340  'am_title' => $this->msg( 'allmessagesname' )->text(),
341  'am_default' => $this->msg( 'allmessagesdefault' )->text()
342  ];
343  }
344 
345  function getTitle() {
346  return SpecialPage::getTitleFor( 'Allmessages', false );
347  }
348 
349  function isFieldSortable( $x ) {
350  return false;
351  }
352 
353  function getDefaultSort() {
354  return '';
355  }
356 
357  function getQueryInfo() {
358  return '';
359  }
360 
361 }
$filter
$filter
Definition: profileinfo.php:341
AllMessagesTablePager\getCellAttrs
getCellAttrs( $field, $value)
Definition: AllMessagesTablePager.php:318
ContextSource\$context
IContextSource $context
Definition: ContextSource.php:33
AllMessagesTablePager
Use TablePager for prettified output.
Definition: AllMessagesTablePager.php:31
AllMessagesTablePager\$custom
null bool $custom
Definition: AllMessagesTablePager.php:56
AllMessagesTablePager\formatValue
formatValue( $field, $value)
Format a table cell.
Definition: AllMessagesTablePager.php:237
IndexPager\QUERY_ASCENDING
const QUERY_ASCENDING
Backwards-compatible constant for reallyDoQuery() (do not change)
Definition: IndexPager.php:76
FormOptions\getValue
getValue( $name)
Get the value for the given option name.
Definition: FormOptions.php:180
captcha-old.count
count
Definition: captcha-old.py:249
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED since 1.28! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1983
TablePager\getTableClass
getTableClass()
TablePager relies on mw-datatable for styling, see T214208.
Definition: TablePager.php:272
$s
$s
Definition: mergeMessageFileList.php:186
$linkRenderer
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1985
SpecialPage\getTitleFor
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
$res
$res
Definition: database.txt:21
AllMessagesTablePager\formatRow
formatRow( $row)
Definition: AllMessagesTablePager.php:289
Wikimedia\Rdbms\FakeResultWrapper
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Definition: FakeResultWrapper.php:11
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
AllMessagesTablePager\$langcode
string $langcode
Definition: AllMessagesTablePager.php:36
php
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
AllMessagesTablePager\getTitle
getTitle()
Definition: AllMessagesTablePager.php:345
$dbr
$dbr
Definition: testCompression.php:50
ContextSource\getLanguage
getLanguage()
Definition: ContextSource.php:128
AllMessagesTablePager\$prefix
string $prefix
Definition: AllMessagesTablePager.php:46
AllMessagesTablePager\getStartBody
getStartBody()
Definition: AllMessagesTablePager.php:211
AllMessagesTablePager\getCustomisedStatuses
static getCustomisedStatuses( $messageNames, $langcode='en', $foreign=false)
Determine which of the MediaWiki and MediaWiki_talk namespace pages exist.
Definition: AllMessagesTablePager.php:129
Language\getLocalisationCache
static getLocalisationCache()
Get the LocalisationCache instance.
Definition: Language.php:447
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
AllMessagesTablePager\getEndBody
getEndBody()
Definition: AllMessagesTablePager.php:233
Title\newFromRow
static newFromRow( $row)
Make a Title object from a DB row.
Definition: Title.php:506
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
AllMessagesTablePager\$foreign
bool $foreign
Definition: AllMessagesTablePager.php:41
NS_MEDIAWIKI_TALK
const NS_MEDIAWIKI_TALK
Definition: Defines.php:73
TablePager
Table-based display with a user-selectable sort order.
Definition: TablePager.php:28
AllMessagesTablePager\getDefaultSort
getDefaultSort()
The database field name used as a default sort order.
Definition: AllMessagesTablePager.php:353
wfGetLangObj
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
Definition: GlobalFunctions.php:1241
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Linker\makeExternalLink
static makeExternalLink( $url, $text, $escape=true, $linktype='', $attribs=[], $title=null)
Make an external link.
Definition: Linker.php:842
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:576
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
AllMessagesTablePager\getFieldNames
getFieldNames()
An array mapping database field names to a textual description of the field name, for use in the tabl...
Definition: AllMessagesTablePager.php:338
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:604
$value
$value
Definition: styleTest.css.php:49
AllMessagesTablePager\getQueryInfo
getQueryInfo()
This function should be overridden to provide all parameters needed for the main paged query.
Definition: AllMessagesTablePager.php:357
AllMessagesTablePager\isFieldSortable
isFieldSortable( $x)
Return true if the named field should be sortable by the UI, false otherwise.
Definition: AllMessagesTablePager.php:349
plain
either a plain
Definition: hooks.txt:2046
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition: IContextSource.php:53
IndexPager\DIR_DESCENDING
const DIR_DESCENDING
Backwards-compatible constant for $mDefaultDirection field (do not change)
Definition: IndexPager.php:73
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
AllMessagesTablePager\__construct
__construct(IContextSource $context=null, FormOptions $opts)
Definition: AllMessagesTablePager.php:62
as
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
AllMessagesTablePager\getAllMessages
getAllMessages( $descending)
Definition: AllMessagesTablePager.php:103
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
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 use $formDescriptor instead 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 unset offset - wrap String Wrap the message in html(usually something like "&lt
AllMessagesTablePager\getRowAttrs
getRowAttrs( $row)
Get attributes to be applied to the given row.
Definition: AllMessagesTablePager.php:309
Language
Internationalisation code.
Definition: Language.php:36
AllMessagesTablePager\$lang
Language $lang
Definition: AllMessagesTablePager.php:51
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:371
AllMessagesTablePager\reallyDoQuery
reallyDoQuery( $offset, $limit, $order)
This function normally does a database query to get the results; we need to make a pretend result usi...
Definition: AllMessagesTablePager.php:177