Пример #1
0
 /**
  * Sets up parser functions
  *
  * @since 2.0
  */
 public static function init(Parser &$parser)
 {
     global $egArraysCompatibilityMode;
     /*
      * store for arrays per Parser object. This will solve several bugs related to
      * 'ParserClearState' hook clearing all variables early in combination with certain
      * other extensions. (since v2.0)
      */
     $parser->mExtArrays = new self();
     // initialize default separator for '#arrayprint'
     if ($egArraysCompatibilityMode) {
         // COMPATIBILITY-MODE
         self::$mDefaultSep = ', ';
     } else {
         // since 2.0 the default separator for arrayprint is set to the languages default
         global $wgLang;
         $wgLang->getMessageFromDB('comma-separator');
         self::$mDefaultSep = $wgLang->getMessageFromDB('comma-separator');
     }
     // SFH_OBJECT_ARGS available since MW 1.12
     self::initFunction($parser, 'arraydefine');
     self::initFunction($parser, 'arrayprint', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arrayindex', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arraysize');
     self::initFunction($parser, 'arraysearch', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arraysearcharray', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arrayslice');
     self::initFunction($parser, 'arrayreset', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arrayunique');
     self::initFunction($parser, 'arraysort');
     self::initFunction($parser, 'arraymerge', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arrayunion', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arraydiff', SFH_OBJECT_ARGS);
     self::initFunction($parser, 'arrayintersect', SFH_OBJECT_ARGS);
     return true;
 }
Пример #2
0
 /**
  * Helper function to create a new Array within 'Arrays' extension. Takes care of different versions
  * as well as the old 'ArrayExtension'.
  */
 protected function createArray($array)
 {
     global $wgArrayExtension;
     $arrayId = $this->mArrayName;
     if (defined('ExtArrays::VERSION')) {
         // 'Arrays' extension 2+
         global $wgParser;
         /** ToDo: is there a way to get the actual parser which has started the query? */
         ExtArrays::get($wgParser)->createArray($arrayId, $array);
         return true;
     }
     // compatbility to 'ArrayExtension' extension before 2.0:
     if (!isset($wgArrayExtension)) {
         //Hash extension is not installed in this wiki
         return false;
     }
     $version = null;
     if (defined('ArrayExtension::VERSION')) {
         $version = ArrayExtension::VERSION;
     } elseif (defined('ExtArrayExtension::VERSION')) {
         $version = ExtArrayExtension::VERSION;
     }
     if ($version !== null && version_compare($version, '1.3.2', '>=')) {
         // ArrayExtension 1.3.2+
         $wgArrayExtension->createArray($arrayId, $array);
     } else {
         // dirty way
         $wgArrayExtension->mArrays[trim($arrayId)] = $array;
     }
     return true;
 }
Пример #3
0
 /**
  * Sends an array to ArrayExtension and stores it. Takes care of different ArrayExtension versions.
  * The array should be sanitized in case ArrayExtension before 2.0 is being used.
  * 
  * @since 1.0
  * 
  * @return boolean whether array was sent to ArrayExtension successful
  */
 protected static function setArrayExtensionArray($parser, $arrayId, $array = array())
 {
     if (class_exists('ExtArrays')) {
         // ArrayExtension 2.0+
         ExtArrays::get($parser)->createArray($arrayId, $array);
         return true;
     } elseif (isset($wgArrayExtension) && isset($wgArrayExtension->mArrayExtension)) {
         // ArrayExtension before 2.0
         if (array_key_exists($arrayId, $wgArrayExtension->mArrayExtension)) {
             // array exist
             $array = $wgArrayExtension->mArrayExtension[$arrayId];
         } else {
             $array = array();
         }
     }
     return false;
 }