From: umherirrender Date: Thu, 2 Jan 2014 11:16:21 +0000 (+0100) Subject: Add Title::hasFragment and use it X-Git-Tag: 1.31.0-rc.0~17168 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=c0d3e85b06d628e5c4a7c93cfe5fb7587f9118f0;p=lhc%2Fweb%2Fwiklou.git 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. Change-Id: I27d9c3e40e6de6800f4488de167cf06e83c88ce6 --- diff --git a/includes/Article.php b/includes/Article.php index e0396a19e5..a5d4d5be62 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -972,7 +972,7 @@ class Article implements Page { $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' ); } diff --git a/includes/FakeTitle.php b/includes/FakeTitle.php index efa213fbe5..4aa15bfdf7 100644 --- a/includes/FakeTitle.php +++ b/includes/FakeTitle.php @@ -39,6 +39,7 @@ class FakeTitle extends Title { 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 5eda642dff..a47507185f 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -384,7 +384,7 @@ class Linker { // 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 f2de4b8d1f..79853dfe83 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -60,7 +60,7 @@ class Title { 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 @@ -1200,15 +1200,25 @@ class Title { 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() ); } } @@ -1290,8 +1300,8 @@ class Title { */ 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 0d733a2784..4095fe62f1 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -387,7 +387,7 @@ class ApiPageSet extends ApiBase { '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 1cc7a185ce..3966b9e0e8 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -387,7 +387,7 @@ class CoreParserFunctions { 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 40c0a89b82..0e7c76f4ce 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -501,7 +501,7 @@ class LinkHolderArray { // 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 c27c51f057..9157619302 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -710,7 +710,7 @@ class Parser { $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 @@ class Parser { # 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 b29b3f9160..c054ef7042 100644 --- a/includes/specials/SpecialMovepage.php +++ b/includes/specials/SpecialMovepage.php @@ -467,7 +467,7 @@ class MovePageForm extends UnlistedSpecialPage { $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;