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
25 * @author Daniel Kinzler
28 namespace MediaWiki\Content
;
30 use MediaWiki\Title\Title
;
33 * Content object for CSS pages.
38 class CssContent
extends TextContent
{
41 * @var Title|null|false
43 private $redirectTarget = false;
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 );
55 * @param Title $target
58 public function updateRedirect( Title
$target ) {
59 if ( !$this->isRedirect() ) {
63 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
64 return $this->getContentHandler()->makeRedirectContent( $target );
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] ) );
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' );