r108138 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108137‎ | r108138 | r108139 >
Date:13:09, 5 January 2012
Author:maxsem
Status:ok
Tags:
Comment:
Added a limit of coordinates per page
Modified paths:
  • /trunk/extensions/GeoData/GeoData.php (modified) (history)
  • /trunk/extensions/GeoData/GeoDataHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GeoData/GeoData.php
@@ -42,3 +42,7 @@
4343 */
4444 $wgDefaultGlobe = 'earth';
4545
 46+/**
 47+ * Maximum number of coordinates per page
 48+ */
 49+$wgMaxCoordinatesPerPage = 50;
Index: trunk/extensions/GeoData/GeoDataHooks.php
@@ -82,7 +82,13 @@
8383 $parser->getTitle()->getText()
8484 );
8585 }
86 - return array( "<span class=\"error\">{$status->getWikiText()}</span>", 'noparse' => false );
 86+ $errorText = $status->getWikiText();
 87+ if ( $errorText == '&lt;&gt;' ) {
 88+ // Error condition that doesn't require a message,
 89+ // can't think of a better way to pass this condition
 90+ return '';
 91+ }
 92+ return array( "<span class=\"error\">{$errorText}</span>", 'noparse' => false );
8793 }
8894
8995 /**
@@ -95,6 +101,7 @@
96102 'primary' => false,
97103 'secondary' => array(),
98104 'failures' => false,
 105+ 'limitExceeded' => false,
99106 );
100107 }
101108 }
@@ -107,6 +114,15 @@
108115 * @return Status: whether save went OK
109116 */
110117 private static function applyCoord( ParserOutput $output, Coord $coord ) {
 118+ global $wgMaxCoordinatesPerPage;
 119+ $count = count( $output->geoData['secondary'] ) + $output->geoData['primary'] ? 1 : 0;
 120+ if ( $count >= $wgMaxCoordinatesPerPage ) {
 121+ if ( $output->geoData['limitExceeded'] ) {
 122+ return Status::newFatal( '' );
 123+ }
 124+ $output->geoData['limitExceeded'] = true;
 125+ return Status::newFatal( 'geodata-limit-exceeded' );
 126+ }
111127 if ( $coord->primary ) {
112128 if ( $output->geoData['primary'] ) {
113129 $output->geoData['secondary'][] = $coord;

Status & tagging log