Debian Codegraph @

includes/content/CodeContentHandler.php

raw symbols SCIP
1 <?php
2 /**
3 * Content handler for the pages with code, such as CSS, JavaScript, JSON.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Content
22 */
23
24 namespace MediaWiki\Content;
25
26 use LogicException;
27 use MediaWiki\Language\Language;
28 use MediaWiki\MediaWikiServices;
29 use MediaWiki\Title\Title;
30
31 /**
32 * Content handler for code content such as CSS, JavaScript, JSON, etc.
33 *
34 * @stable to extend
35 * @since 1.24
36 * @ingroup Content
37 */
38 abstract class CodeContentHandler extends TextContentHandler {
39
40 /**
41 * Returns the English language, because code is English, and should be handled as such.
42 *
43 * @stable to override
44 *
45 * @param Title $title
46 * @param Content|null $content
47 *
48 * @return Language
49 *
50 * @see ContentHandler::getPageLanguage()
51 */
52 public function getPageLanguage( Title $title, ?Content $content = null ) {
53 return MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
54 }
55
56 /**
57 * Returns the English language, because code is English, and should be handled as such.
58 *
59 * @stable to override
60 *
61 * @param Title $title
62 * @param Content|null $content
63 *
64 * @return Language
65 *
66 * @see ContentHandler::getPageViewLanguage()
67 */
68 public function getPageViewLanguage( Title $title, ?Content $content = null ) {
69 return MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
70 }
71
72 /** @inheritDoc */
73 protected function getContentClass() {
74 throw new LogicException( 'Subclass must override' );
75 }
76
77 }
78 /** @deprecated class alias since 1.43 */
79 class_alias( CodeContentHandler::class, 'CodeContentHandler' );