| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Wikitext scripting infrastructure for MediaWiki: base classes. |
| 5 | * Copyright (C) 2012 Victor Vasiliev <[email protected]> et al |
| 6 | * https://www.mediawiki.org/ |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | * http://www.gnu.org/copyleft/gpl.html |
| 22 | */ |
| 23 | |
| 24 | namespace MediaWiki\Extension\Scribunto; |
| 25 | |
| 26 | use MediaWiki\Parser\PPFrame; |
| 27 | use MediaWiki\Status\Status; |
| 28 | |
| 29 | /** |
| 30 | * Class that represents a module. Responsible for initial module parsing |
| 31 | * and maintaining the contents of the module. |
| 32 | */ |
| 33 | abstract class ScribuntoModuleBase { |
| 34 | /** |
| 35 | * @var ScribuntoEngineBase |
| 36 | */ |
| 37 | protected $engine; |
| 38 | |
| 39 | /** |
| 40 | * @var string |
| 41 | */ |
| 42 | protected $code; |
| 43 | |
| 44 | /** |
| 45 | * @var string|bool |
| 46 | */ |
| 47 | protected $chunkName; |
| 48 | |
| 49 | /** |
| 50 | * @param ScribuntoEngineBase $engine |
| 51 | * @param string $code |
| 52 | * @param string|bool $chunkName |
| 53 | */ |
| 54 | public function __construct( ScribuntoEngineBase $engine, $code, $chunkName ) { |
| 55 | $this->engine = $engine; |
| 56 | $this->code = $code; |
| 57 | $this->chunkName = $chunkName; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return ScribuntoEngineBase |
| 62 | */ |
| 63 | public function getEngine() { |
| 64 | return $this->engine; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return string |
| 69 | */ |
| 70 | public function getCode() { |
| 71 | return $this->code; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return string|bool |
| 76 | */ |
| 77 | public function getChunkName() { |
| 78 | return $this->chunkName; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Validates the script and returns a Status object containing the syntax |
| 83 | * errors for the given code. |
| 84 | * |
| 85 | * @return Status |
| 86 | */ |
| 87 | abstract public function validate(); |
| 88 | |
| 89 | /** |
| 90 | * Invoke the function with the specified name. |
| 91 | * |
| 92 | * @param string $name |
| 93 | * @param PPFrame $frame |
| 94 | * @return string |
| 95 | */ |
| 96 | abstract public function invoke( $name, $frame ); |
| 97 | } |