15 if ( !isset( $gadgets[$id] ) ) {
16 throw new InvalidArgumentException(
"No gadget registered for '$id'" );
25 return array_keys( $gadgets );
36 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
51 if ( $this->definitionCache !==
null ) {
56 $t1Cache = ObjectCache::getLocalServerInstance(
'hash' );
57 $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
62 $value = $t1Cache->get( $key );
64 if (
$value && ( microtime(
true ) -
$value[
'time'] ) < 10 ) {
65 $this->definitionCache =
$value[
'gadgets'];
69 $ckTime = $wanCache->getCheckKeyTime( $key ) + WANObjectCache::HOLDOFF_TTL;
71 $this->definitionCache =
$value[
'gadgets'];
78 $value = $wanCache->getWithSetCallback(
81 function ( $old, &$ttl, &$setOpts ) use ( $us ) {
84 $now = microtime(
true );
85 $gadgets = $us->fetchStructuredList();
86 if ( $gadgets ===
false ) {
87 $ttl = WANObjectCache::TTL_UNCACHEABLE;
90 return [
'gadgets' => $gadgets,
'time' => $now ];
92 [
'checkKeys' => [ $key ],
'lockTSE' => 300 ]
96 if (
$value[
'gadgets'] !==
false &&
$value[
'time'] > $ckTime ) {
98 $t1Cache->set( $key,
$value, mt_rand( 300, 600 ) );
101 $this->definitionCache =
$value[
'gadgets'];
113 if ( $forceNewText ===
null ) {
115 $title = Title::makeTitle( NS_MEDIAWIKI,
'Gadgets-definition' );
117 if ( !
$rev || !
$rev->getContent() ||
$rev->getContent()->isEmpty() ) {
121 $g =
$rev->getContent()->getNativeData();
127 if ( !count( $gadgets ) ) {
131 $source = $forceNewText !==
null ?
'input text' :
'MediaWiki:Gadgets-definition';
132 wfDebug( __METHOD__ .
": $source parsed, cache entry should be updated\n" );
144 $definition = preg_replace(
'/<!--.*?-->/s',
'', $definition );
145 $lines = preg_split(
'/(\r\n|\r|\n)+/', $definition );
152 if ( preg_match(
'/^==+ *([^*:\s|]+?)\s*==+\s*$/',
$line, $m ) ) {
157 $gadgets[$gadget->getName()] = $gadget;
174 '/^\*+ *([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)(\s*\[.*?\])?\s*((\|[^|]*)+)\s*$/',
183 $info = [
'category' => $category ];
184 $info[
'name'] = trim( str_replace(
' ',
'_', $m[1] ) );
190 $info[
'definition'] = $definition;
193 foreach ( preg_split(
'/\s*\|\s*/',
$options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) {
194 $arr = preg_split(
'/\s*=\s*/', $option, 2 );
196 if ( isset( $arr[1] ) ) {
197 $params = explode(
',', $arr[1] );
204 case 'ResourceLoader':
205 $info[
'resourceLoaded'] =
true;
208 $info[
'dependencies'] =
$params;
214 $info[
'requiredRights'] =
$params;
217 $info[
'hidden'] =
true;
220 $info[
'requiredSkins'] =
$params;
223 $info[
'onByDefault'] =
true;
235 foreach ( preg_split(
'/\s*\|\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY ) as $page ) {
236 $page =
"MediaWiki:Gadget-$page";
238 if ( preg_match(
'/\.js/', $page ) ) {
239 $info[
'scripts'][] = $page;
240 } elseif ( preg_match(
'/\.css/', $page ) ) {
241 $info[
'styles'][] = $page;
245 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.
wfMemcKey()
Make a cache key for the local wiki.
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