MediaWiki  1.32.5
CiteHooks.php
Go to the documentation of this file.
1 <?php
8 
9 class CiteHooks {
10 
19  public static function onContentHandlerDefaultModelFor( Title $title, &$model ) {
20  if (
21  $title->inNamespace( NS_MEDIAWIKI ) &&
22  (
23  $title->getText() == 'Visualeditor-cite-tool-definition.json' ||
24  $title->getText() == 'Cite-tool-definition.json'
25  )
26  ) {
27  $model = CONTENT_MODEL_JSON;
28  }
29  }
30 
38  public static function onResourceLoaderTestModules(
39  array &$testModules,
40  ResourceLoader $resourceLoader
41  ) {
42  $resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' );
43 
44  if (
45  isset( $resourceModules[ 'ext.visualEditor.mediawiki' ] ) ||
46  $resourceLoader->isModuleRegistered( 'ext.visualEditor.mediawiki' )
47  ) {
48  $testModules['qunit']['ext.cite.visualEditor.test'] = [
49  'scripts' => [
50  'modules/ve-cite/tests/ve.dm.citeExample.js',
51  'modules/ve-cite/tests/ve.dm.Converter.test.js',
52  'modules/ve-cite/tests/ve.dm.InternalList.test.js',
53  'modules/ve-cite/tests/ve.dm.Transaction.test.js',
54  'modules/ve-cite/tests/ve.ui.DiffElement.test.js',
55  'modules/ve-cite/tests/ve.ui.MWWikitextStringTransferHandler.test.js',
56  ],
57  'dependencies' => [
58  'ext.cite.visualEditor',
59  'ext.visualEditor.test'
60  ],
61  'localBasePath' => dirname( __DIR__ ),
62  'remoteExtPath' => 'Cite',
63  ];
64  }
65  }
66 
73  public static function onResourceLoaderRegisterModules( ResourceLoader $resourceLoader ) {
74  if ( ! class_exists( 'VisualEditorHooks' ) ) {
75  return;
76  }
77 
78  $dir = dirname( __DIR__ ) . DIRECTORY_SEPARATOR;
79 
80  $resourceLoader->register( "ext.cite.visualEditor.core", [
81  'localBasePath' => $dir . 'modules',
82  'remoteExtPath' => 'Cite/modules',
83  "scripts" => [
84  "ve-cite/ve.dm.MWReferenceModel.js",
85  "ve-cite/ve.dm.MWReferencesListNode.js",
86  "ve-cite/ve.dm.MWReferenceNode.js",
87  "ve-cite/ve.ce.MWReferencesListNode.js",
88  "ve-cite/ve.ce.MWReferenceNode.js",
89  "ve-cite/ve.ui.MWReferencesListCommand.js"
90  ],
91  "styles" => [
92  "ve-cite/ve.ce.MWReferencesListNode.css",
93  "ve-cite/ve.ce.MWReferenceNode.css"
94  ],
95  "dependencies" => [
96  "ext.visualEditor.mwcore"
97  ],
98  "messages" => [
99  "cite-ve-referenceslist-isempty",
100  "cite-ve-referenceslist-isempty-default",
101  "cite-ve-referenceslist-missingref",
102  "cite-ve-referenceslist-missingref-in-list",
103  "cite-ve-referenceslist-missingreflist",
104  "visualeditor-internal-list-diff-default-group-name-mwreference",
105  "visualeditor-internal-list-diff-group-name-mwreference"
106  ],
107  "targets" => [
108  "desktop",
109  "mobile"
110  ]
111  ] );
112 
113  $resourceLoader->register( "ext.cite.visualEditor.data",
114  [ "class" => "CiteDataModule" ] );
115 
116  $resourceLoader->register( "ext.cite.visualEditor.icons", [
117  'localBasePath' => $dir . 'modules',
118  'remoteExtPath' => 'Cite/modules',
119  "class" => "ResourceLoaderImageModule",
120  "selectorWithoutVariant" => ".oo-ui-icon-{name}",
121  "selectorWithVariant" => ".oo-ui-image-{variant}.oo-ui-icon-{name}",
122  "variants" => [
123  "progressive" => [
124  "color" => "#36c"
125  ]
126  ],
127  "images" => [
128  "ref-cite-book" => [
129  "file" => "ve-cite/icons/ref-cite-book.svg"
130  ],
131  "ref-cite-journal" => [
132  "file" => [
133  "ltr" => "ve-cite/icons/ref-cite-journal-ltr.svg",
134  "rtl" => "ve-cite/icons/ref-cite-journal-rtl.svg"
135  ]
136  ],
137  "ref-cite-news" => [
138  "file" => [
139  "ltr" => "ve-cite/icons/ref-cite-news-ltr.svg",
140  "rtl" => "ve-cite/icons/ref-cite-news-rtl.svg"
141  ]
142  ],
143  "ref-cite-web" => [
144  "file" => "ve-cite/icons/ref-cite-web.svg"
145  ],
146  "reference" => [
147  "file" => [
148  "ltr" => "ve-cite/icons/reference-ltr.svg",
149  "rtl" => "ve-cite/icons/reference-rtl.svg"
150  ]
151  ],
152  "reference-existing" => [
153  "file" => [
154  "ltr" => "ve-cite/icons/reference-existing-ltr.svg",
155  "rtl" => "ve-cite/icons/reference-existing-rtl.svg"
156  ]
157  ],
158  "references" => [
159  "file" => [
160  "ltr" => "ve-cite/icons/references-ltr.svg",
161  "rtl" => "ve-cite/icons/references-rtl.svg"
162  ]
163  ],
164  ]
165  ] );
166 
167  $resourceLoader->register( "ext.cite.visualEditor", [
168  'localBasePath' => $dir . 'modules',
169  'remoteExtPath' => 'Cite/modules',
170  "scripts" => [
171  "ve-cite/ve.ui.MWReferenceGroupInputWidget.js",
172  "ve-cite/ve.ui.MWReferenceSearchWidget.js",
173  "ve-cite/ve.ui.MWReferenceResultWidget.js",
174  "ve-cite/ve.ui.MWUseExistingReferenceCommand.js",
175  "ve-cite/ve.ui.MWCitationDialog.js",
176  "ve-cite/ve.ui.MWReferencesListDialog.js",
177  "ve-cite/ve.ui.MWReferenceDialog.js",
178  "ve-cite/ve.ui.MWReferenceDialogTool.js",
179  "ve-cite/ve.ui.MWCitationDialogTool.js",
180  "ve-cite/ve.ui.MWReferenceContextItem.js",
181  "ve-cite/ve.ui.MWReferencesListContextItem.js",
182  "ve-cite/ve.ui.MWCitationContextItem.js",
183  "ve-cite/ve.ui.MWCitationAction.js",
184  "ve-cite/ve.ui.MWReference.init.js"
185  ],
186  "styles" => [
187  "ve-cite/ve.ui.MWReferenceContextItem.css",
188  "ve-cite/ve.ui.MWReferenceGroupInputWidget.css",
189  "ve-cite/ve.ui.MWReferenceResultWidget.css",
190  "ve-cite/ve.ui.MWReferenceSearchWidget.css"
191  ],
192  "dependencies" => [
193  "oojs-ui.styles.icons-alerts",
194  "oojs-ui.styles.icons-editing-citation",
195  "oojs-ui.styles.icons-interactions",
196  "ext.cite.visualEditor.core",
197  "ext.cite.visualEditor.data",
198  "ext.cite.visualEditor.icons",
199  "ext.cite.style",
200  "ext.cite.styles",
201  "ext.visualEditor.mwtransclusion",
202  "ext.visualEditor.mediawiki"
203  ],
204  "messages" => [
205  "cite-ve-changedesc-ref-group-both",
206  "cite-ve-changedesc-ref-group-from",
207  "cite-ve-changedesc-ref-group-to",
208  "cite-ve-changedesc-reflist-group-both",
209  "cite-ve-changedesc-reflist-group-from",
210  "cite-ve-changedesc-reflist-group-to",
211  "cite-ve-changedesc-reflist-item-id",
212  "cite-ve-changedesc-reflist-responsive-set",
213  "cite-ve-changedesc-reflist-responsive-unset",
214  "cite-ve-dialog-reference-editing-reused",
215  "cite-ve-dialog-reference-options-group-label",
216  "cite-ve-dialog-reference-options-group-placeholder",
217  "cite-ve-dialog-reference-options-name-label",
218  "cite-ve-dialog-reference-options-responsive-label",
219  "cite-ve-dialog-reference-options-section",
220  "cite-ve-dialog-reference-placeholder",
221  "cite-ve-dialog-reference-title",
222  "cite-ve-dialog-reference-useexisting-full-label",
223  "cite-ve-dialog-reference-useexisting-label",
224  "cite-ve-dialog-reference-useexisting-tool",
225  "cite-ve-dialog-referenceslist-contextitem-description-general",
226  "cite-ve-dialog-referenceslist-contextitem-description-named",
227  "cite-ve-dialog-referenceslist-title",
228  "cite-ve-dialogbutton-citation-educationpopup-title",
229  "cite-ve-dialogbutton-citation-educationpopup-text",
230  "cite-ve-dialogbutton-reference-full-label",
231  "cite-ve-dialogbutton-reference-tooltip",
232  "cite-ve-dialogbutton-reference-title",
233  "cite-ve-dialogbutton-referenceslist-tooltip",
234  "cite-ve-reference-input-placeholder",
235  "cite-ve-toolbar-group-label",
236  "cite-ve-othergroup-item"
237  ],
238  "targets" => [
239  "desktop",
240  "mobile"
241  ]
242  ] );
243  }
244 
252  public static function onLinksUpdate( LinksUpdate $linksUpdate ) {
253  global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
254  if ( !$wgCiteStoreReferencesData ) {
255  return;
256  }
257  $refData = $linksUpdate->getParserOutput()->getExtensionData( Cite::EXT_DATA_KEY );
258  if ( $refData === null ) {
259  return;
260  }
261  if ( $wgCiteCacheRawReferencesOnParse ) {
262  // caching
263  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
264  $articleID = $linksUpdate->getTitle()->getArticleID();
265  $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
266  $cache->set( $key, $refData, Cite::CACHE_DURATION_ONPARSE );
267  }
268  // JSON encode
269  $ppValue = FormatJson::encode( $refData, false, FormatJson::ALL_OK );
270  // GZIP encode references data at maximum compression
271  $ppValue = gzencode( $ppValue, 9 );
272  // split the string in smaller parts that can fit into a db blob
273  $ppValues = str_split( $ppValue, Cite::MAX_STORAGE_LENGTH );
274  foreach ( $ppValues as $num => $ppValue ) {
275  $key = 'references-' . intval( $num + 1 );
276  $linksUpdate->mProperties[$key] = $ppValue;
277  }
278  $linksUpdate->getParserOutput()->setExtensionData( Cite::EXT_DATA_KEY, null );
279  }
280 
288  public static function onLinksUpdateComplete( LinksUpdate $linksUpdate ) {
289  global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
290  if ( !$wgCiteStoreReferencesData || $wgCiteCacheRawReferencesOnParse ) {
291  return;
292  }
293  // if we can, avoid clearing the cache when references were not changed
294  if ( method_exists( $linksUpdate, 'getAddedProperties' )
295  && method_exists( $linksUpdate, 'getRemovedProperties' )
296  ) {
297  $addedProps = $linksUpdate->getAddedProperties();
298  $removedProps = $linksUpdate->getRemovedProperties();
299  if ( !isset( $addedProps['references-1'] )
300  && !isset( $removedProps['references-1'] )
301  ) {
302  return;
303  }
304  }
305  $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
306  $articleID = $linksUpdate->getTitle()->getArticleID();
307  $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
308  // delete with reduced hold off period (LinksUpdate uses a master connection)
309  $cache->delete( $key, WANObjectCache::MAX_COMMIT_DELAY );
310  }
311 
316  public static function onResourceLoaderGetConfigVars( array &$vars ) {
317  $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
318  $vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' );
319  $vars['wgCiteResponsiveReferences'] = $config->get( 'CiteResponsiveReferences' );
320  }
321 
330  public static function onAPIQuerySiteInfoGeneralInfo( ApiQuerySiteInfo $api, array &$data ) {
331  $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
332  $data['citeresponsivereferences'] = $config->get( 'CiteResponsiveReferences' );
333  }
334 
335 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:239
WANObjectCache\MAX_COMMIT_DELAY
const MAX_COMMIT_DELAY
Max time expected to pass between delete() and DB commit finishing.
Definition: WANObjectCache.php:158
LinksUpdate
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition: LinksUpdate.php:35
$resourceLoader
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition: hooks.txt:2683
CiteHooks\onLinksUpdateComplete
static onLinksUpdateComplete(LinksUpdate $linksUpdate)
Callback for LinksUpdateComplete hook If $wgCiteCacheRawReferencesOnParse is set to false,...
Definition: CiteHooks.php:288
FormatJson\ALL_OK
const ALL_OK
Skip escaping as many characters as reasonably possible.
Definition: FormatJson.php:55
CiteHooks\onResourceLoaderTestModules
static onResourceLoaderTestModules(array &$testModules, ResourceLoader $resourceLoader)
Conditionally register the unit testing module for the ext.cite.visualEditor module only if that modu...
Definition: CiteHooks.php:38
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
CiteHooks\onResourceLoaderRegisterModules
static onResourceLoaderRegisterModules(ResourceLoader $resourceLoader)
Conditionally register resource loader modules that depends on the VisualEditor MediaWiki extension.
Definition: CiteHooks.php:73
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:115
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:964
CiteHooks\onContentHandlerDefaultModelFor
static onContentHandlerDefaultModelFor(Title $title, &$model)
Convert the content model of a message that is actually JSON to JSON.
Definition: CiteHooks.php:19
CiteHooks\onAPIQuerySiteInfoGeneralInfo
static onAPIQuerySiteInfoGeneralInfo(ApiQuerySiteInfo $api, array &$data)
Hook: APIQuerySiteInfoGeneralInfo.
Definition: CiteHooks.php:330
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2278
CiteHooks\onResourceLoaderGetConfigVars
static onResourceLoaderGetConfigVars(array &$vars)
Adds extra variables to the global config.
Definition: CiteHooks.php:316
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$linksUpdate
either a unescaped string or a HtmlArmor object after in associative array form externallinks $linksUpdate
Definition: hooks.txt:2123
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$cache
$cache
Definition: mcc.php:33
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:72
CiteHooks
Definition: CiteHooks.php:9
MediaWikiServices
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
CiteHooks\onLinksUpdate
static onLinksUpdate(LinksUpdate $linksUpdate)
Callback for LinksUpdate hook Post-output processing of references property, for proper db storage De...
Definition: CiteHooks.php:252