http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89231
Revision: 89231
Author: foxtrott
Date: 2011-05-31 22:00:15 +0000 (Tue, 31 May 2011)
Log Message:
-----------
followup r89188: markup style improved, generation of term/definition html
moved completely into Element, code formatting
Modified Paths:
--------------
trunk/extensions/SemanticGlossary/SemanticGlossary.php
trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php
trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
Modified: trunk/extensions/SemanticGlossary/SemanticGlossary.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-05-31
21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/SemanticGlossary.php 2011-05-31
22:00:15 UTC (rev 89231)
@@ -35,7 +35,7 @@
$wgExtensionCredits[defined( 'SEMANTIC_EXTENSION_TYPE' ) ? 'semantic' :
'other'][] = array(
'path' => __FILE__,
'name' => 'Semantic Glossary',
- 'author' => '[[mw:User:F.trott|Stephan Gambke]]',
+ 'author' => '[http://www.mediawiki.org/wiki/User:F.trott|Stephan
Gambke]',
'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Glossary',
'descriptionmsg' => 'semanticglossary-desc',
'version' => SG_VERSION,
@@ -62,7 +62,7 @@
$wgSpecialPageGroups['SemanticGlossaryBrowser'] = 'other';
// register hook handlers
-//$wgHooks['ParserFirstCallInit'][] = 'SemanticGlossarySetup'; // Define a
setup function
+// $wgHooks['ParserFirstCallInit'][] = 'SemanticGlossarySetup'; // Define a
setup function
$wgHooks['ParserAfterTidy'][] = 'SemanticGlossaryParser::parse';
$wgHooks['smwInitProperties'][] = 'SemanticGlossaryRegisterProperties';
@@ -71,16 +71,16 @@
// register resource modules with the Resource Loader
$wgResourceModules['ext.SemanticGlossary'] = array(
// JavaScript and CSS styles. To combine multiple file, just list them
as an array.
- //'scripts' => 'js/ext.myExtension.js',
+ // 'scripts' => 'js/ext.myExtension.js',
'styles' => 'css/SemanticGlossary.css',
// When your module is loaded, these messages will be available to
mediaWiki.msg()
- //'messages' => array( 'myextension-hello-world',
'myextension-goodbye-world' ),
+ // 'messages' => array( 'myextension-hello-world',
'myextension-goodbye-world' ),
// If your scripts need code from other modules, list their identifiers
as dependencies
// and ResourceLoader will make sure they're loaded before you.
// You don't need to manually list 'mediawiki' or 'jquery', which are
always loaded.
- //'dependencies' => array( 'jquery.ui.datepicker' ),
+ // 'dependencies' => array( 'jquery.ui.datepicker' ),
// ResourceLoader needs to know where your files are; specify your
// subdir relative to "extensions" or $wgExtensionAssetsPath
@@ -100,10 +100,10 @@
/**
* Handler for late setup of Semantic Glossary
*/
-//function SemanticGlossarySetup () {
+// function SemanticGlossarySetup () {
//
// return true;
-//}
+// }
define( 'SG_PROP_GLT', 'Glossary-Term' );
define( 'SG_PROP_GLD', 'Glossary-Definition' );
Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
2011-05-31 21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryBackend.php
2011-05-31 22:00:15 UTC (rev 89231)
@@ -2,7 +2,7 @@
/**
* File holding the SemanticGlossaryBackend class
- *
+ *
* @author Stephan Gambke
* @file
* @ingroup SemanticGlossary
Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
2011-05-31 21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryElement.php
2011-05-31 22:00:15 UTC (rev 89231)
@@ -26,9 +26,13 @@
private $mFullDefinition = null;
private $mDefinitions = array();
+ private $mTerm = null;
static private $mLinkTemplate = null;
- public function __construct( &$definition = null ) {
+ public function __construct( &$term, &$definition = null ) {
+
+ $this->mTerm = $term;
+
if ( $definition ) {
$this->addDefinition( $definition );
}
@@ -41,8 +45,22 @@
public function getFullDefinition( DOMDocument &$doc ) {
// only create if not yet created
if ( $this->mFullDefinition == null ||
$this->mFullDefinition->ownerDocument !== $doc ) {
- $this->mFullDefinition = $doc->createElement( 'span' );
+ // Wrap term and definition in <span> tags
+ $span = $doc->createElement( 'span' );
+ $span->setAttribute( 'class', 'tooltip' );
+
+ // Wrap term in <span> tag, hidden
+ $spanTerm = $doc->createElement( 'span', $this->mTerm );
+ $spanTerm->setAttribute( 'class', 'tooltip_abbr' );
+
+ // Wrap definition in two <span> tags
+ $spanDefinitionOuter = $doc->createElement( 'span' );
+ $spanDefinitionOuter->setAttribute( 'class',
'tooltip_tipwrapper' );
+
+ $spanDefinitionInner = $doc->createElement( 'span' );
+ $spanDefinitionInner->setAttribute( 'class',
'tooltip_tip' );
+
foreach ( $this->mDefinitions as $definition ) {
$element = $doc->createElement( 'span',
htmlentities( $definition[self::SG_DEFINITION], ENT_COMPAT, 'UTF-8' ) . ' ' );
if ( $definition[self::SG_LINK] ) {
@@ -53,8 +71,16 @@
$element->appendChild( $link );
}
}
- $this->mFullDefinition->appendChild( $element );
+ $spanDefinitionInner->appendChild( $element );
}
+
+ // insert term and definition
+ $span->appendChild( $spanTerm );
+ $span->appendChild( $spanDefinitionOuter );
+ $spanDefinitionOuter->appendChild( $spanDefinitionInner
);
+
+ $this->mFullDefinition = $span;
+
}
return $this->mFullDefinition->cloneNode( true );
Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
2011-05-31 21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryParser.php
2011-05-31 22:00:15 UTC (rev 89231)
@@ -17,7 +17,7 @@
* terms.
*
* Contains a static function to initiate the parsing.
- *
+ *
* @ingroup SemanticGlossary
*/
class SemanticGlossaryParser {
@@ -32,21 +32,21 @@
* @param $text
* @return Boolean
*/
- static function parse ( &$parser, &$text ) {
+ static function parse( &$parser, &$text ) {
wfProfileIn( __METHOD__ );
if ( !self::$parserSingleton ) {
self::$parserSingleton = new SemanticGlossaryParser();
}
- self::$parserSingleton -> realParse( $parser, $text );
+ self::$parserSingleton->realParse( $parser, $text );
wfProfileOut( __METHOD__ );
return true;
}
- function getBackend () {
+ function getBackend() {
return new SemanticGlossaryBackend();
}
@@ -55,17 +55,17 @@
*
* @return Array an array mapping terms (keys) to descriptions (values)
*/
- function getGlossaryArray ( SemanticGlossaryMessageLog &$messages =
null ) {
+ function getGlossaryArray( SemanticGlossaryMessageLog &$messages = null
) {
wfProfileIn( __METHOD__ );
// build glossary array only once per request
- if ( !$this -> mGlossaryArray ) {
- $this -> buildGlossary( $messages );
+ if ( !$this->mGlossaryArray ) {
+ $this->buildGlossary( $messages );
}
wfProfileOut( __METHOD__ );
- return $this -> mGlossaryArray;
+ return $this->mGlossaryArray;
}
/**
@@ -73,44 +73,44 @@
*
* @return Array an array mapping terms (keys) to descriptions (values)
*/
- function getGlossaryTree ( SemanticGlossaryMessageLog &$messages = null
) {
+ function getGlossaryTree( SemanticGlossaryMessageLog &$messages = null
) {
wfProfileIn( __METHOD__ );
// build glossary array only once per request
- if ( !$this -> mGlossaryTree ) {
- $this -> buildGlossary( $messages );
+ if ( !$this->mGlossaryTree ) {
+ $this->buildGlossary( $messages );
}
wfProfileOut( __METHOD__ );
- return $this -> mGlossaryTree;
+ return $this->mGlossaryTree;
}
- protected function buildGlossary ( SemanticGlossaryMessageLog
&$messages = null ) {
+ protected function buildGlossary( SemanticGlossaryMessageLog &$messages
= null ) {
wfProfileIn( __METHOD__ );
- $this -> mGlossaryTree = new SemanticGlossaryTree();
+ $this->mGlossaryTree = new SemanticGlossaryTree();
- $backend = $this -> getBackEnd();
+ $backend = $this->getBackEnd();
// assemble the result array
- $this -> mGlossaryArray = array( );
- while ( $backend -> next() ) {
+ $this->mGlossaryArray = array();
+ while ( $backend->next() ) {
$elementData = array(
- SemanticGlossaryElement::SG_TERM => ($term =
$backend -> getTerm()),
- SemanticGlossaryElement::SG_DEFINITION =>
$backend -> getDefinition(),
- SemanticGlossaryElement::SG_LINK => $backend ->
getLink(),
- SemanticGlossaryElement::SG_SOURCE => $backend
-> getSource()
+ SemanticGlossaryElement::SG_TERM => ( $term =
$backend->getTerm() ),
+ SemanticGlossaryElement::SG_DEFINITION =>
$backend->getDefinition(),
+ SemanticGlossaryElement::SG_LINK =>
$backend->getLink(),
+ SemanticGlossaryElement::SG_SOURCE =>
$backend->getSource()
);
- if ( array_key_exists( $term, $this -> mGlossaryArray )
) {
- $this -> mGlossaryArray[ $term ] ->
addDefinition( $elementData );
+ if ( array_key_exists( $term, $this->mGlossaryArray ) )
{
+ $this->mGlossaryArray[$term]->addDefinition(
$elementData );
} else {
- $this -> mGlossaryArray[ $term ] = new
SemanticGlossaryElement( $elementData );
+ $this->mGlossaryArray[$term] = new
SemanticGlossaryElement( $term, $elementData );
}
- $this -> mGlossaryTree -> addTerm( $term, $elementData
);
+ $this->mGlossaryTree->addTerm( $term, $elementData );
}
wfProfileOut( __METHOD__ );
@@ -125,18 +125,18 @@
* @param $text
* @return Boolean
*/
- protected function realParse ( &$parser, &$text ) {
+ protected function realParse( &$parser, &$text ) {
global $wgRequest;
wfProfileIn( __METHOD__ );
- $action = $wgRequest -> getVal( 'action', 'view' );
+ $action = $wgRequest->getVal( 'action', 'view' );
if ( $text == null ||
$text == '' ||
$action == 'edit' ||
$action == 'ajax' ||
- isset( $_POST[ 'wpPreview' ] )
+ isset( $_POST['wpPreview'] )
) {
wfProfileOut( __METHOD__ );
@@ -144,7 +144,7 @@
}
// Get array of terms
- $glossary = $this -> getGlossaryTree();
+ $glossary = $this->getGlossaryTree();
if ( $glossary == null ) {
wfProfileOut( __METHOD__ );
@@ -166,84 +166,63 @@
wfProfileIn( __METHOD__ . ' 2 xpath' );
// Find all text in HTML.
$xpath = new DOMXpath( $doc );
- $elements = $xpath -> query(
+ $elements = $xpath->query(
"//*[not(ancestor-or-self::*[@class='noglossary'] or
ancestor-or-self::a)][text()!=' ']/text()"
);
wfProfileOut( __METHOD__ . ' 2 xpath' );
// Iterate all HTML text matches
- $nb = $elements -> length;
+ $nb = $elements->length;
$changedDoc = false;
for ( $pos = 0; $pos < $nb; $pos++ ) {
- $el = $elements -> item( $pos );
+ $el = $elements->item( $pos );
- if ( strlen( $el -> nodeValue ) < $glossary ->
getMinTermLength() ) {
+ if ( strlen( $el->nodeValue ) <
$glossary->getMinTermLength() ) {
continue;
}
wfProfileIn( __METHOD__ . ' 3 lexer' );
- $matches = array( );
+ $matches = array();
preg_match_all(
'/[[:alpha:]]+|[^[:alpha:]]/u',
- $el -> nodeValue,
+ $el->nodeValue,
$matches,
PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER
);
wfProfileOut( __METHOD__ . ' 3 lexer' );
- if ( count( $matches ) == 0 || count( $matches[ 0 ] )
== 0 ) {
+ if ( count( $matches ) == 0 || count( $matches[0] ) ==
0 ) {
continue;
}
- $lexemes = &$matches[ 0 ];
+ $lexemes = &$matches[0];
$countLexemes = count( $lexemes );
- $parent = &$el -> parentNode;
+ $parent = &$el->parentNode;
$index = 0;
$changedElem = false;
while ( $index < $countLexemes ) {
wfProfileIn( __METHOD__ . ' 4 findNextTerm' );
- list( $skipped, $used, $definition ) =
$glossary -> findNextTerm( $lexemes, $index, $countLexemes );
+ list( $skipped, $used, $definition ) =
+ $glossary->findNextTerm( $lexemes,
$index, $countLexemes );
wfProfileOut( __METHOD__ . ' 4 findNextTerm' );
wfProfileIn( __METHOD__ . ' 5 insert' );
if ( $used > 0 ) { // found a term
if ( $skipped > 0 ) { // skipped some
text, insert it as is
- $parent -> insertBefore(
- $doc -> createTextNode(
- substr( $el ->
nodeValue,
-
$currLexIndex = $lexemes[ $index ][ 1 ],
-
$lexemes[ $index + $skipped ][ 1 ] - $currLexIndex )
+ $parent->insertBefore(
+ $doc->createTextNode(
+ substr(
$el->nodeValue,
+
$currLexIndex = $lexemes[$index][1],
+
$lexemes[$index + $skipped][1] - $currLexIndex )
),
$el
);
}
- $index += $skipped;
+ $parent->insertBefore(
$definition->getFullDefinition( $doc ), $el );
- // Wrap abbreviation in <span> tags
- $span = $doc -> createElement( 'span' );
- $span -> setAttribute( 'class',
'tooltip' );
-
- // Wrap abbreviation in <span> tags,
hidden
- $lastLex = $lexemes[ $index + $used - 1
];
- $spanTerm = $doc -> createElement(
'span',
- substr( $el ->
nodeValue,
- $currLexIndex =
$lexemes[ $index ][ 1 ],
- $lastLex[ 1 ] -
$currLexIndex + strlen( $lastLex[ 0 ] ) )
- );
- $spanTerm -> setAttribute( 'class',
'tooltip_abbr' );
-
- // Wrap definition in <span> tags,
hidden
- $spanDefinition = $definition ->
getFullDefinition( $doc );
- $spanDefinition -> setAttribute(
'class', 'tooltip_tip' );
-
- // insert term and definition
- $span -> appendChild( $spanTerm );
- $span -> appendChild( $spanDefinition );
- $parent -> insertBefore( $span, $el );
-
$changedElem = true;
} else { // did not find term, just use the
rest of the text
// If we found no term now and no term
before, there was no
@@ -251,9 +230,9 @@
// element at all.
// Only change element if found term
before
if ( $changedElem ) {
- $parent -> insertBefore(
- $doc -> createTextNode(
- substr( $el ->
nodeValue, $lexemes[ $index ][ 1 ] )
+ $parent->insertBefore(
+ $doc->createTextNode(
+ substr(
$el->nodeValue, $lexemes[$index][1] )
),
$el
);
@@ -263,30 +242,27 @@
// anyway. Might save a bit of
time.
break;
}
-
- $index += $skipped;
}
wfProfileOut( __METHOD__ . ' 5 insert' );
-
- $index += $used;
+ $index += $used + $skipped;
}
if ( $changedElem ) {
- $parent -> removeChild( $el );
+ $parent->removeChild( $el );
$changedDoc = true;
}
}
if ( $changedDoc ) {
- $body = $xpath -> query( '/html/body' );
+ $body = $xpath->query( '/html/body' );
$text = '';
- foreach ( $body -> item( 0 ) -> childNodes as $child ) {
- $text .= $doc -> saveXML( $child );
+ foreach ( $body->item( 0 )->childNodes as $child ) {
+ $text .= $doc->saveXML( $child );
}
- $this -> loadModules( $parser );
+ $this->loadModules( $parser );
}
wfProfileOut( __METHOD__ );
@@ -294,20 +270,20 @@
return true;
}
- protected function loadModules ( &$parser ) {
+ protected function loadModules( &$parser ) {
global $wgOut, $wgScriptPath;
if ( defined( 'MW_SUPPORTS_RESOURCE_MODULES' ) ) {
if ( !is_null( $parser ) ) {
- $parser -> getOutput() -> addModules(
'ext.SemanticGlossary' );
+ $parser->getOutput()->addModules(
'ext.SemanticGlossary' );
} else {
- $wgOut -> addModules( 'ext.SemanticGlossary' );
+ $wgOut->addModules( 'ext.SemanticGlossary' );
}
} else {
- if ( !is_null( $parser ) && ( $wgOut -> isArticle() ) )
{
- $parser -> getOutput() -> addHeadItem( '<link
rel="stylesheet" href="' . $wgScriptPath .
'/extensions/SemanticGlossary/skins/SemanticGlossary.css" />',
'ext.SemanticGlossary.css' );
+ if ( !is_null( $parser ) && ( $wgOut->isArticle() ) ) {
+ $parser->getOutput()->addHeadItem( '<link
rel="stylesheet" href="' . $wgScriptPath .
'/extensions/SemanticGlossary/skins/SemanticGlossary.css" />',
'ext.SemanticGlossary.css' );
} else {
- $wgOut -> addHeadItem(
'ext.SemanticGlossary.css', '<link rel="stylesheet" href="' . $wgScriptPath .
'/extensions/SemanticGlossary/skins/SemanticGlossary.css" />' );
+ $wgOut->addHeadItem(
'ext.SemanticGlossary.css', '<link rel="stylesheet" href="' . $wgScriptPath .
'/extensions/SemanticGlossary/skins/SemanticGlossary.css" />' );
}
}
}
Modified: trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php
===================================================================
--- trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php 2011-05-31
21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/SemanticGlossaryTree.php 2011-05-31
22:00:15 UTC (rev 89231)
@@ -2,7 +2,7 @@
/**
* File holding the SemanticGlossaryTree class
- *
+ *
* @author Stephan Gambke
* @file
* @ingroup SemanticGlossary
@@ -40,7 +40,7 @@
$matches;
preg_match_all( '/[[:alpha:]]+|[^[:alpha:]]/u', $term, $matches
);
- $this->addElement( $matches[0], $definition );
+ $this->addElement( $matches[0], $term, $definition );
if ( $this->mMinLength > -1 ) {
$this->mMinLength = min( array( $this->mMinLength,
strlen( $term ) ) );
@@ -55,10 +55,10 @@
* @param array $path
* @param <type> $index
*/
- protected function addElement( Array &$path, &$definition ) {
+ protected function addElement( Array &$path, &$term, &$definition ) {
// end of path, store description; end of recursion
if ( $path == null ) {
- $this -> addDefinition( $definition );
+ $this -> addDefinition( $term, $definition );
} else {
$step = array_shift( $path );
@@ -66,7 +66,7 @@
$this->mTree[$step] = new
SemanticGlossaryTree();
}
- $this->mTree[$step]->addElement( $path, $definition );
+ $this->mTree[$step]->addElement( $path, $term,
$definition );
}
}
@@ -74,11 +74,11 @@
* Adds a defintion to the treenodes list of definitions
* @param <type> $definition
*/
- protected function addDefinition( &$definition ) {
+ protected function addDefinition( &$term, &$definition ) {
if ( $this->mDefinition ) {
$this->mDefinition->addDefinition( $definition );
} else {
- $this->mDefinition = new SemanticGlossaryElement(
$definition );
+ $this->mDefinition = new SemanticGlossaryElement(
$term, $definition );
}
}
@@ -95,7 +95,7 @@
// skip until ther start of a term is found
while ( $index < $countLexemes && !$definition ) {
$currLex = &$lexemes[$index][0];
-
+
// Did we find the start of a term?
if ( array_key_exists( $currLex, $this->mTree ) ) {
list( $lastindex, $definition ) =
$this->mTree[$currLex]->findNextTermNoSkip( $lexemes, $index, $countLexemes );
Modified: trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
===================================================================
--- trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
2011-05-31 21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/SpecialSemanticGlossaryBrowser.php
2011-05-31 22:00:15 UTC (rev 89231)
@@ -461,7 +461,7 @@
/**
* Checks if the user wants to perform an action, has the necessary
right
* and submitted a valid edit token.
- *
+ *
* @return Boolean
*/
private function isActionAllowed() {
Modified: trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
===================================================================
--- trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
2011-05-31 21:52:39 UTC (rev 89230)
+++ trunk/extensions/SemanticGlossary/skins/SemanticGlossary.css
2011-05-31 22:00:15 UTC (rev 89231)
@@ -4,7 +4,7 @@
.tooltip {
display: inline;
- position: static;
+ position: relative;
cursor: help;
}
@@ -12,28 +12,44 @@
border-bottom: 1px dotted #bbf;
}
-.tooltip_tip {
+.tooltip_tipwrapper {
display: none;
- border: 1px solid gray;
- background-color: white;
- padding: 0.1em 0.2em 0.1em 0.1em;
+ position: absolute;
+ top: 0;
+ left: 0;
+
+ padding: 1.5em 0 0 2em;
+ width: 20em;
+
+ z-index: 2;
+}
+
+.tooltip_tip {
+ display: block;
+
+ position: relative;
+ top: 0em;
+ left: 0em;
+
+ background-color: #F9F9F9;
+ padding: 0.5em;
margin: 0;
line-height: 1.2em;
- position: absolute;
- top: 1.1em;
- left: 1em;
+ border: 1px solid #aaa;
+
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+
+ -webkit-box-shadow: 3px 3px 3px #888;
+ box-shadow: 3px 3px 3px #888;
}
.tooltip_tip span {
display: block;
}
-.tooltip:hover {
- position: relative;
-}
-
-.tooltip:hover .tooltip_tip {
+.tooltip:hover .tooltip_tipwrapper {
display: block;
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs