MediaWiki REL1_31
CiteHooks.php
Go to the documentation of this file.
1<?php
8
9class CiteHooks {
10
20 public static function onContentHandlerDefaultModelFor( Title $title, &$model ) {
21 if (
22 $title->inNamespace( NS_MEDIAWIKI ) &&
23 (
24 $title->getText() == 'Visualeditor-cite-tool-definition.json' ||
25 $title->getText() == 'Cite-tool-definition.json'
26 )
27 ) {
28 $model = CONTENT_MODEL_JSON;
29 }
30
31 return true;
32 }
33
42 public static function onResourceLoaderTestModules(
43 array &$testModules,
45 ) {
46 $resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' );
47
48 if (
49 isset( $resourceModules[ 'ext.visualEditor.mediawiki' ] ) ||
50 $resourceLoader->isModuleRegistered( 'ext.visualEditor.mediawiki' )
51 ) {
52 $testModules['qunit']['ext.cite.visualEditor.test'] = [
53 'scripts' => [
54 'modules/ve-cite/tests/ve.dm.citeExample.js',
55 'modules/ve-cite/tests/ve.dm.Converter.test.js',
56 'modules/ve-cite/tests/ve.dm.InternalList.test.js',
57 'modules/ve-cite/tests/ve.dm.Transaction.test.js',
58 'modules/ve-cite/tests/ve.ui.DiffElement.test.js',
59 'modules/ve-cite/tests/ve.ui.MWWikitextStringTransferHandler.test.js',
60 ],
61 'dependencies' => [
62 'ext.cite.visualEditor',
63 'ext.visualEditor.test'
64 ],
65 'localBasePath' => dirname( __DIR__ ),
66 'remoteExtPath' => 'Cite',
67 ];
68 }
69
70 return true;
71 }
72
81 if ( ! class_exists( 'VisualEditorHooks' ) ) {
82 return true;
83 }
84
85 $dir = dirname( __DIR__ ) . DIRECTORY_SEPARATOR;
86
87 $resourceLoader->register( "ext.cite.visualEditor.core", [
88 'localBasePath' => $dir . 'modules',
89 'remoteExtPath' => 'Cite/modules',
90 "scripts" => [
91 "ve-cite/ve.dm.MWReferenceModel.js",
92 "ve-cite/ve.dm.MWReferencesListNode.js",
93 "ve-cite/ve.dm.MWReferenceNode.js",
94 "ve-cite/ve.ce.MWReferencesListNode.js",
95 "ve-cite/ve.ce.MWReferenceNode.js",
96 "ve-cite/ve.ui.MWReferencesListCommand.js"
97 ],
98 "styles" => [
99 "ve-cite/ve.ce.MWReferencesListNode.css",
100 "ve-cite/ve.ce.MWReferenceNode.css"
101 ],
102 "dependencies" => [
103 "ext.visualEditor.mwcore"
104 ],
105 "messages" => [
106 "cite-ve-referenceslist-isempty",
107 "cite-ve-referenceslist-isempty-default",
108 "cite-ve-referenceslist-missingref",
109 "cite-ve-referenceslist-missingref-in-list",
110 "cite-ve-referenceslist-missingreflist",
111 "visualeditor-internal-list-diff-default-group-name-mwreference",
112 "visualeditor-internal-list-diff-group-name-mwreference"
113 ],
114 "targets" => [
115 "desktop",
116 "mobile"
117 ]
118 ] );
119
120 $resourceLoader->register( "ext.cite.visualEditor.data",
121 [ "class" => "CiteDataModule" ] );
122
123 $resourceLoader->register( "ext.cite.visualEditor.icons", [
124 'localBasePath' => $dir . 'modules',
125 'remoteExtPath' => 'Cite/modules',
126 "class" => "ResourceLoaderImageModule",
127 "selectorWithoutVariant" => ".oo-ui-icon-{name}",
128 "selectorWithVariant" => ".oo-ui-image-{variant}.oo-ui-icon-{name}",
129 "variants" => [
130 "progressive" => [
131 "color" => "#36c"
132 ]
133 ],
134 "images" => [
135 "ref-cite-book" => [
136 "file" => "ve-cite/icons/ref-cite-book.svg"
137 ],
138 "ref-cite-journal" => [
139 "file" => [
140 "ltr" => "ve-cite/icons/ref-cite-journal-ltr.svg",
141 "rtl" => "ve-cite/icons/ref-cite-journal-rtl.svg"
142 ]
143 ],
144 "ref-cite-news" => [
145 "file" => [
146 "ltr" => "ve-cite/icons/ref-cite-news-ltr.svg",
147 "rtl" => "ve-cite/icons/ref-cite-news-rtl.svg"
148 ]
149 ],
150 "ref-cite-web" => [
151 "file" => "ve-cite/icons/ref-cite-web.svg"
152 ],
153 "reference" => [
154 "file" => [
155 "ltr" => "ve-cite/icons/reference-ltr.svg",
156 "rtl" => "ve-cite/icons/reference-rtl.svg"
157 ]
158 ],
159 "reference-existing" => [
160 "file" => [
161 "ltr" => "ve-cite/icons/reference-existing-ltr.svg",
162 "rtl" => "ve-cite/icons/reference-existing-rtl.svg"
163 ]
164 ],
165 "references" => [
166 "file" => [
167 "ltr" => "ve-cite/icons/references-ltr.svg",
168 "rtl" => "ve-cite/icons/references-rtl.svg"
169 ]
170 ],
171 ]
172 ] );
173
174 $resourceLoader->register( "ext.cite.visualEditor", [
175 'localBasePath' => $dir . 'modules',
176 'remoteExtPath' => 'Cite/modules',
177 "scripts" => [
178 "ve-cite/ve.ui.MWReferenceGroupInputWidget.js",
179 "ve-cite/ve.ui.MWReferenceSearchWidget.js",
180 "ve-cite/ve.ui.MWReferenceResultWidget.js",
181 "ve-cite/ve.ui.MWUseExistingReferenceCommand.js",
182 "ve-cite/ve.ui.MWCitationDialog.js",
183 "ve-cite/ve.ui.MWReferencesListDialog.js",
184 "ve-cite/ve.ui.MWReferenceDialog.js",
185 "ve-cite/ve.ui.MWReferenceDialogTool.js",
186 "ve-cite/ve.ui.MWCitationDialogTool.js",
187 "ve-cite/ve.ui.MWReferenceContextItem.js",
188 "ve-cite/ve.ui.MWReferencesListContextItem.js",
189 "ve-cite/ve.ui.MWCitationContextItem.js",
190 "ve-cite/ve.ui.MWCitationAction.js",
191 "ve-cite/ve.ui.MWReference.init.js"
192 ],
193 "styles" => [
194 "ve-cite/ve.ui.MWReferenceContextItem.css",
195 "ve-cite/ve.ui.MWReferenceGroupInputWidget.css",
196 "ve-cite/ve.ui.MWReferenceResultWidget.css",
197 "ve-cite/ve.ui.MWReferenceSearchWidget.css"
198 ],
199 "dependencies" => [
200 "oojs-ui.styles.icons-alerts",
201 "oojs-ui.styles.icons-interactions",
202 "ext.cite.visualEditor.core",
203 "ext.cite.visualEditor.data",
204 "ext.cite.visualEditor.icons",
205 "ext.cite.style",
206 "ext.cite.styles",
207 "ext.visualEditor.mwtransclusion",
208 "ext.visualEditor.mediawiki"
209 ],
210 "messages" => [
211 "cite-ve-changedesc-ref-group-both",
212 "cite-ve-changedesc-ref-group-from",
213 "cite-ve-changedesc-ref-group-to",
214 "cite-ve-changedesc-reflist-group-both",
215 "cite-ve-changedesc-reflist-group-from",
216 "cite-ve-changedesc-reflist-group-to",
217 "cite-ve-changedesc-reflist-item-id",
218 "cite-ve-changedesc-reflist-responsive-set",
219 "cite-ve-changedesc-reflist-responsive-unset",
220 "cite-ve-dialog-reference-editing-reused",
221 "cite-ve-dialog-reference-options-group-label",
222 "cite-ve-dialog-reference-options-group-placeholder",
223 "cite-ve-dialog-reference-options-name-label",
224 "cite-ve-dialog-reference-options-responsive-label",
225 "cite-ve-dialog-reference-options-section",
226 "cite-ve-dialog-reference-placeholder",
227 "cite-ve-dialog-reference-title",
228 "cite-ve-dialog-reference-useexisting-full-label",
229 "cite-ve-dialog-reference-useexisting-label",
230 "cite-ve-dialog-reference-useexisting-tool",
231 "cite-ve-dialog-referenceslist-contextitem-description-general",
232 "cite-ve-dialog-referenceslist-contextitem-description-named",
233 "cite-ve-dialog-referenceslist-title",
234 "cite-ve-dialogbutton-citation-educationpopup-title",
235 "cite-ve-dialogbutton-citation-educationpopup-text",
236 "cite-ve-dialogbutton-reference-full-label",
237 "cite-ve-dialogbutton-reference-tooltip",
238 "cite-ve-dialogbutton-reference-title",
239 "cite-ve-dialogbutton-referenceslist-tooltip",
240 "cite-ve-reference-input-placeholder",
241 "cite-ve-toolbar-group-label",
242 "cite-ve-othergroup-item"
243 ],
244 "targets" => [
245 "desktop",
246 "mobile"
247 ]
248 ] );
249 return true;
250 }
251
259 public static function onLinksUpdate( LinksUpdate &$linksUpdate ) {
260 global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
261 if ( !$wgCiteStoreReferencesData ) {
262 return;
263 }
264 $refData = $linksUpdate->getParserOutput()->getExtensionData( Cite::EXT_DATA_KEY );
265 if ( $refData === null ) {
266 return;
267 }
268 if ( $wgCiteCacheRawReferencesOnParse ) {
269 // caching
270 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
271 $articleID = $linksUpdate->getTitle()->getArticleID();
272 $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
273 $cache->set( $key, $refData, Cite::CACHE_DURATION_ONPARSE );
274 }
275 // JSON encode
276 $ppValue = FormatJson::encode( $refData, false, FormatJson::ALL_OK );
277 // GZIP encode references data at maximum compression
278 $ppValue = gzencode( $ppValue, 9 );
279 // split the string in smaller parts that can fit into a db blob
280 $ppValues = str_split( $ppValue, Cite::MAX_STORAGE_LENGTH );
281 foreach ( $ppValues as $num => $ppValue ) {
282 $key = 'references-' . intval( $num + 1 );
283 $linksUpdate->mProperties[$key] = $ppValue;
284 }
285 $linksUpdate->getParserOutput()->setExtensionData( Cite::EXT_DATA_KEY, null );
286 }
287
295 public static function onLinksUpdateComplete( LinksUpdate &$linksUpdate ) {
296 global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
297 if ( !$wgCiteStoreReferencesData || $wgCiteCacheRawReferencesOnParse ) {
298 return;
299 }
300 // if we can, avoid clearing the cache when references were not changed
301 if ( method_exists( $linksUpdate, 'getAddedProperties' )
302 && method_exists( $linksUpdate, 'getRemovedProperties' )
303 ) {
304 $addedProps = $linksUpdate->getAddedProperties();
305 $removedProps = $linksUpdate->getRemovedProperties();
306 if ( !isset( $addedProps['references-1'] )
307 && !isset( $removedProps['references-1'] )
308 ) {
309 return;
310 }
311 }
312 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
313 $articleID = $linksUpdate->getTitle()->getArticleID();
314 $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
315 // delete with reduced hold off period (LinksUpdate uses a master connection)
316 $cache->delete( $key, WANObjectCache::MAX_COMMIT_DELAY );
317 }
318
324 public static function onResourceLoaderGetConfigVars( array &$vars ) {
325 $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
326 $vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' );
327 $vars['wgCiteResponsiveReferences'] = $config->get( 'CiteResponsiveReferences' );
328 return true;
329 }
330
339 public static function onAPIQuerySiteInfoGeneralInfo( ApiQuerySiteInfo $api, array &$data ) {
340 $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
341 $data['citeresponsivereferences'] = $config->get( 'CiteResponsiveReferences' );
342 }
343
344}
static onContentHandlerDefaultModelFor(Title $title, &$model)
Convert the content model of a message that is actually JSON to JSON.
Definition CiteHooks.php:20
static onResourceLoaderGetConfigVars(array &$vars)
Adds extra variables to the global config.
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:42
static onLinksUpdateComplete(LinksUpdate &$linksUpdate)
Callback for LinksUpdateComplete hook If $wgCiteCacheRawReferencesOnParse is set to false,...
static onResourceLoaderRegisterModules(&$resourceLoader)
Conditionally register resource loader modules that depends on the VisualEditor MediaWiki extension.
Definition CiteHooks.php:80
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.
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:2228
either a unescaped string or a HtmlArmor object after in associative array form externallinks $linksUpdate
Definition hooks.txt:2090
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:2818
const CONTENT_MODEL_JSON
Definition Defines.php:249
$cache
Definition mcc.php:33