Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php |
— | — | @@ -1,12 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -# Needs to be called within MediaWiki; not standalone |
| 4 | +// Needs to be called within MediaWiki; not standalone |
5 | 5 | if ( !defined( 'MEDIAWIKI' ) ) { |
6 | 6 | echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); |
7 | 7 | die( -1 ); |
8 | 8 | } |
9 | 9 | |
10 | | -# Define the extension; allows us make sure the extension is used correctly |
| 10 | +// Define the extension; allows us make sure the extension is used correctly |
11 | 11 | define( 'PATCHOUTPUTMOBILE', 'PatchOutputMobile' ); |
12 | 12 | |
13 | 13 | // Extension credits that will show up on Special:Version |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | 'onOutputPageBeforeHTML' ); |
26 | 26 | |
27 | 27 | class ExtPatchOutputMobile { |
28 | | - const VERSION = '0.2.1'; |
| 28 | + const VERSION = '0.2.2'; |
29 | 29 | |
30 | 30 | private $doc; |
31 | 31 | |
— | — | @@ -112,14 +112,10 @@ |
113 | 113 | } |
114 | 114 | |
115 | 115 | public function parse( $s ) { |
116 | | - // foreach( self::$mTable as $from => $to ) { |
117 | | - // $s =& str_replace( $from, $to, $s ); |
118 | | - // } |
119 | | - |
120 | 116 | return $this->DOMParse( $s ); |
121 | 117 | } |
122 | 118 | |
123 | | - private function parse_items_to_remove() { |
| 119 | + private function _parse_items_to_remove() { |
124 | 120 | $item_to_remove_records = array(); |
125 | 121 | |
126 | 122 | foreach ( $this->items_to_remove as $item_to_remove ) { |
— | — | @@ -139,7 +135,7 @@ |
140 | 136 | $this->doc->preserveWhiteSpace = false; |
141 | 137 | $this->doc->strictErrorChecking = false; |
142 | 138 | |
143 | | - $item_to_remove_records = $this->parse_items_to_remove(); |
| 139 | + $item_to_remove_records = $this->_parse_items_to_remove(); |
144 | 140 | |
145 | 141 | // Tags |
146 | 142 | |
— | — | @@ -199,7 +195,23 @@ |
200 | 196 | $removed_element = $element->parentNode->removeChild( $element ); |
201 | 197 | } |
202 | 198 | } |
| 199 | + |
| 200 | + // Handle red links with action equal to edit |
| 201 | + $redlinks = $xpath->query( '//a[@class="new"]' ); |
| 202 | + foreach( $redlinks as $redlink ) { |
| 203 | + //PHP Bug #36795 — Inappropriate "unterminated entity reference" |
| 204 | + $spannode = $this->doc->createElement( "span", str_replace( "&", "&", $redlink->nodeValue ) ); |
203 | 205 | |
| 206 | + if ( $redlink->hasAttributes() ) { |
| 207 | + $attributes = $redlink->attributes; |
| 208 | + foreach ( $attributes as $i => $attribute ) { |
| 209 | + $spannode->setAttribute( $attribute->name, $attribute->value ); |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + $redlink->parentNode->replaceChild( $spannode, $redlink ); |
| 214 | + } |
| 215 | + |
204 | 216 | $content = $this->doc->getElementById( 'content' ); |
205 | 217 | |
206 | 218 | $content_html = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG ); |