This change reverts most of commit
3dff713fe4.
Especially the return type hints for getTitle() and Title() are reduced
to allow the type null as return value, because SematicMediaWiki uses
this by
$this->parser->getTitle() instanceof Title
to check if there is a valid Title object.
The parameter type hints for setTitle() and Title() are kept.
Bug: T235392
Change-Id: I72ac1c9d37059876dbc7cd38158e7abd212da8fe
(cherry picked from commit
d91a136ae7b53f07bac62aba944f5a7ba1ccd7ec)
+ * @var Title|null Beware - this is not always set
*/
public $mTitle; # Title context, used for self-link rendering and similar things
public $mOutputType; # Output type, one of the OT_xxx constants
*/
public $mTitle; # Title context, used for self-link rendering and similar things
public $mOutputType; # Output type, one of the OT_xxx constants
if ( $this->mGeneratedPPNodeCount > $this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) {
wfDebugLog( 'generated-pp-node-count', $this->mGeneratedPPNodeCount . ' ' .
if ( $this->mGeneratedPPNodeCount > $this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) {
wfDebugLog( 'generated-pp-node-count', $this->mGeneratedPPNodeCount . ' ' .
- $this->getTitle()->getPrefixedDBkey() );
+ $this->mTitle->getPrefixedDBkey() );
/**
* Accessor for the Title object
*
/**
* Accessor for the Title object
*
- public function getTitle() : Title {
+ public function getTitle() : ?Title {
* Accessor/mutator for the Title object
*
* @param Title|null $x Title object or null to just get the current one
* Accessor/mutator for the Title object
*
* @param Title|null $x Title object or null to just get the current one
- public function Title( Title $x = null ) : Title {
+ public function Title( Title $x = null ) : ?Title {
return wfSetVar( $this->mTitle, $x );
}
return wfSetVar( $this->mTitle, $x );
}
* @return Language
*/
public function getTargetLanguage() {
* @return Language
*/
public function getTargetLanguage() {
return $target;
} elseif ( $this->mOptions->getInterfaceMessage() ) {
return $this->mOptions->getUserLangObj();
return $target;
} elseif ( $this->mOptions->getInterfaceMessage() ) {
return $this->mOptions->getUserLangObj();
+ } elseif ( is_null( $this->mTitle ) ) {
+ throw new MWException( __METHOD__ . ': $this->mTitle is null' );
- return $this->getTitle()->getPageLanguage();
+ return $this->mTitle->getPageLanguage();
}
$url = wfMessage( $urlmsg, $id )->inContentLanguage()->text();
$this->addTrackingCategory( $trackingCat );
}
$url = wfMessage( $urlmsg, $id )->inContentLanguage()->text();
$this->addTrackingCategory( $trackingCat );
- return Linker::makeExternalLink(
- $url,
- "{$keyword} {$id}",
- true,
- $cssClass,
- [],
- $this->getTitle()
- );
+ return Linker::makeExternalLink( $url, "{$keyword} {$id}", true, $cssClass, [], $this->mTitle );
} elseif ( isset( $m[6] ) && $m[6] !== ''
&& $this->mOptions->getMagicISBNLinks()
) {
} elseif ( isset( $m[6] ) && $m[6] !== ''
&& $this->mOptions->getMagicISBNLinks()
) {
$text = Linker::makeExternalLink( $url,
$this->getTargetLanguage()->getConverter()->markNoConversion( $url ),
true, 'free',
$text = Linker::makeExternalLink( $url,
$this->getTargetLanguage()->getConverter()->markNoConversion( $url ),
true, 'free',
- $this->getExternalLinkAttribs( $url ), $this->getTitle() );
+ $this->getExternalLinkAttribs( $url ), $this->mTitle );
# Register it in the output object...
$this->mOutput->addExternalLink( $url );
}
# Register it in the output object...
$this->mOutput->addExternalLink( $url );
}
# Funny characters like ö aren't valid in URLs anyway
# This was changed in August 2004
$s .= Linker::makeExternalLink( $url, $text, false, $linktype,
# Funny characters like ö aren't valid in URLs anyway
# This was changed in August 2004
$s .= Linker::makeExternalLink( $url, $text, false, $linktype,
- $this->getExternalLinkAttribs( $url ), $this->getTitle() ) . $dtrail . $trail;
+ $this->getExternalLinkAttribs( $url ), $this->mTitle ) . $dtrail . $trail;
# Register link in the output object.
$this->mOutput->addExternalLink( $url );
# Register link in the output object.
$this->mOutput->addExternalLink( $url );
*/
public function getExternalLinkAttribs( $url ) {
$attribs = [];
*/
public function getExternalLinkAttribs( $url ) {
$attribs = [];
- $rel = self::getExternalLinkRel( $url, $this->getTitle() );
+ $rel = self::getExternalLinkRel( $url, $this->mTitle );
$target = $this->mOptions->getExternalLinkTarget();
if ( $target ) {
$target = $this->mOptions->getExternalLinkTarget();
if ( $target ) {
/**
* Process [[ ]] wikilinks (RIL)
* @param string &$s
/**
* Process [[ ]] wikilinks (RIL)
* @param string &$s
* @return LinkHolderArray
*
* @private
* @return LinkHolderArray
*
* @private
$line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
$s = substr( $s, 1 );
$line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void"
$s = substr( $s, 1 );
- $nottalk = !$this->getTitle()->isTalkPage();
+ if ( is_null( $this->mTitle ) ) {
+ throw new MWException( __METHOD__ . ": \$this->mTitle is null\n" );
+ }
+ $nottalk = !$this->mTitle->isTalkPage();
$useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
$e2 = null;
$useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
$e2 = null;
}
if ( $ns == NS_FILE ) {
}
if ( $ns == NS_FILE ) {
- if ( !$this->badFileLookup->isBadFile( $nt->getDBkey(), $this->getTitle() ) ) {
+ if ( !$this->badFileLookup->isBadFile( $nt->getDBkey(), $this->mTitle ) ) {
if ( $wasblank ) {
# if no parameters were passed, $text
# becomes something like "File:Foo.png",
if ( $wasblank ) {
# if no parameters were passed, $text
# becomes something like "File:Foo.png",
# Self-link checking. For some languages, variants of the title are checked in
# LinkHolderArray::doVariants() to allow batching the existence checks necessary
# for linking to a different variant.
# Self-link checking. For some languages, variants of the title are checked in
# LinkHolderArray::doVariants() to allow batching the existence checks necessary
# for linking to a different variant.
- if ( $ns != NS_SPECIAL && $nt->equals( $this->getTitle() ) && !$nt->hasFragment() ) {
+ if ( $ns != NS_SPECIAL && $nt->equals( $this->mTitle ) && !$nt->hasFragment() ) {
$s .= $prefix . Linker::makeSelfLinkObj( $nt, $text, '', $trail );
continue;
}
$s .= $prefix . Linker::makeSelfLinkObj( $nt, $text, '', $trail );
continue;
}
*/
public function areSubpagesAllowed() {
# Some namespaces don't allow subpages
*/
public function areSubpagesAllowed() {
# Some namespaces don't allow subpages
- return $this->nsInfo->hasSubpages( $this->getTitle()->getNamespace() );
+ return $this->nsInfo->hasSubpages( $this->mTitle->getNamespace() );
* @private
*/
public function maybeDoSubpageLink( $target, &$text ) {
* @private
*/
public function maybeDoSubpageLink( $target, &$text ) {
- return Linker::normalizeSubpageLink( $this->getTitle(), $target, $text );
+ return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
* @param string $index Magic variable identifier as mapped in MagicWordFactory::$mVariableIDs
* @param bool|PPFrame $frame
*
* @param string $index Magic variable identifier as mapped in MagicWordFactory::$mVariableIDs
* @param bool|PPFrame $frame
*
* @return string
*/
public function getVariableValue( $index, $frame = false ) {
* @return string
*/
public function getVariableValue( $index, $frame = false ) {
+ if ( is_null( $this->mTitle ) ) {
+ // If no title set, bad things are going to happen
+ // later. Title should always be set since this
+ // should only be called in the middle of a parse
+ // operation (but the unit-tests do funky stuff)
+ throw new MWException( __METHOD__ . ' Should only be '
+ . ' called while parsing (no title set)' );
+ }
+
// Avoid PHP 7.1 warning from passing $this by reference
$parser = $this;
// Avoid PHP 7.1 warning from passing $this by reference
$parser = $this;
$value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'd' ), true );
break;
case 'pagename':
$value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'd' ), true );
break;
case 'pagename':
- $value = wfEscapeWikiText( $this->getTitle()->getText() );
+ $value = wfEscapeWikiText( $this->mTitle->getText() );
- $value = wfEscapeWikiText( $this->getTitle()->getPartialURL() );
+ $value = wfEscapeWikiText( $this->mTitle->getPartialURL() );
break;
case 'fullpagename':
break;
case 'fullpagename':
- $value = wfEscapeWikiText( $this->getTitle()->getPrefixedText() );
+ $value = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
break;
case 'fullpagenamee':
break;
case 'fullpagenamee':
- $value = wfEscapeWikiText( $this->getTitle()->getPrefixedURL() );
+ $value = wfEscapeWikiText( $this->mTitle->getPrefixedURL() );
break;
case 'subpagename':
break;
case 'subpagename':
- $value = wfEscapeWikiText( $this->getTitle()->getSubpageText() );
+ $value = wfEscapeWikiText( $this->mTitle->getSubpageText() );
break;
case 'subpagenamee':
break;
case 'subpagenamee':
- $value = wfEscapeWikiText( $this->getTitle()->getSubpageUrlForm() );
+ $value = wfEscapeWikiText( $this->mTitle->getSubpageUrlForm() );
break;
case 'rootpagename':
break;
case 'rootpagename':
- $value = wfEscapeWikiText( $this->getTitle()->getRootText() );
+ $value = wfEscapeWikiText( $this->mTitle->getRootText() );
break;
case 'rootpagenamee':
$value = wfEscapeWikiText( wfUrlencode( str_replace(
' ',
'_',
break;
case 'rootpagenamee':
$value = wfEscapeWikiText( wfUrlencode( str_replace(
' ',
'_',
- $this->getTitle()->getRootText()
+ $this->mTitle->getRootText()
) ) );
break;
case 'basepagename':
) ) );
break;
case 'basepagename':
- $value = wfEscapeWikiText( $this->getTitle()->getBaseText() );
+ $value = wfEscapeWikiText( $this->mTitle->getBaseText() );
break;
case 'basepagenamee':
$value = wfEscapeWikiText( wfUrlencode( str_replace(
' ',
'_',
break;
case 'basepagenamee':
$value = wfEscapeWikiText( wfUrlencode( str_replace(
' ',
'_',
- $this->getTitle()->getBaseText()
+ $this->mTitle->getBaseText()
) ) );
break;
case 'talkpagename':
) ) );
break;
case 'talkpagename':
- if ( $this->getTitle()->canHaveTalkPage() ) {
- $talkPage = $this->getTitle()->getTalkPage();
+ if ( $this->mTitle->canHaveTalkPage() ) {
+ $talkPage = $this->mTitle->getTalkPage();
$value = wfEscapeWikiText( $talkPage->getPrefixedText() );
} else {
$value = '';
}
break;
case 'talkpagenamee':
$value = wfEscapeWikiText( $talkPage->getPrefixedText() );
} else {
$value = '';
}
break;
case 'talkpagenamee':
- if ( $this->getTitle()->canHaveTalkPage() ) {
- $talkPage = $this->getTitle()->getTalkPage();
+ if ( $this->mTitle->canHaveTalkPage() ) {
+ $talkPage = $this->mTitle->getTalkPage();
$value = wfEscapeWikiText( $talkPage->getPrefixedURL() );
} else {
$value = '';
}
break;
case 'subjectpagename':
$value = wfEscapeWikiText( $talkPage->getPrefixedURL() );
} else {
$value = '';
}
break;
case 'subjectpagename':
- $subjPage = $this->getTitle()->getSubjectPage();
+ $subjPage = $this->mTitle->getSubjectPage();
$value = wfEscapeWikiText( $subjPage->getPrefixedText() );
break;
case 'subjectpagenamee':
$value = wfEscapeWikiText( $subjPage->getPrefixedText() );
break;
case 'subjectpagenamee':
- $subjPage = $this->getTitle()->getSubjectPage();
+ $subjPage = $this->mTitle->getSubjectPage();
$value = wfEscapeWikiText( $subjPage->getPrefixedURL() );
break;
case 'pageid': // requested in T25427
# Inform the edit saving system that getting the canonical output
# after page insertion requires a parse that used that exact page ID
$this->setOutputFlag( 'vary-page-id', '{{PAGEID}} used' );
$value = wfEscapeWikiText( $subjPage->getPrefixedURL() );
break;
case 'pageid': // requested in T25427
# Inform the edit saving system that getting the canonical output
# after page insertion requires a parse that used that exact page ID
$this->setOutputFlag( 'vary-page-id', '{{PAGEID}} used' );
- $value = $this->getTitle()->getArticleID();
+ $value = $this->mTitle->getArticleID();
if ( !$value ) {
$value = $this->mOptions->getSpeculativePageId();
if ( $value ) {
if ( !$value ) {
$value = $this->mOptions->getSpeculativePageId();
if ( $value ) {
$this->svcOptions->get( 'MiserMode' ) &&
!$this->mOptions->getInterfaceMessage() &&
// @TODO: disallow this word on all namespaces
$this->svcOptions->get( 'MiserMode' ) &&
!$this->mOptions->getInterfaceMessage() &&
// @TODO: disallow this word on all namespaces
- $this->nsInfo->isContent( $this->getTitle()->getNamespace() )
+ $this->nsInfo->isContent( $this->mTitle->getNamespace() )
) {
// Use a stub result instead of the actual revision ID in order to avoid
// double parses on page save but still allow preview detection (T137900)
) {
// Use a stub result instead of the actual revision ID in order to avoid
// double parses on page save but still allow preview detection (T137900)
break;
case 'namespace':
$value = str_replace( '_', ' ',
break;
case 'namespace':
$value = str_replace( '_', ' ',
- $this->contLang->getNsText( $this->getTitle()->getNamespace() ) );
+ $this->contLang->getNsText( $this->mTitle->getNamespace() ) );
break;
case 'namespacee':
break;
case 'namespacee':
- $value = wfUrlencode( $this->contLang->getNsText( $this->getTitle()->getNamespace() ) );
+ $value = wfUrlencode( $this->contLang->getNsText( $this->mTitle->getNamespace() ) );
break;
case 'namespacenumber':
break;
case 'namespacenumber':
- $value = $this->getTitle()->getNamespace();
+ $value = $this->mTitle->getNamespace();
- $value = $this->getTitle()->canHaveTalkPage()
- ? str_replace( '_', ' ', $this->getTitle()->getTalkNsText() )
+ $value = $this->mTitle->canHaveTalkPage()
+ ? str_replace( '_', ' ', $this->mTitle->getTalkNsText() )
: '';
break;
case 'talkspacee':
: '';
break;
case 'talkspacee':
- $value = $this->getTitle()->canHaveTalkPage()
- ? wfUrlencode( $this->getTitle()->getTalkNsText() )
- : '';
+ $value = $this->mTitle->canHaveTalkPage() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
break;
case 'subjectspace':
break;
case 'subjectspace':
- $value = str_replace( '_', ' ', $this->getTitle()->getSubjectNsText() );
+ $value = str_replace( '_', ' ', $this->mTitle->getSubjectNsText() );
break;
case 'subjectspacee':
break;
case 'subjectspacee':
- $value = ( wfUrlencode( $this->getTitle()->getSubjectNsText() ) );
+ $value = ( wfUrlencode( $this->mTitle->getSubjectNsText() ) );
break;
case 'currentdayname':
$value = $pageLang->getWeekdayName( (int)MWTimestamp::getInstance( $ts )->format( 'w' ) + 1 );
break;
case 'currentdayname':
$value = $pageLang->getWeekdayName( (int)MWTimestamp::getInstance( $ts )->format( 'w' ) + 1 );
$relative = $this->maybeDoSubpageLink( $part1, $subpage );
if ( $part1 !== $relative ) {
$part1 = $relative;
$relative = $this->maybeDoSubpageLink( $part1, $subpage );
if ( $part1 !== $relative ) {
$part1 = $relative;
- $ns = $this->getTitle()->getNamespace();
+ $ns = $this->mTitle->getNamespace();
}
$title = Title::newFromText( $part1, $ns );
if ( $title ) {
}
$title = Title::newFromText( $part1, $ns );
if ( $title ) {
* @param PPFrame $frame The current frame, contains template arguments
* @param string $function Function name
* @param array $args Arguments to the function
* @param PPFrame $frame The current frame, contains template arguments
* @param string $function Function name
* @param array $args Arguments to the function
* @return array
*/
public function callParserFunction( $frame, $function, array $args = [] ) {
* @return array
*/
public function callParserFunction( $frame, $function, array $args = [] ) {
$this->mShowToc = false;
}
if ( isset( $this->mDoubleUnderscores['hiddencat'] )
$this->mShowToc = false;
}
if ( isset( $this->mDoubleUnderscores['hiddencat'] )
- && $this->getTitle()->getNamespace() == NS_CATEGORY
+ && $this->mTitle->getNamespace() == NS_CATEGORY
) {
$this->addTrackingCategory( 'hidden-category-category' );
}
# (T10068) Allow control over whether robots index a page.
# __INDEX__ always overrides __NOINDEX__, see T16899
) {
$this->addTrackingCategory( 'hidden-category-category' );
}
# (T10068) Allow control over whether robots index a page.
# __INDEX__ always overrides __NOINDEX__, see T16899
- if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->getTitle()->canUseNoindex() ) {
+ if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) {
$this->mOutput->setIndexPolicy( 'noindex' );
$this->addTrackingCategory( 'noindex-category' );
}
$this->mOutput->setIndexPolicy( 'noindex' );
$this->addTrackingCategory( 'noindex-category' );
}
- if ( isset( $this->mDoubleUnderscores['index'] ) && $this->getTitle()->canUseNoindex() ) {
+ if ( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ) {
$this->mOutput->setIndexPolicy( 'index' );
$this->addTrackingCategory( 'index-category' );
}
$this->mOutput->setIndexPolicy( 'index' );
$this->addTrackingCategory( 'index-category' );
}
* @return bool Whether the addition was successful
*/
public function addTrackingCategory( $msg ) {
* @return bool Whether the addition was successful
*/
public function addTrackingCategory( $msg ) {
- return $this->mOutput->addTrackingCategory( $msg, $this->getTitle() );
+ return $this->mOutput->addTrackingCategory( $msg, $this->mTitle );
$toclevel = 0;
$prevtoclevel = 0;
$markerRegex = self::MARKER_PREFIX . "-h-(\d+)-" . self::MARKER_SUFFIX;
$toclevel = 0;
$prevtoclevel = 0;
$markerRegex = self::MARKER_PREFIX . "-h-(\d+)-" . self::MARKER_SUFFIX;
- $baseTitleText = $this->getTitle()->getPrefixedDBkey();
+ $baseTitleText = $this->mTitle->getPrefixedDBkey();
$oldType = $this->mOutputType;
$this->setOutputType( self::OT_WIKI );
$frame = $this->getPreprocessor()->newFrame();
$oldType = $this->mOutputType;
$this->setOutputType( self::OT_WIKI );
$frame = $this->getPreprocessor()->newFrame();
$editsectionSection = "T-$sectionIndex";
$editsectionContent = null;
} else {
$editsectionSection = "T-$sectionIndex";
$editsectionContent = null;
} else {
- $editsectionPage = $this->getTitle()->getPrefixedText();
+ $editsectionPage = $this->mTitle->getPrefixedText();
$editsectionSection = $sectionIndex;
$editsectionContent = $headlineHint;
}
$editsectionSection = $sectionIndex;
$editsectionContent = $headlineHint;
}
$text = preg_replace( $p4, '[[\\1\\2\\3|\\2]]', $text );
$text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text );
$text = preg_replace( $p4, '[[\\1\\2\\3|\\2]]', $text );
$text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text );
- $t = $this->getTitle()->getText();
+ $t = $this->mTitle->getText();
$m = [];
if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
$text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
$m = [];
if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) {
$text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text );
$ig = ImageGalleryBase::factory( false );
}
$ig = ImageGalleryBase::factory( false );
}
- $ig->setContextTitle( $this->getTitle() );
+ $ig->setContextTitle( $this->mTitle );
$ig->setShowBytes( false );
$ig->setShowDimensions( false );
$ig->setShowFilename( false );
$ig->setShowBytes( false );
$ig->setShowDimensions( false );
$ig->setShowFilename( false );
*/
protected function setOutputFlag( $flag, $reason ) {
$this->mOutput->setFlag( $flag );
*/
protected function setOutputFlag( $flag, $reason ) {
$this->mOutput->setFlag( $flag );
- $name = $this->getTitle()->getPrefixedText();
+ $name = $this->mTitle->getPrefixedText();
$this->logger->debug( __METHOD__ . ": set $flag flag on '$name'; $reason" );
}
}
$this->logger->debug( __METHOD__ . ": set $flag flag on '$name'; $reason" );
}
}