Nemo bis has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/356863 )
Change subject: Some style changes ...................................................................... Some style changes Bug: T155087 Change-Id: Iee14f8b8b58ad8ccf4e4f53892f7949030e196df --- M NamespaceRelations_body.php 1 file changed, 99 insertions(+), 43 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NamespaceRelations refs/changes/63/356863/1 diff --git a/NamespaceRelations_body.php b/NamespaceRelations_body.php index 59bd0fe..e170421 100644 --- a/NamespaceRelations_body.php +++ b/NamespaceRelations_body.php @@ -7,41 +7,41 @@ const STARTING_WEIGHT = 20; const WEIGHT_INCREMENT = 10; - private $_currentWeight = self::STARTING_WEIGHT; + private $currentWeight = self::STARTING_WEIGHT; /** * Processed $wgNamespaceRelations configuration * * @var array */ - private $_namespaces; + private $namespaces; /** - * References to $this->_namespaces per target + * References to $this->namespaces per target * * @var array */ - private $_namespacesToTarget; + private $namespacesToTarget; /** - * References to $this->_namespaces per allowed namespace + * References to $this->namespaces per allowed namespace * * @var array */ - private $_namespacesToNamespace; + private $namespacesToNamespace; /** * Per-namespace array of patterns to match against the title * * @var array */ - private $_namespacesSubjectPattern; + private $namespacesSubjectPattern; public function __construct() { wfProfileIn( 'NamespaceRelations: ' . __METHOD__ ); global $wgNamespaceRelations; - $this->_namespaces = array(); + $this->namespaces = array(); if ( !empty( $wgNamespaceRelations ) ) { foreach ( $wgNamespaceRelations as $key => $data ) { $this->setNamespace( $key, null, @@ -59,7 +59,8 @@ $this->setNamespace( $key, 'weight', $data['weight'] ); } if ( isset( $data['customTarget'] ) ) { - $this->_namespacesSubjectPattern[$this->getNamespace( $key, 'target' )][] = + $this->namespacesSubjectPattern[$this->getNamespace( + $key, 'target' )][] = '#^' . str_replace( '$1', '(.*)', $data['customTarget'] ) . '$#'; $this->setNamespace( $key, 'customTarget', $data['customTarget'] ); } @@ -79,7 +80,8 @@ $title = $skinTemplate->getRelevantTitle(); $titleText = $title->getText(); $subjectNS = $title->getSubjectPage()->getNamespace(); - $rootText = $this->getRootTitle( $titleText, $subjectNS ); // the root title to link other tabs against + $rootText = $this->getRootTitle( $titleText, $subjectNS ); + // the root title to link other tabs against $userCanRead = $title->quickUserCan( 'read', $skinTemplate->getUser() ); /** @@ -94,27 +96,40 @@ */ $tabs = array(); - if ( array_key_exists( $subjectNS, $this->_namespacesToNamespace ) ) { // in Main/Talk NS + if ( array_key_exists( $subjectNS, $this->namespacesToNamespace ) ) { + // in Main/Talk NS // make a Subject tab $subjectOptions['checkExists'] = $userCanRead; $subjectOptions['title'] = Title::makeTitle( $subjectNS, $rootText ); if ( $title->equals( $subjectOptions['title'] ) ) { $subjectOptions['isActive'] = true; } - $tabs['subject'] = $this->makeSubjectTab( $subjectNS, $rootText, $subjectOptions ); - unset( $subjectOptions ); + $tabs['subject'] = $this->makeSubjectTab( + $subjectNS, + $rootText, + $subjectOptions + ); // make a Talk tab $talkOptions['checkExists'] = $userCanRead; - $talkOptions['title'] = Title::makeTitle( MWNamespace::getTalk( $subjectNS ), $rootText ); + $talkOptions['title'] = Title::makeTitle( + MWNamespace::getTalk( $subjectNS ), + $rootText + ); if ( $title->equals( $talkOptions['title'] ) ) { $talkOptions['isActive'] = true; } - $tabs['talk'] = $this->makeTalkTab( MWNamespace::getTalk( $subjectNS ), $rootText, $talkOptions ); + $tabs['talk'] = $this->makeTalkTab( + MWNamespace::getTalk( $subjectNS ), + $rootText, + $talkOptions + ); unset( $talkOptions ); - foreach ( $this->_namespacesToNamespace[$subjectNS] as $key ) { - if ( $title->getSubjectPage()->isMainPage() && !$this->getNamespace( $key, 'inMainPage' ) ) { + foreach ( $this->namespacesToNamespace[$subjectNS] as $key ) { + if ( $title->getSubjectPage()->isMainPage() + && !$this->getNamespace( $key, 'inMainPage' ) + ) { continue; } if ( $this->getNamespace( $key, 'hideTalk' ) ) { @@ -124,19 +139,30 @@ $tabOptions = array( 'title' => $this->getCustomTargetTitle( $key, $rootText ), 'messages' => $this->getNamespace( $key, 'message' ), - 'query' => $this->getKeyQuery( $key, $this->getCustomTargetTitle( $key, $rootText ) ), + 'query' => $this->getKeyQuery( + $key, + $this->getCustomTargetTitle( $key, $rootText ) + ), 'checkExists' => $userCanRead, 'weight' => $this->getNamespace( $key, 'weight' ) ); if ( $title->equals( $tabOptions['title'] ) ) { $tabOptions['isActive'] = true; } - $tabs[$key] = $this->makeTab( $this->getNamespace( $key, 'target' ), $this->getCustomTargetTitle( $key, $rootText, true ), $tabOptions ); + $tabs[$key] = $this->makeTab( + $this->getNamespace( $key, 'target' ), + $this->getCustomTargetTitle( $key, $rootText, true ), + $tabOptions + ); unset( $tabOptions ); } - } elseif ( array_key_exists( $subjectNS, $this->_namespacesToTarget ) ) { // in additional NS + } elseif ( array_key_exists( $subjectNS, $this->namespacesToTarget ) ) { + // in additional NS // redefine the subject namespace to point to the real one - $subjectNS = $this->getNamespace( $this->_namespacesToTarget[$subjectNS], 'namespace' ); + $subjectNS = $this->getNamespace( + $this->namespacesToTarget[$subjectNS], + 'namespace' + ); // make a Subject tab $subjectOptions['checkExists'] = $userCanRead; @@ -144,23 +170,36 @@ if ( $title->equals( $subjectOptions['title'] ) ) { $subjectOptions['isActive'] = true; } - $tabs['subject'] = $this->makeSubjectTab( $subjectNS, $rootText, $subjectOptions ); - unset( $subjectOptions ); + $tabs['subject'] = $this->makeSubjectTab( + $subjectNS, + $rootText, + $subjectOptions + ); // make a Talk tab $talkOptions['checkExists'] = $userCanRead; - $talkOptions['title'] = Title::makeTitle( MWNamespace::getTalk( $subjectNS ), $rootText ); + $talkOptions['title'] = Title::makeTitle( + MWNamespace::getTalk( $subjectNS ), + $rootText + ); if ( $title->equals( $talkOptions['title'] ) ) { $talkOptions['isActive'] = true; } - $tabs['talk'] = $this->makeTalkTab( MWNamespace::getTalk( $subjectNS ), $rootText, $talkOptions ); + $tabs['talk'] = $this->makeTalkTab( + MWNamespace::getTalk( $subjectNS ), + $rootText, + $talkOptions + ); unset( $talkOptions ); - foreach ( $this->_namespacesToNamespace[$subjectNS] as $key ) { + foreach ( $this->namespacesToNamespace[$subjectNS] as $key ) { $tabOptions = array( 'title' => $this->getCustomTargetTitle( $key, $rootText ), 'messages' => $this->getNamespace( $key, 'message' ), - 'query' => $this->getKeyQuery( $key, $this->getCustomTargetTitle( $key, $rootText ) ), + 'query' => $this->getKeyQuery( + $key, + $this->getCustomTargetTitle( $key, $rootText ) + ), 'checkExists' => $userCanRead, 'weight' => $this->getNamespace( $key, 'weight' ), 'isActive' => false @@ -168,11 +207,18 @@ if ( $title->equals( $tabOptions['title'] ) ) { $tabOptions['isActive'] = true; } - $tabs[$key] = $this->makeTab( $this->getNamespace( $key, 'target' ), $this->getCustomTargetTitle( $key, $rootText, true ), $tabOptions ); + $tabs[$key] = $this->makeTab( + $this->getNamespace( $key, 'target' ), + $this->getCustomTargetTitle( $key, $rootText, true ), + $tabOptions + ); unset( $tabOptions ); if ( isset( $tabs['talk'] ) ) { - if ( ( $tabs['subject']['title']->isMainPage() && $this->getNamespace( $key, 'inMainPage' ) && $this->getNamespace( $key, 'hideTalk' ) ) || $this->getNamespace( $key, 'hideTalk' ) + if ( ( + && $this->getNamespace( $key, 'inMainPage' ) + && $this->getNamespace( $key, 'hideTalk' ) ) + || $this->getNamespace( $key, 'hideTalk' ) ) { unset( $tabs['talk'] ); } @@ -187,7 +233,9 @@ $navigation = array(); // rebuild the navigation // get Subject&Talk IDs - list( $subjectTabId, $talkTabId ) = $this->getDefaultTabsIDs( $tabs['subject']['title'] ); + list( $subjectTabId, $talkTabId ) = $this->getDefaultTabsIDs( + $tabs['subject']['title'] + ); foreach ( $tabs as $key => $definition ) { $tabId = $key; // assign real IDs to default $navigation members @@ -196,7 +244,13 @@ } elseif ( $key === 'talk' ) { $tabId = $talkTabId; } - $navigation[$tabId] = $skinTemplate->tabAction( $definition['title'], $definition['messages'], $definition['isActive'], $definition['query'], $definition['checkExists'] ); + $navigation[$tabId] = $skinTemplate->tabAction( + $definition['title'], + $definition['messages'], + $definition['isActive'], + $definition['query'], + $definition['checkExists'] + ); // for subject/talk it's essential, otherwise MediaWiki will just ignore it $navigation[$tabId]['context'] = $key; } @@ -333,8 +387,8 @@ * @return string */ private function getRootTitle( $title, $namespace ) { - if ( isset( $this->_namespacesSubjectPattern[$namespace] ) ) { - foreach ( $this->_namespacesSubjectPattern[$namespace] as $pattern ) { + if ( isset( $this->namespacesSubjectPattern[$namespace] ) ) { + foreach ( $this->namespacesSubjectPattern[$namespace] as $pattern ) { $title = preg_replace( $pattern, '$1', $title ); } } @@ -389,10 +443,12 @@ * @return array|mixed */ private function getNamespace( $key, $param = null, $default = null ) { - if ( is_null( $param ) && isset( $this->_namespaces[$key] ) ) { - return $this->_namespaces[$key]; - } elseif ( isset( $this->_namespaces[$key][$param] ) && !is_null( $this->_namespaces[$key][$param] ) ) { - return $this->_namespaces[$key][$param]; + if ( is_null( $param ) && isset( $this->namespaces[$key] ) ) { + return $this->namespaces[$key]; + } elseif ( isset( $this->namespaces[$key][$param] ) + && !is_null( $this->namespaces[$key][$param] ) + ) { + return $this->namespaces[$key][$param]; } else { return $default; } @@ -409,9 +465,9 @@ */ private function setNamespace( $key, $param = null, $value = null ) { if ( is_null( $param ) && !is_null( $value ) ) { - $this->_namespaces[$key] = $value; + $this->namespaces[$key] = $value; } elseif ( !is_null( $param ) && !is_null( $value ) ) { - $this->_namespaces[$key][$param] = $value; + $this->namespaces[$key][$param] = $value; } return $this; @@ -427,7 +483,7 @@ */ private function addToNamespace( $ns, $key ) { if ( MWNamespace::exists( $ns ) ) { - $this->_namespacesToNamespace[$ns][] = $key; + $this->namespacesToNamespace[$ns][] = $key; } else { throw new MWException( "Namespace doesn't exist." ); } @@ -443,7 +499,7 @@ */ private function addToTarget( $ns, $key ) { if ( MWNamespace::exists( $ns ) ) { - $this->_namespacesToTarget[$ns] = $key; + $this->namespacesToTarget[$ns] = $key; } else { throw new MWException( "Namespace doesn't exist." ); } @@ -457,8 +513,8 @@ * @return int */ private function generateWeight( $increment = self::WEIGHT_INCREMENT ) { - $this->_currentWeight += $increment; + $this->currentWeight += $increment; - return $this->_currentWeight; + return $this->currentWeight; } } -- To view, visit https://gerrit.wikimedia.org/r/356863 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iee14f8b8b58ad8ccf4e4f53892f7949030e196df Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/NamespaceRelations Gerrit-Branch: master Gerrit-Owner: Nemo bis <federicol...@tiscali.it> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits