r62430 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62429‎ | r62430 | r62431 >
Date:14:27, 13 February 2010
Author:siebrand
Status:deferred
Tags:
Comment:
Update code formatting, run stylize.php, whitespace updates
Modified paths:
  • /trunk/extensions/ActiveAbstract/AbstractFilter.php (modified) (history)
  • /trunk/extensions/ActiveAbstract/GoogleCoopFilter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ActiveAbstract/AbstractFilter.php
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * Generate XML feed for Yahoo's Active Abstracts project
65 * Plugin for dumpBackup.php; call as eg:
@@ -29,60 +28,60 @@
3029 $dumper->registerFilter( 'abstract', 'AbstractFilter' );
3130 $dumper->registerFilter( 'noredirect', 'NoredirectFilter' );
3231 }
33 -
34 - function AbstractFilter( &$sink, $params='' ) {
 32+
 33+ function AbstractFilter( &$sink, $params = '' ) {
3534 $this->sink =& $sink;
36 -
 35+
3736 $bits = explode( '=', $params, 2 );
38 - if( count( $bits ) == 2 && $bits[0] == 'variant' ) {
 37+ if ( count( $bits ) == 2 && $bits[0] == 'variant' ) {
3938 $this->variant = $bits[1];
4039 } else {
4140 $this->variant = false;
4241 }
4342 }
44 -
 43+
4544 function writeOpenStream( $string ) {
4645 $this->sink->writeOpenStream( "<feed>\n" );
4746 }
48 -
 47+
4948 function writeCloseStream( $string ) {
5049 $this->sink->writeCloseStream( "</feed>\n" );
5150 }
52 -
 51+
5352 function writeOpenPage( $page, $string ) {
5453 global $wgSitename;
5554 $this->title = Title::makeTitle( $page->page_namespace, $page->page_title );
5655 $title = $wgSitename . wfMsg( 'colon-separator' ) . $this->title->getPrefixedText();
57 -
 56+
5857 $xml = "<doc>\n";
5958 $xml .= Xml::element( 'title', null, $this->_variant( $title ) ) . "\n";
6059 $xml .= Xml::element( 'url', null, $this->title->getFullUrl() ) . "\n";
61 -
 60+
6261 // add abstract and links when we have revision data...
6362 $this->revision = null;
64 -
 63+
6564 $this->sink->writeOpenPage( $page, $xml );
6665 }
67 -
 66+
6867 function writeClosePage( $string ) {
6968 $xml = '';
70 - if( $this->revision ) {
 69+ if ( $this->revision ) {
7170 $xml .= Xml::element( 'abstract', null,
7271 $this->_variant(
7372 $this->_abstract( $this->revision ) ) ) . "\n";
7473 $xml .= "<links>\n";
75 -
 74+
7675 $links = $this->_sectionLinks( $this->revision );
77 - if( empty( $links ) ) {
 76+ if ( empty( $links ) ) {
7877 // If no TOC, they want us to fall back to categories.
7978 $links = $this->_categoryLinks( $this->revision );
8079 }
81 - foreach( $links as $anchor => $url ) {
 80+ foreach ( $links as $anchor => $url ) {
8281 $xml .= $this->_formatLink( $url, $anchor, 'nav' );
8382 }
84 -
 83+
8584 // @todo: image links
86 -
 85+
8786 $xml .= "</links>\n";
8887 }
8988 $xml .= "</doc>\n";
@@ -90,12 +89,12 @@
9190 $this->title = null;
9291 $this->revision = null;
9392 }
94 -
 93+
9594 function writeRevision( $rev, $string ) {
9695 // Only use one revision's worth of data to output
9796 $this->revision = $rev;
9897 }
99 -
 98+
10099 /**
101100 * Extract an abstract from the page
102101 * @params object $rev Database rows with revision data
@@ -104,14 +103,14 @@
105104 */
106105 function _abstract( $rev ) {
107106 $text = Revision::getRevisionText( $rev ); // FIXME cache this
108 -
 107+
109108 $stripped = $this->_stripMarkup( $text );
110109 $extract = $this->_extractStart( $stripped );
111110 $clipped = substr( $extract, 0, 1024 ); // not too long pls
112 -
 111+
113112 return UtfNormal::cleanUp( $clipped );
114113 }
115 -
 114+
116115 /**
117116 * Convert text to the preferred output language variant, if set.
118117 * @param string $text
@@ -119,14 +118,14 @@
120119 * @access private
121120 */
122121 function _variant( $text ) {
123 - if( $this->variant ) {
 122+ if ( $this->variant ) {
124123 global $wgContLang;
125124 return $wgContLang->mConverter->translate( $text, $this->variant );
126125 } else {
127126 return $text;
128127 }
129128 }
130 -
 129+
131130 /**
132131 * Strip markup to show plaintext
133132 * @param string $text
@@ -135,9 +134,9 @@
136135 */
137136 function _stripMarkup( $text ) {
138137 global $wgContLang;
139 -
 138+
140139 $text = substr( $text, 0, 4096 ); // don't bother with long text...
141 -
 140+
142141 $image = preg_quote( $wgContLang->getNsText( NS_IMAGE ), '#' );
143142 $text = str_replace( "'''", "", $text );
144143 $text = str_replace( "''", "", $text );
@@ -163,7 +162,7 @@
164163 $text = Sanitizer::decodeCharReferences( $text );
165164 return trim( $text );
166165 }
167 -
 166+
168167 /**
169168 * Extract the first two sentences, if detectable, from the text.
170169 * @param string $text
@@ -177,13 +176,13 @@
178177 '.', '!', '?', // double-width roman forms
179178 '。', // half-width ideographic full stop
180179 );
181 -
 180+
182181 $endgroup = implode( '', array_map( 'preg_quote', $endchars ) );
183182 $end = "[$endgroup]";
184183 $sentence = ".*?$end+";
185184 $firsttwo = "/^($sentence$sentence)/u";
186 -
187 - if( preg_match( $firsttwo, $text, $matches ) ) {
 185+
 186+ if ( preg_match( $firsttwo, $text, $matches ) ) {
188187 return $matches[1];
189188 } else {
190189 // Just return the first line
@@ -191,7 +190,7 @@
192191 return trim( $lines[0] );
193192 }
194193 }
195 -
 194+
196195 /**
197196 * Extract a list of TOC links
198197 * @param object $rev Database rows with revision data
@@ -206,11 +205,11 @@
207206 $secs =
208207 preg_split(
209208 '/(^=+.+?=+|^<h[1-6].*?' . '>.*?<\/h[1-6].*?' . '>)(?!\S)/mi',
210 - $text, -1,
 209+ $text, - 1,
211210 PREG_SPLIT_DELIM_CAPTURE );
212 -
 211+
213212 $headers = array();
214 - for( $i = 1; $i < count( $secs ); $i += 2 ) {
 213+ for ( $i = 1; $i < count( $secs ); $i += 2 ) {
215214 $inside = preg_replace( '/^=+\s*(.*?)\s*=+/', '$1', $secs[$i] );
216215 $stripped = $this->_stripMarkup( $inside ); // strip internal markup and <h[1-6]>
217216 $header = UtfNormal::cleanUp( $stripped );
@@ -220,7 +219,7 @@
221220 }
222221 return $headers;
223222 }
224 -
 223+
225224 /**
226225 * Fetch the list of category links for this page
227226 * @param object $rev Database rows with revision data
@@ -234,17 +233,17 @@
235234 array( 'cl_to' ),
236235 array( 'cl_from' => $id ),
237236 'AbstractFilter::_categoryLinks' );
238 -
 237+
239238 $links = array();
240 - while( $row = $dbr->fetchObject( $result ) ) {
 239+ while ( $row = $dbr->fetchObject( $result ) ) {
241240 $category = Title::makeTitle( NS_CATEGORY, $row->cl_to );
242241 $links[$category->getText()] = $category->getFullUrl();
243242 }
244243 $dbr->freeResult( $result );
245 -
 244+
246245 return $links;
247246 }
248 -
 247+
249248 /**
250249 * Format a <sublink> element, like so:
251250 * <sublink linktype="nav">
@@ -265,7 +264,6 @@
266265 Xml::element( 'link', null, substr( $url, 0, $maxUrlLength ) ) .
267266 Xml::closeElement( 'sublink' ) . "\n";
268267 }
269 -
270268 }
271269
272270 class NoredirectFilter extends DumpFilter {
@@ -273,4 +271,3 @@
274272 return !$page->page_is_redirect;
275273 }
276274 }
277 -
Index: trunk/extensions/ActiveAbstract/GoogleCoopFilter.php
@@ -1,10 +1,9 @@
22 <?php
 3+require_once( 'AbstractFilter.php' );
34
4 -require_once('AbstractFilter.php');
5 -
65 /**
76 * Dump filter for creation of a Google Coop 'Subscribed Links' file
8 - *
 7+ *
98 * Usage:
109 *
1110 * HOSTNAME=kamelopedia.mormo.org php dumpBackup.php \
@@ -36,6 +35,7 @@
3736 * @addtogroup maintenance
3837 *
3938 */
 39+
4040 class GoogleCoopFilter extends AbstractFilter {
4141 /**
4242 * Register the filter function with the dump manager
@@ -72,7 +72,7 @@
7373 $wgSitename . ':' . $this->title->getPrefixedText() ) . "\n";
7474 $xml .= ' ' . Xml::element( 'Output', array( 'name' => 'more_url' ),
7575 $this->title->getFullUrl() ) . "\n";
76 -
 76+
7777 // add abstract and links when we have revision data...
7878 $this->revision = null;
7979
@@ -87,9 +87,9 @@
8888 $text = '-';
8989 }
9090 $lines = $this->_threeLines( $text );
91 - for( $i=1; $i<4; $i++ ) {
 91+ for ( $i = 1; $i < 4; $i++ ) {
9292 if ( $lines[$i] != '' ) {
93 - $xml .= ' ' . Xml::element( 'Output', array( 'name' => 'text'.$i ), $lines[$i] ) . "\n";
 93+ $xml .= ' ' . Xml::element( 'Output', array( 'name' => 'text' . $i ), $lines[$i] ) . "\n";
9494 }
9595 }
9696 }
@@ -105,14 +105,14 @@
106106
107107 /**
108108 * Returns an array of three strings, each string of the array has no more than
109 - * 79 characters. The three strings are the first three 'lines' of the text
 109+ * 79 characters. The three strings are the first three 'lines' of the text
110110 * given in $str.
111111 *
112112 * Lines are split at the last blank before position 79.
113113 * If there's no blank before position, the entire string is returned as first
114114 * element of the result array.
115115 *
116 - * This code needs a cleanup, it became rather ugly after adding exception
 116+ * This code needs a cleanup, it became rather ugly after adding exception
117117 * handling :-(
118118 */
119119 function _threeLines( $str ) {
@@ -153,6 +153,4 @@
154154
155155 return $s;
156156 }
157 -
158157 }
159 -

Status & tagging log