|
| 1 | +import { User } from "./user"; |
| 2 | + |
1 | 3 | /**
|
2 |
| - * Registry and firing of events. |
| 4 | + * An instance of a hook, created via {@link mw.hook mw.hook method}. |
3 | 5 | *
|
4 | 6 | * MediaWiki has various interface components that are extended, enhanced
|
5 | 7 | * or manipulated in some other way by extensions, gadgets and even
|
|
43 | 45 | */
|
44 | 46 | interface Hook<T extends any[] = any[]> {
|
45 | 47 | /**
|
46 |
| - * Register a hook handler |
| 48 | + * Register a hook handler. |
47 | 49 | *
|
48 | 50 | * @param {...Function} handler Function to bind.
|
49 | 51 | * @chainable
|
50 | 52 | */
|
51 | 53 | add(...handler: Array<(...data: T) => any>): this;
|
52 | 54 |
|
53 | 55 | /**
|
54 |
| - * Run a hook. |
| 56 | + * Call hook handlers with data. |
55 | 57 | *
|
56 | 58 | * @param {*} data
|
57 | 59 | * @chainable
|
58 | 60 | */
|
59 | 61 | fire(...data: T): this;
|
60 | 62 |
|
61 | 63 | /**
|
62 |
| - * Unregister a hook handler |
| 64 | + * Unregister a hook handler. |
63 | 65 | *
|
64 | 66 | * @param {...Function} handler Function to unbind.
|
65 | 67 | * @chainable
|
66 | 68 | */
|
67 | 69 | remove(...handler: Array<(...data: T) => any>): this;
|
68 | 70 | }
|
69 | 71 |
|
| 72 | +interface PostEditData { |
| 73 | + /** |
| 74 | + * Message that listeners should use when displaying notifications. |
| 75 | + * String for plain text, use array or jQuery object to pass actual nodes. |
| 76 | + */ |
| 77 | + message?: string | JQuery | HTMLElement[]; |
| 78 | + /** |
| 79 | + * User that made the edit. |
| 80 | + */ |
| 81 | + user?: string | User; |
| 82 | + /** |
| 83 | + * Whether a temporary user account was created. |
| 84 | + */ |
| 85 | + tempUserCreated?: boolean; |
| 86 | +} |
| 87 | + |
| 88 | +interface SearchIndex { |
| 89 | + [k: string]: SearchIndexEntry[]; |
| 90 | +} |
| 91 | + |
| 92 | +interface SearchIndexEntry { |
| 93 | + $highlight: JQuery; |
| 94 | + $field: JQuery; |
| 95 | + $wrapper: JQuery; |
| 96 | + $tabPanel: JQuery; |
| 97 | +} |
| 98 | + |
| 99 | +interface EditRecovery { |
| 100 | + fieldChangeHandler(): void; |
| 101 | +} |
| 102 | + |
70 | 103 | declare global {
|
71 | 104 | namespace mw {
|
72 | 105 | /**
|
73 | 106 | * Create an instance of mw.hook.
|
74 | 107 | *
|
75 |
| - * @method hook |
76 |
| - * @member mw |
77 | 108 | * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook
|
78 | 109 | */
|
79 |
| - function hook<T extends any[] = any[]>(event: string): Hook<T>; |
| 110 | + function hook( |
| 111 | + event: "apisandbox.formatRequest" |
| 112 | + ): Hook< |
| 113 | + [ |
| 114 | + items: OO.ui.MenuOptionWidget[], |
| 115 | + displayParams: object, |
| 116 | + rawParams: object, |
| 117 | + method: string, |
| 118 | + ajaxOptions: JQuery.AjaxSettings |
| 119 | + ] |
| 120 | + >; |
| 121 | + |
| 122 | + /** |
| 123 | + * Create an instance of mw.hook, fired after EditRecovery has loaded any recovery data, added event handlers, etc. |
| 124 | + * |
| 125 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 126 | + */ |
| 127 | + function hook(event: "editRecovery.loadEnd"): Hook<[editRecovery: EditRecovery]>; |
| 128 | + |
| 129 | + /** |
| 130 | + * Create an instance of mw.hook. |
| 131 | + * |
| 132 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 133 | + */ |
| 134 | + function hook(event: "htmlform.enhance"): Hook<[$root: JQuery]>; |
| 135 | + |
| 136 | + /** |
| 137 | + * Create an instance of mw.hook, fired after an edit was successfully saved. |
| 138 | + * |
| 139 | + * Does not fire for null edits. |
| 140 | + * |
| 141 | + * Code that fires the postEdit hook should first set `wgRevisionId` and `wgCurRevisionId` to the revision associated with the edit that triggered the postEdit hook, then fire the postEdit hook, e.g.: |
| 142 | + * |
| 143 | + * ``` |
| 144 | + * mw.config.set( { |
| 145 | + * wgCurRevisionId: data.newrevid, |
| 146 | + * wgRevisionId: data.newrevid |
| 147 | + * } ); |
| 148 | + * // Now fire the hook. |
| 149 | + * mw.hook( 'postEdit' ).fire(); |
| 150 | + * ``` |
| 151 | + * |
| 152 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 153 | + */ |
| 154 | + function hook(event: "postEdit"): Hook<[data?: PostEditData]>; |
| 155 | + |
| 156 | + /** |
| 157 | + * Create an instance of mw.hook, fired after the listener for #postEdit removes the notification. |
| 158 | + * |
| 159 | + * @deprecated |
| 160 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 161 | + */ |
| 162 | + function hook(event: "postEdit.afterRemoval"): Hook<[]>; |
| 163 | + |
| 164 | + /** |
| 165 | + * Create an instance of mw.hook. |
| 166 | + * |
| 167 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 168 | + */ |
| 169 | + function hook(event: "prefs.search.buildIndex"): Hook<[index: SearchIndex]>; |
| 170 | + |
| 171 | + /** |
| 172 | + * Create an instance of mw.hook, fired when a trusted UI element to perform a logout has been activated. |
| 173 | + * |
| 174 | + * This will end the user session, and either redirect to the given URL on success, or queue an error message via mw.notification. |
| 175 | + * |
| 176 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 177 | + */ |
| 178 | + function hook(event: "skin.logout"): Hook<[href: string]>; |
| 179 | + |
| 180 | + /** |
| 181 | + * Create an instance of mw.hook, fired when initialization of the filtering interface for changes list is complete. |
| 182 | + * |
| 183 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 184 | + */ |
| 185 | + function hook(event: "structuredChangeFilters.ui.initialized"): Hook<[]>; |
| 186 | + |
| 187 | + /** |
| 188 | + * Create an instance of mw.hook, fired when a portlet is successfully created. |
| 189 | + * |
| 190 | + * Example usage: |
| 191 | + * |
| 192 | + * ``` |
| 193 | + * mw.hook( 'util.addPortlet' ).add( ( p ) => { |
| 194 | + * p.style.border = 'solid 1px black'; |
| 195 | + * } ); |
| 196 | + * ``` |
| 197 | + * |
| 198 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 199 | + */ |
| 200 | + function hook( |
| 201 | + event: "util.addPortlet" |
| 202 | + ): Hook<[portlet: HTMLElement, before: string | undefined]>; |
| 203 | + |
| 204 | + /** |
| 205 | + * Create an instance of mw.hook, fired when a portlet link is successfully created. |
| 206 | + * |
| 207 | + * Example usage: |
| 208 | + * |
| 209 | + * ``` |
| 210 | + * mw.hook( 'util.addPortletLink' ).add( ( link ) => { |
| 211 | + * const span = $( '<span class="icon">' ); |
| 212 | + * link.appendChild( span ); |
| 213 | + * } ); |
| 214 | + * ``` |
| 215 | + * |
| 216 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 217 | + */ |
| 218 | + function hook(event: "util.addPortletLink"): Hook<[item: HTMLLIElement, data: object]>; |
| 219 | + |
| 220 | + /** |
| 221 | + * Create an instance of mw.hook, fired when categories are being added to the DOM. |
| 222 | + * |
| 223 | + * It is encouraged to fire it before the main DOM is changed (when $content is still detached). However, this order is not defined either way, so you should only rely on $content itself. |
| 224 | + * |
| 225 | + * This includes the ready event on a page load (including post-edit loads) and when content has been previewed with LivePreview. |
| 226 | + * |
| 227 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 228 | + */ |
| 229 | + function hook(event: "wikipage.categories"): Hook<[$content: JQuery]>; |
| 230 | + |
| 231 | + /** |
| 232 | + * Create an instance of mw.hook, fired after collapsible content has been initialized. |
| 233 | + * |
| 234 | + * This gives an option to modify the collapsible behavior. |
| 235 | + * |
| 236 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 237 | + */ |
| 238 | + function hook(event: "wikipage.collapsibleContent"): Hook<[$collapsible: JQuery]>; |
| 239 | + |
| 240 | + /** |
| 241 | + * Create an instance of mw.hook, fired when wiki content has been added to the DOM. |
| 242 | + * |
| 243 | + * This should only be fired after $content has been attached. |
| 244 | + * |
| 245 | + * This includes the ready event on a page load (including post-edit loads) and when content has been previewed with LivePreview. |
| 246 | + * |
| 247 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 248 | + */ |
| 249 | + function hook(event: "wikipage.content"): Hook<[$content: JQuery]>; |
| 250 | + |
| 251 | + /** |
| 252 | + * Create an instance of mw.hook, fired when a diff is added to a page or dynamically displayed to the user. |
| 253 | + * |
| 254 | + * Similar to the wikipage.content hook, `$diff` may still be detached when the hook is fired. |
| 255 | + * |
| 256 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 257 | + */ |
| 258 | + function hook(event: "wikipage.diff"): Hook<[$table: JQuery<HTMLTableElement>]>; |
| 259 | + |
| 260 | + /** |
| 261 | + * Create an instance of mw.hook. |
| 262 | + * |
| 263 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 264 | + */ |
| 265 | + function hook( |
| 266 | + event: "wikipage.diff.diffTypeSwitch" |
| 267 | + ): Hook<[inlineToggleSwitch: OO.ui.ToggleSwitchWidget]>; |
| 268 | + |
| 269 | + /** |
| 270 | + * Create an instance of mw.hook. |
| 271 | + * |
| 272 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 273 | + */ |
| 274 | + function hook(event: "wikipage.diff.wikitextBodyUpdate"): Hook<[$wikitextDiffBody: JQuery]>; |
| 275 | + |
| 276 | + /** |
| 277 | + * Create an instance of mw.hook, fired when the editform is added to the edit page. |
| 278 | + * |
| 279 | + * Similar to the wikipage.content hoo $editForm can still be detached when this hook is fired. |
| 280 | + * |
| 281 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 282 | + */ |
| 283 | + function hook(event: "wikipage.editform"): Hook<[$editForm: JQuery]>; |
| 284 | + |
| 285 | + /** |
| 286 | + * Create an instance of mw.hook, fired when a page's {@link https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Page_status_indicators status indicators} are being added to the DOM or updated. |
| 287 | + * |
| 288 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 289 | + */ |
| 290 | + function hook(event: "wikipage.indicators"): Hook<[$indicators: JQuery]>; |
| 291 | + |
| 292 | + /** |
| 293 | + * Create an instance of mw.hook, fired when dynamic changes have been made to the table of contents. |
| 294 | + * |
| 295 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 296 | + */ |
| 297 | + function hook(event: "wikipage.tableOfContents"): Hook<[sections: any[]]>; |
| 298 | + |
| 299 | + /** |
| 300 | + * Create an instance of mw.hook, fired when the page watch status has changed. |
| 301 | + * |
| 302 | + * Example usage: |
| 303 | + * ``` |
| 304 | + * mw.hook( 'wikipage.watchlistChange' ).add( ( isWatched, expiry, expirySelected ) => { |
| 305 | + * // Do things |
| 306 | + * } ); |
| 307 | + * ``` |
| 308 | + * |
| 309 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 310 | + */ |
| 311 | + function hook( |
| 312 | + event: "wikipage.watchlistChange" |
| 313 | + ): Hook<[isWatched: boolean, expiry: string, expirySelected: string]>; |
| 314 | + |
| 315 | + /** |
| 316 | + * Create an instance of mw.hook. |
| 317 | + * |
| 318 | + * @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.hook |
| 319 | + */ |
| 320 | + function hook<T extends any[] = any[]>(name: string): Hook<T>; |
80 | 321 | }
|
81 | 322 | }
|
82 | 323 |
|
|
0 commit comments