23 if ( !isset( $gadgets[$id] ) ) {
24 throw new InvalidArgumentException(
"No gadget registered for '$id'" );
33 return array_keys( $gadgets );
40 if ( $target->
getNamespace() == NS_MEDIAWIKI && $target->
getText() ==
'Gadgets-definition' ) {
50 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
55 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
71 if ( $this->definitionCache !==
null ) {
76 $t1Cache = ObjectCache::getLocalServerInstance(
'hash' );
77 $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
82 $value = $t1Cache->get( $key );
84 if (
$value && ( microtime(
true ) -
$value[
'time'] ) < 10 ) {
85 $this->definitionCache =
$value[
'gadgets'];
89 $ckTime = $wanCache->getCheckKeyTime( $key ) + WANObjectCache::HOLDOFF_TTL;
91 $this->definitionCache =
$value[
'gadgets'];
98 $value = $wanCache->getWithSetCallback(
101 function ( $old, &$ttl, &$setOpts ) use ( $us ) {
104 $now = microtime(
true );
105 $gadgets = $us->fetchStructuredList();
106 if ( $gadgets ===
false ) {
107 $ttl = WANObjectCache::TTL_UNCACHEABLE;
110 return [
'gadgets' => $gadgets,
'time' => $now ];
112 [
'checkKeys' => [ $key ],
'lockTSE' => 300 ]
116 if (
$value[
'gadgets'] !==
false &&
$value[
'time'] > $ckTime ) {
118 $t1Cache->set( $key,
$value, mt_rand( 300, 600 ) );
121 $this->definitionCache =
$value[
'gadgets'];
133 if ( $forceNewText ===
null ) {
135 $title = Title::makeTitle( NS_MEDIAWIKI,
'Gadgets-definition' );
137 if ( !
$rev || !
$rev->getContent() ||
$rev->getContent()->isEmpty() ) {
141 $g =
$rev->getContent()->getNativeData();
147 if ( !count( $gadgets ) ) {
151 $source = $forceNewText !==
null ?
'input text' :
'MediaWiki:Gadgets-definition';
152 wfDebug( __METHOD__ .
": $source parsed, cache entry should be updated\n" );
164 $definition = preg_replace(
'/<!--.*?-->/s',
'', $definition );
165 $lines = preg_split(
'/(\r\n|\r|\n)+/', $definition );
172 if ( preg_match(
'/^==+ *([^*:\s|]+?)\s*==+\s*$/',
$line, $m ) ) {
177 $gadgets[$gadget->getName()] = $gadget;
194 '/^\*+ *([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)(\s*\[.*?\])?\s*((\|[^|]*)+)\s*$/',
203 $info = [
'category' => $category ];
204 $info[
'name'] = trim( str_replace(
' ',
'_', $m[1] ) );
210 $info[
'definition'] = $definition;
213 foreach ( preg_split(
'/\s*\|\s*/',
$options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) {
214 $arr = preg_split(
'/\s*=\s*/', $option, 2 );
216 if ( isset( $arr[1] ) ) {
217 $params = explode(
',', $arr[1] );
224 case 'ResourceLoader':
225 $info[
'resourceLoaded'] =
true;
228 $info[
'dependencies'] =
$params;
234 $info[
'requiredRights'] =
$params;
237 $info[
'hidden'] =
true;
240 $info[
'requiredSkins'] =
$params;
243 $info[
'onByDefault'] =
true;
255 foreach ( preg_split(
'/\s*\|\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY ) as $page ) {
256 $page =
"MediaWiki:Gadget-$page";
258 if ( preg_match(
'/\.js/', $page ) ) {
259 $info[
'scripts'][] = $page;
260 } elseif ( preg_match(
'/\.css/', $page ) ) {
261 $info[
'styles'][] = $page;
265 return new Gadget( $info );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
const GADGET_CLASS_VERSION
Increment this when changing class structure.
static isValidGadgetID( $id)
Whether the provided gadget id is valid.
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev