MediaWiki REL1_34
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 'test.VisualEditor'
60 ],
61 'localBasePath' => dirname( __DIR__ ),
62 'remoteExtPath' => 'Cite',
63 ];
64 }
65 }
66
74 if ( !ExtensionRegistry::getInstance()->isLoaded( 'VisualEditor' ) ) {
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", [
117 'localBasePath' => $dir . 'modules',
118 'remoteExtPath' => 'Cite/modules',
119 "scripts" => [
120 "ve-cite/ve.ui.MWReferenceGroupInputWidget.js",
121 "ve-cite/ve.ui.MWReferenceSearchWidget.js",
122 "ve-cite/ve.ui.MWReferenceResultWidget.js",
123 "ve-cite/ve.ui.MWUseExistingReferenceCommand.js",
124 "ve-cite/ve.ui.MWCitationDialog.js",
125 "ve-cite/ve.ui.MWReferencesListDialog.js",
126 "ve-cite/ve.ui.MWReferenceDialog.js",
127 "ve-cite/ve.ui.MWReferenceDialogTool.js",
128 "ve-cite/ve.ui.MWCitationDialogTool.js",
129 "ve-cite/ve.ui.MWReferenceContextItem.js",
130 "ve-cite/ve.ui.MWReferencesListContextItem.js",
131 "ve-cite/ve.ui.MWCitationContextItem.js",
132 "ve-cite/ve.ui.MWCitationAction.js",
133 "ve-cite/ve.ui.MWReference.init.js",
134 "ve-cite/ve.ui.MWCitationNeededContextItem.js",
135 ],
136 "styles" => [
137 "ve-cite/ve.ui.MWReferenceDialog.css",
138 "ve-cite/ve.ui.MWReferenceContextItem.css",
139 "ve-cite/ve.ui.MWReferenceGroupInputWidget.css",
140 "ve-cite/ve.ui.MWReferenceResultWidget.css",
141 "ve-cite/ve.ui.MWReferenceSearchWidget.css"
142 ],
143 "dependencies" => [
144 "oojs-ui.styles.icons-alerts",
145 "oojs-ui.styles.icons-editing-citation",
146 "oojs-ui.styles.icons-interactions",
147 "ext.cite.visualEditor.core",
148 "ext.cite.visualEditor.data",
149 "ext.cite.style",
150 "ext.cite.styles",
151 "ext.visualEditor.mwtransclusion",
152 "ext.visualEditor.mediawiki"
153 ],
154 "messages" => [
155 "cite-ve-changedesc-ref-group-both",
156 "cite-ve-changedesc-ref-group-from",
157 "cite-ve-changedesc-ref-group-to",
158 "cite-ve-changedesc-reflist-group-both",
159 "cite-ve-changedesc-reflist-group-from",
160 "cite-ve-changedesc-reflist-group-to",
161 "cite-ve-changedesc-reflist-item-id",
162 "cite-ve-changedesc-reflist-responsive-set",
163 "cite-ve-changedesc-reflist-responsive-unset",
164 "cite-ve-citationneeded-button",
165 "cite-ve-citationneeded-description",
166 "cite-ve-citationneeded-title",
167 "cite-ve-dialog-reference-editing-reused",
168 "cite-ve-dialog-reference-editing-reused-long",
169 "cite-ve-dialog-reference-options-group-label",
170 "cite-ve-dialog-reference-options-group-placeholder",
171 "cite-ve-dialog-reference-options-name-label",
172 "cite-ve-dialog-reference-options-responsive-label",
173 "cite-ve-dialog-reference-options-section",
174 "cite-ve-dialog-reference-placeholder",
175 "cite-ve-dialog-reference-title",
176 "cite-ve-dialog-reference-useexisting-tool",
177 "cite-ve-dialog-referenceslist-contextitem-description-general",
178 "cite-ve-dialog-referenceslist-contextitem-description-named",
179 "cite-ve-dialog-referenceslist-title",
180 "cite-ve-dialogbutton-citation-educationpopup-title",
181 "cite-ve-dialogbutton-citation-educationpopup-text",
182 "cite-ve-dialogbutton-reference-full-label",
183 "cite-ve-dialogbutton-reference-tooltip",
184 "cite-ve-dialogbutton-reference-title",
185 "cite-ve-dialogbutton-referenceslist-tooltip",
186 "cite-ve-reference-input-placeholder",
187 "cite-ve-toolbar-group-label",
188 "cite-ve-othergroup-item"
189 ],
190 "targets" => [
191 "desktop",
192 "mobile"
193 ]
194 ] );
195 }
196
204 public static function onLinksUpdate( LinksUpdate $linksUpdate ) {
205 global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
206 if ( !$wgCiteStoreReferencesData ) {
207 return;
208 }
209 $refData = $linksUpdate->getParserOutput()->getExtensionData( Cite::EXT_DATA_KEY );
210 if ( $refData === null ) {
211 return;
212 }
213 if ( $wgCiteCacheRawReferencesOnParse ) {
214 // caching
215 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
216 $articleID = $linksUpdate->getTitle()->getArticleID();
217 $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
218 $cache->set( $key, $refData, Cite::CACHE_DURATION_ONPARSE );
219 }
220 // JSON encode
221 $ppValue = FormatJson::encode( $refData, false, FormatJson::ALL_OK );
222 // GZIP encode references data at maximum compression
223 $ppValue = gzencode( $ppValue, 9 );
224 // split the string in smaller parts that can fit into a db blob
225 $ppValues = str_split( $ppValue, Cite::MAX_STORAGE_LENGTH );
226 foreach ( $ppValues as $num => $ppValue ) {
227 $key = 'references-' . intval( $num + 1 );
228 $linksUpdate->mProperties[$key] = $ppValue;
229 }
230 $linksUpdate->getParserOutput()->setExtensionData( Cite::EXT_DATA_KEY, null );
231 }
232
240 public static function onLinksUpdateComplete( LinksUpdate $linksUpdate ) {
241 global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
242 if ( !$wgCiteStoreReferencesData || $wgCiteCacheRawReferencesOnParse ) {
243 return;
244 }
245 // if we can, avoid clearing the cache when references were not changed
246 if ( method_exists( $linksUpdate, 'getAddedProperties' )
247 && method_exists( $linksUpdate, 'getRemovedProperties' )
248 ) {
249 $addedProps = $linksUpdate->getAddedProperties();
250 $removedProps = $linksUpdate->getRemovedProperties();
251 if ( !isset( $addedProps['references-1'] )
252 && !isset( $removedProps['references-1'] )
253 ) {
254 return;
255 }
256 }
257 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
258 $articleID = $linksUpdate->getTitle()->getArticleID();
259 $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
260 // delete with reduced hold off period (LinksUpdate uses a master connection)
261 $cache->delete( $key, WANObjectCache::MAX_COMMIT_DELAY );
262 }
263
268 public static function onResourceLoaderGetConfigVars( array &$vars ) {
269 $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
270 $vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' );
271 $vars['wgCiteResponsiveReferences'] = $config->get( 'CiteResponsiveReferences' );
272 }
273
282 public static function onAPIQuerySiteInfoGeneralInfo( ApiQuerySiteInfo $api, array &$data ) {
283 $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'cite' );
284 $data['citeresponsivereferences'] = $config->get( 'CiteResponsiveReferences' );
285 }
286
287}
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:45
const MAX_STORAGE_LENGTH
Maximum storage capacity for pp_value field of page_props table.
Definition Cite.php:40
const CACHE_DURATION_ONPARSE
Cache duration set when parsing a page with references.
Definition Cite.php:55
Class the manages updates of *_link tables as well as similar extension-managed tables.
getTitle()
Return the title object of the page being updated.
getAddedProperties()
Fetch page properties added by this LinksUpdate.
getParserOutput()
Returns parser output.
getRemovedProperties()
Fetch page properties removed by this LinksUpdate.
MediaWikiServices is the service locator for the application scope of MediaWiki.
ResourceLoader is a loading system for JavaScript and CSS resources.
Represents a title within MediaWiki.
Definition Title.php:42
const NS_MEDIAWIKI
Definition Defines.php:77
const CONTENT_MODEL_JSON
Definition Defines.php:228
$resourceLoader
Definition load.php:44
$cache
Definition mcc.php:33