MediaWiki REL1_32
CiteHooks.php
Go to the documentation of this file.
1<?php
8
9class 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,
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
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
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}
static onContentHandlerDefaultModelFor(Title $title, &$model)
Convert the content model of a message that is actually JSON to JSON.
Definition CiteHooks.php:19
static onResourceLoaderGetConfigVars(array &$vars)
Adds extra variables to the global config.
static onResourceLoaderRegisterModules(ResourceLoader $resourceLoader)
Conditionally register resource loader modules that depends on the VisualEditor MediaWiki extension.
Definition CiteHooks.php:73
static onLinksUpdateComplete(LinksUpdate $linksUpdate)
Callback for LinksUpdateComplete hook If $wgCiteCacheRawReferencesOnParse is set to false,...
static onLinksUpdate(LinksUpdate $linksUpdate)
Callback for LinksUpdate hook Post-output processing of references property, for proper db storage De...
static onAPIQuerySiteInfoGeneralInfo(ApiQuerySiteInfo $api, array &$data)
Hook: APIQuerySiteInfoGeneralInfo.
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
const EXT_DATA_KEY
Key used for storage in parser output's ExtensionData and ObjectCache.
Definition Cite.php:49
const MAX_STORAGE_LENGTH
Maximum storage capacity for pp_value field of page_props table.
Definition Cite.php:44
const CACHE_DURATION_ONPARSE
Cache duration set when parsing a page with references.
Definition Cite.php:59
Class the manages updates of *_link tables as well as similar extension-managed tables.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Dynamic JavaScript and CSS resource loading system.
Represents a title within MediaWiki.
Definition Title.php:39
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition hooks.txt:2278
either a unescaped string or a HtmlArmor object after in associative array form externallinks $linksUpdate
Definition hooks.txt:2139
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:2892
const CONTENT_MODEL_JSON
Definition Defines.php:239
$cache
Definition mcc.php:33
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))