r87289 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87288‎ | r87289 | r87290 >
Date:20:02, 2 May 2011
Author:preilly
Status:deferred
Tags:
Comment:
Handle red links with action equal to edit
Modified paths:
  • /trunk/extensions/PatchOutputMobile/PatchOutputMobile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PatchOutputMobile/PatchOutputMobile.php
@@ -1,12 +1,12 @@
22 <?php
33
4 -# Needs to be called within MediaWiki; not standalone
 4+// Needs to be called within MediaWiki; not standalone
55 if ( !defined( 'MEDIAWIKI' ) ) {
66 echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
77 die( -1 );
88 }
99
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
1111 define( 'PATCHOUTPUTMOBILE', 'PatchOutputMobile' );
1212
1313 // Extension credits that will show up on Special:Version
@@ -24,7 +24,7 @@
2525 'onOutputPageBeforeHTML' );
2626
2727 class ExtPatchOutputMobile {
28 - const VERSION = '0.2.1';
 28+ const VERSION = '0.2.2';
2929
3030 private $doc;
3131
@@ -112,14 +112,10 @@
113113 }
114114
115115 public function parse( $s ) {
116 - // foreach( self::$mTable as $from => $to ) {
117 - // $s =& str_replace( $from, $to, $s );
118 - // }
119 -
120116 return $this->DOMParse( $s );
121117 }
122118
123 - private function parse_items_to_remove() {
 119+ private function _parse_items_to_remove() {
124120 $item_to_remove_records = array();
125121
126122 foreach ( $this->items_to_remove as $item_to_remove ) {
@@ -139,7 +135,7 @@
140136 $this->doc->preserveWhiteSpace = false;
141137 $this->doc->strictErrorChecking = false;
142138
143 - $item_to_remove_records = $this->parse_items_to_remove();
 139+ $item_to_remove_records = $this->_parse_items_to_remove();
144140
145141 // Tags
146142
@@ -199,7 +195,23 @@
200196 $removed_element = $element->parentNode->removeChild( $element );
201197 }
202198 }
 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( "&", "&amp;", $redlink->nodeValue ) );
203205
 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+
204216 $content = $this->doc->getElementById( 'content' );
205217
206218 $content_html = $this->doc->saveXML( $content, LIBXML_NOEMPTYTAG );

Status & tagging log