Example #1
0
 /**
  * Construction method for the Image class
  *
  * @access public
  * @param Wiki &$wikiClass The Wiki class object
  * @param string $title The title of the image
  * @param int $pageid The ID of the image page (optional)
  * @return Image
  */
 public function __construct(Wiki &$wikiClass, $title = null, $pageid = null)
 {
     $this->wiki =& $wikiClass;
     $this->title = $title;
     if ($this->wiki->removeNamespace($title) == $title) {
         $namespaces = $this->wiki->get_namespaces();
         $this->title = $namespaces[6] . ':' . $title;
     }
     $ii = $this->imageinfo();
     if (is_array($ii)) {
         $this->title = $ii[0]['canonicaltitle'];
         $this->rawtitle = $this->wiki->removeNamespace($this->title);
         $this->localname = str_replace(array(' ', '+'), array('_', '_'), urlencode($this->rawtitle));
         $this->page =& $this->wiki->initPage($this->title, $pageid);
         $this->mime = $ii[0]['mime'];
         $this->bitdepth = $ii[0]['bitdepth'];
         $this->hash = $ii[0]['sha1'];
         $this->size = $ii[0]['size'];
         $this->width = $ii[0]['width'];
         $this->height = $ii[0]['height'];
         $this->url = $ii[0]['url'];
         $this->timestamp = $ii[0]['timestamp'];
         $this->user = $ii[0]['user'];
         if (is_array($ii[0]['metadata'])) {
             foreach ($ii[0]['metadata'] as $metadata) {
                 $this->metadata[$metadata['name']] = $metadata['value'];
             }
         } else {
             $this->exists = false;
         }
     }
 }
Example #2
0
 /**
  * Analyzes an RFA. Returns TRUE on success, FALSE on failure
  * @param Wiki $wiki Peachy Wiki Class
  * @param $page	Peachy Page class
  * @param null $rawwikitext - raw page text (for use without Peachy)
  */
 public function __construct(Wiki $wiki, $page, $rawwikitext = null)
 {
     if (is_null($rawwikitext)) {
         $pageObj = $wiki->initPage($page);
         $rawwikitext = $pageObj->get_text();
     }
     #var_export($rawwikitext);
     //Get the page sections & section names
     $sections = array();
     preg_match_all("/" . "^(\\=[=]?\\s*[^\\/\n]*\\s*\\=[\\=]?)\\s*\$" . "/m", $rawwikitext, $sections);
     $splitterRegex = array();
     foreach ($sections[1] as $sectionName) {
         $sectionClear = trim(str_replace("=", "", $sectionName));
         $sectionName = trim($sectionName);
         if (preg_match("/^Pro/", $sectionClear) > 0) {
             $sectionType["support"] = $sectionName;
         }
         if (preg_match("/^(?:Kontra|Contra)/", $sectionClear) > 0) {
             $sectionType["oppose"] = $sectionName;
         }
         if (preg_match("/^Enthaltung[en]*/", $sectionClear) > 0) {
             $sectionType["neutral"] = $sectionName;
         }
         if (preg_match("/^Kommentare/", $sectionClear) > 0) {
             $sectionType["comments"] = $sectionName;
         }
         $splitterRegex[] .= "(" . preg_quote($sectionName) . ")";
     }
     #print_r($sections);die;
     $split = preg_split("/" . "(?:" . implode("|", $splitterRegex) . ")" . "/", $rawwikitext, -1, PREG_SPLIT_DELIM_CAPTURE);
     #print_r($split);die;
     $header = array_shift($split);
     //=== Deal with the header ===//
     $header = str_ireplace(array('<nowiki>', '</nowiki>'), '', $header);
     if (preg_match("/===\\s*\\[\\[User:(.*?)\\|.*?\\]\\]\\s*===/", $header, $matches)) {
         $this->username = $matches[1];
     } elseif (preg_match("/===\\s*\\[\\[.*?\\|(.*?)\\]\\]\\s*===/", $header, $matches)) {
         $this->username = $matches[1];
     }
     $header = str_replace(array('[[', ']]'), '', $header);
     if (preg_match("/(?: endet am) '*(.*) Uhr/i", $header, $matches)) {
         $this->enddate = $matches[1];
     }
     //=== End header stuff ===//
     //Now parse through each non-header section, figuring out what they are
     //Nothing expected = 0, Support = 1, Oppose = 2, Neutral = 3
     $nextsection = 0;
     #print_r($sectionType);
     #print_r($split);die;
     foreach ($split as $i => $splut) {
         $splut = trim($splut);
         if (empty($splut)) {
             continue;
         }
         if (strcasecmp($splut, $sectionType["support"]) == 0) {
             $support = $split[$i + 1];
         } elseif (strcasecmp($splut, $sectionType["oppose"]) == 0) {
             $oppose = $split[$i + 1];
         } elseif (strcasecmp($splut, $sectionType["neutral"]) == 0) {
             $neutral = $split[$i + 1];
         }
     }
     if (!isset($support)) {
         $this->lasterror = "Support section not found";
         return false;
     }
     if (!isset($oppose)) {
         $this->lasterror = "Oppose section not found";
         return false;
     }
     if (!isset($neutral)) {
         $this->lasterror = "Neutral section not found";
         return false;
     }
     #print_r($support);
     #print_r($oppose);
     #print_r($neutral);die;
     $this->support = $this->analyzeSection($support);
     $this->oppose = $this->analyzeSection($oppose);
     $this->neutral = $this->analyzeSection($neutral);
     //Merge all votes in one array and sort:
     $m = array();
     foreach ($this->support as $s) {
         if (isset($s['name'])) {
             $m[] = $s['name'];
         }
     }
     foreach ($this->oppose as $o) {
         if (isset($o['name'])) {
             $m[] = $o['name'];
         }
     }
     foreach ($this->neutral as $n) {
         if (isset($n['name'])) {
             $m[] = $n['name'];
         }
     }
     sort($m);
     //Find duplicates:
     for ($i = 0; $i < count($m); $i++) {
         if ($i != count($m) - 1) {
             if ($m[$i] == $m[$i + 1]) {
                 $this->duplicates[] = $m[$i];
             }
         }
     }
     return true;
 }
Example #3
0
 /**
  * Analyzes an RFA. Returns TRUE on success, FALSE on failure
  * @param Wiki $wiki
  * @param $page
  * @param null $rawwikitext
  */
 public function __construct(Wiki $wiki, $page, $rawwikitext = null)
 {
     if (is_null($rawwikitext)) {
         $rawwikitext = $wiki->initPage($page)->get_text();
     }
     $split = preg_split("/^(?:(?:'''|(?:<includeonly><noin<\\/includeonly><includeonly>clude><\\/includeonly>)?={4,5}(?:<includeonly><\\/noin<\\/includeonly><includeonly>clude><\\/includeonly>''')?)" . "\\s*?(Support|Oppose|Neutral|Comments)\\s*?(?:'''|(?:'''<includeonly><noin<\\/includeonly><includeonly>clude><\\/includeonly>)?={4,5}(?:<includeonly><\\/noin<\\/includeonly><includeonly>clude><\\/includeonly>)?)|;\\s*(Support|Oppose|Neutral|Comments))\\s*(?:<br>|<br \\/>)?\\s*\$/im", $rawwikitext, -1, PREG_SPLIT_DELIM_CAPTURE);
     $header = array_shift($split);
     //=== Deal with the header ===//
     $header = str_ireplace(array('<nowiki>', '</nowiki>'), '', $header);
     if (preg_match("/===\\s*\\[\\[User:(.*?)\\|.*?\\]\\]\\s*===/", $header, $matches)) {
         $this->username = $matches[1];
     } elseif (preg_match("/===\\s*\\[\\[.*?\\|(.*?)\\]\\]\\s*===/", $header, $matches)) {
         $this->username = $matches[1];
     }
     $header = str_replace(array('[[', ']]'), '', $header);
     if (preg_match("/end(?:ing|ed)?(?: no earlier than)? (.*?) \\(UTC\\)/i", $header, $matches)) {
         $this->enddate = $matches[1];
     }
     //=== End header stuff ===//
     //Now parse through each non-header section, figuring out what they are
     //Nothing expected = 0, Support = 1, Oppose = 2, Neutral = 3
     $nextsection = 0;
     foreach ($split as $splut) {
         $splut = trim($splut);
         if (empty($splut)) {
             continue;
         }
         if (strcasecmp($splut, 'Support') == 0) {
             $nextsection = 1;
         } elseif (strcasecmp($splut, 'Oppose') == 0) {
             $nextsection = 2;
         } elseif (strcasecmp($splut, 'Neutral') == 0) {
             $nextsection = 3;
         } else {
             switch ($nextsection) {
                 case 1:
                     $support = $splut;
                     break;
                 case 2:
                     $oppose = $splut;
                     break;
                 case 3:
                     $neutral = $splut;
                     break;
             }
             $nextsection = 0;
         }
     }
     if (!isset($support)) {
         $this->lasterror = "Support section not found";
         return false;
     }
     if (!isset($oppose)) {
         $this->lasterror = "Oppose section not found";
         return false;
     }
     if (!isset($neutral)) {
         $this->lasterror = "Neutral section not found";
         return false;
     }
     $this->support = $this->analyzeSection($support);
     $this->oppose = $this->analyzeSection($oppose);
     $this->neutral = $this->analyzeSection($neutral);
     //Merge all votes in one array and sort:
     $m = array();
     foreach ($this->support as $s) {
         if (isset($s['name'])) {
             $m[] = $s['name'];
         }
     }
     foreach ($this->oppose as $o) {
         if (isset($o['name'])) {
             $m[] = $o['name'];
         }
     }
     foreach ($this->neutral as $n) {
         if (isset($n['name'])) {
             $m[] = $n['name'];
         }
     }
     sort($m);
     //Find duplicates:
     for ($i = 0; $i < count($m); $i++) {
         if ($i != count($m) - 1) {
             if ($m[$i] == $m[$i + 1]) {
                 $this->duplicates[] = $m[$i];
             }
         }
     }
     return true;
 }