Инструменты пользователя

Инструменты сайта


wiki:devel:syntax_plugin_skeleton

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

wiki:devel:syntax_plugin_skeleton [2024/08/26 08:54] – создано vladpolskiywiki:devel:syntax_plugin_skeleton [2025/01/09 13:05] (текущий) vladpolskiy
Строка 4: Строка 4:
 <?php <?php
 /** /**
- Plugin Skeleton: Displays "Hello World!"+ Плагин Skeleton: отображает «Hello World!»
  *  *
- Syntax: <TEST> - will be replaced with "Hello World!" + Синтаксис: <TEST> — будет заменен на «Hello World!» 
- *  + * 
- * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 
- * @author     Christopher Smith <chris@jalakai.co.uk>+ * @автор Кристофер Смит <chris@jalakai.co.uk>
  */  */
- +  
-if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); + 
-if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +
-require_once(DOKU_PLUGIN.'syntax.php'); +
 /** /**
- All DokuWiki plugins to extend the parser/rendering mechanism + Все плагины DokuWiki для расширения механизма парсера/рендеринга 
- need to inherit from this class + необходимо унаследовать от этого класса 
- */+ */ 
 class syntax_plugin_test extends DokuWiki_Syntax_Plugin { class syntax_plugin_test extends DokuWiki_Syntax_Plugin {
  
-   /** +   
-    * Get an associative array with plugin info. +
-    * +
-    * <p> +
-    * The returned array holds the following fields: +
-    * <dl> +
-    * <dt>author</dt><dd>Author of the plugin</dd> +
-    * <dt>email</dt><dd>Email address to contact the author</dd> +
-    * <dt>date</dt><dd>Last modified date of the plugin in +
-    * <tt>YYYY-MM-DD</tt> format</dd> +
-    * <dt>name</dt><dd>Name of the plugin</dd> +
-    * <dt>desc</dt><dd>Short description of the plugin (Text only)</dd> +
-    * <dt>url</dt><dd>Website with more information on the plugin +
-    * (eg. syntax description)</dd> +
-    * </dl> +
-    * @param none +
-    * @return Array Information about this plugin class. +
-    * @public +
-    * @static +
-    */ +
-    function getInfo(){ +
-        return array( +
-            'author' => 'me', +
-            'email'  => 'me@somewhere.com', +
-            'date'   => '20yy-mm-dd', +
-            'name'   => 'Test Plugin', +
-            'desc'   => 'Testing 1, 2, 3...', +
-            'url'    => 'http://www.dokuwiki.org/plugin:test', +
-        ); +
-    }+
  
    /**    /**
-    * Get the type of syntax this plugin defines.+    * Получите тип синтаксиса, который определяет этот плагин.
     *     *
-    * @param none +    * @параметр нет 
-    * @return String <tt>'substition'</tt> (i.e. 'substitution'). +    * @return String <tt>'substition'</tt> (те. 'подстановка'). 
-    * @public +    * @общественность 
-    * @static +    * @статичный 
-    */+    */ 
     function getType(){     function getType(){
         return 'substition';         return 'substition';
Строка 66: Строка 34:
   
     /**     /**
-     What kind of syntax do we allow (optional+     Какой синтаксис мы допускаем (необязательно
-     */+     */ 
 //    function getAllowedTypes() { //    function getAllowedTypes() {
 //        return array(); //        return array();
Строка 73: Строка 41:
        
    /**    /**
-    * Define how this plugin is handled regarding paragraphs.+    * Определите, как этот плагин обрабатывается в отношении абзацев.
     *     *
-    * <p+    * <р
-    * This method is important for correct XHTML nestingIt returns +    * Этот метод важен для правильного вложения XHTML. Он возвращает 
-    * one of the following values+    * одно из следующих значений
-    * </p+    * </р
-    * <dl+    * <дл
-    * <dt>normal</dt><dd>The plugin can be used inside paragraphs.</dd> +    * <dt>normal</dt><dd>Плагин можно использовать внутри абзацев.</dd> 
-    * <dt>block</dt><dd>Open paragraphs need to be closed before +    * <dt>блок</dt><dd>Открытые абзацы необходимо закрыть перед 
-    * plugin output.</dd> +    * вывод плагина.</dd> 
-    * <dt>stack</dt><dd>Special casePlugin wraps other paragraphs.</dd>+    * <dt>стек</dt><dd>Особый случайплагин оборачивает другие абзацы.</dd>
     * </dl>     * </dl>
-    * @param none +    * @параметр нет 
-    * @return String <tt>'block'</tt>+    * @return String <tt>'блок'</tt>
-    * @public +    * @общественность 
-    * @static +    * @статичный 
-    */+    */ 
 //    function getPType(){ //    function getPType(){
 //        return 'normal'; //        return 'normal';
 //    } //    }
  
-   /** +   /**  
-    * Where to sort in+    * Где сортировать?  
-    * +    *  
-    * @param none +    * @param none  
-    * @return Integer <tt>6</tt>+    * @return Integer <tt>6</tt>.  
-    * @public +    * @public  
-    * @static +    * @static  
-    */+    */ 
     function getSort(){     function getSort(){
         return 999;         return 999;
Строка 107: Строка 75:
  
  
-   /** +   /**  
-    * Connect lookup pattern to lexer+    * Подключить шаблон поиска к лексеру.  
-    * +    *  
-    * @param $aMode String The desired rendermode+    * @param $aMode String Требуемый режим визуализации
-    * @return none +    * @return none  
-    * @public +    * @public  
-    * @see render() +    * @see render()  
-    */+    */ 
     function connectTo($mode) {     function connectTo($mode) {
       $this->Lexer->addSpecialPattern('<TEST>',$mode,'plugin_test');       $this->Lexer->addSpecialPattern('<TEST>',$mode,'plugin_test');
Строка 125: Строка 93:
  
  
-   /** +   /**  
-    * Handler to prepare matched data for the rendering process+    * Обработчик для подготовки сопоставленных данных для процесса рендеринга.  
-    * +    *  
-    * <p> +    * <p>  
-    * The <tt>$aState</tt> parameter gives the type of pattern +    * Параметр <tt>$aState</tt> задает тип шаблона  
-    * which triggered the call to this method+    который вызвал вызов этого метода:  
-    * </p> +    * </p>  
-    * <dl> +    * <dl>  
-    * <dt>DOKU_LEXER_ENTER</dt> +    * <dt>DOKU_LEXER_ENTER</dt>  
-    * <dd>a pattern set by <tt>addEntryPattern()</tt></dd> +    * <dd>шаблон , установленный функцией <tt>addEntryPattern()</tt></dd>  
-    <dt>DOKU_LEXER_MATCHED</dt> +    <dt>DOKU_LEXER_MATCHED </dt> * <dd>  
-    * <dd>a pattern set by <tt>addPattern()</tt></dd> +    шаблон, установленный функцией <tt>addPattern()</tt></dd>  
-    * <dt>DOKU_LEXER_EXIT</dt> +    * <dt>DOKU_LEXER_EXIT </dt>  
-    * <dd> a pattern set by <tt>addExitPattern()</tt></dd> +    * <dd>шаблон, установленный функцией <tt>addExitPattern()</tt> </dd>  
-    * <dt>DOKU_LEXER_SPECIAL</dt> +    * <dt>DOKU_LEXER_SPECIAL</dt>  
-    * <dd>a pattern set by <tt>addSpecialPattern()</tt></dd> +    * <dd>шаблон, установленный функцией <tt>addSpecialPattern()</tt></dd>  
-    * <dt>DOKU_LEXER_UNMATCHED</dt> +    * <dt>DOKU_LEXER_UNMATCHED</dt>  
-    * <dd>ordinary text encountered within the plugin's syntax mode +    * <dd>обычный текст, встречающийся в режим синтаксиса плагина  
-    * which doesn't match any pattern.</dd> +    который не соответствует ни одному шаблону.</dd>  
-    * </dl> +    * </dl>  
-    * @param $aMatch String The text matched by the patterns+    * @param $aMatch String Текст, соответствующий шаблонам.  
-    * @param $aState Integer The lexer state for the match+    * @param $aState Integer Состояние лексера для сопоставления.  
-    * @param $aPos Integer The character position of the matched text+    * @param $aPos Integer Позиция символа сопоставленного текста.  
-    * @param $aHandler Object Reference to the Doku_Handler object+    * @param $aHandler Object Ссылка на объект Doku_Handler.  
-    * @return Integer The current lexer state for the match+    * @return Integer Текущее состояние лексера для сопоставления.  
-    * @public +    * @public  
-    * @see render() +    * @see render()  
-    * @static +    * @static  
-    */ +    */  
-    function handle($match, $state, $pos, &$handler){+    function handle($match, $state, $pos, Doku_Handler $handler){
         switch ($state) {         switch ($state) {
           case DOKU_LEXER_ENTER :            case DOKU_LEXER_ENTER : 
Строка 170: Строка 138:
     }     }
  
-   /** +   /**  
-    * Handle the actual output creation+    * Обработка фактического создания выходных данных.  
-    * +    *  
-    * <p> +    * <p>  
-    * The method checks for the given <tt>$aFormat</tt> and returns +    * Метод проверяет заданный <tt>$aFormat</tt> и возвращает 
-    * <tt>FALSE</tt> when a format isn't supported. <tt>$aRenderer</tt> +    * <tt>FALSE</tt>, если формат не поддерживается. <tt>$aRenderer</tt>  
-    * contains a reference to the renderer object which is currently +    * содержит ссылку на объект рендерера, который в данный момент  
-    * handling the renderingThe contents of <tt>$aData</tt> is the +    * обрабатывает рендерингСодержимое <tt>$aData</tt> является  
-    * return value of the <tt>handle()</tt> method+    * возвращаемым значением метода <tt>handle()</tt>.  
-    * </p> +    * </p>  
-    * @param $aFormat String The output format to generate+    * @param $aFormat String Формат выходных данных для генерации.  
-    * @param $aRenderer Object A reference to the renderer object+    * @param $aRenderer Object Ссылка на объект рендерера.  
-    * @param $aData Array The data created by the <tt>handle()</tt> +    * @param $aData Array Данные, созданные методом <tt>handle()</tt>  
-    * method+    *.  
-    * @return Boolean <tt>TRUE</tt> if rendered successfully, or +    * @return Boolean <tt>TRUE</tt> при успешном рендеринге или  
-    * <tt>FALSE</tt> otherwise+    * <tt>FALSE</tt> в противном случае.  
-    * @public +    * @public  
-    * @see handle() +    * @see handle()  
-    */ +    */  
-    function render($mode, &$renderer, $data) {+    function render($mode, Doku_Renderer $renderer, $data) {
         if($mode == 'xhtml'){         if($mode == 'xhtml'){
             $renderer->doc .= "Hello World!";            // ptype = 'normal'             $renderer->doc .= "Hello World!";            // ptype = 'normal'
Строка 199: Строка 167:
 } }
  
-//Setup VIM: ex: et ts=4 enc=utf-8 : 
-?> 
 </code> </code>
  
-===== Замечание =====+===== Примечание: ===== 
 + 
 +Имя этого плагина — ''test''. Это видно по имени класса: ''syntax_plugin_test'' — всечто следует далее, ''syntax_plugin_'' воспринимается как имя плагина. 
 + 
 +Поскольку имя плагина — ''test'', его нужно сохранить в  ''lib/plugins/test'' чтобы DokuWiki автоматически распознал его. Его нужно сохранить как syntax.php 
 + 
 +===== Дополнения и Файлы===== 
 +см. также    
 +  * [[wiki:devel:plugin_programming_tips]] 
 +  * [[https://www.dokuwiki.org/devel:syntax_plugin_skeleton|Ссылки на источник статьи]] 
 +  * [[wiki:devel:plugin_development_icon]] 
  
-Имя этого плагина --- «test». You can see that by the name of the class: ''syntax_plugin_test'' --- everything following ''syntax_plugin_'' is taken as the name of the plugin. 
  
-Т. к. имя плагина --- «test», то и храниться он должен в папке ''lib/plugins/test'' для автоматического определения движком «ДокуВики». Имя файла должно быть «syntax.php». 
  
wiki/devel/syntax_plugin_skeleton.1724651690.txt.gz · Последнее изменение: vladpolskiy