function getSentences()
 {
     //global $wgMemc;
     $key = "startertool_sentences";
     //$sentences = $wgMemc->get($key);
     if (!$sentences) {
         $msg = ConfigStorage::dbGetConfig('startertool_sentences');
         //startup companies
         $sentences = split("\n", $msg);
         //$wgMemc->set($key, $sentences);
     }
     return $sentences;
 }
Example #2
0
 public function getExcludedArticles()
 {
     global $IP;
     $excludedKey = $this->config->getExludedArticlesKeyName();
     $excludeList = ConfigStorage::dbGetConfig($excludedKey);
     $report = "";
     if ($excludeList) {
         $excludeList = explode("\n", ConfigStorage::dbGetConfig($excludedKey));
         require_once "{$IP}/extensions/wikihow/DatabaseHelper.class.php";
         $dbr = self::getDBR();
         $aids = "(" . implode(",", $excludeList) . ")";
         $articleTable = $this->config->getArticleTableName();
         $rows = DatabaseHelper::batchSelect($articleTable, array('*'), array("ct_page_id IN {$aids}"), __METHOD__, array(), DatabaseHelper::DEFAULT_BATCH_SIZE, $dbr);
         $data = WAPUtil::generateTSVOutput($rows);
     }
     $report = self::getReportArray($data);
     return $report;
 }
Example #3
0
 public function isCreatorKnownScreenShotter($creator)
 {
     $userIsScreenshotter = false;
     $screenshotters = explode("\n", ConfigStorage::dbGetConfig('wikiphoto-exclude-from-image-warning'));
     foreach ($screenshotters as $ssUser) {
         $ssUser = trim($ssUser);
         if (!$ssUser) {
             continue;
         }
         if (strtolower($ssUser) == strtolower($creator)) {
             $userIsScreenshotter = true;
             break;
         }
     }
     return $userIsScreenshotter;
 }
Example #4
0
 protected static function isABTestArticle()
 {
     global $wgTitle;
     $isTest = false;
     if ($wgTitle && !preg_match("@^DocViewer\$@", $wgTitle->getText())) {
         if (is_null(wikihowAds::$isABTest)) {
             // Turn on new ad test for all articles
             $wikihowUrl = "http://www.wikihow.com/" . $wgTitle->getPartialURL();
             $msg = ConfigStorage::dbGetConfig('beta_test');
             $articles = split("\n", $msg);
             if (in_array($wikihowUrl, $articles)) {
                 wikihowAds::$isABTest = true;
             }
         }
         $isTest = wikihowAds::$isABTest;
     }
     return $isTest;
 }
 /**
  * Execute special page.  Only available to wikihow staff.
  */
 public function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser, $wgLang;
     if (strtolower($par) == 'url') {
         $style = 'url';
     } else {
         $style = '';
     }
     $userGroups = $wgUser->getGroups();
     if ($wgUser->isBlocked() || !in_array('staff', $userGroups)) {
         $wgOut->setRobotpolicy('noindex,nofollow');
         $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     if ($wgRequest->wasPosted()) {
         $action = $wgRequest->getVal('action');
         $wgOut->setArticleBodyOnly(true);
         if ('load-config' == $action) {
             $key = $wgRequest->getVal('config-key', '');
             $val = ConfigStorage::dbGetConfig($key);
             $style = $wgRequest->getVal('style', '');
             if ($style == 'url') {
                 //translate ids to readable urls
                 $val = $this->translateValues($val, $style);
             }
             $result = array('result' => $val);
         } elseif ('save-config' == $action) {
             $errors = '';
             $key = $wgRequest->getVal('config-key', '');
             $val = $wgRequest->getVal('config-val', '');
             $style = $wgRequest->getVal('style', '');
             if ($style == 'url') {
                 //validate for errors
                 $errors = self::validateInput($key, $val);
                 //grab the existing values from the db
                 $val_db = ConfigStorage::dbGetConfig($key);
                 //translate the good urls back to ids for storage purposes
                 $val = $this->translateValues($val, 'id');
                 //add the new and old values together
                 $val = $val_db . "\r\n" . $val;
             }
             ConfigStorage::dbStoreConfig($key, $val);
             $errors .= self::validateInput($key, $val);
             $output = 'saved and checked input<br/><br/>';
             if ($errors) {
                 $output .= 'ERRORS:<br/>' . str_replace("\n", "<br/>\n", $errors);
             } else {
                 $output .= "no errors.";
             }
             if ($style == 'url') {
                 // ** commentting out because it times out if the input was too big
                 //translate back to urls for updated display
                 //$val = $this->translateValues($val,'url');
                 $val = '';
             }
             $result = array('result' => $output, 'val' => $val);
         } elseif ('remove-line' == $action) {
             $key = $wgRequest->getVal('config-key', '');
             $id = $wgRequest->getVal('id', '');
             $result = $this->removeLine($key, $id);
             $result = array('result' => $result['result'], 'error' => $result['error']);
         } else {
             $result = array('error' => 'bad action');
         }
         print json_encode($result);
         return;
     }
     $wgOut->setHTMLTitle(wfMsg('pagetitle', 'Admin - Generalized Config Editor'));
     $listConfigs = ConfigStorage::dbListConfigKeys();
     $tmpl = self::getGuts($listConfigs, $style);
     $wgOut->addHTML($tmpl);
 }
 protected function generateBody()
 {
     global $wgLanguageCode;
     $device = $this->getDevice();
     list($sections, $intro, $firstImage) = $this->getArticleParts();
     if ($firstImage) {
         $title = Title::newFromURL($firstImage, NS_IMAGE);
         if ($title) {
             $introImage = RepoGroup::singleton()->findFile($title);
         }
         if ($introImage) {
             list($thumb, $width, $height) = self::makeThumbDPI($introImage, 290, 194, $device['enlarge-thumb-high-dpi']);
             //make a srcset value
             $bigWidth = 600;
             $bigHeight = 800;
             list($thumb_big, $newWidth, $newHeight) = self::makeThumbDPI($introImage, $bigWidth, $bigHeight, $device['enlarge-thumb-high-dpi']);
             $url = wfGetPad($thumb_big->getUrl());
             $thumb_ss = $url . ' ' . $bigWidth . 'w';
             $thumb_id = md5($thumb->getUrl());
             $swap_script = '<script type="text/javascript">if (isBig) WH.mobile.swapEm("' . $thumb_id . '");</script>';
         } else {
             $firstImage = '';
         }
     }
     //articles that we don't want to have a top (above tabs)
     //image displayed
     $titleUrl = "";
     if ($this->t != null) {
         $titleUrl = $this->t->getFullURL();
     }
     $exceptions = ConfigStorage::dbGetConfig('mobile-topimage-exception');
     $exceptionArray = explode("\n", $exceptions);
     if (in_array($titleUrl, $exceptionArray)) {
         $firstImage = false;
     }
     if (!$firstImage) {
         $thumb = null;
         $width = 0;
         $height = 0;
     }
     $redirMainBase = '/' . wfMsg('special') . ':' . wfMsg('MobileWikihow') . '?redirect-non-mobile=';
     $articleVars = array('title' => $this->t->getText(), 'title_class' => self::getTitleClass($this->t->getText()), 'sections' => $sections, 'intro' => $intro, 'thumb' => &$thumb, 'thumb_id' => &$thumb_id, 'thumb_ss' => &$thumb_ss, 'swap_script' => &$swap_script, 'width' => $width, 'height' => $height, 'deviceOpts' => $device, 'nonEng' => $wgLanguageCode != 'en', 'isGerman' => $wgLanguageCode == 'de', 'redirMainUrl' => $redirMainBase);
     $this->addExtendedArticleVars(&$articleVars);
     $this->setTemplatePath();
     return EasyTemplate::html('article.tmpl.php', $articleVars);
 }
 function getJump()
 {
     global $wgLanguageCode, $wgTitle;
     if ($wgLanguageCode == "en") {
         $msg = ConfigStorage::dbGetConfig('ad_jump');
         //articles that need the jump
         $articles = explode("\n", $msg);
         if (in_array($wgTitle->getArticleID(), $articles)) {
             return wfMsg('ad_jump');
         }
     }
     return "";
 }
Example #8
0
 private static function showPdf($doc_name)
 {
     if (!isset(self::$isPdf)) {
         $val = ConfigStorage::dbGetConfig('sample_pdfs');
         $pageList = preg_split('@[\\r\\n]+@', $val);
         self::$isPdf = in_array($doc_name, $pageList);
     }
     return self::$isPdf;
 }
 private function checkupExcluded()
 {
     $excludedKey = $this->wapConfig->getExludedArticlesKeyName();
     $excludedAids = explode("\n", ConfigStorage::dbGetConfig($excludedKey));
     $ids = array();
     foreach ($excludedAids as $aid) {
         if (is_numeric($aid)) {
             $ids[] = $aid;
         }
     }
     if (!empty($ids)) {
         $articleTable = $this->wapConfig->getArticleTableName();
         $sql = "SELECT ct_lang_code, ct_user_text, ct_user_id, ct_page_id, ct_page_title FROM {$articleTable} WHERE ct_page_id IN (" . implode(',', $ids) . ")";
         $this->genericCheckup($sql, self::EXCLUDED_TYPE);
     }
 }
Example #10
0
 function isTPCoachEnabled()
 {
     return ConfigStorage::dbGetConfig(self::TPCOACH_ENABLED) > 0;
 }
	this script takes the article ids from the config storage db table for wikihow watermark article list
	and puts it into a db table with one entry per article id

	this is done so that we can iterate over this list and process the articles in it, adding watermarks to the images as necessary 
	and removing the data from this table
*/
require_once "commandLine.inc";
/*
    wikiphoto_article_watermark DB Table
    CREATE TABLE `wikiphoto_article_watermark` (
    `waw_article_id` int(8) unsigned NOT NULL,
	`waw_version` tinyint(3) unsigned default NULL,
    PRIMARY KEY  (`waw_article_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
echo "migrating articleids...\n";
$fname = 'migrateUnwatermarkedImagesList';
$dbw = wfGetDB(DB_MASTER);
$article_ids = explode("\n", ConfigStorage::dbGetConfig('wikihow-watermark-article-list'));
$insertArray = array();
foreach ($article_ids as $id) {
    array_push($insertArray, array("waw_article_id" => $id));
}
$table = "wikiphoto_article_watermark";
$c = count($insertArray);
echo "inserting {$c} articles into {$table} ...\n";
foreach (array_chunk($insertArray, 1000) as $input) {
    $dbw->insert($table, $insertArray, $fname, array('IGNORE'), $fname);
}
$dbw->update($table, array("waw_version=0"), array("waw_version is NULL"), $fname);
echo "done...\n";
Example #12
0
 public function isNewLayoutPage()
 {
     global $wgTitle, $wgRequest, $wgOut, $wgUser;
     if ($wgRequest->getVal('oldid') != '' || $wgRequest->getVal('action') != '' && $wgRequest->getVal('action') != 'view' || $wgTitle->getNamespace() != NS_MAIN) {
         return false;
     }
     if ($wgUser->getID() != 0) {
         return false;
     }
     if (self::isUserAgentMobile()) {
         return false;
     }
     $wikihowUrl = "http://www.wikihow.com/" . $wgTitle->getPartialURL();
     $msg = ConfigStorage::dbGetConfig('redesign_test');
     $articles = split("\n", $msg);
     if (in_array($wikihowUrl, $articles)) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Process all images for an article from the wikiphoto upload dir
  */
 private static function processImages($articleID, $creator, $imageList, $warning)
 {
     $err = '';
     $numSteps = 0;
     $replaced = 0;
     // load article
     list($text, $url, $title) = self::getArticleDetails($articleID);
     if (!$text || !$title) {
         $err = 'Could not find article ID ' . $articleID;
     }
     // parse out steps section replacing it with a token, leaving
     // the above and below wikitext intact
     if (!$err) {
         list($text, $steps, $stepsToken) = self::cutStepsSection($text);
         if (!$stepsToken) {
             if (preg_match('@^(\\s|\\n)*#redirect@i', $text)) {
                 $err = 'Could not parse Steps section out of article -- article text is #REDIRECT';
             } else {
                 $err = 'Could not parse Steps section out of article';
             }
         }
     }
     // check if user is a known screenshot uploader
     if (!$err) {
         $userIsScreenshotter = false;
         $screenshotters = explode("\n", ConfigStorage::dbGetConfig('wikiphoto-exclude-from-image-warning'));
         foreach ($screenshotters as $ssUser) {
             $ssUser = trim($ssUser);
             if (!$ssUser) {
                 continue;
             }
             if (strtolower($ssUser) == strtolower($creator)) {
                 $userIsScreenshotter = true;
                 break;
             }
         }
     }
     // try to place images into wikitext, using tokens as placeholders.
     if (!$err) {
         $err = self::placeImagesInSteps($articleID, $title, $imageList, $text, $steps, $numSteps, $replaced, $userIsScreenshotter);
     }
     // detect if no photos were to be processed
     if (!$err) {
         if (count($imageList) == 0) {
             $err = 'No photos to process';
         }
     }
     // replace the tokens within the image tag
     if (!$err) {
         $isAllLandscape = true;
         $hadColourProblems = false;
         $hadSizeProblems = false;
         $text = str_replace($stepsToken, $steps, $text);
         foreach ($imageList as $image) {
             if (!empty($image['width']) && !empty($image['height']) && $image['width'] > $image['height']) {
                 $sizeParam = self::IMAGE_LANDSCAPE_WIDTH;
             } else {
                 $sizeParam = self::IMAGE_PORTRAIT_WIDTH;
                 // Log first portrait image
                 if (!$isAllLandscape) {
                     $warning .= "portrait:{$image['name']}\n";
                 }
                 $isAllLandscape = false;
             }
             // Detect colour profile issues
             if (!$hadColourProblems && !empty($image['filename'])) {
                 $exifProfile = WikiPhoto::getExifColourProfile($image['filename']);
                 if ($exifProfile && WikiPhoto::isBadWebColourProfile($exifProfile)) {
                     $warning .= "colour:{$exifProfile}:{$image['name']}\n";
                     $hadColourProblems = true;
                 }
             }
             // Log pixel width issues
             if (!$userIsScreenshotter && !$hadSizeProblems && !empty($image['width']) && $image['width'] < self::WARNING_MIN_WIDTH) {
                 $warning .= "size:{$image['width']}px:{$image['name']}\n";
                 $hadSizeProblems = true;
             }
             $imageTag = '[[Image:' . $image['mediawikiName'] . '|right|' . $sizeParam . ']]';
             $text = str_replace($image['token'], $imageTag, $text);
         }
     }
     // remove certain templates from start of wikitext
     if (!$err) {
         $templates = array('illustrations', 'pictures', 'screenshots', 'stub');
         $text = self::removeTemplates($text, $templates);
     }
     // write wikitext and add/update wikiphoto row
     if (!$err) {
         $err = self::saveArticleText($articleID, $text);
     }
     // try to enlarge the uploaded photos of certain users
     if (!$err) {
         // now we want to ALWAYS enlarge the images for articles with ALL Landscape
         if ($isAllLandscape) {
             Wikitext::enlargeImages($title, true, AdminEnlargeImages::DEFAULT_CENTER_PIXELS);
         }
     }
     if ($err) {
         self::dbSetArticleProcessed($articleID, $creator, $err, $warning, $url, 0, $numSteps, 0);
     } else {
         self::dbSetArticleProcessed($articleID, $creator, '', $warning, $url, count($imageList), $numSteps, $replaced);
     }
     return array($err, $title);
 }
 public static function isIncubated($creator)
 {
     if (!self::$incubationCreators) {
         $val = ConfigStorage::dbGetConfig(self::ADMIN_CONFIG_INCUBATION_LIST);
         $incubationCreators = preg_split('@\\s+@', trim($val));
     }
     return array_search($creator, $incubationCreators);
 }
Example #15
0
 public function removeExcludedArticles($langCode)
 {
     $excludedKey = $this->getWAPConfig()->getExludedArticlesKeyName();
     $excludeList = explode("\n", ConfigStorage::dbGetConfig($excludedKey));
     if (!empty($excludeList)) {
         $this->removeArticles($excludeList, $langCode);
     }
 }
 function loadExcluded()
 {
     if (is_null($this->excluded)) {
         $this->excluded = explode("\n", ConfigStorage::dbGetConfig('wikiphoto-article-exclude-list'));
     }
     return $ids;
 }
Example #17
0
 /** 
  * Wikiphoto has an exclude list so that important community member articles
  * can't have their photos overwritten. This is done by never uploading
  * new photos for a given articleID.
  */
 public static function checkExcludeList($articleID)
 {
     static $excludes = null;
     if (!$excludes) {
         $list = ConfigStorage::dbGetConfig('wikiphoto-article-exclude-list');
         $excludes = array();
         $lines = preg_split('@[\\r\\n]+@', $list);
         foreach ($lines as $line) {
             $line = trim($line);
             if ($line) {
                 if (preg_match('@^[0-9]+$@', $line)) {
                     $id = $line;
                 } else {
                     $title = self::getArticleTitleNoCheck($line);
                     $id = $title ? $title->getArticleID() : 0;
                 }
                 if ($id) {
                     $excludes[$id] = true;
                 }
             }
         }
     }
     return @$excludes[strval($articleID)];
 }