[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/extensions/TitleBlacklist/modules/ -> mediawiki.api.titleblacklist.js (source)

   1  /**
   2   * @class mw.Api.plugin.titleblacklist
   3   */
   4  ( function ( mw, $ ) {
   5  
   6      $.extend( mw.Api.prototype, {
   7          /**
   8           * Convinience method for `action=titleblacklist`.
   9           *
  10           * @param {mw.Title|string} title
  11           * @param {Function} [ok] Success callback (deprecated)
  12           * @param {Function} [err] Error callback (deprecated)
  13           * @return {jQuery.Promise}
  14           * @return {Function} return.done
  15           * @return {Object|boolean} return.done.result False if title wasn't blacklisted, an object with 'reason', 'line'
  16           *  and 'message' properties if title was blacklisted.
  17           */
  18          isBlacklisted: function ( title, ok, err ) {
  19              var d = $.Deferred();
  20              // Backwards compatibility (< MW 1.20)
  21              d.done( ok );
  22              d.fail( err );
  23  
  24              this.get( {
  25                      action: 'titleblacklist',
  26                      tbaction: 'create',
  27                      tbtitle: title.toString()
  28                  } )
  29                  .done( function ( data ) {
  30                      var result;
  31  
  32                      // this fails open (if nothing valid is returned by the api, allows the title)
  33                      // also fails open when the API is not present, which will be most of the time
  34                      // as this API module is part of the TitleBlacklist extension.
  35                      if ( data.titleblacklist && data.titleblacklist.result && data.titleblacklist.result === 'blacklisted' ) {
  36                          if ( data.titleblacklist.reason ) {
  37                              result = {
  38                                  reason: data.titleblacklist.reason,
  39                                  line: data.titleblacklist.line,
  40                                  message: data.titleblacklist.message
  41                              };
  42                          } else {
  43                              mw.log( 'mw.Api.titleblacklist::isBlacklisted> no reason data for blacklisted title', 'debug' );
  44                              result = {
  45                                  reason: 'Blacklisted, but no reason supplied',
  46                                  line: 'Unknown',
  47                                  message: null
  48                              };
  49                          }
  50                          d.resolve( result );
  51                      } else {
  52                          d.resolve( false );
  53                      }
  54                  } )
  55                  .fail( d.reject );
  56  
  57              return d.promise();
  58          }
  59  
  60      } );
  61  
  62      /**
  63       * @class mw.Api
  64       * @mixins mw.Api.plugin.titleblacklist
  65       */
  66  
  67  }( mediaWiki, jQuery ) );


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1