Nischayn22 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53565
Change subject: Make Title.exists() call the api
......................................................................
Make Title.exists() call the api
Cleanup and api call implementation
Change-Id: I76263cdcafaccab50df52e31271d1fc4398887f8
---
M resources/mediawiki/mediawiki.Title.js
1 file changed, 25 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/65/53565/1
diff --git a/resources/mediawiki/mediawiki.Title.js
b/resources/mediawiki/mediawiki.Title.js
index b86a14b..ffda713 100644
--- a/resources/mediawiki/mediawiki.Title.js
+++ b/resources/mediawiki/mediawiki.Title.js
@@ -186,16 +186,31 @@
* @return {Mixed} Boolean true/false if the information is available.
Otherwise null.
*/
Title.exists = function ( title ) {
- var type = $.type( title ), obj = Title.exist.pages, match;
- if ( type === 'string' ) {
- match = obj[title];
- } else if ( type === 'object' && title instanceof Title ) {
- match = obj[title.toString()];
+ var pageName;
+ if ( typeof title === 'string' ) {
+ pageName = title;
+ } else if ( typeof title === 'object' && title instanceof Title
) {
+ pageName = title.toString();
} else {
throw new Error( 'mw.Title.exists: title must be a
string or an instance of Title' );
}
- if ( typeof match === 'boolean' ) {
- return match;
+
+ if ( !$.inArray( pageName, Title.exist.pages ) ) {
+ var api = new mw.Api( { async:true } );
+ api.get( {
+ action: 'query',
+ titles: pageName
+ } ).done( function ( data ) {
+ if ( $.inArray( -1, data.query.pages ) ) {
+ Title.exist.set( pageName, false );
+ } else {
+ Title.exist.set( pageName, true );
+ }
+ } );
+ }
+
+ if ( typeof Title.exist.pages[pageName] === 'boolean' ) {
+ return Title.exist.pages[pageName];
}
return null;
};
@@ -226,10 +241,9 @@
set: function ( titles, state ) {
titles = $.isArray( titles ) ? titles : [titles];
state = state === undefined ? true : !!state;
- var pages = this.pages, i, len = titles.length;
- for ( i = 0; i < len; i++ ) {
- pages[ titles[i] ] = state;
- }
+ $.each( titles, function ( index, value ) {
+ this.pages[ value ] = state;
+ } );
return true;
}
};
--
To view, visit https://gerrit.wikimedia.org/r/53565
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I76263cdcafaccab50df52e31271d1fc4398887f8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Nischayn22 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits