Index: trunk/extensions/Maps/Services/Maps_MappingService.php |
— | — | @@ -45,6 +45,8 @@ |
46 | 46 | */ |
47 | 47 | private $mAddedDependencies = array(); |
48 | 48 | |
| 49 | + private $mDependencies = array(); |
| 50 | + |
49 | 51 | /** |
50 | 52 | * Constructor. Creates a new instance of MapsMappingService. |
51 | 53 | * |
— | — | @@ -95,7 +97,26 @@ |
96 | 98 | * @param mixed $parserOrOut |
97 | 99 | */ |
98 | 100 | public final function addDependencies( &$parserOrOut ) { |
99 | | - $allDependencies = $this->getDependencies(); |
| 101 | + $dependencies = $this->getDependencyHtml(); |
| 102 | + |
| 103 | + // Only aff a head item when there are dependencies. |
| 104 | + if ( $dependencies ) { |
| 105 | + if ( $parserOrOut instanceof Parser ) { |
| 106 | + $parserOrOut->getOutput()->addHeadItem( $dependencies ); |
| 107 | + } |
| 108 | + else if ( $parserOrOut instanceof OutputPage ) { |
| 109 | + $parserOrOut->addHeadItem( md5( $dependencies ), $dependencies ); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Returns the html for the needed dependencies or false. |
| 116 | + * |
| 117 | + * @return mixed Steing or false |
| 118 | + */ |
| 119 | + public final function getDependencyHtml() { |
| 120 | + $allDependencies = array_merge( $this->getDependencies(), $this->mDependencies ); |
100 | 121 | $dependencies = array(); |
101 | 122 | |
102 | 123 | // Only add dependnecies that have not yet been added. |
— | — | @@ -106,20 +127,21 @@ |
107 | 128 | } |
108 | 129 | } |
109 | 130 | |
110 | | - // If there are dependencies, put them all together in a string and add them to the header. |
111 | | - if ( count( $dependencies ) > 0 ) { |
112 | | - $dependencies = implode( '', $dependencies ); |
113 | | - |
114 | | - if ( $parserOrOut instanceof Parser ) { |
115 | | - $parserOrOut->getOutput()->addHeadItem( $dependencies ); |
116 | | - } |
117 | | - else if ( $parserOrOut instanceof OutputPage ) { |
118 | | - $parserOrOut->addHeadItem( md5($dependencies), $dependencies ); |
119 | | - } |
120 | | - } |
| 131 | + // If there are dependencies, put them all together in a string, otherwise return false. |
| 132 | + return count( $dependencies ) > 0 ? implode( '', $dependencies ) : false; |
121 | 133 | } |
122 | 134 | |
123 | 135 | /** |
| 136 | + * Adds a dependency that is needed for this service. It will be passed along with the next |
| 137 | + * call to getDependencyHtml or addDependencies. |
| 138 | + * |
| 139 | + * @param string $dependencyHtml |
| 140 | + */ |
| 141 | + public final function addDependency( $dependencyHtml ) { |
| 142 | + $this->mDependencies[] = $dependencyHtml; |
| 143 | + } |
| 144 | + |
| 145 | + /** |
124 | 146 | * Returns a list of html fragments, such as script includes, the current service depends on. |
125 | 147 | * |
126 | 148 | * @return array |