Nikerabbit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/89509


Change subject: Refactorings
......................................................................

Refactorings

* Separate content generation to makeContent
* Make ProjectHandler non-static so that it can be replaced by another 
implementation

Change-Id: I9be6534e1234627c1b5a75e4f8968ba83ee76029
---
M ProjectHandler.php
M specials/SpecialTwnMainPage.php
2 files changed, 29 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TwnMainPage 
refs/changes/09/89509/1

diff --git a/ProjectHandler.php b/ProjectHandler.php
index 319229c..a08810c 100644
--- a/ProjectHandler.php
+++ b/ProjectHandler.php
@@ -4,11 +4,11 @@
  *
  * @file
  * @author Niklas Laxström
- * @license GPL2+
+ * @license GPL-2.0+
  */
 
 class ProjectHandler {
-       public static function getProjects() {
+       public function getProjects() {
                $projects = array();
                $groups = MessageGroups::getGroupStructure();
 
@@ -34,7 +34,7 @@
         * @param string $language Language code.
         * @param array $stats Message group stats.
         */
-       public static function sortByPriority( &$groups, $language, array 
$stats ) {
+       public function sortByPriority( &$groups, $language, array $stats ) {
                foreach ( $groups as $index => $g ) {
                        $supported = $g->getTranslatableLanguages();
                        if ( is_array( $supported ) && !isset( 
$supported[$language] ) ) {
diff --git a/specials/SpecialTwnMainPage.php b/specials/SpecialTwnMainPage.php
index 199ea47..fb6720b 100644
--- a/specials/SpecialTwnMainPage.php
+++ b/specials/SpecialTwnMainPage.php
@@ -22,6 +22,14 @@
                return $this->msg( 'twnmp-mainpage' )->text();
        }
 
+       protected function getProjectHandler() {
+               if ( !isset( $this->projectHandler ) ) {
+                       $this->projectHandler = new ProjectHandler();
+               }
+
+               return $this->projectHandler;
+       }
+
        public function execute( $parameters ) {
                $out = $this->getOutput();
                $skin = $this->getSkin();
@@ -52,6 +60,19 @@
                $out->addJsConfigVars( 'wgULSPosition', 'personal' );
 
                $out->addHTML( $out->headElement( $skin ) );
+
+               $this->makeContent();
+
+               // Enable this if you need useful debugging information
+               // $out->addHtml( MWDebug::getDebugHTML( $this->getContext() ) 
);
+               wfRunHooks( 'BeforePageDisplay', array( &$out, &$skin ) );
+               $out->addHTML( $skin->bottomScripts() );
+               $out->addHTML( '</body></html>' );
+       }
+
+       public function makeContent() {
+               $out = $this->getOutput();
+
                $out->addHTML( Html::openElement(
                        'div',
                        array( 'class' => 'grid twn-mainpage' )
@@ -62,11 +83,6 @@
                $out->addHTML( $this->projectSelector() );
                $out->addHTML( $this->footer() );
                $out->addHTML( Html::closeElement( 'div' ) ); // grid 
twn-mainpage
-               // Enable this if you need useful debugging information
-               // $out->addHtml( MWDebug::getDebugHTML( $this->getContext() ) 
);
-               wfRunHooks( 'BeforePageDisplay', array( &$out, &$skin ) );
-               $out->addHTML( $skin->bottomScripts() );
-               $out->addHTML( '</body></html>' );
        }
 
        public function header() {
@@ -169,11 +185,12 @@
                        )
                );
 
-               $projects = ProjectHandler::getProjects();
+               $handler = $this->getProjectHandler();
+               $projects = $handler->getProjects();
                $language = $this->getLanguage()->getCode();
                MessageGroupStats::setTimeLimit( 1 );
                $stats = MessageGroupStats::forLanguage( $language );
-               ProjectHandler::sortByPriority( $projects, $language, $stats );
+               $handler->sortByPriority( $projects, $language, $stats );
 
                $tiles = array();
 
@@ -355,7 +372,8 @@
 
        // Callback for CachedStat
        public static function getTwnStats() {
-               $projects = count( ProjectHandler::getProjects() );
+               $handler = $this->getProjectHandler();
+               $projects = count( $handler->getProjects() );
                $translators = SiteStats::numberingroup( 'translator' );
                $messages = count( MessageIndex::singleton()->retrieve() );
                $languages = self::numberOfLanguages( 180 );

-- 
To view, visit https://gerrit.wikimedia.org/r/89509
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9be6534e1234627c1b5a75e4f8968ba83ee76029
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TwnMainPage
Gerrit-Branch: master
Gerrit-Owner: Nikerabbit <niklas.laxst...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to