Permalink
Browse files

Add helper method that removes preprocessor limit reports.

  • Loading branch information...
1 parent 8a3d565 commit dc8221d618355af7c9ba16164c6f265fde886ab1 @jimsafley jimsafley committed Dec 14, 2011
Showing with 19 additions and 0 deletions.
  1. +19 −0 lib/Scripto.php
View
@@ -762,4 +762,23 @@ static public function removeHtmlAttributes($html)
return $doc->saveHTML();
}
+
+ /**
+ * Remove all preprocessor limit reports from the provided markup.
+ *
+ * This filter is useful after getting HTML from the MediaWiki API, which
+ * always contains a preprocessor limit report within hidden tags.
+ *
+ * @see http://en.wikipedia.org/wiki/Wikipedia:Template_limits#How_can_you_find_out.3F
+ * @param string $text
+ * @return string
+ */
+ static public function removeNewPPLimitReports($html)
+ {
+ // The "s" modifier means the "." meta-character will include newlines.
+ // The "?" means the "+" quantifier is not greedy, thus will not remove
+ // text between pages when importing document transcriptions.
+ $html = preg_replace("/<!-- \nNewPP limit report.+?-->/s", '', $html);
+ return $html;
+ }
}

0 comments on commit dc8221d

Please sign in to comment.