Add Title::hasFragment and use it
authorumherirrender <umherirrender_de.wp@web.de>
Thu, 2 Jan 2014 11:16:21 +0000 (12:16 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Fri, 24 Jan 2014 15:42:13 +0000 (15:42 +0000)
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

includes/Article.php
includes/FakeTitle.php
includes/Linker.php
includes/Title.php
includes/api/ApiPageSet.php
includes/parser/CoreParserFunctions.php
includes/parser/LinkHolderArray.php
includes/parser/Parser.php
includes/specials/SpecialMovepage.php

index e0396a1..a5d4d5b 100644 (file)
@@ -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' );
                                }
index efa213f..4aa15bf 100644 (file)
@@ -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(); }
index 5eda642..a475071 100644 (file)
@@ -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() );
index f2de4b8..79853df 100644 (file)
@@ -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;
        }
index 0d733a2..4095fe6 100644 (file)
@@ -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;
index 1cc7a18..3966b9e 100644 (file)
@@ -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 );
                }
 
index 40c0a89..0e7c76f 100644 (file)
@@ -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;
                                }
index c27c51f..9157619 100644 (file)
@@ -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;
                        }
index b29b3f9..c054ef7 100644 (file)
@@ -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;