2012-09-24 20:51:53 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-12-20 19:44:47 +00:00
|
|
|
* Content for JavaScript pages.
|
|
|
|
|
*
|
2012-10-16 18:04:32 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-10-05 13:03:24 +00:00
|
|
|
* @since 1.21
|
2012-10-16 18:04:32 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Content
|
|
|
|
|
*
|
|
|
|
|
* @author Daniel Kinzler
|
2012-09-24 20:51:53 +00:00
|
|
|
*/
|
2012-12-20 19:44:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Content for JavaScript pages.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Content
|
|
|
|
|
*/
|
2012-09-24 20:51:53 +00:00
|
|
|
class JavaScriptContent extends TextContent {
|
2014-03-03 17:08:05 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $text JavaScript code.
|
|
|
|
|
*/
|
2012-09-24 20:51:53 +00:00
|
|
|
public function __construct( $text ) {
|
|
|
|
|
parent::__construct( $text, CONTENT_MODEL_JAVASCRIPT );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a Content object with pre-save transformations applied using
|
|
|
|
|
* Parser::preSaveTransform().
|
|
|
|
|
*
|
|
|
|
|
* @param Title $title
|
|
|
|
|
* @param User $user
|
|
|
|
|
* @param ParserOptions $popts
|
2014-03-03 17:08:05 +00:00
|
|
|
*
|
|
|
|
|
* @return JavaScriptContent
|
2012-09-24 20:51:53 +00:00
|
|
|
*/
|
|
|
|
|
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
|
|
|
|
|
global $wgParser;
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo Make pre-save transformation optional for script pages
|
2012-09-24 20:51:53 +00:00
|
|
|
// See bug #32858
|
|
|
|
|
|
|
|
|
|
$text = $this->getNativeData();
|
|
|
|
|
$pst = $wgParser->preSaveTransform( $text, $title, $user, $popts );
|
|
|
|
|
|
|
|
|
|
return new JavaScriptContent( $pst );
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-03 17:08:05 +00:00
|
|
|
/**
|
|
|
|
|
* @return string JavaScript wrapped in a <pre> tag.
|
|
|
|
|
*/
|
2013-03-17 15:13:22 +00:00
|
|
|
protected function getHtml() {
|
2012-09-24 20:51:53 +00:00
|
|
|
$html = "";
|
|
|
|
|
$html .= "<pre class=\"mw-code mw-js\" dir=\"ltr\">\n";
|
2013-06-10 19:13:00 +00:00
|
|
|
$html .= $this->getHighlightHtml();
|
2012-09-24 20:51:53 +00:00
|
|
|
$html .= "\n</pre>\n";
|
|
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
|
}
|
2014-03-03 17:08:05 +00:00
|
|
|
|
2012-12-20 19:44:47 +00:00
|
|
|
}
|