示例#1
0
 public static function addCategories($surnames, $places, $addPlaceCategories = true, $titleString = '', $ns = NS_MAIN, $displayCats = false)
 {
     global $wrStdSurnames, $wrStdPlaces, $wgParser;
     // TODO figure out how to not disable caching
     // disable caching because we're passing wrStdSurnames and wrStdPlaces as globals
     $wgParser->disableCache();
     $result = '';
     $titleString = mb_strtolower($titleString);
     $wrStdSurnames = array();
     $wrStdPlaces = array();
     $hlPlaces = array();
     // standardize names and make them unique
     foreach ($surnames as $surname) {
         $s = (string) $surname;
         if ($s) {
             // add an entry for the entire surname as well as separate entries for each piece
             $wrStdSurnames[] = StructuredData::standardizeNameCase($s);
             $surnamePieces = StructuredData::parseSurnamePieces($s);
             foreach ($surnamePieces as $surnamePiece) {
                 $wrStdSurnames[] = StructuredData::standardizeNameCase($surnamePiece);
             }
         }
     }
     $wrStdSurnames = array_unique($wrStdSurnames);
     // standardize places and make them unique
     foreach ($places as $place) {
         $p = (string) $place;
         if ($p) {
             // if you change the transformation for titleText, change it also in UserPage.formatResearchLinks
             $fields = explode('|', $p);
             $titleText = trim($fields[0]);
             $t = Title::newFromText($titleText, NS_PLACE);
             if ($t) {
                 $t = StructuredData::getRedirectToTitle($t);
                 $titleText = $t->getText();
             }
             $wrStdPlaces[] = $titleText;
             $fields = explode(',', $titleText);
             $hlPlace = trim($fields[count($fields) - 1]);
             if (count($fields) > 1 && strcasecmp($hlPlace, 'united states') == 0) {
                 $hlPlace = trim($fields[count($fields) - 2]);
             }
             $hlPlaces[] = $hlPlace;
         }
     }
     $wrStdPlaces = array_unique($wrStdPlaces);
     $hlPlaces = array_unique($hlPlaces);
     // write out categories
     $colon = $displayCats ? ':' : '';
     //	   foreach ($stdSurnames as $surname) {
     //	      if ($result && $displayCats) {
     //	         $result .= ', ';
     //	      }
     //		   $result .= "[[{$colon}Category:$surname surname" . ($displayCats ? "|$surname surname" : '') ."]]";
     //		}
     if ($addPlaceCategories) {
         foreach ($wrStdPlaces as $place) {
             if ($result && $displayCats) {
                 $result .= ', ';
             }
             $result .= "[[{$colon}Category:{$place}" . ($displayCats ? "|{$place}" : '') . "]]";
         }
     }
     //		foreach ($hlPlaces as $place) {
     //		   foreach ($stdSurnames as $surname) {
     //		      $catName = "$surname in $place";
     //		      if (!$displayCats && $titleString && $ns == NS_MAIN && mb_strtolower($catName) == $titleString) { // main Surname in Place article
     //		         $catName .= "|*";
     //		      }
     //   	      if ($result && $displayCats) {
     //   	         $result .= ', ';
     //   	      }
     //		      $result .= "[[{$colon}Category:$catName" . ($displayCats ? "|$catName" : '') ."]]";
     //		   }
     //		}
     return $result;
 }