Cicalese has submitted this change and it was merged.

Change subject: made compatible with SemanticTitle
......................................................................


made compatible with SemanticTitle

Change-Id: I31d7ce562dd720269e31fcab584b629858eb8163
---
M TitleIcon.class.php
M TitleIcon.php
2 files changed, 93 insertions(+), 107 deletions(-)

Approvals:
  Cicalese: Verified; Looks good to me, approved



diff --git a/TitleIcon.class.php b/TitleIcon.class.php
index 8e3d06a..7cc75c6 100644
--- a/TitleIcon.class.php
+++ b/TitleIcon.class.php
@@ -26,50 +26,79 @@
 
        private static $m_already_invoked = false;
 
-       static function showIconInPageTitle(&$out, &$skin) {
+       public static function showIconInPageTitle(&$out, &$skin) {
+
                if (self::$m_already_invoked) {
                        return true;
                }
                self::$m_already_invoked = true;
-               $instance = new TitleIcon;
-               $instance->instanceShowIconInPageTitle($out, $skin);
-               return true;
-       }
 
-       static function showIconInSearchTitle(&$title, &$text, $result, $terms,
-               $page) {
-               $instance = new TitleIcon;
-               $text = $instance->getIconHTML($title) . 
$instance->getPageLink($title);
-               return true;
-       }
+               $iconhtml = self::getIconHTML($skin->getTitle());
 
-       private function instanceShowIconInPageTitle($out, $skin) {
-               $iconhtml = $this->getIconHTML($skin->getTitle());
                if (strlen($iconhtml) > 0) {
+
                        $iconhtml = strtr($iconhtml, array('"' => "'"));
-                       global $TitleIcon_UseDisplayTitle;
-                       if ($TitleIcon_UseDisplayTitle) {
-                               $title = $this->getPageTitle($skin->getTitle());
-                               $script =<<<END
-jQuery(document).ready(function() {
-       jQuery('#firstHeading').html("$iconhtml" + "$title");
-});
-END;
-                       } else {
-                               $script =<<<END
+
+                       $prefix = Html::openElement('table', array(
+                               'style' => 'border:none;'
+                       ));
+                       $prefix .= Html::openElement('tr');
+                       $prefix .= Html::openElement('td', array(
+                               'style' => 'border:none;'
+                       ));
+
+                       $middle = Html::closeElement('td');
+                       $middle .= Html::openElement('td', array(
+                               'style' => 'border:none;'
+                       ));
+
+                       $suffix = Html::closeElement('td');
+                       $suffix .= Html::closeElement('tr');
+                       $suffix .= Html::closeElement('table');
+
+                       $script =<<<END
 jQuery(document).ready(function() {
        var title = jQuery('#firstHeading').html();
-       jQuery('#firstHeading').html("$iconhtml" + title);
+       jQuery('#firstHeading').html('$prefix' + "$iconhtml" + '$middle' + 
title + '$suffix');
 });
 END;
-                       }
                        $script = Html::inlineScript($script);
                        $out->addScript($script);
                }
+
+               return true;
        }
 
-       private function getIconHTML($title) {
-               $icons = $this->getIcons($title);
+       public static function showIconInSearchTitle(&$title, &$text, $result,
+               $terms, $page) {
+
+               $pagelink = '[[' . $title->getPrefixedText() . ']]';
+               $pagelink = $GLOBALS['wgParser']->parse($pagelink,
+                       $GLOBALS['wgTitle'], new ParserOptions())->getText();
+               $pagelink = substr($pagelink, 3, strlen($pagelink) - 7);
+
+               $text = Html::openElement('table', array(
+                       'style' => 'border:none;'
+               ));
+               $text .= Html::openElement('tr');
+               $text .= Html::openElement('td', array(
+                       'style' => 'vertical-align:top;border:none;'
+               ));
+               $text .= self::getIconHTML($title);
+               $text .= Html::closeElement('td');
+               $text .= Html::openElement('td', array(
+                       'style' => 'vertical-align:top;border:none;'
+               ));
+               $text .= $pagelink;
+               $text .= Html::closeElement('td');
+               $text .= Html::closeElement('tr');
+               $text .= Html::closeElement('table');
+
+               return true;
+       }
+
+       private static function getIconHTML($title) {
+               $icons = self::getIcons($title);
                $iconhtml = "";
                foreach ($icons as $iconinfo) {
                        $page = $iconinfo["page"];
@@ -78,8 +107,7 @@
                        if ($imagefile !== false) {
                                $imageurl = $imagefile->getURL();
                                $pageurl = $page->getLinkURL();
-                               global $TitleIcon_UseFileNameAsToolTip;
-                               if ($TitleIcon_UseFileNameAsToolTip) {
+                               if ($GLOBALS['TitleIcon_UseFileNameAsToolTip']) 
{
                                        $tooltip = $icon;
                                        if (strpos($tooltip, '.' ) !==  false) {
                                                $tooltip = substr($tooltip, 0, 
strpos($tooltip, '.'));
@@ -100,7 +128,7 @@
                                                'title' => $tooltip)) .
                                        Html::element('img', array(
                                                'alt' => $tooltip,
-                                               'src' =>  $imageurl,
+                                               'src' => $imageurl,
                                                $dimension => '36')) .
                                        Html::closeElement('a') . "&nbsp;";
                        }
@@ -108,28 +136,9 @@
                return $iconhtml;
        }
 
-       private function getPageTitle($title) {
-               global $TitleIcon_UseDisplayTitle;
-               if ($TitleIcon_UseDisplayTitle) {
-                       $displaytitle = $this->queryPageDisplayTitle($title);
-                       if (strlen($displaytitle) != 0) {
-                               return $displaytitle;
-                       }
-               }
-               return $title->getPrefixedText();
-       }
-
-       private function getPageLink($pagetitle) {
-               $pageurl = $pagetitle->getLinkURL();
-               $title = $this->getPageTitle($pagetitle);
-               $pagelink = Html::element('a', array('href' => $pageurl,
-                       'title' => $title), $title) . '&nbsp;';
-               return $pagelink;
-       }
-
-       private function getIcons($title) {
+       private static function getIcons($title) {
                list($hide_page_title_icon, $hide_category_title_icon) =
-                       $this->queryHideTitleIcon($title);
+                       self::queryHideTitleIcon($title);
                $pages = array();
                if (!$hide_category_title_icon) {
                        $categories = $title->getParentCategories();
@@ -142,7 +151,7 @@
                }
                $icons = array();
                foreach ($pages as $page) {
-                       $discoveredIcons = $this->queryIconLinksOnPage($page);
+                       $discoveredIcons = self::queryIconLinksOnPage($page);
                        if ($discoveredIcons) {
                                foreach ($discoveredIcons as $icon) {
                                        $found = false;
@@ -164,26 +173,14 @@
                return $icons;
        }
 
-       private function queryIconLinksOnPage($title) {
-               global $TitleIcon_TitleIconPropertyName;
-               return $this->getPropertyValues($title,
-                       $TitleIcon_TitleIconPropertyName);
+       private static function queryIconLinksOnPage($title) {
+               return self::getPropertyValues($title,
+                       $GLOBALS['TitleIcon_TitleIconPropertyName']);
        }
 
-       private function queryPageDisplayTitle($title) {
-               global $TitleIcon_DisplayTitlePropertyName;
-               $result = $this->getPropertyValues($title,
-                       $TitleIcon_DisplayTitlePropertyName);
-               if (count($result) > 0) {
-                       return $result[0];
-               }
-               return "";
-       }
-
-       private function queryHideTitleIcon($title) {
-               global $TitleIcon_HideTitleIconPropertyName;
-               $result = $this->getPropertyValues($title,
-                       $TitleIcon_HideTitleIconPropertyName);
+       private static function queryHideTitleIcon($title) {
+               $result = self::getPropertyValues($title,
+                       $GLOBALS['TitleIcon_HideTitleIconPropertyName']);
                if (count($result) > 0) {
                        switch ($result[0]) {
                        case "page":
@@ -197,7 +194,7 @@
                return array(false, false);
        }
 
-       private function getPropertyValues($title, $propertyname) {
+       private static function getPropertyValues($title, $propertyname) {
                $store = smwfGetStore();
                $subject = SMWDIWikiPage::newFromTitle($title);
                $data = $store->getSemanticData($subject);
diff --git a/TitleIcon.php b/TitleIcon.php
index fbbad20..ea84d78 100644
--- a/TitleIcon.php
+++ b/TitleIcon.php
@@ -25,13 +25,13 @@
        die('<b>Error:</b> This file is part of a MediaWiki extension and 
cannot be run standalone.');
 }
 
-if (version_compare($wgVersion, '1.21', 'lt')) {
+if (version_compare($GLOBALS['wgVersion'], '1.21', 'lt')) {
        die('<b>Error:</b> This version of TitleIcon is only compatible with 
MediaWiki 1.21 or above.');
 }
 
-$wgExtensionCredits['semantic'][] = array (
+$GLOBALS['wgExtensionCredits']['semantic'][] = array (
        'name' => 'Title Icon',
-       'version' => '1.3',
+       'version' => '2.0',
        'author' => array(
                '[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]'
        ),
@@ -44,56 +44,45 @@
 // for the original idea that inspired this extension and to Keven Ring
 // for an early implementation of this extension.
 
-$wgAutoloadClasses['TitleIcon'] = __DIR__ . '/TitleIcon.class.php';
+$GLOBALS['wgAutoloadClasses']['TitleIcon'] = __DIR__ . '/TitleIcon.class.php';
 
-$wgMessagesDirs['TitleIcon'] = __DIR__ . '/i18n';
-$wgExtensionMessagesFiles['TitleIcon'] = __DIR__ . '/TitleIcon.i18n.php';
+$GLOBALS['wgMessagesDirs']['TitleIcon'] = __DIR__ . '/i18n';
+$GLOBALS['wgExtensionMessagesFiles']['TitleIcon'] =
+       __DIR__ . '/TitleIcon.i18n.php';
 
-$wgHooks['ParserFirstCallInit'][] = 'efTitleIconSetup';
+$GLOBALS['wgHooks']['ParserFirstCallInit'][] = 'efTitleIconSetup';
 
 function efTitleIconSetup (& $parser) {
-       global $TitleIcon_EnableIconInPageTitle;
-       if (!isset($TitleIcon_EnableIconInPageTitle)) {
-               $TitleIcon_EnableIconInPageTitle = true;
+
+       if (!isset($GLOBALS['TitleIcon_EnableIconInPageTitle'])) {
+               $GLOBALS['TitleIcon_EnableIconInPageTitle'] = true;
        }
 
-       global $TitleIcon_EnableIconInSearchTitle;
-       if (!isset($TitleIcon_EnableIconInSearchTitle)) {
-               $TitleIcon_EnableIconInSearchTitle = true;
+       if (!isset($GLOBALS['TitleIcon_EnableIconInSearchTitle'])) {
+               $GLOBALS['TitleIcon_EnableIconInSearchTitle'] = true;
        }
 
-       global $TitleIcon_UseFileNameAsToolTip;
-       if (!isset($TitleIcon_UseFileNameAsToolTip)) {
-               $TitleIcon_UseFileNameAsToolTip = true;
+       if (!isset($GLOBALS['TitleIcon_UseFileNameAsToolTip'])) {
+               $GLOBALS['TitleIcon_UseFileNameAsToolTip'] = true;
        }
 
-       global $TitleIcon_TitleIconPropertyName;
-       if (!isset($TitleIcon_TitleIconPropertyName)) {
-               $TitleIcon_TitleIconPropertyName = "Title Icon";
+       if (!isset($GLOBALS['TitleIcon_TitleIconPropertyName'])) {
+               $GLOBALS['TitleIcon_TitleIconPropertyName'] = "Title Icon";
        }
 
-       global $TitleIcon_HideTitleIconPropertyName;
-       if (!isset($TitleIcon_HideTitleIconPropertyName)) {
-               $TitleIcon_HideTitleIconPropertyName = "Hide Title Icon";
+       if (!isset($GLOBALS['TitleIcon_HideTitleIconPropertyName'])) {
+               $GLOBALS['TitleIcon_HideTitleIconPropertyName'] = "Hide Title 
Icon";
        }
 
-       global $TitleIcon_UseDisplayTitle;
-       if (!isset($TitleIcon_UseDisplayTitle)) {
-               $TitleIcon_UseDisplayTitle = false;
+       if ($GLOBALS['TitleIcon_EnableIconInPageTitle']) {
+               $GLOBALS['wgHooks']['BeforePageDisplay'][] =
+                       'TitleIcon::showIconInPageTitle';
        }
 
-       global $TitleIcon_DisplayTitlePropertyName;
-       if (!isset($TitleIcon_DisplayTitlePropertyName)) {
-               $TitleIcon_DisplayTitlePropertyName = "Display Title";
+       if ($GLOBALS['TitleIcon_EnableIconInSearchTitle']) {
+               $GLOBALS['wgHooks']['ShowSearchHitTitle'][] =
+                       'TitleIcon::showIconInSearchTitle';
        }
 
-       global $TitleIcon_EnableIconInPageTitle, 
$TitleIcon_EnableIconInSearchTitle,
-               $wgHooks;
-       if ($TitleIcon_EnableIconInPageTitle) {
-               $wgHooks['BeforePageDisplay'][] = 
'TitleIcon::showIconInPageTitle';
-       }
-       if ($TitleIcon_EnableIconInSearchTitle) {
-               $wgHooks['ShowSearchHitTitle'][] = 
'TitleIcon::showIconInSearchTitle';
-       }
        return true;
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I31d7ce562dd720269e31fcab584b629858eb8163
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/TitleIcon
Gerrit-Branch: master
Gerrit-Owner: Cicalese <cical...@mitre.org>
Gerrit-Reviewer: Cicalese <cical...@mitre.org>

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

Reply via email to