Umherirrender has uploaded a new change for review. https://gerrit.wikimedia.org/r/104750
Change subject: Add Title::hasFragment and use it ...................................................................... Add Title::hasFragment and use it Makes checks against the fragment easier to read and all the same. At the moment some using strval, some use type safe comparsion. The new function used the same check as used in Title.php before. Change-Id: I27d9c3e40e6de6800f4488de167cf06e83c88ce6 --- M includes/Article.php M includes/FakeTitle.php M includes/Linker.php M includes/Title.php M includes/api/ApiPageSet.php M includes/parser/CoreParserFunctions.php M includes/parser/LinkHolderArray.php M includes/parser/Parser.php M includes/specials/SpecialMovepage.php 9 files changed, 23 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/50/104750/1 diff --git a/includes/Article.php b/includes/Article.php index c82b39f..d0d9919 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -988,7 +988,7 @@ $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->addInlineScript( Xml::encodeJsCall( 'redirectToFragment', array( $this->getTitle()->getFragmentForURL() ) ) ); diff --git a/includes/FakeTitle.php b/includes/FakeTitle.php index efa213f..4aa15bf 100644 --- a/includes/FakeTitle.php +++ b/includes/FakeTitle.php @@ -39,6 +39,7 @@ 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(); } diff --git a/includes/Linker.php b/includes/Linker.php index 27f8ab4..db0063b 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -387,7 +387,7 @@ // 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() ); diff --git a/includes/Title.php b/includes/Title.php index 5ab9e94..62d74d3 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1201,14 +1201,24 @@ } /** + * 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() ); } } @@ -1291,8 +1301,8 @@ */ public function getFullText() { $text = $this->getPrefixedText(); - if ( $this->mFragment != '' ) { - $text .= '#' . $this->mFragment; + if ( $this->hasFragment() ) { + $text .= '#' . $this->getFragment(); } return $text; } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index e95e680..a25c445 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -387,7 +387,7 @@ 'from' => strval( $titleStrFrom ), 'to' => $titleTo->getPrefixedText(), ); - if ( $titleTo->getFragment() !== '' ) { + if ( $titleTo->hasFragment() ) { $r['tofragment'] = $titleTo->getFragment(); } $values[] = $r; diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index ca27112..f6bd9d8 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -387,7 +387,7 @@ 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 ); } diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 40c0a89..0e7c76f 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -501,7 +501,7 @@ // 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; } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 27065e5..24e5d6d 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -710,7 +710,7 @@ $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( '' ); @@ -2120,7 +2120,7 @@ # 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; } diff --git a/includes/specials/SpecialMovepage.php b/includes/specials/SpecialMovepage.php index b29b3f9..c054ef7 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -467,7 +467,7 @@ $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; -- To view, visit https://gerrit.wikimedia.org/r/104750 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I27d9c3e40e6de6800f4488de167cf06e83c88ce6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits