MediaWiki  1.29.2
CiteHooks.php
Go to the documentation of this file.
1 <?php
11 class CiteHooks {
21  public static function onContentHandlerDefaultModelFor( Title $title, &$model ) {
22  if (
23  $title->inNamespace( NS_MEDIAWIKI ) &&
24  (
25  $title->getText() == 'Visualeditor-cite-tool-definition.json' ||
26  $title->getText() == 'Cite-tool-definition.json'
27  )
28  ) {
29  $model = CONTENT_MODEL_JSON;
30  }
31 
32  return true;
33  }
34 
43  public static function onResourceLoaderTestModules(
44  array &$testModules,
45  ResourceLoader &$resourceLoader
46  ) {
47  $resourceModules = $resourceLoader->getConfig()->get( 'ResourceModules' );
48 
49  if (
50  isset( $resourceModules[ 'ext.visualEditor.mediawiki' ] ) ||
51  $resourceLoader->isModuleRegistered( 'ext.visualEditor.mediawiki' )
52  ) {
53  $testModules['qunit']['ext.cite.visualEditor.test'] = [
54  'scripts' => [
55  'modules/ve-cite/tests/ve.dm.citeExample.js',
56  'modules/ve-cite/tests/ve.dm.Converter.test.js',
57  'modules/ve-cite/tests/ve.dm.InternalList.test.js',
58  'modules/ve-cite/tests/ve.dm.Transaction.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 
80  public static function onResourceLoaderRegisterModules( &$resourceLoader ) {
81 
82  if ( ! class_exists( 'VisualEditorHooks' ) ) {
83  return true;
84  }
85 
86  $dir = dirname( __DIR__ ) . DIRECTORY_SEPARATOR;
87 
88  $resourceLoader->register( "ext.cite.visualEditor.core", [
89  'localBasePath' => $dir . 'modules',
90  'remoteExtPath' => 'Cite/modules',
91  "scripts" => [
92  "ve-cite/ve.dm.MWReferenceModel.js",
93  "ve-cite/ve.dm.MWReferencesListNode.js",
94  "ve-cite/ve.dm.MWReferenceNode.js",
95  "ve-cite/ve.ce.MWReferencesListNode.js",
96  "ve-cite/ve.ce.MWReferenceNode.js",
97  "ve-cite/ve.ui.MWReferencesListCommand.js"
98  ],
99  "styles" => [
100  "ve-cite/ve.ce.MWReferencesListNode.css",
101  "ve-cite/ve.ce.MWReferenceNode.css"
102  ],
103  "dependencies" => [
104  "ext.visualEditor.mwcore"
105  ],
106  "messages" => [
107  "cite-ve-referenceslist-isempty",
108  "cite-ve-referenceslist-isempty-default",
109  "cite-ve-referenceslist-missingref"
110  ],
111  "targets" => [
112  "desktop",
113  "mobile"
114  ]
115  ] );
116 
117  $resourceLoader->register( "ext.cite.visualEditor.data",
118  [ "class" => "CiteDataModule" ] );
119 
120  $resourceLoader->register( "ext.cite.visualEditor", [
121  'localBasePath' => $dir . 'modules',
122  'remoteExtPath' => 'Cite/modules',
123  "scripts" => [
124  "ve-cite/ve.ui.MWReferenceGroupInputWidget.js",
125  "ve-cite/ve.ui.MWReferenceSearchWidget.js",
126  "ve-cite/ve.ui.MWReferenceResultWidget.js",
127  "ve-cite/ve.ui.MWUseExistingReferenceCommand.js",
128  "ve-cite/ve.ui.MWCitationDialog.js",
129  "ve-cite/ve.ui.MWReferencesListDialog.js",
130  "ve-cite/ve.ui.MWReferenceDialog.js",
131  "ve-cite/ve.ui.MWReferenceDialogTool.js",
132  "ve-cite/ve.ui.MWCitationDialogTool.js",
133  "ve-cite/ve.ui.MWReferenceContextItem.js",
134  "ve-cite/ve.ui.MWReferencesListContextItem.js",
135  "ve-cite/ve.ui.MWCitationContextItem.js",
136  "ve-cite/ve.ui.MWCitationAction.js",
137  "ve-cite/ve.ui.MWReference.init.js"
138  ],
139  "styles" => [
140  "ve-cite/ve.ui.MWReferenceContextItem.css",
141  "ve-cite/ve.ui.MWReferenceGroupInputWidget.css",
142  "ve-cite/ve.ui.MWReferenceIcons.css",
143  "ve-cite/ve.ui.MWReferenceResultWidget.css",
144  "ve-cite/ve.ui.MWReferenceSearchWidget.css"
145  ],
146  "dependencies" => [
147  "ext.cite.visualEditor.core",
148  "ext.cite.visualEditor.data",
149  "ext.cite.style",
150  "ext.visualEditor.mwtransclusion",
151  "ext.visualEditor.mediawiki"
152  ],
153  "messages" => [
154  "cite-ve-dialog-reference-editing-reused",
155  "cite-ve-dialog-reference-options-group-label",
156  "cite-ve-dialog-reference-options-group-placeholder",
157  "cite-ve-dialog-reference-options-name-label",
158  "cite-ve-dialog-reference-options-section",
159  "cite-ve-dialog-reference-title",
160  "cite-ve-dialog-reference-useexisting-full-label",
161  "cite-ve-dialog-reference-useexisting-label",
162  "cite-ve-dialog-reference-useexisting-tool",
163  "cite-ve-dialog-referenceslist-contextitem-description-general",
164  "cite-ve-dialog-referenceslist-contextitem-description-named",
165  "cite-ve-dialog-referenceslist-title",
166  "cite-ve-dialogbutton-citation-educationpopup-title",
167  "cite-ve-dialogbutton-citation-educationpopup-text",
168  "cite-ve-dialogbutton-reference-full-label",
169  "cite-ve-dialogbutton-reference-tooltip",
170  "cite-ve-dialogbutton-reference-title",
171  "cite-ve-dialogbutton-referenceslist-tooltip",
172  "cite-ve-reference-input-placeholder",
173  "cite-ve-toolbar-group-label",
174  "cite-ve-othergroup-item"
175  ],
176  "targets" => [
177  "desktop",
178  "mobile"
179  ]
180  ] );
181  return true;
182  }
183 
191  public static function onLinksUpdate( LinksUpdate &$linksUpdate ) {
192  global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
193  if ( !$wgCiteStoreReferencesData ) {
194  return;
195  }
196  $refData = $linksUpdate->getParserOutput()->getExtensionData( Cite::EXT_DATA_KEY );
197  if ( $refData === null ) {
198  return;
199  }
200  if ( $wgCiteCacheRawReferencesOnParse ) {
201  // caching
203  $articleID = $linksUpdate->getTitle()->getArticleID();
204  $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
205  $cache->set( $key, $refData, Cite::CACHE_DURATION_ONPARSE );
206  }
207  // JSON encode
208  $ppValue = FormatJson::encode( $refData, false, FormatJson::ALL_OK );
209  // GZIP encode references data at maximum compression
210  $ppValue = gzencode( $ppValue, 9 );
211  // split the string in smaller parts that can fit into a db blob
212  $ppValues = str_split( $ppValue, Cite::MAX_STORAGE_LENGTH );
213  foreach ( $ppValues as $num => $ppValue ) {
214  $key = 'references-' . intval( $num + 1 );
215  $linksUpdate->mProperties[$key] = $ppValue;
216  }
217  $linksUpdate->getParserOutput()->setExtensionData( Cite::EXT_DATA_KEY, null );
218  }
219 
227  public static function onLinksUpdateComplete( LinksUpdate &$linksUpdate ) {
228  global $wgCiteStoreReferencesData, $wgCiteCacheRawReferencesOnParse;
229  if ( !$wgCiteStoreReferencesData || $wgCiteCacheRawReferencesOnParse ) {
230  return;
231  }
232  // if we can, avoid clearing the cache when references were not changed
233  if ( method_exists( $linksUpdate, 'getAddedProperties' )
234  && method_exists( $linksUpdate, 'getRemovedProperties' )
235  ) {
236  $addedProps = $linksUpdate->getAddedProperties();
237  $removedProps = $linksUpdate->getRemovedProperties();
238  if ( !isset( $addedProps['references-1'] )
239  && !isset( $removedProps['references-1'] )
240  ) {
241  return;
242  }
243  }
245  $articleID = $linksUpdate->getTitle()->getArticleID();
246  $key = $cache->makeKey( Cite::EXT_DATA_KEY, $articleID );
247  // delete with reduced hold off period (LinksUpdate uses a master connection)
248  $cache->delete( $key, WANObjectCache::MAX_COMMIT_DELAY );
249  }
250 
254  public static function onResourceLoaderGetConfigVars( array &$vars ) {
255  $config = ConfigFactory::getDefaultInstance()->makeConfig( 'cite' );
256  $vars['wgCiteVisualEditorOtherGroup'] = $config->get( 'CiteVisualEditorOtherGroup' );
257  return true;
258  }
259 }
CONTENT_MODEL_JSON
const CONTENT_MODEL_JSON
Definition: Defines.php:237
ContextSource\getConfig
getConfig()
Get the Config object.
Definition: ContextSource.php:68
CiteHooks\onLinksUpdate
static onLinksUpdate(LinksUpdate &$linksUpdate)
Callback for LinksUpdate hook Post-output processing of references property, for proper db storage De...
Definition: CiteHooks.php:191
WANObjectCache\MAX_COMMIT_DELAY
const MAX_COMMIT_DELAY
Max time expected to pass between delete() and DB commit finishing.
Definition: WANObjectCache.php:102
LinksUpdate
Class the manages updates of *_link tables as well as similar extension-managed tables.
Definition: LinksUpdate.php:34
FormatJson\ALL_OK
const ALL_OK
Skip escaping as many characters as reasonably possible.
Definition: FormatJson.php:55
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
FormatJson\encode
static encode( $value, $pretty=false, $escaping=0)
Returns the JSON representation of a value.
Definition: FormatJson.php:127
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
CiteHooks\onContentHandlerDefaultModelFor
static onContentHandlerDefaultModelFor(Title $title, &$model)
Convert the content model of a message that is actually JSON to JSON.
Definition: CiteHooks.php:21
ConfigFactory\getDefaultInstance
static getDefaultInstance()
Definition: ConfigFactory.php:51
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$vars
static configuration should be added through ResourceLoaderGetConfigVars instead & $vars
Definition: hooks.txt:2179
CiteHooks\onResourceLoaderGetConfigVars
static onResourceLoaderGetConfigVars(array &$vars)
Adds extra variables to the global config.
Definition: CiteHooks.php:254
$dir
$dir
Definition: Autoload.php:8
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:43
$linksUpdate
either a unescaped string or a HtmlArmor object after in associative array form externallinks $linksUpdate
Definition: hooks.txt:2025
$resourceLoader
error also a ContextSource 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:2612
Title
Represents a title within MediaWiki.
Definition: Title.php:39
$cache
$cache
Definition: mcc.php:33
ObjectCache\getMainWANInstance
static getMainWANInstance()
Get the main WAN cache object.
Definition: ObjectCache.php:370
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:70
CiteHooks
Definition: CiteHooks.php:11
CiteHooks\onResourceLoaderRegisterModules
static onResourceLoaderRegisterModules(&$resourceLoader)
Conditionally register resource loader modules that depends on the VisualEditor MediaWiki extension.
Definition: CiteHooks.php:80
CiteHooks\onLinksUpdateComplete
static onLinksUpdateComplete(LinksUpdate &$linksUpdate)
Callback for LinksUpdateComplete hook If $wgCiteCacheRawReferencesOnParse is set to false,...
Definition: CiteHooks.php:227
array
the array() calling protocol came about after MediaWiki 1.4rc1.