r88541 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88540‎ | r88541 | r88542 >
Date:19:55, 21 May 2011
Author:reedy
Status:ok
Tags:
Comment:
Lots more documentation lines to MagicWord
Modified paths:
  • /trunk/phase3/includes/MagicWord.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/MagicWord.php
@@ -191,6 +191,9 @@
192192
193193 /**
194194 * Factory: creates an object representing an ID
 195+ *
 196+ * @param $id
 197+ *
195198 * @return MagicWord
196199 */
197200 static function &get( $id ) {
@@ -206,6 +209,8 @@
207210
208211 /**
209212 * Get an array of parser variable IDs
 213+ *
 214+ * @return array
210215 */
211216 static function getVariableIDs() {
212217 if ( !self::$mVariableIDsInitialised ) {
@@ -230,16 +235,24 @@
231236 return self::$mSubstIDs;
232237 }
233238
234 - /* Allow external reads of TTL array */
 239+ /**
 240+ * Allow external reads of TTL array
 241+ *
 242+ * @return array
 243+ */
235244 static function getCacheTTL($id) {
236 - if (array_key_exists($id,self::$mCacheTTLs)) {
 245+ if ( array_key_exists( $id, self::$mCacheTTLs ) ) {
237246 return self::$mCacheTTLs[$id];
238247 } else {
239248 return -1;
240249 }
241250 }
242251
243 - /** Get a MagicWordArray of double-underscore entities */
 252+ /**
 253+ * Get a MagicWordArray of double-underscore entities
 254+ *
 255+ * @return array
 256+ */
244257 static function getDoubleUnderscoreArray() {
245258 if ( is_null( self::$mDoubleUnderscoreArray ) ) {
246259 self::$mDoubleUnderscoreArray = new MagicWordArray( self::$mDoubleUnderscoreIDs );
@@ -255,7 +268,11 @@
256269 self::$mObjects = array();
257270 }
258271
259 - # Initialises this object with an ID
 272+ /**
 273+ * Initialises this object with an ID
 274+ *
 275+ * @param $id
 276+ */
260277 function load( $id ) {
261278 global $wgContLang;
262279 $this->mId = $id;
@@ -295,6 +312,11 @@
296313 * A comparison function that returns -1, 0 or 1 depending on whether the
297314 * first string is longer, the same length or shorter than the second
298315 * string.
 316+ *
 317+ * @param $s1 string
 318+ * @param $s2 string
 319+ *
 320+ * @return int
299321 */
300322 function compareStringLength( $s1, $s2 ) {
301323 $l1 = strlen( $s1 );
@@ -310,6 +332,8 @@
311333
312334 /**
313335 * Gets a regex representing matching the word
 336+ *
 337+ * @return string
314338 */
315339 function getRegex() {
316340 if ($this->mRegex == '' ) {
@@ -322,6 +346,8 @@
323347 * Gets the regexp case modifier to use, i.e. i or nothing, to be used if
324348 * one is using MagicWord::getBaseRegex(), otherwise it'll be included in
325349 * the complete expression
 350+ *
 351+ * @return string
326352 */
327353 function getRegexCase() {
328354 if ( $this->mRegex === '' )
@@ -332,6 +358,8 @@
333359
334360 /**
335361 * Gets a regex matching the word, if it is at the string start
 362+ *
 363+ * @return string
336364 */
337365 function getRegexStart() {
338366 if ($this->mRegex == '' ) {
@@ -342,6 +370,8 @@
343371
344372 /**
345373 * regex without the slashes and what not
 374+ *
 375+ * @return string
346376 */
347377 function getBaseRegex() {
348378 if ($this->mRegex == '') {
@@ -352,6 +382,9 @@
353383
354384 /**
355385 * Returns true if the text contains the word
 386+ *
 387+ * @paran $text string
 388+ *
356389 * @return bool
357390 */
358391 function match( $text ) {
@@ -360,6 +393,9 @@
361394
362395 /**
363396 * Returns true if the text starts with the word
 397+ *
 398+ * @param $text string
 399+ *
364400 * @return bool
365401 */
366402 function matchStart( $text ) {
@@ -371,6 +407,10 @@
372408 * The return code is the matched string, if there's no variable
373409 * part in the regex and the matched variable part ($1) if there
374410 * is one.
 411+ *
 412+ * @param $text string
 413+ *
 414+ * @return string
375415 */
376416 function matchVariableStartToEnd( $text ) {
377417 $matches = array();
@@ -385,8 +425,11 @@
386426
387427 $matches = array_values(array_filter($matches));
388428
389 - if ( count($matches) == 1 ) { return $matches[0]; }
390 - else { return $matches[1]; }
 429+ if ( count($matches) == 1 ) {
 430+ return $matches[0];
 431+ } else {
 432+ return $matches[1];
 433+ }
391434 }
392435 }
393436
@@ -394,6 +437,10 @@
395438 /**
396439 * Returns true if the text matches the word, and alters the
397440 * input string, removing all instances of the word
 441+ *
 442+ * @param $text string
 443+ *
 444+ * @return bool
398445 */
399446 function matchAndRemove( &$text ) {
400447 $this->mFound = false;
@@ -401,6 +448,10 @@
402449 return $this->mFound;
403450 }
404451
 452+ /**
 453+ * @param $text
 454+ * @return bool
 455+ */
405456 function matchStartAndRemove( &$text ) {
406457 $this->mFound = false;
407458 $text = preg_replace_callback( $this->getRegexStart(), array( &$this, 'pregRemoveAndRecord' ), $text );
@@ -409,17 +460,24 @@
410461
411462 /**
412463 * Used in matchAndRemove()
413 - * @private
414 - **/
415 - function pregRemoveAndRecord( ) {
 464+ *
 465+ * @return string
 466+ */
 467+ function pregRemoveAndRecord() {
416468 $this->mFound = true;
417469 return '';
418470 }
419471
420472 /**
421473 * Replaces the word with something else
 474+ *
 475+ * @param $replacement
 476+ * @param $subject
 477+ * @param $limit int
 478+ *
 479+ * @return string
422480 */
423 - function replace( $replacement, $subject, $limit=-1 ) {
 481+ function replace( $replacement, $subject, $limit = -1 ) {
424482 $res = preg_replace( $this->getRegex(), StringUtils::escapeRegexReplacement( $replacement ), $subject, $limit );
425483 $this->mModified = !($res === $subject);
426484 return $res;
@@ -429,6 +487,11 @@
430488 * Variable handling: {{SUBST:xxx}} style words
431489 * Calls back a function to determine what to replace xxx with
432490 * Input word must contain $1
 491+ *
 492+ * @param $text string
 493+ * @param $callback
 494+ *
 495+ * @return string
433496 */
434497 function substituteCallback( $text, $callback ) {
435498 $res = preg_replace_callback( $this->getVariableRegex(), $callback, $text );
@@ -438,6 +501,8 @@
439502
440503 /**
441504 * Matches the word, where $1 is a wildcard
 505+ *
 506+ * @return string
442507 */
443508 function getVariableRegex() {
444509 if ( $this->mVariableRegex == '' ) {
@@ -448,6 +513,8 @@
449514
450515 /**
451516 * Matches the entire string, where $1 is a wildcard
 517+ *
 518+ * @return string
452519 */
453520 function getVariableStartToEndRegex() {
454521 if ( $this->mVariableStartToEndRegex == '' ) {
@@ -458,11 +525,18 @@
459526
460527 /**
461528 * Accesses the synonym list directly
 529+ *
 530+ * @param $i int
 531+ *
 532+ * @return string
462533 */
463534 function getSynonym( $i ) {
464535 return $this->mSynonyms[$i];
465536 }
466537
 538+ /**
 539+ * @return array
 540+ */
467541 function getSynonyms() {
468542 return $this->mSynonyms;
469543 }
@@ -470,6 +544,8 @@
471545 /**
472546 * Returns true if the last call to replace() or substituteCallback()
473547 * returned a modified text, otherwise false.
 548+ *
 549+ * @return bool
474550 */
475551 function getWasModified(){
476552 return $this->mModified;
@@ -480,9 +556,14 @@
481557 * This method uses the php feature to do several replacements at the same time,
482558 * thereby gaining some efficiency. The result is placed in the out variable
483559 * $result. The return value is true if something was replaced.
484 - * @static
485560 * @todo Should this be static? It doesn't seem to be used at all
486 - **/
 561+ *
 562+ * @param $magicarr
 563+ * @param $subject
 564+ * @param $result
 565+ *
 566+ * @return bool
 567+ */
487568 function replaceMultiple( $magicarr, $subject, &$result ){
488569 $search = array();
489570 $replace = array();
@@ -499,6 +580,9 @@
500581 /**
501582 * Adds all the synonyms of this MagicWord to an array, to allow quick
502583 * lookup in a list of magic words
 584+ *
 585+ * @param $array
 586+ * @param $value
503587 */
504588 function addToArray( &$array, $value ) {
505589 global $wgContLang;
@@ -507,10 +591,16 @@
508592 }
509593 }
510594
 595+ /**
 596+ * @return bool
 597+ */
511598 function isCaseSensitive() {
512599 return $this->mCaseSensitive;
513600 }
514601
 602+ /**
 603+ * @return int
 604+ */
515605 function getId() {
516606 return $this->mId;
517607 }
@@ -532,6 +622,8 @@
533623
534624 /**
535625 * Add a magic word by name
 626+ *
 627+ * @param $name string
536628 */
537629 public function add( $name ) {
538630 $this->names[] = $name;
@@ -540,6 +632,8 @@
541633
542634 /**
543635 * Add a number of magic words by name
 636+ *
 637+ * $param $names array
544638 */
545639 public function addArray( $names ) {
546640 $this->names = array_merge( $this->names, array_values( $names ) );
@@ -608,6 +702,8 @@
609703
610704 /**
611705 * Get a regex for matching variables with parameters
 706+ *
 707+ * @return string
612708 */
613709 function getVariableRegex() {
614710 return str_replace( "\\$1", "(.*?)", $this->getRegex() );
@@ -615,6 +711,8 @@
616712
617713 /**
618714 * Get a regex anchored to the start of the string that does not match parameters
 715+ *
 716+ * @return string
619717 */
620718 function getRegexStart() {
621719 $base = $this->getBaseRegex();
@@ -630,6 +728,8 @@
631729
632730 /**
633731 * Get an anchored regex for matching variables with parameters
 732+ *
 733+ * @return string
634734 */
635735 function getVariableStartToEndRegex() {
636736 $base = $this->getBaseRegex();
@@ -647,6 +747,10 @@
648748 * Parse a match array from preg_match
649749 * Returns array(magic word ID, parameter value)
650750 * If there is no parameter value, that element will be false.
 751+ *
 752+ * @param $m arrray
 753+ *
 754+ * @return array
651755 */
652756 function parseMatch( $m ) {
653757 reset( $m );
@@ -673,6 +777,10 @@
674778 * Returns an array with the magic word name in the first element and the
675779 * parameter in the second element.
676780 * Both elements are false if there was no match.
 781+ *
 782+ * @param $text string
 783+ *
 784+ * @return array
677785 */
678786 public function matchVariableStartToEnd( $text ) {
679787 $regexes = $this->getVariableStartToEndRegex();
@@ -690,6 +798,10 @@
691799 /**
692800 * Match some text, without parameter capture
693801 * Returns the magic word name, or false if there was no capture
 802+ *
 803+ * @param $text string
 804+ *
 805+ * @return string|false
694806 */
695807 public function matchStartToEnd( $text ) {
696808 $hash = $this->getHash();
@@ -707,6 +819,10 @@
708820 /**
709821 * Returns an associative array, ID => param value, for all items that match
710822 * Removes the matched items from the input string (passed by reference)
 823+ *
 824+ * @param $text string
 825+ *
 826+ * @return array
711827 */
712828 public function matchAndRemove( &$text ) {
713829 $found = array();
@@ -730,6 +846,10 @@
731847 * the prefix from $text.
732848 * Return false if no match found and $text is not modified.
733849 * Does not match parameters.
 850+ *
 851+ * @param $text string
 852+ *
 853+ * @return int|false
734854 */
735855 public function matchStartAndRemove( &$text ) {
736856 $regexes = $this->getRegexStart();

Status & tagging log