2006-07-03 11:07:00 +00:00
|
|
|
<?php
|
2010-08-22 14:31:05 +00:00
|
|
|
/**
|
|
|
|
|
* Parser functions provided by MediaWiki core
|
|
|
|
|
*
|
2012-04-30 09:22:16 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2010-08-22 14:31:05 +00:00
|
|
|
* @file
|
2012-04-30 09:22:16 +00:00
|
|
|
* @ingroup Parser
|
2010-08-22 14:31:05 +00:00
|
|
|
*/
|
2020-04-17 20:51:02 +00:00
|
|
|
|
2016-11-22 23:14:43 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-04-17 20:51:02 +00:00
|
|
|
use MediaWiki\Revision\RevisionAccessException;
|
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2006-07-03 11:07:00 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Various core parser functions, registered in Parser::firstCallInit()
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Parser
|
2006-07-03 11:07:00 +00:00
|
|
|
*/
|
|
|
|
|
class CoreParserFunctions {
|
2011-02-08 23:18:13 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-02-08 23:18:13 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function register( $parser ) {
|
2008-02-20 08:53:12 +00:00
|
|
|
global $wgAllowDisplayTitle, $wgAllowSlowParserFunctions;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-08-04 09:43:03 +00:00
|
|
|
# Syntax for arguments (see Parser::setFunctionHook):
|
2008-02-20 08:53:12 +00:00
|
|
|
# "name for lookup in localized magic words array",
|
|
|
|
|
# function callback,
|
2014-11-11 19:28:28 +00:00
|
|
|
# optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
|
2008-02-20 08:53:12 +00:00
|
|
|
# instead of {{#int:...}})
|
2016-02-17 09:09:32 +00:00
|
|
|
$noHashFunctions = [
|
2013-12-27 20:57:50 +00:00
|
|
|
'ns', 'nse', 'urlencode', 'lcfirst', 'ucfirst', 'lc', 'uc',
|
|
|
|
|
'localurl', 'localurle', 'fullurl', 'fullurle', 'canonicalurl',
|
2015-06-29 21:48:41 +00:00
|
|
|
'canonicalurle', 'formatnum', 'grammar', 'gender', 'plural', 'bidi',
|
2013-12-27 20:57:50 +00:00
|
|
|
'numberofpages', 'numberofusers', 'numberofactiveusers',
|
|
|
|
|
'numberofarticles', 'numberoffiles', 'numberofadmins',
|
2014-07-30 20:56:20 +00:00
|
|
|
'numberingroup', 'numberofedits', 'language',
|
2013-12-27 20:57:50 +00:00
|
|
|
'padleft', 'padright', 'anchorencode', 'defaultsort', 'filepath',
|
2015-11-27 18:44:11 +00:00
|
|
|
'pagesincategory', 'pagesize', 'protectionlevel', 'protectionexpiry',
|
2013-12-27 20:57:50 +00:00
|
|
|
'namespacee', 'namespacenumber', 'talkspace', 'talkspacee',
|
|
|
|
|
'subjectspace', 'subjectspacee', 'pagename', 'pagenamee',
|
|
|
|
|
'fullpagename', 'fullpagenamee', 'rootpagename', 'rootpagenamee',
|
|
|
|
|
'basepagename', 'basepagenamee', 'subpagename', 'subpagenamee',
|
|
|
|
|
'talkpagename', 'talkpagenamee', 'subjectpagename',
|
|
|
|
|
'subjectpagenamee', 'pageid', 'revisionid', 'revisionday',
|
|
|
|
|
'revisionday2', 'revisionmonth', 'revisionmonth1', 'revisionyear',
|
2014-01-02 18:27:29 +00:00
|
|
|
'revisiontimestamp', 'revisionuser', 'cascadingsources',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-12-27 20:57:50 +00:00
|
|
|
foreach ( $noHashFunctions as $func ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$parser->setFunctionHook( $func, [ __CLASS__, $func ], Parser::SFH_NO_HASH );
|
2013-12-27 20:57:50 +00:00
|
|
|
}
|
2008-02-20 08:53:12 +00:00
|
|
|
|
2015-09-26 17:17:49 +00:00
|
|
|
$parser->setFunctionHook(
|
|
|
|
|
'namespace',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ __CLASS__, 'mwnamespace' ],
|
2015-09-26 17:17:49 +00:00
|
|
|
Parser::SFH_NO_HASH
|
|
|
|
|
);
|
2016-02-17 09:09:32 +00:00
|
|
|
$parser->setFunctionHook( 'int', [ __CLASS__, 'intFunction' ], Parser::SFH_NO_HASH );
|
|
|
|
|
$parser->setFunctionHook( 'special', [ __CLASS__, 'special' ] );
|
|
|
|
|
$parser->setFunctionHook( 'speciale', [ __CLASS__, 'speciale' ] );
|
|
|
|
|
$parser->setFunctionHook( 'tag', [ __CLASS__, 'tagObj' ], Parser::SFH_OBJECT_ARGS );
|
|
|
|
|
$parser->setFunctionHook( 'formatdate', [ __CLASS__, 'formatDate' ] );
|
2008-02-20 08:53:12 +00:00
|
|
|
|
|
|
|
|
if ( $wgAllowDisplayTitle ) {
|
2015-09-26 17:17:49 +00:00
|
|
|
$parser->setFunctionHook(
|
|
|
|
|
'displaytitle',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ __CLASS__, 'displaytitle' ],
|
2015-09-26 17:17:49 +00:00
|
|
|
Parser::SFH_NO_HASH
|
|
|
|
|
);
|
2008-02-20 08:53:12 +00:00
|
|
|
}
|
|
|
|
|
if ( $wgAllowSlowParserFunctions ) {
|
2014-05-10 23:03:45 +00:00
|
|
|
$parser->setFunctionHook(
|
|
|
|
|
'pagesinnamespace',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ __CLASS__, 'pagesinnamespace' ],
|
2014-11-11 19:28:28 +00:00
|
|
|
Parser::SFH_NO_HASH
|
2014-05-10 23:03:45 +00:00
|
|
|
);
|
2008-02-20 08:53:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
* @param string $part1 Message key
|
|
|
|
|
* @param mixed ...$params To pass to wfMessage()
|
2011-02-19 01:02:56 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
public static function intFunction( $parser, $part1 = '', ...$params ) {
|
2006-09-30 04:53:36 +00:00
|
|
|
if ( strval( $part1 ) !== '' ) {
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
$message = wfMessage( $part1, $params )
|
2015-07-24 20:02:54 +00:00
|
|
|
->inLanguage( $parser->getOptions()->getUserLangObj() );
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $message->plain(), 'noparse' => false ];
|
2006-09-30 04:53:36 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'found' => false ];
|
2006-09-30 04:53:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-09 10:33:55 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $date
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $defaultPref
|
2014-04-09 10:33:55 +00:00
|
|
|
*
|
|
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function formatDate( $parser, $date, $defaultPref = null ) {
|
2012-06-01 09:52:57 +00:00
|
|
|
$lang = $parser->getFunctionLang();
|
Rehabilitate DateFormatter
This code is surprisingly little changed since I added the class in
November 2003, and needs some modernisation.
* Remove the "linked" option, unused since 1.21. Similarly, make the
"match-whole" option implied. This allows the regexes to be
simplified. Nothing will be broken, according to CodeSearch.
* Instead of ucfirst(), use the canonical month name from the language.
This will work with e.g. French which does not capitalise month names.
* Stop caching DateFormatter instances in APC. Caching was added
in 2005 when initialisation was being done on every request, but now
it is only needed when parsing a page with {{#formatdate}}, which is
rarely, and the constructor overhead is only 200µs after Language
object data initialisation. Instead, use an in-process cache via a
factory service.
* Add docs and extra tests.
* Remove todo note obsolete since 38 minutes after the original commit.
* Rename many variables.
* Use double-slash comments
* Don't store the Language object, just get arrays.
* Use mb_strtolower() instead of Language::lc() -- any customisation of
Language::lc() would break PCRE case-insensitive matching.
* Use named subpatterns instead of "keys"
* Remove the ISO1/ISO2 distinction, the only difference was linking.
* Use closure variables instead of temporary object members
Change-Id: I25fb1203dba2930724d7bc28ad0d51f59f88e1ea
2019-04-10 05:33:57 +00:00
|
|
|
$df = MediaWikiServices::getInstance()->getDateFormatterFactory()->get( $lang );
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2010-02-11 14:57:43 +00:00
|
|
|
$date = trim( $date );
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2010-10-15 23:10:05 +00:00
|
|
|
$pref = $parser->getOptions()->getDateFormat();
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2014-12-16 00:41:45 +00:00
|
|
|
// Specify a different default date format other than the normal default
|
2013-06-11 23:01:52 +00:00
|
|
|
// if the user has 'default' for their setting
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $pref == 'default' && $defaultPref ) {
|
2009-03-10 05:19:05 +00:00
|
|
|
$pref = $defaultPref;
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$date = $df->reformat( $pref, $date, [ 'match-whole' ] );
|
2009-03-10 01:07:47 +00:00
|
|
|
return $date;
|
|
|
|
|
}
|
2009-06-03 14:51:08 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function ns( $parser, $part1 = '' ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
if ( intval( $part1 ) || $part1 == "0" ) {
|
2008-10-09 00:56:26 +00:00
|
|
|
$index = intval( $part1 );
|
2006-07-03 11:07:00 +00:00
|
|
|
} else {
|
2018-07-26 12:39:15 +00:00
|
|
|
$index = $parser->getContentLanguage()->getNsIndex( str_replace( ' ', '_', $part1 ) );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
2008-10-09 00:56:26 +00:00
|
|
|
if ( $index !== false ) {
|
2018-07-26 12:39:15 +00:00
|
|
|
return $parser->getContentLanguage()->getFormattedNsText( $index );
|
2006-07-03 11:07:00 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'found' => false ];
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-02-11 14:57:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function nse( $parser, $part1 = '' ) {
|
2012-03-26 18:26:32 +00:00
|
|
|
$ret = self::ns( $parser, $part1 );
|
|
|
|
|
if ( is_string( $ret ) ) {
|
|
|
|
|
$ret = wfUrlencode( str_replace( ' ', '_', $ret ) );
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
2009-08-02 18:16:56 +00:00
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
|
2010-04-08 00:29:58 +00:00
|
|
|
/**
|
2017-02-20 22:44:19 +00:00
|
|
|
* urlencodes a string according to one of three patterns: (T24474)
|
2010-04-08 00:29:58 +00:00
|
|
|
*
|
|
|
|
|
* By default (for HTTP "query" strings), spaces are encoded as '+'.
|
|
|
|
|
* Or to encode a value for the HTTP "path", spaces are encoded as '%20'.
|
|
|
|
|
* For links to "wiki"s, or similar software, spaces are encoded as '_',
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $s The text to encode.
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $arg (optional): The type of encoding.
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2010-04-08 00:29:58 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function urlencode( $parser, $s = '', $arg = null ) {
|
2010-04-08 00:29:58 +00:00
|
|
|
static $magicWords = null;
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $magicWords === null ) {
|
2018-07-25 12:22:00 +00:00
|
|
|
$magicWords =
|
|
|
|
|
$parser->getMagicWordFactory()->newArray( [ 'url_path', 'url_query', 'url_wiki' ] );
|
2010-04-08 00:29:58 +00:00
|
|
|
}
|
2013-04-26 14:42:31 +00:00
|
|
|
switch ( $magicWords->matchStartToEnd( $arg ) ) {
|
2010-04-08 00:29:58 +00:00
|
|
|
// Encode as though it's a wiki page, '_' for ' '.
|
|
|
|
|
case 'url_wiki':
|
2012-03-20 04:39:09 +00:00
|
|
|
$func = 'wfUrlencode';
|
|
|
|
|
$s = str_replace( ' ', '_', $s );
|
|
|
|
|
break;
|
2010-04-08 00:29:58 +00:00
|
|
|
|
|
|
|
|
// Encode for an HTTP Path, '%20' for ' '.
|
|
|
|
|
case 'url_path':
|
2012-03-20 04:39:09 +00:00
|
|
|
$func = 'rawurlencode';
|
|
|
|
|
break;
|
2010-04-08 00:29:58 +00:00
|
|
|
|
|
|
|
|
// Encode for HTTP query, '+' for ' '.
|
|
|
|
|
case 'url_query':
|
|
|
|
|
default:
|
2012-03-20 04:39:09 +00:00
|
|
|
$func = 'urlencode';
|
2010-04-08 00:29:58 +00:00
|
|
|
}
|
2015-01-07 20:03:02 +00:00
|
|
|
// See T105242, where the choice to kill markers and various
|
|
|
|
|
// other options were discussed.
|
|
|
|
|
return $func( $parser->killMarkers( $s ) );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function lcfirst( $parser, $s = '' ) {
|
2018-07-26 12:39:15 +00:00
|
|
|
return $parser->getContentLanguage()->lcfirst( $s );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function ucfirst( $parser, $s = '' ) {
|
2018-07-26 12:39:15 +00:00
|
|
|
return $parser->getContentLanguage()->ucfirst( $s );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2011-02-19 01:02:56 +00:00
|
|
|
* @param string $s
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function lc( $parser, $s = '' ) {
|
2018-07-26 12:39:15 +00:00
|
|
|
return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'lc' ] );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2011-02-19 01:02:56 +00:00
|
|
|
* @param string $s
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function uc( $parser, $s = '' ) {
|
2018-07-26 12:39:15 +00:00
|
|
|
return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'uc' ] );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function localurl( $parser, $s = '', $arg = null ) {
|
2013-12-27 21:01:17 +00:00
|
|
|
return self::urlFunction( 'getLocalURL', $s, $arg );
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function localurle( $parser, $s = '', $arg = null ) {
|
2014-01-12 07:10:23 +00:00
|
|
|
$temp = self::urlFunction( 'getLocalURL', $s, $arg );
|
2014-03-20 18:59:20 +00:00
|
|
|
if ( !is_string( $temp ) ) {
|
2014-01-12 07:10:23 +00:00
|
|
|
return $temp;
|
|
|
|
|
} else {
|
|
|
|
|
return htmlspecialchars( $temp );
|
|
|
|
|
}
|
2013-12-27 21:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function fullurl( $parser, $s = '', $arg = null ) {
|
2013-12-27 21:01:17 +00:00
|
|
|
return self::urlFunction( 'getFullURL', $s, $arg );
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function fullurle( $parser, $s = '', $arg = null ) {
|
2014-01-12 07:10:23 +00:00
|
|
|
$temp = self::urlFunction( 'getFullURL', $s, $arg );
|
2014-03-20 18:59:20 +00:00
|
|
|
if ( !is_string( $temp ) ) {
|
2014-01-12 07:10:23 +00:00
|
|
|
return $temp;
|
|
|
|
|
} else {
|
|
|
|
|
return htmlspecialchars( $temp );
|
|
|
|
|
}
|
2013-12-27 21:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function canonicalurl( $parser, $s = '', $arg = null ) {
|
2013-12-27 21:01:17 +00:00
|
|
|
return self::urlFunction( 'getCanonicalURL', $s, $arg );
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function canonicalurle( $parser, $s = '', $arg = null ) {
|
2014-06-27 15:12:37 +00:00
|
|
|
$temp = self::urlFunction( 'getCanonicalURL', $s, $arg );
|
|
|
|
|
if ( !is_string( $temp ) ) {
|
|
|
|
|
return $temp;
|
|
|
|
|
} else {
|
|
|
|
|
return htmlspecialchars( $temp );
|
|
|
|
|
}
|
2013-12-27 21:01:17 +00:00
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function urlFunction( $func, $s = '', $arg = null ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
$title = Title::newFromText( $s );
|
|
|
|
|
# Due to order of execution of a lot of bits, the values might be encoded
|
|
|
|
|
# before arriving here; if that's true, then the title can't be created
|
|
|
|
|
# and the variable will fail. If we can't get a decent title from the first
|
|
|
|
|
# attempt, url-decode and try for a second.
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title === null ) {
|
2010-02-13 23:58:30 +00:00
|
|
|
$title = Title::newFromURL( urldecode( $s ) );
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title !== null ) {
|
2008-12-23 21:12:43 +00:00
|
|
|
# Convert NS_MEDIA -> NS_FILE
|
2016-12-21 09:54:33 +00:00
|
|
|
if ( $title->inNamespace( NS_MEDIA ) ) {
|
2009-05-24 08:29:10 +00:00
|
|
|
$title = Title::makeTitle( NS_FILE, $title->getDBkey() );
|
2008-12-23 21:12:43 +00:00
|
|
|
}
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $arg !== null ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
$text = $title->$func( $arg );
|
|
|
|
|
} else {
|
|
|
|
|
$text = $title->$func();
|
|
|
|
|
}
|
|
|
|
|
return $text;
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'found' => false ];
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2011-02-19 01:02:56 +00:00
|
|
|
* @param string $num
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $arg
|
2012-11-28 10:24:45 +00:00
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function formatnum( $parser, $num = '', $arg = null ) {
|
2018-07-25 12:14:13 +00:00
|
|
|
if ( self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'rawsuffix', $arg ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$func = [ $parser->getFunctionLang(), 'parseFormattedNumber' ];
|
2018-07-25 12:14:13 +00:00
|
|
|
} elseif (
|
|
|
|
|
self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'nocommafysuffix', $arg )
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$func = [ $parser->getFunctionLang(), 'formatNumNoSeparators' ];
|
2017-06-02 08:42:28 +00:00
|
|
|
$func = self::getLegacyFormatNum( $parser, $func );
|
2008-03-15 10:39:56 +00:00
|
|
|
} else {
|
2017-06-02 08:42:28 +00:00
|
|
|
$func = [ $parser->getFunctionLang(), 'formatNum' ];
|
|
|
|
|
$func = self::getLegacyFormatNum( $parser, $func );
|
2008-03-15 10:39:56 +00:00
|
|
|
}
|
2012-03-20 04:39:09 +00:00
|
|
|
return $parser->markerSkipCallback( $num, $func );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
2007-01-13 12:58:33 +00:00
|
|
|
|
2020-09-27 14:55:19 +00:00
|
|
|
/**
|
|
|
|
|
* @param Parser $parser
|
2017-06-02 08:42:28 +00:00
|
|
|
* @param callable $callback
|
2020-09-27 14:55:19 +00:00
|
|
|
*
|
2017-06-02 08:42:28 +00:00
|
|
|
* @return callable
|
2020-09-27 14:55:19 +00:00
|
|
|
*/
|
2017-06-02 08:42:28 +00:00
|
|
|
private static function getLegacyFormatNum( $parser, $callback ) {
|
2020-09-09 01:41:52 +00:00
|
|
|
// For historic reasons, the formatNum parser function will
|
|
|
|
|
// take arguments which are not actually formatted numbers,
|
2017-06-02 08:42:28 +00:00
|
|
|
// which then trigger deprecation warnings in Language::formatNum*.
|
|
|
|
|
// Instead emit a tracking category instead to allow linting.
|
2021-02-10 22:31:02 +00:00
|
|
|
return static function ( $number ) use ( $parser, $callback ) {
|
2020-11-11 00:18:09 +00:00
|
|
|
$validNumberRe = '(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?([Ee][-+]?\d+)?';
|
2020-11-09 22:04:41 +00:00
|
|
|
if (
|
|
|
|
|
!is_numeric( $number ) &&
|
|
|
|
|
$number !== (string)NAN &&
|
|
|
|
|
$number !== (string)INF &&
|
|
|
|
|
$number !== (string)-INF
|
|
|
|
|
) {
|
2020-09-09 01:41:52 +00:00
|
|
|
$parser->addTrackingCategory( 'nonnumeric-formatnum' );
|
2020-11-09 22:04:41 +00:00
|
|
|
// Don't split on NAN/INF in the legacy case since they are
|
|
|
|
|
// likely to be found embedded inside non-numeric text.
|
2021-02-10 22:31:02 +00:00
|
|
|
return preg_replace_callback( "/{$validNumberRe}/", static function ( $m ) use ( $callback ) {
|
2020-11-11 00:18:09 +00:00
|
|
|
return call_user_func( $callback, $m[0] );
|
|
|
|
|
}, $number );
|
2020-09-09 01:41:52 +00:00
|
|
|
}
|
2020-11-11 00:18:09 +00:00
|
|
|
return call_user_func( $callback, $number );
|
2020-09-09 01:41:52 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2011-02-19 01:02:56 +00:00
|
|
|
* @param string $case
|
|
|
|
|
* @param string $word
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function grammar( $parser, $case = '', $word = '' ) {
|
2012-03-20 04:39:09 +00:00
|
|
|
$word = $parser->killMarkers( $word );
|
2006-07-03 11:07:00 +00:00
|
|
|
return $parser->getFunctionLang()->convertGrammar( $word, $case );
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-19 01:02:56 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $username
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
* @param string ...$forms What to output for each gender
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
public static function gender( $parser, $username, ...$forms ) {
|
2012-02-08 06:09:58 +00:00
|
|
|
// Some shortcuts to avoid loading user data unnecessarily
|
|
|
|
|
if ( count( $forms ) === 0 ) {
|
|
|
|
|
return '';
|
|
|
|
|
} elseif ( count( $forms ) === 1 ) {
|
|
|
|
|
return $forms[0];
|
|
|
|
|
}
|
2009-01-26 09:48:17 +00:00
|
|
|
|
2011-06-20 10:04:55 +00:00
|
|
|
$username = trim( $username );
|
|
|
|
|
|
2021-03-16 15:16:18 +00:00
|
|
|
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
|
|
|
|
|
$gender = $userOptionsLookup->getDefaultOption( 'gender' );
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2017-12-17 22:12:06 +00:00
|
|
|
// allow prefix and normalize (e.g. "*foo" -> "*foo" ).
|
|
|
|
|
$title = Title::newFromText( $username, NS_USER );
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2016-12-21 09:54:33 +00:00
|
|
|
if ( $title && $title->inNamespace( NS_USER ) ) {
|
2011-06-20 10:04:55 +00:00
|
|
|
$username = $title->getText();
|
|
|
|
|
}
|
2009-01-26 09:48:17 +00:00
|
|
|
|
2010-12-10 18:17:20 +00:00
|
|
|
// check parameter, or use the ParserOptions if in interface message
|
2011-06-20 10:04:55 +00:00
|
|
|
$user = User::newFromName( $username );
|
2016-11-22 23:14:43 +00:00
|
|
|
$genderCache = MediaWikiServices::getInstance()->getGenderCache();
|
2009-01-26 09:48:17 +00:00
|
|
|
if ( $user ) {
|
2016-11-22 23:14:43 +00:00
|
|
|
$gender = $genderCache->getGenderOf( $user, __METHOD__ );
|
2011-06-20 10:04:55 +00:00
|
|
|
} elseif ( $username === '' && $parser->getOptions()->getInterfaceMessage() ) {
|
2016-11-22 23:14:43 +00:00
|
|
|
$gender = $genderCache->getGenderOf( $parser->getOptions()->getUser(), __METHOD__ );
|
2009-01-26 09:48:17 +00:00
|
|
|
}
|
2009-06-03 06:28:19 +00:00
|
|
|
$ret = $parser->getFunctionLang()->gender( $gender, $forms );
|
|
|
|
|
return $ret;
|
2009-01-26 09:48:17 +00:00
|
|
|
}
|
2011-02-19 01:02:56 +00:00
|
|
|
|
|
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2011-02-19 01:02:56 +00:00
|
|
|
* @param string $text
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
* @param string ...$forms What to output for each number (singular, dual, plural, etc.)
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2011-02-19 01:02:56 +00:00
|
|
|
*/
|
Get rid of unnecessary func_get_args() and friends
HHVM does not support variadic arguments with type hints. This is
mostly not a big problem, because we can just drop the type hint, but
for some reason PHPUnit adds a type hint of "array" when it creates
mocks, so a class with a variadic method can't be mocked (at least in
some cases). As such, I left alone all the classes that seem like
someone might like to mock them, like Title and User. If anyone wants
to mock them in the future, they'll have to switch back to
func_get_args(). Some of the changes are definitely safe, like
functions and test classes.
In most cases, func_get_args() (and/or func_get_arg(), func_num_args() )
were only present because the code was written before we required PHP
5.6, and writing them as variadic functions is strictly superior. In
some cases I left them alone, aside from HHVM compatibility:
* Forwarding all arguments to another function. It's useful to keep
func_get_args() here where we want to keep the list of expected
arguments and their meanings in the function signature line for
documentation purposes, but don't want to copy-paste a long line of
argument names.
* Handling deprecated calling conventions.
* One or two miscellaneous cases where we're basically using the
arguments individually but want to use them as an array as well for
some reason.
Change-Id: I066ec95a7beb7c0665146195a08e7cce1222c788
2018-10-08 14:10:45 +00:00
|
|
|
public static function plural( $parser, $text = '', ...$forms ) {
|
2006-12-23 18:58:44 +00:00
|
|
|
$text = $parser->getFunctionLang()->parseFormattedNumber( $text );
|
2012-08-27 08:53:42 +00:00
|
|
|
settype( $text, ctype_digit( $text ) ? 'int' : 'float' );
|
2007-11-18 20:15:49 +00:00
|
|
|
return $parser->getFunctionLang()->convertPlural( $text, $forms );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-29 21:48:41 +00:00
|
|
|
/**
|
|
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function bidi( $parser, $text = '' ) {
|
|
|
|
|
return $parser->getFunctionLang()->embedBidi( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-23 18:39:23 +00:00
|
|
|
/**
|
|
|
|
|
* Shorthand for getting a Language Converter for Target language
|
|
|
|
|
* @param Parser $parser Parent parser
|
|
|
|
|
* @return ILanguageConverter
|
|
|
|
|
*/
|
|
|
|
|
private static function getTargetLanguageConverter( Parser $parser ) : ILanguageConverter {
|
|
|
|
|
return MediaWikiServices::getInstance()->getLanguageConverterFactory()
|
|
|
|
|
->getLanguageConverter( $parser->getTargetLanguage() );
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-25 15:51:09 +00:00
|
|
|
/**
|
2008-04-18 14:19:00 +00:00
|
|
|
* Override the title of the page when viewed, provided we've been given a
|
|
|
|
|
* title which will normalise to the canonical title
|
2007-06-25 15:51:09 +00:00
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser Parent parser
|
|
|
|
|
* @param string $text Desired title text
|
2014-08-11 20:24:54 +00:00
|
|
|
* @param string $uarg
|
2014-04-21 23:38:39 +00:00
|
|
|
* @return string
|
2007-06-25 15:51:09 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function displaytitle( $parser, $text = '', $uarg = '' ) {
|
2009-04-19 23:48:50 +00:00
|
|
|
global $wgRestrictDisplayTitle;
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2014-07-09 03:34:50 +00:00
|
|
|
static $magicWords = null;
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $magicWords === null ) {
|
2018-07-25 12:22:00 +00:00
|
|
|
$magicWords = $parser->getMagicWordFactory()->newArray(
|
|
|
|
|
[ 'displaytitle_noerror', 'displaytitle_noreplace' ] );
|
2014-07-09 03:34:50 +00:00
|
|
|
}
|
|
|
|
|
$arg = $magicWords->matchStartToEnd( $uarg );
|
|
|
|
|
|
2013-05-22 08:48:14 +00:00
|
|
|
// parse a limited subset of wiki markup (just the single quote items)
|
2009-06-08 16:53:39 +00:00
|
|
|
$text = $parser->doQuotes( $text );
|
|
|
|
|
|
2013-05-22 08:48:14 +00:00
|
|
|
// remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
|
2014-10-20 06:52:02 +00:00
|
|
|
$text = $parser->killMarkers( $text );
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2013-05-22 08:48:14 +00:00
|
|
|
// list of disallowed tags for DISPLAYTITLE
|
|
|
|
|
// these will be escaped even though they are allowed in normal wiki text
|
2016-02-17 09:09:32 +00:00
|
|
|
$bad = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
|
|
|
|
|
'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rtc', 'rp', 'br' ];
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2013-05-22 08:48:14 +00:00
|
|
|
// disallow some styles that could be used to bypass $wgRestrictDisplayTitle
|
|
|
|
|
if ( $wgRestrictDisplayTitle ) {
|
2021-02-10 22:31:02 +00:00
|
|
|
$htmlTagsCallback = static function ( &$params ) {
|
2013-05-22 08:48:14 +00:00
|
|
|
$decoded = Sanitizer::decodeTagAttributes( $params );
|
|
|
|
|
|
|
|
|
|
if ( isset( $decoded['style'] ) ) {
|
|
|
|
|
// this is called later anyway, but we need it right now for the regexes below to be safe
|
|
|
|
|
// calling it twice doesn't hurt
|
|
|
|
|
$decoded['style'] = Sanitizer::checkCss( $decoded['style'] );
|
|
|
|
|
|
|
|
|
|
if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
|
|
|
|
|
$decoded['style'] = '/* attempt to bypass $wgRestrictDisplayTitle */';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$params = Sanitizer::safeEncodeTagAttributes( $decoded );
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
$htmlTagsCallback = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only requested titles that normalize to the actual title are allowed through
|
|
|
|
|
// if $wgRestrictDisplayTitle is true (it is by default)
|
|
|
|
|
// mimic the escaping process that occurs in OutputPage::setPageTitle
|
2014-05-10 23:03:45 +00:00
|
|
|
$text = Sanitizer::normalizeCharReferences( Sanitizer::removeHTMLtags(
|
|
|
|
|
$text,
|
|
|
|
|
$htmlTagsCallback,
|
2016-02-17 09:09:32 +00:00
|
|
|
[],
|
|
|
|
|
[],
|
2014-05-10 23:03:45 +00:00
|
|
|
$bad
|
|
|
|
|
) );
|
2009-04-19 23:48:50 +00:00
|
|
|
$title = Title::newFromText( Sanitizer::stripAllTags( $text ) );
|
2008-12-31 16:49:38 +00:00
|
|
|
|
2014-07-09 03:34:50 +00:00
|
|
|
if ( !$wgRestrictDisplayTitle ||
|
|
|
|
|
( $title instanceof Title
|
2014-05-10 23:03:45 +00:00
|
|
|
&& !$title->hasFragment()
|
2019-08-27 10:29:39 +00:00
|
|
|
&& $title->equals( $parser->getTitle() ) )
|
2014-05-10 23:03:45 +00:00
|
|
|
) {
|
2014-07-09 03:34:50 +00:00
|
|
|
$old = $parser->mOutput->getProperty( 'displaytitle' );
|
|
|
|
|
if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
|
|
|
|
|
$parser->mOutput->setDisplayTitle( $text );
|
|
|
|
|
}
|
|
|
|
|
if ( $old !== false && $old !== $text && !$arg ) {
|
2020-01-23 18:39:23 +00:00
|
|
|
|
|
|
|
|
$converter = self::getTargetLanguageConverter( $parser );
|
2014-07-09 03:34:50 +00:00
|
|
|
return '<span class="error">' .
|
|
|
|
|
wfMessage( 'duplicate-displaytitle',
|
|
|
|
|
// Message should be parsed, but these params should only be escaped.
|
|
|
|
|
$converter->markNoConversion( wfEscapeWikiText( $old ) ),
|
|
|
|
|
$converter->markNoConversion( wfEscapeWikiText( $text ) )
|
|
|
|
|
)->inContentLanguage()->text() .
|
|
|
|
|
'</span>';
|
2014-09-03 14:25:47 +00:00
|
|
|
} else {
|
|
|
|
|
return '';
|
2014-07-09 03:34:50 +00:00
|
|
|
}
|
2014-09-03 14:25:47 +00:00
|
|
|
} else {
|
2016-05-22 17:30:07 +00:00
|
|
|
$parser->getOutput()->addWarning(
|
2014-09-03 14:25:47 +00:00
|
|
|
wfMessage( 'restricted-displaytitle',
|
|
|
|
|
// Message should be parsed, but this param should only be escaped.
|
2018-10-29 20:11:54 +00:00
|
|
|
wfEscapeWikiText( $text )
|
2016-05-22 17:30:07 +00:00
|
|
|
)->text()
|
|
|
|
|
);
|
|
|
|
|
$parser->addTrackingCategory( 'restricted-displaytitle-ignored' );
|
2008-08-17 21:08:58 +00:00
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-28 10:24:45 +00:00
|
|
|
/**
|
|
|
|
|
* Matches the given value against the value of given magic word
|
|
|
|
|
*
|
2018-07-25 12:14:13 +00:00
|
|
|
* @param MagicWordFactory $magicWordFactory A factory to get the word from, e.g., from
|
|
|
|
|
* $parser->getMagicWordFactory()
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string $magicword Magic word key
|
|
|
|
|
* @param string $value Value to match
|
|
|
|
|
* @return bool True on successful match
|
2012-11-28 10:24:45 +00:00
|
|
|
*/
|
2018-07-25 12:14:13 +00:00
|
|
|
private static function matchAgainstMagicword(
|
|
|
|
|
MagicWordFactory $magicWordFactory, $magicword, $value
|
|
|
|
|
) {
|
2013-12-17 18:14:15 +00:00
|
|
|
$value = trim( strval( $value ) );
|
|
|
|
|
if ( $value === '' ) {
|
2006-07-03 11:07:00 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2018-07-25 12:14:13 +00:00
|
|
|
$mwObject = $magicWordFactory->get( $magicword );
|
2013-12-17 18:14:15 +00:00
|
|
|
return $mwObject->matchStartToEnd( $value );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-11-03 07:57:48 +00:00
|
|
|
/**
|
|
|
|
|
* Formats a number according to a language.
|
|
|
|
|
*
|
|
|
|
|
* @param int|float $num
|
|
|
|
|
* @param string $raw
|
2017-10-05 16:51:11 +00:00
|
|
|
* @param Language|StubUserLang $language
|
2018-07-25 12:14:13 +00:00
|
|
|
* @param MagicWordFactory|null $magicWordFactory To evaluate $raw
|
2016-11-03 07:57:48 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-07-25 12:14:13 +00:00
|
|
|
public static function formatRaw(
|
|
|
|
|
$num, $raw, $language, MagicWordFactory $magicWordFactory = null
|
|
|
|
|
) {
|
|
|
|
|
if ( $raw !== null && !$magicWordFactory ) {
|
|
|
|
|
$magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
$raw !== null && self::matchAgainstMagicword( $magicWordFactory, 'rawsuffix', $raw )
|
|
|
|
|
) {
|
2008-03-18 22:34:10 +00:00
|
|
|
return $num;
|
2006-07-03 13:55:52 +00:00
|
|
|
} else {
|
2016-11-03 07:57:48 +00:00
|
|
|
return $language->formatNum( $num );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberofpages( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( SiteStats::pages(), $raw, $parser->getFunctionLang() );
|
2008-03-18 22:34:10 +00:00
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberofusers( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( SiteStats::users(), $raw, $parser->getFunctionLang() );
|
2008-03-18 22:34:10 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberofactiveusers( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( SiteStats::activeUsers(), $raw, $parser->getFunctionLang() );
|
2009-02-04 22:16:35 +00:00
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberofarticles( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( SiteStats::articles(), $raw, $parser->getFunctionLang() );
|
2008-03-18 22:34:10 +00:00
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberoffiles( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( SiteStats::images(), $raw, $parser->getFunctionLang() );
|
2008-03-18 22:34:10 +00:00
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberofadmins( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw(
|
|
|
|
|
SiteStats::numberingroup( 'sysop' ),
|
|
|
|
|
$raw,
|
|
|
|
|
$parser->getFunctionLang()
|
|
|
|
|
);
|
2008-03-18 22:34:10 +00:00
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberofedits( $parser, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( SiteStats::edits(), $raw, $parser->getFunctionLang() );
|
2008-03-18 22:34:10 +00:00
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw(
|
|
|
|
|
SiteStats::pagesInNs( intval( $namespace ) ),
|
|
|
|
|
$raw,
|
|
|
|
|
$parser->getFunctionLang()
|
|
|
|
|
);
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function numberingroup( $parser, $name = '', $raw = null ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw(
|
|
|
|
|
SiteStats::numberingroup( strtolower( $name ) ),
|
|
|
|
|
$raw,
|
|
|
|
|
$parser->getFunctionLang()
|
|
|
|
|
);
|
2009-06-08 16:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-04 18:59:28 +00:00
|
|
|
/**
|
|
|
|
|
* Given a title, return the namespace name that would be given by the
|
|
|
|
|
* corresponding magic word
|
|
|
|
|
* Note: function name changed to "mwnamespace" rather than "namespace"
|
|
|
|
|
* to not break PHP 5.3
|
2014-05-10 23:05:51 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return mixed|string
|
2009-03-04 18:59:28 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function mwnamespace( $parser, $title = null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-01-31 01:35:18 +00:00
|
|
|
return str_replace( '_', ' ', $t->getNsText() );
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function namespacee( $parser, $title = null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-01-31 01:35:18 +00:00
|
|
|
return wfUrlencode( $t->getNsText() );
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function namespacenumber( $parser, $title = null ) {
|
2012-04-01 10:27:59 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2012-04-01 10:27:59 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2012-04-01 10:27:59 +00:00
|
|
|
return $t->getNamespace();
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function talkspace( $parser, $title = null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null || !$t->canHaveTalkPage() ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-01-31 01:35:18 +00:00
|
|
|
return str_replace( '_', ' ', $t->getTalkNsText() );
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function talkspacee( $parser, $title = null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null || !$t->canHaveTalkPage() ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-01-31 01:35:18 +00:00
|
|
|
return wfUrlencode( $t->getTalkNsText() );
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function subjectspace( $parser, $title = null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-01-31 01:35:18 +00:00
|
|
|
return str_replace( '_', ' ', $t->getSubjectNsText() );
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function subjectspacee( $parser, $title = null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 01:35:18 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2009-01-31 01:35:18 +00:00
|
|
|
return wfUrlencode( $t->getSubjectNsText() );
|
|
|
|
|
}
|
2011-05-21 19:35:16 +00:00
|
|
|
|
|
|
|
|
/**
|
2009-01-31 22:25:01 +00:00
|
|
|
* Functions to get and normalize pagenames, corresponding to the magic words
|
|
|
|
|
* of the same names
|
2014-05-10 23:05:51 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title
|
2014-04-21 23:38:39 +00:00
|
|
|
* @return string
|
2011-05-21 19:35:16 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function pagename( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getText() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function pagenamee( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getPartialURL() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function fullpagename( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null || !$t->canHaveTalkPage() ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getPrefixedText() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function fullpagenamee( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null || !$t->canHaveTalkPage() ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getPrefixedURL() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function subpagename( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getSubpageText() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function subpagenamee( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getSubpageUrlForm() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function rootpagename( $parser, $title = null ) {
|
2013-04-21 14:09:49 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-04-21 14:09:49 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getRootText() );
|
2013-04-21 14:09:49 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function rootpagenamee( $parser, $title = null ) {
|
2013-04-21 14:09:49 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-04-21 14:09:49 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getRootText() ) ) );
|
2013-04-21 14:09:49 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function basepagename( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getBaseText() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function basepagenamee( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getBaseText() ) ) );
|
2009-06-08 16:53:39 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function talkpagename( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null || !$t->canHaveTalkPage() ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function talkpagenamee( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null || !$t->canHaveTalkPage() ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getTalkPage()->getPrefixedURL() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function subjectpagename( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2016-09-23 00:29:21 +00:00
|
|
|
public static function subjectpagenamee( $parser, $title = null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2009-01-31 22:25:01 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2016-09-23 00:29:21 +00:00
|
|
|
return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedURL() );
|
2009-01-31 22:25:01 +00:00
|
|
|
}
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2008-04-18 14:19:00 +00:00
|
|
|
/**
|
2012-07-25 15:51:05 +00:00
|
|
|
* Return the number of pages, files or subcats in the given category,
|
|
|
|
|
* or 0 if it's nonexistent. This is an expensive parser function and
|
|
|
|
|
* can't be called too many times per page.
|
2014-05-10 23:05:51 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $name
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $arg1
|
|
|
|
|
* @param string|null $arg2
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2008-04-18 14:19:00 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function pagesincategory( $parser, $name = '', $arg1 = null, $arg2 = null ) {
|
2012-07-25 15:51:05 +00:00
|
|
|
static $magicWords = null;
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $magicWords === null ) {
|
2018-07-25 12:22:00 +00:00
|
|
|
$magicWords = $parser->getMagicWordFactory()->newArray( [
|
2012-07-25 15:51:05 +00:00
|
|
|
'pagesincategory_all',
|
|
|
|
|
'pagesincategory_pages',
|
|
|
|
|
'pagesincategory_subcats',
|
|
|
|
|
'pagesincategory_files'
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-07-25 15:51:05 +00:00
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
static $cache = [];
|
2008-04-18 14:34:38 +00:00
|
|
|
|
2012-07-25 15:51:05 +00:00
|
|
|
// split the given option to its variable
|
2018-07-25 12:14:13 +00:00
|
|
|
if ( self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'rawsuffix', $arg1 ) ) {
|
2015-09-11 13:44:59 +00:00
|
|
|
// {{pagesincategory:|raw[|type]}}
|
2012-07-25 15:51:05 +00:00
|
|
|
$raw = $arg1;
|
|
|
|
|
$type = $magicWords->matchStartToEnd( $arg2 );
|
|
|
|
|
} else {
|
2015-09-11 13:44:59 +00:00
|
|
|
// {{pagesincategory:[|type[|raw]]}}
|
2012-07-25 15:51:05 +00:00
|
|
|
$type = $magicWords->matchStartToEnd( $arg1 );
|
|
|
|
|
$raw = $arg2;
|
|
|
|
|
}
|
2015-09-11 13:44:59 +00:00
|
|
|
if ( !$type ) { // backward compatibility
|
2012-07-25 15:51:05 +00:00
|
|
|
$type = 'pagesincategory_all';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = Title::makeTitleSafe( NS_CATEGORY, $name );
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !$title ) { # invalid title
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
|
2008-04-18 14:42:24 +00:00
|
|
|
}
|
2020-05-06 00:26:09 +00:00
|
|
|
$languageConverter = MediaWikiServices::getInstance()
|
|
|
|
|
->getLanguageConverterFactory()
|
|
|
|
|
->getLanguageConverter( $parser->getContentLanguage() );
|
|
|
|
|
$languageConverter->findVariantLink( $name, $title, true );
|
2008-04-18 14:42:24 +00:00
|
|
|
|
2012-07-25 15:51:05 +00:00
|
|
|
// Normalize name for cache
|
|
|
|
|
$name = $title->getDBkey();
|
|
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !isset( $cache[$name] ) ) {
|
2012-07-25 15:51:05 +00:00
|
|
|
$category = Category::newFromTitle( $title );
|
2008-04-18 14:34:38 +00:00
|
|
|
|
2012-07-25 15:51:05 +00:00
|
|
|
$allCount = $subcatCount = $fileCount = $pagesCount = 0;
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $parser->incrementExpensiveFunctionCount() ) {
|
2012-07-25 15:51:05 +00:00
|
|
|
// $allCount is the total number of cat members,
|
|
|
|
|
// not the count of how many members are normal pages.
|
|
|
|
|
$allCount = (int)$category->getPageCount();
|
|
|
|
|
$subcatCount = (int)$category->getSubcatCount();
|
|
|
|
|
$fileCount = (int)$category->getFileCount();
|
|
|
|
|
$pagesCount = $allCount - $subcatCount - $fileCount;
|
|
|
|
|
}
|
|
|
|
|
$cache[$name]['pagesincategory_all'] = $allCount;
|
|
|
|
|
$cache[$name]['pagesincategory_pages'] = $pagesCount;
|
|
|
|
|
$cache[$name]['pagesincategory_subcats'] = $subcatCount;
|
|
|
|
|
$cache[$name]['pagesincategory_files'] = $fileCount;
|
2008-04-07 22:11:31 +00:00
|
|
|
}
|
2012-07-25 15:51:05 +00:00
|
|
|
|
|
|
|
|
$count = $cache[$name][$type];
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( $count, $raw, $parser->getFunctionLang() );
|
2008-04-07 22:11:31 +00:00
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
|
2008-04-18 15:01:04 +00:00
|
|
|
/**
|
|
|
|
|
* Return the size of the given page, or 0 if it's nonexistent. This is an
|
|
|
|
|
* expensive parser function and can't be called too many times per page.
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $page Name of page to check (Default: empty string)
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $raw Should number be human readable with commas or just number
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2008-04-18 15:01:04 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function pagesize( $parser, $page = '', $raw = null ) {
|
2010-02-11 14:57:43 +00:00
|
|
|
$title = Title::newFromText( $page );
|
2008-04-18 15:01:04 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( !is_object( $title ) ) {
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
|
2008-04-18 15:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-29 21:02:59 +00:00
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $title, 'vary-revision-sha1' );
|
2013-10-29 21:02:59 +00:00
|
|
|
$length = $rev ? $rev->getSize() : 0;
|
2016-05-16 18:12:12 +00:00
|
|
|
if ( $length === null ) {
|
|
|
|
|
// We've had bugs where rev_len was not being recorded for empty pages, see T135414
|
|
|
|
|
$length = 0;
|
|
|
|
|
}
|
2016-11-03 07:57:48 +00:00
|
|
|
return self::formatRaw( $length, $raw, $parser->getFunctionLang() );
|
2008-04-18 15:01:04 +00:00
|
|
|
}
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2009-01-08 23:21:06 +00:00
|
|
|
/**
|
2014-01-13 20:01:17 +00:00
|
|
|
* Returns the requested protection level for the current page. This
|
|
|
|
|
* is an expensive parser function and can't be called too many times
|
2015-11-27 18:44:11 +00:00
|
|
|
* per page, unless the protection levels/expiries for the given title
|
|
|
|
|
* have already been retrieved
|
2013-01-18 19:03:01 +00:00
|
|
|
*
|
|
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @param string $title
|
|
|
|
|
*
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function protectionlevel( $parser, $type = '', $title = '' ) {
|
2019-08-27 10:29:39 +00:00
|
|
|
$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
|
2014-01-13 20:01:17 +00:00
|
|
|
if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
|
|
|
|
|
$restrictions = $titleObject->getRestrictions( strtolower( $type ) );
|
|
|
|
|
# Title::getRestrictions returns an array, its possible it may have
|
|
|
|
|
# multiple values in the future
|
2018-02-22 19:24:00 +00:00
|
|
|
return implode( ',', $restrictions );
|
2014-01-13 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
return '';
|
2009-01-08 23:21:06 +00:00
|
|
|
}
|
2008-04-18 15:01:04 +00:00
|
|
|
|
2015-11-27 18:44:11 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the requested protection expiry for the current page. This
|
|
|
|
|
* is an expensive parser function and can't be called too many times
|
|
|
|
|
* per page, unless the protection levels/expiries for the given title
|
|
|
|
|
* have already been retrieved
|
|
|
|
|
*
|
|
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $type
|
|
|
|
|
* @param string $title
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function protectionexpiry( $parser, $type = '', $title = '' ) {
|
2019-08-27 10:29:39 +00:00
|
|
|
$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
|
2015-11-27 18:44:11 +00:00
|
|
|
if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
|
2016-01-14 17:10:33 +00:00
|
|
|
$expiry = $titleObject->getRestrictionExpiry( strtolower( $type ) );
|
2015-11-27 18:44:11 +00:00
|
|
|
// getRestrictionExpiry() returns false on invalid type; trying to
|
|
|
|
|
// match protectionlevel() function that returns empty string instead
|
|
|
|
|
if ( $expiry === false ) {
|
|
|
|
|
$expiry = '';
|
|
|
|
|
}
|
|
|
|
|
return $expiry;
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-11 18:05:32 +00:00
|
|
|
/**
|
|
|
|
|
* Gives language names.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $code Language code (of which to get name)
|
|
|
|
|
* @param string $inLanguage Language code (in which to get name)
|
|
|
|
|
* @return string
|
2011-07-11 18:05:32 +00:00
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function language( $parser, $code = '', $inLanguage = '' ) {
|
2011-07-11 12:23:39 +00:00
|
|
|
$code = strtolower( $code );
|
2012-02-27 11:59:24 +00:00
|
|
|
$inLanguage = strtolower( $inLanguage );
|
2020-01-03 23:03:14 +00:00
|
|
|
$lang = MediaWikiServices::getInstance()
|
|
|
|
|
->getLanguageNameUtils()
|
|
|
|
|
->getLanguageName( $code, $inLanguage );
|
2017-04-06 15:17:19 +00:00
|
|
|
return $lang !== '' ? $lang : LanguageCode::bcp47( $code );
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|
2007-01-13 12:58:33 +00:00
|
|
|
|
2009-01-14 17:54:52 +00:00
|
|
|
/**
|
|
|
|
|
* Unicode-safe str_pad with the restriction that $length is forced to be <= 500
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $string
|
2018-06-10 18:09:07 +00:00
|
|
|
* @param string $length
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param string $padding
|
|
|
|
|
* @param int $direction
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2011-08-01 15:40:02 +00:00
|
|
|
*/
|
2015-09-26 17:17:49 +00:00
|
|
|
public static function pad(
|
|
|
|
|
$parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
|
|
|
|
|
) {
|
2012-03-20 04:39:09 +00:00
|
|
|
$padding = $parser->killMarkers( $padding );
|
2009-06-08 16:53:39 +00:00
|
|
|
$lengthOfPadding = mb_strlen( $padding );
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $lengthOfPadding == 0 ) {
|
|
|
|
|
return $string;
|
|
|
|
|
}
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2009-01-14 17:54:52 +00:00
|
|
|
# The remaining length to add counts down to 0 as padding is added
|
2018-06-10 18:09:07 +00:00
|
|
|
$length = min( (int)$length, 500 ) - mb_strlen( $string );
|
|
|
|
|
if ( $length <= 0 ) {
|
|
|
|
|
// Nothing to add
|
|
|
|
|
return $string;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-08 16:53:39 +00:00
|
|
|
# $finalPadding is just $padding repeated enough times so that
|
2009-01-14 17:54:52 +00:00
|
|
|
# mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
|
|
|
|
|
$finalPadding = '';
|
|
|
|
|
while ( $length > 0 ) {
|
|
|
|
|
# If $length < $lengthofPadding, truncate $padding so we get the
|
|
|
|
|
# exact length desired.
|
|
|
|
|
$finalPadding .= mb_substr( $padding, 0, $length );
|
|
|
|
|
$length -= $lengthOfPadding;
|
|
|
|
|
}
|
2009-06-08 16:53:39 +00:00
|
|
|
|
2009-01-14 17:54:52 +00:00
|
|
|
if ( $direction == STR_PAD_LEFT ) {
|
|
|
|
|
return $finalPadding . $string;
|
|
|
|
|
} else {
|
|
|
|
|
return $string . $finalPadding;
|
|
|
|
|
}
|
2006-08-21 11:07:58 +00:00
|
|
|
}
|
2007-01-13 12:58:33 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
|
2012-03-20 04:39:09 +00:00
|
|
|
return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
|
2006-08-18 17:30:35 +00:00
|
|
|
}
|
2007-01-13 12:58:33 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
|
2012-03-20 04:39:09 +00:00
|
|
|
return self::pad( $parser, $string, $length, $padding );
|
2006-08-18 17:30:35 +00:00
|
|
|
}
|
2007-01-13 12:58:33 +00:00
|
|
|
|
2011-02-08 23:18:13 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $text
|
2011-02-08 23:18:13 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function anchorencode( $parser, $text ) {
|
2012-03-20 04:39:09 +00:00
|
|
|
$text = $parser->killMarkers( $text );
|
2017-11-13 23:53:24 +00:00
|
|
|
$section = (string)substr( $parser->guessSectionNameFromWikiText( $text ), 1 );
|
|
|
|
|
return Sanitizer::safeEncodeAttribute( $section );
|
2006-08-30 07:51:44 +00:00
|
|
|
}
|
2006-10-31 13:25:47 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function special( $parser, $text ) {
|
2018-08-12 09:08:58 +00:00
|
|
|
list( $page, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
|
|
|
|
|
resolveAlias( $text );
|
2010-03-16 19:47:24 +00:00
|
|
|
if ( $page ) {
|
|
|
|
|
$title = SpecialPage::getTitleFor( $page, $subpage );
|
2012-04-05 17:22:34 +00:00
|
|
|
return $title->getPrefixedText();
|
2006-10-31 13:25:47 +00:00
|
|
|
} else {
|
2013-04-20 12:42:22 +00:00
|
|
|
// unknown special page, just use the given text as its title, if at all possible
|
|
|
|
|
$title = Title::makeTitleSafe( NS_SPECIAL, $text );
|
|
|
|
|
return $title ? $title->getPrefixedText() : self::special( $parser, 'Badtitle' );
|
2006-10-31 13:25:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2014-08-11 20:24:54 +00:00
|
|
|
public static function speciale( $parser, $text ) {
|
2012-04-05 17:22:34 +00:00
|
|
|
return wfUrlencode( str_replace( ' ', '_', self::special( $parser, $text ) ) );
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 23:18:13 +00:00
|
|
|
/**
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $text The sortkey to use
|
|
|
|
|
* @param string $uarg Either "noreplace" or "noerror" (in en)
|
2011-09-11 02:20:20 +00:00
|
|
|
* both suppress errors, and noreplace does nothing if
|
|
|
|
|
* a default sortkey already exists.
|
2011-02-08 23:18:13 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-09-11 20:32:58 +00:00
|
|
|
public static function defaultsort( $parser, $text, $uarg = '' ) {
|
|
|
|
|
static $magicWords = null;
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $magicWords === null ) {
|
2018-07-25 12:22:00 +00:00
|
|
|
$magicWords = $parser->getMagicWordFactory()->newArray(
|
|
|
|
|
[ 'defaultsort_noerror', 'defaultsort_noreplace' ] );
|
2011-09-11 20:32:58 +00:00
|
|
|
}
|
|
|
|
|
$arg = $magicWords->matchStartToEnd( $uarg );
|
|
|
|
|
|
2006-12-29 10:39:35 +00:00
|
|
|
$text = trim( $text );
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( strlen( $text ) == 0 ) {
|
2008-11-02 14:21:04 +00:00
|
|
|
return '';
|
2013-04-20 15:38:24 +00:00
|
|
|
}
|
2008-11-02 14:21:04 +00:00
|
|
|
$old = $parser->getCustomDefaultSort();
|
2011-09-11 20:32:58 +00:00
|
|
|
if ( $old === false || $arg !== 'defaultsort_noreplace' ) {
|
2011-09-11 02:20:20 +00:00
|
|
|
$parser->setDefaultSort( $text );
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $old === false || $old == $text || $arg ) {
|
2008-11-02 14:21:04 +00:00
|
|
|
return '';
|
2011-09-11 02:20:20 +00:00
|
|
|
} else {
|
2018-06-08 15:45:07 +00:00
|
|
|
$converter = $parser->getTargetLanguage()->getConverter();
|
2013-04-26 14:42:31 +00:00
|
|
|
return '<span class="error">' .
|
2013-06-15 14:13:35 +00:00
|
|
|
wfMessage( 'duplicate-defaultsort',
|
2013-07-04 19:15:05 +00:00
|
|
|
// Message should be parsed, but these params should only be escaped.
|
|
|
|
|
$converter->markNoConversion( wfEscapeWikiText( $old ) ),
|
|
|
|
|
$converter->markNoConversion( wfEscapeWikiText( $text ) )
|
2013-06-15 14:13:35 +00:00
|
|
|
)->inContentLanguage()->text() .
|
2013-04-26 14:42:31 +00:00
|
|
|
'</span>';
|
2011-09-11 02:20:20 +00:00
|
|
|
}
|
2006-12-29 10:39:35 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2015-04-01 00:13:47 +00:00
|
|
|
/**
|
|
|
|
|
* Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}}
|
|
|
|
|
* or {{filepath|300|nowiki}} or {{filepath|300px}}, {{filepath|200x300px}},
|
|
|
|
|
* {{filepath|nowiki|200x300px}}, {{filepath|200x300px|nowiki}}.
|
|
|
|
|
*
|
|
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param string $argA
|
|
|
|
|
* @param string $argB
|
|
|
|
|
* @return array|string
|
|
|
|
|
*/
|
2013-02-03 19:42:08 +00:00
|
|
|
public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
|
2019-05-14 17:00:34 +00:00
|
|
|
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
|
2011-01-23 13:09:15 +00:00
|
|
|
|
2013-04-20 15:38:24 +00:00
|
|
|
if ( $argA == 'nowiki' ) {
|
2012-07-25 15:31:47 +00:00
|
|
|
// {{filepath: | option [| size] }}
|
|
|
|
|
$isNowiki = true;
|
2016-06-19 06:41:43 +00:00
|
|
|
$parsedWidthParam = Parser::parseWidthParam( $argB );
|
2011-01-23 13:09:15 +00:00
|
|
|
} else {
|
2012-07-25 15:31:47 +00:00
|
|
|
// {{filepath: [| size [|option]] }}
|
2016-06-19 06:41:43 +00:00
|
|
|
$parsedWidthParam = Parser::parseWidthParam( $argA );
|
2013-04-20 15:38:24 +00:00
|
|
|
$isNowiki = ( $argB == 'nowiki' );
|
2011-01-23 13:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $file ) {
|
2011-04-23 19:38:53 +00:00
|
|
|
$url = $file->getFullUrl();
|
2011-01-23 13:09:15 +00:00
|
|
|
|
2011-08-01 15:40:02 +00:00
|
|
|
// If a size is requested...
|
2012-07-25 15:31:47 +00:00
|
|
|
if ( count( $parsedWidthParam ) ) {
|
|
|
|
|
$mto = $file->transform( $parsedWidthParam );
|
2011-01-23 13:09:15 +00:00
|
|
|
// ... and we can
|
|
|
|
|
if ( $mto && !$mto->isError() ) {
|
|
|
|
|
// ... change the URL to point to a thumbnail.
|
2011-08-03 13:11:42 +00:00
|
|
|
$url = wfExpandUrl( $mto->getUrl(), PROTO_RELATIVE );
|
2011-01-23 13:09:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-07-25 15:31:47 +00:00
|
|
|
if ( $isNowiki ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ $url, 'nowiki' => true ];
|
2007-09-14 15:29:52 +00:00
|
|
|
}
|
|
|
|
|
return $url;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-01-09 07:13:54 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parser function to extension tag adaptor
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param PPFrame $frame
|
2015-04-01 00:13:47 +00:00
|
|
|
* @param PPNode[] $args
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return string
|
2008-01-09 07:13:54 +00:00
|
|
|
*/
|
|
|
|
|
public static function tagObj( $parser, $frame, $args ) {
|
|
|
|
|
if ( !count( $args ) ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
|
2008-01-16 07:46:27 +00:00
|
|
|
|
|
|
|
|
if ( count( $args ) ) {
|
|
|
|
|
$inner = $frame->expand( array_shift( $args ) );
|
|
|
|
|
} else {
|
|
|
|
|
$inner = null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$attributes = [];
|
2008-01-09 07:13:54 +00:00
|
|
|
foreach ( $args as $arg ) {
|
2008-01-26 05:40:51 +00:00
|
|
|
$bits = $arg->splitArg();
|
|
|
|
|
if ( strval( $bits['index'] ) === '' ) {
|
2008-10-06 07:37:37 +00:00
|
|
|
$name = trim( $frame->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
|
2008-01-26 05:40:51 +00:00
|
|
|
$value = trim( $frame->expand( $bits['value'] ) );
|
2008-01-19 09:03:45 +00:00
|
|
|
if ( preg_match( '/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
|
2017-10-06 22:17:58 +00:00
|
|
|
$value = $m[1] ?? '';
|
2008-01-09 07:13:54 +00:00
|
|
|
}
|
2008-01-16 07:46:27 +00:00
|
|
|
$attributes[$name] = $value;
|
|
|
|
|
}
|
2008-01-09 07:13:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 19:56:19 +00:00
|
|
|
$stripList = $parser->getStripList();
|
|
|
|
|
if ( !in_array( $tagName, $stripList ) ) {
|
|
|
|
|
// we can't handle this tag (at least not now), so just re-emit it as an ordinary tag
|
|
|
|
|
$attrText = '';
|
|
|
|
|
foreach ( $attributes as $name => $value ) {
|
|
|
|
|
$attrText .= ' ' . htmlspecialchars( $name ) . '="' . htmlspecialchars( $value ) . '"';
|
|
|
|
|
}
|
|
|
|
|
if ( $inner === null ) {
|
|
|
|
|
return "<$tagName$attrText/>";
|
|
|
|
|
}
|
|
|
|
|
return "<$tagName$attrText>$inner</$tagName>";
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$params = [
|
2008-01-09 07:13:54 +00:00
|
|
|
'name' => $tagName,
|
|
|
|
|
'inner' => $inner,
|
2008-01-19 09:03:45 +00:00
|
|
|
'attributes' => $attributes,
|
|
|
|
|
'close' => "</$tagName>",
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2008-01-09 07:13:54 +00:00
|
|
|
return $parser->extensionSubstitution( $params, $frame );
|
|
|
|
|
}
|
2013-10-29 21:02:59 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetched the current revision of the given title and return this.
|
|
|
|
|
* Will increment the expensive function count and
|
|
|
|
|
* add a template link to get the value refreshed on changes.
|
|
|
|
|
* For a given title, which is equal to the current parser title,
|
|
|
|
|
* the revision object from the parser is used, when that is the current one
|
|
|
|
|
*
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param Title $title
|
2019-07-04 10:01:31 +00:00
|
|
|
* @param string $vary ParserOuput vary-* flag
|
2020-04-17 20:51:02 +00:00
|
|
|
* @return RevisionRecord|null
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
2019-07-04 10:01:31 +00:00
|
|
|
private static function getCachedRevisionObject( $parser, $title, $vary ) {
|
|
|
|
|
if ( !$title ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 20:51:02 +00:00
|
|
|
$revisionRecord = null;
|
2019-07-04 10:01:31 +00:00
|
|
|
|
|
|
|
|
$isSelfReferential = $title->equals( $parser->getTitle() );
|
|
|
|
|
if ( $isSelfReferential ) {
|
|
|
|
|
// Revision is for the same title that is currently being parsed. Only use the last
|
|
|
|
|
// saved revision, regardless of Parser::getRevisionId() or fake revision injection
|
|
|
|
|
// callbacks against the current title.
|
2020-04-17 20:29:22 +00:00
|
|
|
$parserRevisionRecord = $parser->getRevisionRecordObject();
|
|
|
|
|
if ( $parserRevisionRecord && $parserRevisionRecord->isCurrent() ) {
|
2020-04-17 20:51:02 +00:00
|
|
|
$revisionRecord = $parserRevisionRecord;
|
2013-10-29 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 10:01:31 +00:00
|
|
|
$parserOutput = $parser->getOutput();
|
2020-04-17 20:51:02 +00:00
|
|
|
if ( !$revisionRecord ) {
|
2019-07-04 10:01:31 +00:00
|
|
|
if (
|
|
|
|
|
!$parser->isCurrentRevisionOfTitleCached( $title ) &&
|
|
|
|
|
!$parser->incrementExpensiveFunctionCount()
|
|
|
|
|
) {
|
|
|
|
|
return null; // not allowed
|
|
|
|
|
}
|
|
|
|
|
// Get the current revision, ignoring Parser::getRevisionId() being null/old
|
2020-04-17 20:51:02 +00:00
|
|
|
$revisionRecord = $parser->fetchCurrentRevisionRecordOfTitle( $title );
|
2020-05-27 16:08:04 +00:00
|
|
|
if ( !$revisionRecord ) {
|
|
|
|
|
// Convert `false` error return to `null`
|
|
|
|
|
$revisionRecord = null;
|
|
|
|
|
}
|
2019-07-04 10:01:31 +00:00
|
|
|
// Register dependency in templatelinks
|
|
|
|
|
$parserOutput->addTemplate(
|
|
|
|
|
$title,
|
2020-04-17 20:51:02 +00:00
|
|
|
$revisionRecord ? $revisionRecord->getPageId() : 0,
|
|
|
|
|
$revisionRecord ? $revisionRecord->getId() : 0
|
2019-07-04 10:01:31 +00:00
|
|
|
);
|
2013-10-29 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-04 10:01:31 +00:00
|
|
|
if ( $isSelfReferential ) {
|
2020-02-08 07:08:25 +00:00
|
|
|
wfDebug( __METHOD__ . ": used current revision, setting $vary" );
|
2019-07-04 10:01:31 +00:00
|
|
|
// Upon page save, the result of the parser function using this might change
|
|
|
|
|
$parserOutput->setFlag( $vary );
|
2020-04-17 20:51:02 +00:00
|
|
|
if ( $vary === 'vary-revision-sha1' && $revisionRecord ) {
|
|
|
|
|
try {
|
|
|
|
|
$sha1 = $revisionRecord->getSha1();
|
|
|
|
|
} catch ( RevisionAccessException $e ) {
|
|
|
|
|
$sha1 = null;
|
|
|
|
|
}
|
|
|
|
|
$parserOutput->setRevisionUsedSha1Base36( $sha1 );
|
2019-07-04 10:01:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-10-29 21:02:59 +00:00
|
|
|
|
2020-04-17 20:51:02 +00:00
|
|
|
return $revisionRecord;
|
2013-10-29 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the pageid of a specified page
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the pageid from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return int|null|string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function pageid( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2019-06-27 04:30:35 +00:00
|
|
|
if ( !$t ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
2019-06-27 04:30:35 +00:00
|
|
|
} elseif ( !$t->canExist() || $t->isExternal() ) {
|
|
|
|
|
return 0; // e.g. special page or interwiki link
|
2013-10-29 21:02:59 +00:00
|
|
|
}
|
2019-06-27 04:30:35 +00:00
|
|
|
|
|
|
|
|
$parserOutput = $parser->getOutput();
|
|
|
|
|
|
2013-10-29 21:02:59 +00:00
|
|
|
if ( $t->equals( $parser->getTitle() ) ) {
|
2019-06-27 04:30:35 +00:00
|
|
|
// Revision is for the same title that is currently being parsed.
|
|
|
|
|
// Use the title from Parser in case a new page ID was injected into it.
|
|
|
|
|
$parserOutput->setFlag( 'vary-page-id' );
|
|
|
|
|
$id = $parser->getTitle()->getArticleID();
|
|
|
|
|
if ( $id ) {
|
|
|
|
|
$parserOutput->setSpeculativePageIdUsed( $id );
|
|
|
|
|
}
|
2014-01-14 20:36:48 +00:00
|
|
|
|
2019-06-27 04:30:35 +00:00
|
|
|
return $id;
|
2014-01-14 20:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-27 04:30:35 +00:00
|
|
|
// Check the link cache for the title
|
2018-06-11 06:55:11 +00:00
|
|
|
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
|
2014-01-14 20:36:48 +00:00
|
|
|
$pdbk = $t->getPrefixedDBkey();
|
|
|
|
|
$id = $linkCache->getGoodLinkID( $pdbk );
|
2019-06-27 04:30:35 +00:00
|
|
|
if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
|
|
|
|
|
$parserOutput->addLink( $t, $id );
|
|
|
|
|
|
2014-01-14 20:36:48 +00:00
|
|
|
return $id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We need to load it from the DB, so mark expensive
|
|
|
|
|
if ( $parser->incrementExpensiveFunctionCount() ) {
|
|
|
|
|
$id = $t->getArticleID();
|
2019-06-27 04:30:35 +00:00
|
|
|
$parserOutput->addLink( $t, $id );
|
|
|
|
|
|
2014-01-14 20:36:48 +00:00
|
|
|
return $id;
|
|
|
|
|
}
|
2019-06-27 04:30:35 +00:00
|
|
|
|
2014-01-14 20:36:48 +00:00
|
|
|
return null;
|
2013-10-29 21:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the id from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the id from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return int|null|string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionid( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
2020-02-24 19:05:45 +00:00
|
|
|
|
2020-02-08 07:08:25 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
|
if (
|
2020-02-24 19:05:45 +00:00
|
|
|
$t->equals( $parser->getTitle() ) &&
|
2020-02-08 07:08:25 +00:00
|
|
|
$services->getMainConfig()->get( 'MiserMode' ) &&
|
|
|
|
|
!$parser->getOptions()->getInterfaceMessage() &&
|
|
|
|
|
// @TODO: disallow this word on all namespaces (T235957)
|
2020-02-24 19:05:45 +00:00
|
|
|
$services->getNamespaceInfo()->isSubject( $t->getNamespace() )
|
2020-02-08 07:08:25 +00:00
|
|
|
) {
|
|
|
|
|
// Use a stub result instead of the actual revision ID in order to avoid
|
|
|
|
|
// double parses on page save but still allow preview detection (T137900)
|
|
|
|
|
if ( $parser->getRevisionId() || $parser->getOptions()->getSpeculativeRevId() ) {
|
|
|
|
|
return '-';
|
|
|
|
|
} else {
|
|
|
|
|
$parser->getOutput()->setFlag( 'vary-revision-exists' );
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-29 21:02:59 +00:00
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-id' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? $rev->getId() : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the day from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the day from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionday( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'j' ) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the day with leading zeros from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the day from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionday2( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'd' ) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the month with leading zeros from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the month from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionmonth( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'm' ) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the month from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the month from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionmonth1( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'n' ) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the year from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the year from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionyear( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'Y' ) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the timestamp from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the timestamp from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisiontimestamp( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
|
2013-10-29 21:02:59 +00:00
|
|
|
return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'YmdHis' ) : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the user from the last revision of a specified page.
|
2014-04-21 23:38:39 +00:00
|
|
|
* @param Parser $parser
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|null $title Title to get the user from
|
2014-05-10 23:05:51 +00:00
|
|
|
* @return string
|
2013-10-29 21:02:59 +00:00
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function revisionuser( $parser, $title = null ) {
|
|
|
|
|
$t = Title::newFromText( $title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $t === null ) {
|
2013-10-29 21:02:59 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
// fetch revision from cache/database and return the value
|
2019-07-04 10:01:31 +00:00
|
|
|
$rev = self::getCachedRevisionObject( $parser, $t, 'vary-user' );
|
2020-05-27 19:22:22 +00:00
|
|
|
if ( $rev === null ) {
|
2020-04-17 20:51:02 +00:00
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$user = $rev->getUser();
|
|
|
|
|
return $user ? $user->getName() : '';
|
2013-10-29 21:02:59 +00:00
|
|
|
}
|
2014-01-02 18:27:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the sources of any cascading protection acting on a specified page.
|
|
|
|
|
* Pages will not return their own title unless they transclude themselves.
|
2014-01-15 21:13:13 +00:00
|
|
|
* This is an expensive parser function and can't be called too many times per page,
|
|
|
|
|
* unless cascading protection sources for the page have already been loaded.
|
2014-01-02 18:27:29 +00:00
|
|
|
*
|
|
|
|
|
* @param Parser $parser
|
|
|
|
|
* @param string $title
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 1.23
|
|
|
|
|
*/
|
|
|
|
|
public static function cascadingsources( $parser, $title = '' ) {
|
2019-08-27 10:29:39 +00:00
|
|
|
$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
|
2014-01-15 21:13:13 +00:00
|
|
|
if ( $titleObject->areCascadeProtectionSourcesLoaded()
|
|
|
|
|
|| $parser->incrementExpensiveFunctionCount()
|
|
|
|
|
) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$names = [];
|
2014-01-02 18:27:29 +00:00
|
|
|
$sources = $titleObject->getCascadeProtectionSources();
|
|
|
|
|
foreach ( $sources[0] as $sourceTitle ) {
|
2014-01-06 21:53:43 +00:00
|
|
|
$names[] = $sourceTitle->getPrefixedText();
|
2014-01-02 18:27:29 +00:00
|
|
|
}
|
2018-02-22 19:24:00 +00:00
|
|
|
return implode( '|', $names );
|
2014-01-02 18:27:29 +00:00
|
|
|
}
|
2014-01-15 21:13:13 +00:00
|
|
|
return '';
|
2014-01-02 18:27:29 +00:00
|
|
|
}
|
2006-07-03 11:07:00 +00:00
|
|
|
}
|