Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@
"ext.wikioasismagic.simpleBlogPageFix": {
"scripts": [
"ext.wikioasismagic.simpleBlogPageFix.js"
],
"dependencies": [
"ext.oOJSPlus.data"
]
}
},
Expand Down
85 changes: 43 additions & 42 deletions modules/ext.wikioasismagic.simpleBlogPageFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,57 @@
* becomes a safe no-op (the paginator is already set up via its constructor
* in older OOJSPlus versions).
*
* ext.oOJSPlus.data is declared as a static dependency of this module
* (see extension.json), so it is guaranteed to be fully loaded — and
* OOJSPlus globally available — before this script executes. This makes
* the patch synchronous, eliminating the race condition that existed when
* the previous version used mw.loader.using().then().
*
* The PHP hook that injects this module (onBeforePageDisplay) already
* guards injection behind ExtensionRegistry::isLoaded('SimpleBlogPage'),
* which requires OOJSPlus, so the static dependency is always satisfiable
* on wikis where this shim is loaded.
*
* Remove this file once OOJSPlus is updated to a version that natively
* exposes `Paginator.prototype.init`.
*
* ext.oOJSPlus.data is loaded via mw.loader.using() rather than a static
* extension.json dependency: this shim's own module is registered
* unconditionally, but OOJSPlus is only actually installed alongside
* SimpleBlogPage on wikis that use it, so a hard dependency would not
* resolve everywhere this extension is loaded.
*/
( function () {
'use strict';

mw.loader.using( 'ext.oOJSPlus.data' ).then( function () {
// Guard: only patch if OOJSPlus data pagination is present and init() is missing.
if (
typeof OOJSPlus === 'undefined' ||
!OOJSPlus.ui ||
!OOJSPlus.ui.data ||
!OOJSPlus.ui.data.pagination ||
!OOJSPlus.ui.data.pagination.Paginator
) {
return;
}
// Guard: only patch if OOJSPlus data pagination is present and init() is missing.
if (
typeof OOJSPlus === 'undefined' ||
!OOJSPlus.ui ||
!OOJSPlus.ui.data ||
!OOJSPlus.ui.data.pagination ||
!OOJSPlus.ui.data.pagination.Paginator
) {
return;
}

if ( typeof OOJSPlus.ui.data.pagination.Paginator.prototype.init === 'function' ) {
// Already defined in this OOJSPlus version — nothing to do.
return;
}

if ( typeof OOJSPlus.ui.data.pagination.Paginator.prototype.init === 'function' ) {
// Already defined in this OOJSPlus version — nothing to do.
/**
* Initialise the paginator after the first store load.
*
* In newer OOJSPlus versions this method is called explicitly by the
* consuming panel (e.g. BlogList) once the store has resolved its first
* request. In older versions the equivalent setup happens inside the
* constructor, so this shim is a safe no-op that prevents the TypeError.
*/
OOJSPlus.ui.data.pagination.Paginator.prototype.init = function () {
if ( this._wikioasisPaginatorInitialized ) {
return;
}
this._wikioasisPaginatorInitialized = true;

/**
* Initialise the paginator after the first store load.
*
* In newer OOJSPlus versions this method is called explicitly by the
* consuming panel (e.g. BlogList) once the store has resolved its first
* request. In older versions the equivalent setup happens inside the
* constructor, so this shim is a safe no-op that prevents the TypeError.
*/
OOJSPlus.ui.data.pagination.Paginator.prototype.init = function () {
if ( this._wikioasisPaginatorInitialized ) {
return;
}
this._wikioasisPaginatorInitialized = true;

// If a newer-style `update` method exists, call it to sync the
// paginator UI with the store's current state.
if ( typeof this.update === 'function' ) {
this.update();
}
};
}, function () {
// ext.oOJSPlus.data is not registered on this wiki — nothing to patch.
} );
// If a newer-style `update` method exists, call it to sync the
// paginator UI with the store's current state.
if ( typeof this.update === 'function' ) {
this.update();
}
};
}() );
Loading