r84966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84965‎ | r84966 | r84967 >
Date:16:26, 29 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added word wrap
Modified paths:
  • /trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticResultFormats/GraphViz/SRF_Graph.php
@@ -162,7 +162,7 @@
163163 $isName = $this->m_nameProperty ? ( $i != 0 && $this->m_nameProperty === $propName ) : $i == 0;
164164
165165 if ( $isName ) {
166 - $name = $object->getShortText( $outputmode );
 166+ $name = $this->getWordWrappedText( $object->getShortText( $outputmode ), 20 );
167167 }
168168
169169 if ( !( $this->m_nameProperty && $i == 0 ) ) {
@@ -194,7 +194,11 @@
195195 if ( $this->m_graphLink ) {
196196 $nodeLinkTitle = Title::newFromText( $text );
197197 $nodeLinkURL = $nodeLinkTitle->getLocalURL();
198 -
 198+ }
 199+
 200+ $text = $this->getWordWrappedText( $text, 20 );
 201+
 202+ if ( $this->m_graphLink ) {
199203 $graphInput .= " \"$text\" [URL = \"$nodeLinkURL\"]; ";
200204 }
201205
@@ -230,6 +234,37 @@
231235 }
232236
233237 /**
 238+ * Returns the word wrapped version of the provided text.
 239+ *
 240+ * @param string $text
 241+ * @param integer $charLimit
 242+ *
 243+ * @return string
 244+ */
 245+ protected function getWordWrappedText( $text, $charLimit ) {
 246+ $segments = array();
 247+
 248+ while ( strlen( $text ) > $charLimit ) {
 249+ $splitPosition = strrpos( substr( $text, 0, $charLimit ), ' ' );
 250+
 251+ if ( $splitPosition === false ) {
 252+ $splitPosition = strpos( $text, ' ' );
 253+
 254+ if ( $splitPosition === false ) {
 255+ $splitPosition = strlen( $text );
 256+ }
 257+ }
 258+
 259+ $segments[] = substr( $text, 0, $splitPosition );
 260+ $text = substr( $text, $splitPosition );
 261+ }
 262+
 263+ $segments[] = $text;
 264+
 265+ return implode( '\n', $segments );
 266+ }
 267+
 268+ /**
234269 * (non-PHPdoc)
235270 * @see SMWResultPrinter::getName()
236271 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r84967follow up to r84966jeroendedauw16:34, 29 March 2011

Status & tagging log