Fixed spacing in files direct in includes folder
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index 17ec88a..83ae4c6 100644 (file)
@@ -43,7 +43,7 @@ class MediaWiki_I18N {
                $value = wfMessage( $value )->text();
                // interpolate variables
                $m = array();
-               while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
+               while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
                        list( $src, $var ) = $m;
                        wfSuppressWarnings();
                        $varValue = $this->_context[$var];
@@ -122,6 +122,49 @@ class SkinTemplate extends Skin {
                return new $classname();
        }
 
+       /**
+        * Generates array of language links for the current page
+        *
+        * @return array
+        * @public
+        */
+       public function getLanguages() {
+               global $wgHideInterlanguageLinks;
+               $out = $this->getOutput();
+
+               # Language links
+               $language_urls = array();
+
+               if ( !$wgHideInterlanguageLinks ) {
+                       foreach ( $out->getLanguageLinks() as $languageLinkText ) {
+                               $languageLinkParts = explode( ':', $languageLinkText, 2 );
+                               $class = 'interwiki-' . $languageLinkParts[0];
+                               unset( $languageLinkParts );
+                               $languageLinkTitle = Title::newFromText( $languageLinkText );
+                               if ( $languageLinkTitle ) {
+                                       $ilInterwikiCode = $languageLinkTitle->getInterwiki();
+                                       $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
+
+                                       if ( strval( $ilLangName ) === '' ) {
+                                               $ilLangName = $languageLinkText;
+                                       } else {
+                                               $ilLangName = $this->formatLanguageName( $ilLangName );
+                                       }
+
+                                       $language_urls[] = array(
+                                               'href' => $languageLinkTitle->getFullURL(),
+                                               'text' => $ilLangName,
+                                               'title' => $languageLinkTitle->getText(),
+                                               'class' => $class,
+                                               'lang' => $ilInterwikiCode,
+                                               'hreflang' => $ilInterwikiCode
+                                       );
+                               }
+                       }
+               }
+               return $language_urls;
+       }
+
        /**
         * initialize various variables and generate the template
         *
@@ -132,7 +175,7 @@ class SkinTemplate extends Skin {
                global $wgScript, $wgStylePath;
                global $wgMimeType, $wgJsMimeType;
                global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
-               global $wgDisableCounters, $wgSitename, $wgLogo, $wgHideInterlanguageLinks;
+               global $wgDisableCounters, $wgSitename, $wgLogo;
                global $wgMaxCredits, $wgShowCreditsIfMax;
                global $wgPageShowWatchingUsers;
                global $wgArticlePath, $wgScriptPath, $wgServer;
@@ -229,9 +272,9 @@ class SkinTemplate extends Skin {
                }
 
                $tpl->set( 'catlinks', $this->getCategories() );
-               if( $out->isSyndicated() ) {
+               if ( $out->isSyndicated() ) {
                        $feeds = array();
-                       foreach( $out->getSyndicationLinks() as $format => $link ) {
+                       foreach ( $out->getSyndicationLinks() as $format => $link ) {
                                $feeds[$format] = array(
                                        'text' => $this->msg( "feed-$format" )->text(),
                                        'href' => $link
@@ -409,36 +452,7 @@ class SkinTemplate extends Skin {
                $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
                $tpl->setRef( 'bodytext', $out->mBodytext );
 
-               # Language links
-               $language_urls = array();
-
-               if ( !$wgHideInterlanguageLinks ) {
-                       foreach( $out->getLanguageLinks() as $languageLinkText ) {
-                               $languageLinkParts = explode( ':', $languageLinkText, 2 );
-                               $class = 'interwiki-' . $languageLinkParts[0];
-                               unset( $languageLinkParts );
-                               $languageLinkTitle = Title::newFromText( $languageLinkText );
-                               if ( $languageLinkTitle ) {
-                                       $ilInterwikiCode = $languageLinkTitle->getInterwiki();
-                                       $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
-
-                                       if ( strval( $ilLangName ) === '' ) {
-                                               $ilLangName = $languageLinkText;
-                                       } else {
-                                               $ilLangName = $this->formatLanguageName( $ilLangName );
-                                       }
-
-                                       $language_urls[] = array(
-                                               'href' => $languageLinkTitle->getFullURL(),
-                                               'text' => $ilLangName,
-                                               'title' => $languageLinkTitle->getText(),
-                                               'class' => $class,
-                                               'lang' => $ilInterwikiCode,
-                                               'hreflang' => $ilInterwikiCode
-                                       );
-                               }
-                       }
-               }
+               $language_urls = $this->getLanguages();
                if ( count( $language_urls ) ) {
                        $tpl->setRef( 'language_urls', $language_urls );
                } else {
@@ -469,7 +483,7 @@ class SkinTemplate extends Skin {
                $tpl->set( 'reporttime', wfReportTime() );
 
                // original version by hansm
-               if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
+               if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
                        wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
                }
 
@@ -568,7 +582,7 @@ class SkinTemplate extends Skin {
                if ( strval( $page ) !== '' ) {
                        $a['returnto'] = $page;
                        $query = $request->getVal( 'returntoquery', $this->thisquery );
-                       if( $query != '' ) {
+                       if ( $query != '' ) {
                                $a['returntoquery'] = $query;
                        }
                }
@@ -578,7 +592,7 @@ class SkinTemplate extends Skin {
                }
 
                $returnto = wfArrayToCgi( $a );
-               if( $this->loggedin ) {
+               if ( $this->loggedin ) {
                        $personal_urls['userpage'] = array(
                                'text' => $this->username,
                                'href' => &$this->userpageUrlDetails['href'],
@@ -614,7 +628,7 @@ class SkinTemplate extends Skin {
                        # thickens, because the Title object is altered for special pages,
                        # so it doesn't contain the original alias-with-subpage.
                        $origTitle = Title::newFromText( $request->getText( 'title' ) );
-                       if( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
+                       if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
                                list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
                                $active = $spName == 'Contributions'
                                        && ( ( $spPar && $spPar == $this->username )
@@ -662,7 +676,7 @@ class SkinTemplate extends Skin {
                                'class' => $wgSecureLogin ? 'link-https' : ''
                        );
 
-                       if( $this->showIPinHeader() ) {
+                       if ( $this->showIPinHeader() ) {
                                $href = &$this->userpageUrlDetails['href'];
                                $personal_urls['anonuserpage'] = array(
                                        'text' => $this->username,
@@ -705,10 +719,10 @@ class SkinTemplate extends Skin {
         */
        function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
                $classes = array();
-               if( $selected ) {
+               if ( $selected ) {
                        $classes[] = 'selected';
                }
-               if( $checkEdit && !$title->isKnown() ) {
+               if ( $checkEdit && !$title->isKnown() ) {
                        $classes[] = 'new';
                        if ( $query !== '' ) {
                                $query = 'action=edit&redlink=1&' . $query;
@@ -733,7 +747,7 @@ class SkinTemplate extends Skin {
                }
 
                $result = array();
-               if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
+               if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
                                $title, $message, $selected, $checkEdit,
                                &$classes, &$query, &$text, &$result ) ) ) {
                        return $result;
@@ -748,7 +762,7 @@ class SkinTemplate extends Skin {
 
        function makeTalkUrlDetails( $name, $urlaction = '' ) {
                $title = Title::newFromText( $name );
-               if( !is_object( $title ) ) {
+               if ( !is_object( $title ) ) {
                        throw new MWException( __METHOD__ . " given invalid pagename $name" );
                }
                $title = $title->getTalkPage();
@@ -831,7 +845,7 @@ class SkinTemplate extends Skin {
                wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
 
                // Checks if page is some kind of content
-               if( $title->canExist() ) {
+               if ( $title->canExist() ) {
                        // Gets page objects for the related namespaces
                        $subjectPage = $title->getSubjectPage();
                        $talkPage = $title->getTalkPage();
@@ -1018,7 +1032,7 @@ class SkinTemplate extends Skin {
                                                $params = array();
                                        }
                                        // Loops over each variant
-                                       foreach( $variants as $code ) {
+                                       foreach ( $variants as $code ) {
                                                // Gets variant name from language code
                                                $varname = $pageLang->getVariantname( $code );
                                                // Appends variant link
@@ -1151,9 +1165,9 @@ class SkinTemplate extends Skin {
 
                $nav_urls = array();
                $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
-               if( $wgUploadNavigationUrl ) {
+               if ( $wgUploadNavigationUrl ) {
                        $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
-               } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
+               } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
                        $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
                } else {
                        $nav_urls['upload'] = false;
@@ -1503,8 +1517,9 @@ abstract class BaseTemplate extends QuickTemplate {
                                $ptool['active'] = $plink['active'];
                        }
                        foreach ( array( 'href', 'class', 'text' ) as $k ) {
-                               if ( isset( $plink[$k] ) )
+                               if ( isset( $plink[$k] ) ) {
                                        $ptool['links'][0][$k] = $plink[$k];
+                               }
                        }
                        $personal_tools[$key] = $ptool;
                }
@@ -1543,39 +1558,39 @@ abstract class BaseTemplate extends QuickTemplate {
                        case 'SEARCH':
                                // Search is a special case, skins should custom implement this
                                $boxes[$boxName] = array(
-                                       'id'        => 'p-search',
-                                       'header'    => $this->getMsg( 'search' )->text(),
+                                       'id' => 'p-search',
+                                       'header' => $this->getMsg( 'search' )->text(),
                                        'generated' => false,
-                                       'content'   => true,
+                                       'content' => true,
                                );
                                break;
                        case 'TOOLBOX':
                                $msgObj = $this->getMsg( 'toolbox' );
                                $boxes[$boxName] = array(
-                                       'id'        => 'p-tb',
-                                       'header'    => $msgObj->exists() ? $msgObj->text() : 'toolbox',
+                                       'id' => 'p-tb',
+                                       'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
                                        'generated' => false,
-                                       'content'   => $this->getToolbox(),
+                                       'content' => $this->getToolbox(),
                                );
                                break;
                        case 'LANGUAGES':
                                if ( $this->data['language_urls'] ) {
                                        $msgObj = $this->getMsg( 'otherlanguages' );
                                        $boxes[$boxName] = array(
-                                               'id'        => 'p-lang',
-                                               'header'    => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
+                                               'id' => 'p-lang',
+                                               'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
                                                'generated' => false,
-                                               'content'   => $this->data['language_urls'],
+                                               'content' => $this->data['language_urls'],
                                        );
                                }
                                break;
                        default:
                                $msgObj = $this->getMsg( $boxName );
                                $boxes[$boxName] = array(
-                                       'id'        => "p-$boxName",
-                                       'header'    => $msgObj->exists() ? $msgObj->text() : $boxName,
+                                       'id' => "p-$boxName",
+                                       'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
                                        'generated' => true,
-                                       'content'   => $content,
+                                       'content' => $content,
                                );
                                break;
                        }
@@ -1615,10 +1630,10 @@ abstract class BaseTemplate extends QuickTemplate {
                } else {
                        if ( $hookContents ) {
                                $boxes['TOOLBOXEND'] = array(
-                                       'id'        => 'p-toolboxend',
-                                       'header'    => $boxes['TOOLBOX']['header'],
+                                       'id' => 'p-toolboxend',
+                                       'header' => $boxes['TOOLBOX']['header'],
                                        'generated' => false,
-                                       'content'   => "<ul>{$hookContents}</ul>",
+                                       'content' => "<ul>{$hookContents}</ul>",
                                );
                                // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
                                $boxes2 = array();
@@ -1867,10 +1882,10 @@ abstract class BaseTemplate extends QuickTemplate {
 
                // Reduce footer links down to only those which are being used
                $validFooterLinks = array();
-               foreach( $footerlinks as $category => $links ) {
+               foreach ( $footerlinks as $category => $links ) {
                        $validFooterLinks[$category] = array();
-                       foreach( $links as $link ) {
-                               if( isset( $this->data[$link] ) && $this->data[$link] ) {
+                       foreach ( $links as $link ) {
+                               if ( isset( $this->data[$link] ) && $this->data[$link] ) {
                                        $validFooterLinks[$category][] = $link;
                                }
                        }