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();
65 if ( $this->definitionCache !==
null ) {
70 $t1Cache = ObjectCache::getLocalServerInstance(
'hash' );
71 $wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
76 $value = $t1Cache->get( $key );
78 if (
$value && ( microtime(
true ) -
$value[
'time'] ) < 10 ) {
79 $this->definitionCache =
$value[
'gadgets'];
83 $ckTime = $wanCache->getCheckKeyTime( $key ) + WANObjectCache::HOLDOFF_TTL;
85 $this->definitionCache =
$value[
'gadgets'];
92 $value = $wanCache->getWithSetCallback(
95 function ( $old, &$ttl, &$setOpts ) use ( $us ) {
98 $now = microtime(
true );
99 $gadgets = $us->fetchStructuredList();
100 if ( $gadgets ===
false ) {
101 $ttl = WANObjectCache::TTL_UNCACHEABLE;
104 return [
'gadgets' => $gadgets,
'time' => $now ];
106 [
'checkKeys' => [ $key ],
'lockTSE' => 300 ]
110 if (
$value[
'gadgets'] !==
false &&
$value[
'time'] > $ckTime ) {
112 $t1Cache->set( $key,
$value, mt_rand( 300, 600 ) );
115 $this->definitionCache =
$value[
'gadgets'];
127 if ( $forceNewText ===
null ) {
129 $title = Title::makeTitle( NS_MEDIAWIKI,
'Gadgets-definition' );
130 $rev = Revision::newFromTitle( $title );
131 if ( !
$rev || !
$rev->getContent() ||
$rev->getContent()->isEmpty() ) {
135 $g =
$rev->getContent()->getNativeData();
141 if ( !count( $gadgets ) ) {
145 $source = $forceNewText !==
null ?
'input text' :
'MediaWiki:Gadgets-definition';
146 wfDebug( __METHOD__ .
": $source parsed, cache entry should be updated\n" );
158 $definition = preg_replace(
'/<!--.*?-->/s',
'', $definition );
159 $lines = preg_split(
'/(\r\n|\r|\n)+/', $definition );
166 if ( preg_match(
'/^==+ *([^*:\s|]+?)\s*==+\s*$/',
$line, $m ) ) {
171 $gadgets[$gadget->getName()] = $gadget;
188 '/^\*+ *([a-zA-Z](?:[-_:.\w\d ]*[a-zA-Z0-9])?)(\s*\[.*?\])?\s*((\|[^|]*)+)\s*$/',
197 $info = [
'category' => $category ];
198 $info[
'name'] = trim( str_replace(
' ',
'_', $m[1] ) );
204 $info[
'definition'] = $definition;
207 foreach ( preg_split(
'/\s*\|\s*/',
$options, -1, PREG_SPLIT_NO_EMPTY ) as $option ) {
208 $arr = preg_split(
'/\s*=\s*/', $option, 2 );
210 if ( isset( $arr[1] ) ) {
211 $params = explode(
',', $arr[1] );
218 case 'ResourceLoader':
219 $info[
'resourceLoaded'] =
true;
222 $info[
'dependencies'] =
$params;
228 $info[
'requiredRights'] =
$params;
231 $info[
'hidden'] =
true;
234 $info[
'requiredSkins'] =
$params;
237 $info[
'onByDefault'] =
true;
249 foreach ( preg_split(
'/\s*\|\s*/', $m[3], -1, PREG_SPLIT_NO_EMPTY ) as $page ) {
250 $page =
"MediaWiki:Gadget-$page";
252 if ( preg_match(
'/\.js/', $page ) ) {
253 $info[
'scripts'][] = $page;
254 } elseif ( preg_match(
'/\.css/', $page ) ) {
255 $info[
'styles'][] = $page;
259 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.
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