[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/specials/ -> SpecialMyLanguage.php (source)

   1  <?php
   2  /**
   3   * Implements Special:MyLanguage
   4   *
   5   * This program is free software; you can redistribute it and/or modify
   6   * it under the terms of the GNU General Public License as published by
   7   * the Free Software Foundation; either version 2 of the License, or
   8   * (at your option) any later version.
   9   *
  10   * This program is distributed in the hope that it will be useful,
  11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13   * GNU General Public License for more details.
  14   *
  15   * You should have received a copy of the GNU General Public License along
  16   * with this program; if not, write to the Free Software Foundation, Inc.,
  17   * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18   * http://www.gnu.org/copyleft/gpl.html
  19   *
  20   * @file
  21   * @author Niklas Laxström
  22   * @author Siebrand Mazeland
  23   * @copyright Copyright © 2010-2013 Niklas Laxström, Siebrand Mazeland
  24   */
  25  
  26  /**
  27   * Unlisted special page just to redirect the user to the translated version of
  28   * a page, if it exists.
  29   *
  30   * Usage: [[Special:MyLanguage/Page name|link text]]
  31   *
  32   * @since 1.24
  33   * @ingroup SpecialPage
  34   */
  35  class SpecialMyLanguage extends RedirectSpecialArticle {
  36  	public function __construct() {
  37          parent::__construct( 'MyLanguage' );
  38      }
  39  
  40      /**
  41       * If the special page is a redirect, then get the Title object it redirects to.
  42       * False otherwise.
  43       *
  44       * @param string $par Subpage string
  45       * @return Title|bool
  46       */
  47  	public function getRedirect( $par ) {
  48          $title = $this->findTitle( $par );
  49          // Go to the main page if given invalid title.
  50          if ( !$title ) {
  51              $title = Title::newMainPage();
  52          }
  53          return $title;
  54      }
  55  
  56      /**
  57       * Assuming the user's interface language is fi. Given input Page, it
  58       * returns Page/fi if it exists, otherwise Page. Given input Page/de,
  59       * it returns Page/fi if it exists, otherwise Page/de if it exists,
  60       * otherwise Page.
  61       *
  62       * @param string $par
  63       * @return Title|null
  64       */
  65  	public function findTitle( $par ) {
  66          // base = title without language code suffix
  67          // provided = the title as it was given
  68          $base = $provided = Title::newFromText( $par );
  69  
  70          if ( $base && strpos( $par, '/' ) !== false ) {
  71              $pos = strrpos( $par, '/' );
  72              $basepage = substr( $par, 0, $pos );
  73              $code = substr( $par, $pos + 1 );
  74              if ( strlen( $code ) && Language::isKnownLanguageTag( $code ) ) {
  75                  $base = Title::newFromText( $basepage );
  76              }
  77          }
  78  
  79          if ( !$base ) {
  80              return null;
  81          }
  82  
  83          $uiCode = $this->getLanguage()->getCode();
  84          $proposed = $base->getSubpage( $uiCode );
  85          if ( $uiCode !== $this->getConfig()->get( 'LanguageCode' ) && $proposed && $proposed->exists() ) {
  86              return $proposed;
  87          } elseif ( $provided && $provided->exists() ) {
  88              return $provided;
  89          } else {
  90              return $base;
  91          }
  92      }
  93  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1