Makes checks against the fragment easier to read and all the same.
At the moment some using strval, some use type safe comparsion.
Change-Id: I27d9c3e40e6de6800f4488de167cf06e83c88ce6
$outputPage->addSubtitle( wfMessage( 'redirectedfrom' )->rawParams( $redir ) );
// Set the fragment if one was specified in the redirect
- if ( strval( $this->getTitle()->getFragment() ) != '' ) {
+ if ( $this->getTitle()->hasFragment() ) {
$outputPage->addJsConfigVars( 'wgRedirectToFragment', $this->getTitle()->getFragmentForURL() );
$outputPage->addModules( 'mediawiki.action.view.redirectToFragment' );
}
function canTalk() { $this->error(); }
function getInterwiki() { $this->error(); }
function getFragment() { $this->error(); }
+ function hasFragment() { $this->error(); }
function getFragmentForURL() { $this->error(); }
function getDefaultNamespace() { $this->error(); }
function getIndexTitle() { $this->error(); }
// If the target is just a fragment, with no title, we return the fragment
// text. Otherwise, we return the title text itself.
- if ( $target->getPrefixedText() === '' && $target->getFragment() !== '' ) {
+ if ( $target->getPrefixedText() === '' && $target->hasFragment() ) {
return htmlspecialchars( $target->getFragment() );
}
return htmlspecialchars( $target->getPrefixedText() );
var $mUserCaseDBKey; // /< DB key with the initial letter in the case specified by the user
var $mNamespace = NS_MAIN; // /< Namespace index, i.e. one of the NS_xxxx constants
var $mInterwiki = ''; // /< Interwiki prefix
- var $mFragment; // /< Title fragment (i.e. the bit after the #)
+ var $mFragment = ''; // /< Title fragment (i.e. the bit after the #)
var $mArticleID = -1; // /< Article ID, fetched from the link cache on demand
var $mLatestID = false; // /< ID of most recent revision
var $mContentModel = false; // /< ID of the page's content model, i.e. one of the CONTENT_MODEL_XXX constants
return $this->mFragment;
}
+ /**
+ * Check if a Title fragment is set
+ *
+ * @return bool
+ * @since 1.23
+ */
+ public function hasFragment() {
+ return $this->mFragment !== '';
+ }
+
/**
* Get the fragment in URL form, including the "#" character if there is one
* @return String Fragment in URL form
*/
public function getFragmentForURL() {
- if ( $this->mFragment == '' ) {
+ if ( !$this->hasFragment() ) {
return '';
} else {
- return '#' . Title::escapeFragmentForURL( $this->mFragment );
+ return '#' . Title::escapeFragmentForURL( $this->getFragment() );
}
}
*/
public function getFullText() {
$text = $this->getPrefixedText();
- if ( $this->mFragment != '' ) {
- $text .= '#' . $this->mFragment;
+ if ( $this->hasFragment() ) {
+ $text .= '#' . $this->getFragment();
}
return $text;
}
'from' => strval( $titleStrFrom ),
'to' => $titleTo->getPrefixedText(),
);
- if ( $titleTo->getFragment() !== '' ) {
+ if ( $titleTo->hasFragment() ) {
$r['tofragment'] = $titleTo->getFragment();
}
$values[] = $r;
if ( !$wgRestrictDisplayTitle ) {
$parser->mOutput->setDisplayTitle( $text );
- } elseif ( $title instanceof Title && $title->getFragment() == '' && $title->equals( $parser->mTitle ) ) {
+ } elseif ( $title instanceof Title && !$title->hasFragment() && $title->equals( $parser->mTitle ) ) {
$parser->mOutput->setDisplayTitle( $text );
}
// Self-link checking for mixed/different variant titles. At this point, we
// already know the exact title does not exist, so the link cannot be to a
// variant of the current title that exists as a separate page.
- if ( $variantTitle->equals( $parentTitle ) && $title->getFragment() === '' ) {
+ if ( $variantTitle->equals( $parentTitle ) && !$title->hasFragment() ) {
$this->internals[$ns][$index]['selflink'] = true;
continue 2;
}
$t = Title::newFromText( 'NO TITLE' );
}
- if ( strval( $t->getFragment() ) !== '' ) {
+ if ( $t->hasFragment() ) {
# Strip the fragment to avoid various odd effects
$this->mTitle = clone $t;
$this->mTitle->setFragment( '' );
# 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->mTitle ) && $nt->getFragment() === '' ) {
+ if ( $ns != NS_SPECIAL && $nt->equals( $this->mTitle ) && !$nt->hasFragment() ) {
$s .= $prefix . Linker::makeSelfLinkObj( $nt, $text, '', $trail );
continue;
}
$nt = $this->newTitle;
# don't allow moving to pages with # in
- if ( !$nt || $nt->getFragment() != '' ) {
+ if ( !$nt || $nt->hasFragment() ) {
$this->showForm( array( array( 'badtitletext' ) ) );
return;