Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / content / CssContent.php
blob6955dc9280c5727886fee7d1a97f04abe6c01839
1 <?php
2 /**
3 * Content object for CSS pages.
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.
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.
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
20 * @since 1.21
22 * @file
23 * @ingroup Content
25 * @author Daniel Kinzler
28 namespace MediaWiki\Content;
30 use MediaWiki\Title\Title;
32 /**
33 * Content object for CSS pages.
35 * @newable
36 * @ingroup Content
38 class CssContent extends TextContent {
40 /**
41 * @var Title|null|false
43 private $redirectTarget = false;
45 /**
46 * @stable to call
47 * @param string $text CSS code.
48 * @param string $modelId the content content model
50 public function __construct( $text, $modelId = CONTENT_MODEL_CSS ) {
51 parent::__construct( $text, $modelId );
54 /**
55 * @param Title $target
56 * @return CssContent
58 public function updateRedirect( Title $target ) {
59 if ( !$this->isRedirect() ) {
60 return $this;
63 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
64 return $this->getContentHandler()->makeRedirectContent( $target );
67 /**
68 * @return Title|null
70 public function getRedirectTarget() {
71 if ( $this->redirectTarget !== false ) {
72 return $this->redirectTarget;
74 $this->redirectTarget = null;
75 $text = $this->getText();
76 if ( strpos( $text, '/* #REDIRECT */' ) === 0 ) {
77 // Extract the title from the url
78 if ( preg_match( '/title=(.*?)&action=raw/', $text, $matches ) ) {
79 $title = Title::newFromText( urldecode( $matches[1] ) );
80 if ( $title ) {
81 // Have a title, check that the current content equals what
82 // the redirect content should be
83 if ( $this->equals( $this->getContentHandler()->makeRedirectContent( $title ) ) ) {
84 $this->redirectTarget = $title;
90 return $this->redirectTarget;
94 /** @deprecated class alias since 1.43 */
95 class_alias( CssContent::class, 'CssContent' );