function formatRow($row)
 {
     $time = htmlspecialchars($this->getLanguage()->userDate($row->log_timestamp, $this->getUser()));
     $paramsSerialized = unserialize($row->log_params);
     $paramsOldFormat = null;
     // If the params aren't serialized, it's an older log format
     if ($paramsSerialized === false) {
         $paramsOldFormat = explode("\n", $row->log_params);
     }
     $targetName = $paramsSerialized === false ? $paramsOldFormat[0] : $paramsSerialized['4::target'];
     $logPageId = (int) $row->log_page;
     $currentTitle = $logPageId && $logPageId !== 0 ? Title::newFromID($logPageId) : null;
     $targetTitleObj = Title::newFromText($targetName);
     // Make sure the target is NS_MAIN
     if ($targetTitleObj->getNamespace() !== NS_MAIN) {
         return false;
     }
     $originalNameDisplay = '';
     if ($currentTitle && $targetName !== $currentTitle->getFullText()) {
         $originalNameDisplay = ' ' . $this->msg('newarticles-original-title')->params($targetName);
     }
     $pageLink = Linker::link($originalNameDisplay ? $currentTitle : $targetTitleObj);
     $articleTypeDisplay = '';
     if (isset($row->pp_value) && $row->pp_value === 'portal') {
         $pageLink = Html::rawElement('strong', [], $pageLink);
         $articleTypeReadable = WRArticleType::getReadableArticleTypeFromCode($row->pp_value);
         $articleTypeDisplay = $this->msg('newarticles-articletype')->params($articleTypeReadable)->text();
         $articleTypeDisplay = ' ' . $articleTypeDisplay;
     }
     $formattedRow = Html::rawElement('li', [], "{$time}: {$pageLink}{$articleTypeDisplay}{$originalNameDisplay}") . "\n";
     return $formattedRow;
 }
Ejemplo n.º 2
0
 public function expandLinkTree(&$parser, $limit)
 {
     $parser->disableCache();
     // Build exclusions list (if category, add all members to list)
     $exclusions = array();
     $dbr =& wfGetDB(DB_SLAVE);
     $cl = $dbr->tableName('categorylinks');
     $args = func_get_args();
     array_shift($args);
     array_shift($args);
     foreach ($args as $arg) {
         $title = Title::newFromText($arg);
         $exclusions[$title->getPrefixedText()] = 1;
         if ($title->getNamespace() == NS_CATEGORY) {
             $cat = $dbr->addQuotes($title->getDBkey());
             $res = $dbr->select($cl, 'cl_from', "cl_to = {$cat}");
             while ($row = $dbr->fetchRow($res)) {
                 $exclusions[Title::newFromID($row[0])->getPrefixedText()] = 1;
             }
             $dbr->freeResult($res);
         }
     }
     $this->exclusions = array_keys($exclusions);
     $tree = $this->linkTree($parser->getTitle(), $limit);
     return array($tree, 'found' => true, 'nowiki' => false, 'noparse' => false, 'noargs' => false, 'isHTML' => false);
 }
Ejemplo n.º 3
0
function WidgetBookmarkAddPage($pageId)
{
    global $wgCityId, $wgSitename;
    $key = $wgCityId . ':' . $pageId;
    if (is_numeric($pageId)) {
        // articles, talk pages...
        $title = Title::newFromID($pageId);
    } else {
        // special pages, category pages...
        $title = Title::newFromText($pageId);
    }
    // validate
    if (!$title) {
        return;
    }
    $pages = WidgetBookmarkGetPages();
    // don't duplicate entries
    if (isset($pages[$key])) {
        return $pages;
    }
    // add page
    $pages[$key] = array('city' => $wgCityId, 'wiki' => $wgSitename, 'title' => $title->getPrefixedText(), 'href' => $title->getFullURL());
    // limit number of pages to 20 (the last 20 pages)
    $pages = array_slice($pages, -20, 20, true);
    WidgetBookmarkSavePages($pages);
    return $pages;
}
Ejemplo n.º 4
0
 public function replaceVideoGalleryTag($pageId, $test = null)
 {
     global $wgTitle;
     $wgTitle = Title::newFromID($pageId);
     if (!$wgTitle) {
         $this->error("Invalid title", true);
     }
     $page = WikiPage::factory($wgTitle);
     # Read the text
     $text = $page->getText();
     $text = preg_replace('/<(\\/?)videogallery([^>]*)>/', '<$1gallery$2>', $text);
     $summary = 'Updating <videogallery> to <gallery>';
     # Do the edit
     $this->output("Replacing page (" . $wgTitle->getDBkey() . ") ... ");
     if ($test) {
         $this->output("(test: no changes) done\n");
     } else {
         $status = $page->doEdit($text, $summary, EDIT_MINOR | EDIT_FORCE_BOT | EDIT_SUPPRESS_RC);
         if ($status->isOK()) {
             $this->output("done\n");
         } else {
             $this->output("failed\n");
             return 0;
         }
         if (!$status->isGood()) {
             $this->output($status->getWikiText() . "\n");
         }
     }
     return 1;
 }
Ejemplo n.º 5
0
 private function cleanupArticle($id, $domain)
 {
     $title = Title::newFromID($id);
     if (!$title) {
         $this->error("Internal error: no page for ID {$id}");
         return;
     }
     $this->output($title->getPrefixedDBkey() . " ...");
     $rev = Revision::newFromTitle($title);
     $currentRevId = $rev->getId();
     while ($rev && ($rev->isDeleted(Revision::DELETED_TEXT) || LinkFilter::matchEntry($rev->getText(), $domain))) {
         $rev = $rev->getPrevious();
     }
     if ($rev && $rev->getId() == $currentRevId) {
         // The regex didn't match the current article text
         // This happens e.g. when a link comes from a template rather than the page itself
         $this->output("False match\n");
     } else {
         $dbw = wfGetDB(DB_MASTER);
         $dbw->begin();
         $page = WikiPage::factory($title);
         if (!$rev) {
             // Didn't find a non-spammy revision, blank the page
             $this->output("blanking\n");
             $page->doEdit('', wfMsgForContent('spam_blanking', $domain));
         } else {
             // Revert to this revision
             $this->output("reverting\n");
             $page->doEdit($rev->getText(), wfMsgForContent('spam_reverting', $domain), EDIT_UPDATE, $rev->getId());
         }
         $dbw->commit();
     }
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     if (!isset($params['title']) || is_null($params['title'])) {
         $this->dieUsage("The coatitle parameter is required", 'notitle');
     }
     $categoryDBkeys = $this->prepareCategories($params['title']);
     $answeredTitle = Title::newFromText('no' == $params['answered'] ? $this->unanswered_category : $this->answered_category, NS_CATEGORY);
     if (is_null($answeredTitle) || $answeredTitle->getNamespace() != NS_CATEGORY) {
         $this->dieUsage("The name of un/answered category is not valid", 'invalidcategory');
     }
     $this->addFields(array('c1.cl_from', 'c1.cl_timestamp'));
     $this->addTables(array('categorylinks AS c1', 'categorylinks AS c2'));
     $this->addWhere('c1.cl_from = c2.cl_from');
     $this->addWhere('c1.cl_to IN (' . $this->getDB()->makeList($categoryDBkeys) . ')');
     $this->addWhereFld('c2.cl_to', $answeredTitle->getDBkey());
     $this->addOption('ORDER BY', 'c1.cl_timestamp DESC');
     $this->addOption('LIMIT', $params['limit']);
     $this->addOption('DISTINCT');
     $db = $this->getDB();
     $res = $this->select(__METHOD__);
     $data = array();
     while ($row = $db->fetchObject($res)) {
         $title = Title::newFromID($row->cl_from);
         if ($title instanceof Title && $title->isContentPage()) {
             $vals['ns'] = intval($title->getNamespace());
             $vals['title'] = $title->getPrefixedText();
             $data[] = $vals;
         }
     }
     $db->freeResult($res);
     $this->getResult()->setIndexedTagName($data, 'coa');
     $this->getResult()->addValue('query', $this->getModuleName(), $data);
 }
Ejemplo n.º 7
0
function fixLinksFromArticle( $id ) {
	global $wgTitle, $wgParser;

	$wgTitle = Title::newFromID( $id );
	$dbw = wfGetDB( DB_MASTER );

	$linkCache =& LinkCache::singleton();
	$linkCache->clear();

	if ( is_null( $wgTitle ) ) {
		return;
	}
	$dbw->begin();

	$revision = Revision::newFromTitle( $wgTitle );
	if ( !$revision ) {
		return;
	}

	$options = new ParserOptions;
	$parserOutput = $wgParser->parse( $revision->getText(), $wgTitle, $options, true, true, $revision->getId() );
	$update = new LinksUpdate( $wgTitle, $parserOutput, false );
	$update->doUpdate();
	$dbw->commit();
}
Ejemplo n.º 8
0
 /**
  * Returns percentile quality of articleId or null if not found
  * @return int|null
  */
 public function getArticleQuality()
 {
     $cacheKey = wfMemcKey(__CLASS__, self::CACHE_BUSTER, $this->articleId);
     $percentile = $this->app->wg->Memc->get($cacheKey);
     if ($percentile === false) {
         $title = Title::newFromID($this->articleId);
         if ($title === null) {
             return null;
         }
         $article = new Article($title);
         $parserOutput = $article->getParserOutput();
         if (!$parserOutput) {
             //MAIN-3592
             $this->error(__METHOD__, ['message' => 'Article::getParserOutput returned false', 'articleId' => $this->articleId]);
             return null;
         }
         $inputs = ['outbound' => 0, 'inbound' => 0, 'length' => 0, 'sections' => 0, 'images' => 0];
         /**
          *  $title->getLinksTo() and  $title->getLinksFrom() function are
          * too expensive to call it here as we want only the number of links
          */
         $inputs['outbound'] = $this->countOutboundLinks($this->articleId);
         $inputs['inbound'] = $this->countInboundLinks($this->articleId);
         $inputs['sections'] = count($parserOutput->getSections());
         $inputs['images'] = count($parserOutput->getImages());
         $inputs['length'] = $this->getCharsCountFromHTML($parserOutput->getText());
         $quality = $this->computeFormula($inputs);
         $percentile = $this->searchPercentile($quality);
         $this->app->wg->Memc->set($cacheKey, $percentile, self::MEMC_CACHE_TIME);
     }
     return $percentile;
 }
Ejemplo n.º 9
0
 /**
  * Checks some initial queries
  * Note that $title here is *not* a Title object, but a string!
  */
 function checkInitialQueries($title, $action, &$output, $request, $lang)
 {
     if ($request->getVal('printable') == 'yes') {
         $output->setPrintable();
     }
     $ret = NULL;
     if ('' == $title && 'delete' != $action) {
         $ret = Title::newMainPage();
     } elseif ($curid = $request->getInt('curid')) {
         # URLs like this are generated by RC, because rc_title isn't always accurate
         $ret = Title::newFromID($curid);
     } else {
         $ret = Title::newFromURL($title);
         /* check variant links so that interwiki links don't have to worry about
         			   the possible different language variants
         			*/
         if (count($lang->getVariants()) > 1 && !is_null($ret) && $ret->getArticleID() == 0) {
             $lang->findVariantLink($title, $ret);
         }
     }
     if (($oldid = $request->getInt('oldid')) && (is_null($ret) || $ret->getNamespace() != NS_SPECIAL)) {
         // Allow oldid to override a changed or missing title.
         $rev = Revision::newFromId($oldid);
         if ($rev) {
             $ret = $rev->getTitle();
         }
     }
     return $ret;
 }
Ejemplo n.º 10
0
 protected function extractTitle()
 {
     $this->articleTitle = Title::newFromID($this->articleId);
     if (is_null($this->articleTitle)) {
         throw new TitleNotFoundException();
     }
 }
Ejemplo n.º 11
0
 /**
  * Parses the wrapped wikitext and returns an HTML block of code with rendered flags.
  * @param array $templateCalls
  * @param $pageId
  * @return ParserOutput
  */
 public function renderFlags(array $templateCalls, $pageId)
 {
     global $wgUser;
     $wikitext = $this->wrapAllFlags($templateCalls);
     $title = \Title::newFromID($pageId);
     return \ParserPool::parse($wikitext, $title, \ParserOptions::newFromUser($wgUser));
 }
 private function removeImagesFromArticle($articleId)
 {
     $title = Title::newFromID($articleId);
     if ($title) {
         $revision = Revision::newFromTitle($title);
         $text = $revision->getText();
         //regular expressions copied out of maintenance/wikiphotoProcessImages.php
         //but modified to remove the leading BR tags if they exist
         //In the callback we keep track of each image name that we remove
         $text = preg_replace_callback('@(<\\s*br\\s*[\\/]?>)*\\s*\\[\\[Image:([^\\]]*)\\]\\]@im', function ($matches) {
             $image = $matches[2];
             $pipeLoc = strpos($image, "|");
             if ($pipeLoc !== false) {
                 $image = substr($image, 0, $pipeLoc);
             }
             AdminImageRemoval::$imagesRemoved[] = $image;
             return '';
         }, $text);
         $text = preg_replace_callback('@(<\\s*br\\s*[\\/]?>)*\\s*\\{\\{largeimage\\|([^\\}]*)\\}\\}@im', function ($matches) {
             $image = $matches[2];
             AdminImageRemoval::$imagesRemoved[] = $image;
             return '';
         }, $text);
         $text = preg_replace('@(<\\s*br\\s*[\\/]?>)*\\s*\\{\\{largeimage\\|[^\\}]*\\}\\}@im', '', $text);
         $article = new Article($title);
         $saved = $article->doEdit($text, 'Removing all images from article.');
     }
 }
Ejemplo n.º 13
0
 public function run($paramArray, $isAsync, $delay)
 {
     echo "bot started\n";
     if (array_key_exists("WS_WSID", $paramArray) && $paramArray["WS_WSID"] != null) {
         $log = SGAGardeningIssuesAccess::getGardeningIssuesAccess();
         $ws = WebService::newFromID($paramArray["WS_WSID"]);
         $affectedArticles = $this->updateWSResults($ws);
         $this->setNumberOfTasks(2);
     } else {
         $affectedArticles = $this->updateAllWSResults();
     }
     ksort($affectedArticles);
     $affectedArticles = array_flip($affectedArticles);
     echo "\nRefreshing articles: \n";
     foreach ($affectedArticles as $articleId => $dontCare) {
         echo "\t refreshing articleId: " . $articleId . "\n";
         $title = Title::newFromID($articleId);
         $updatejob = new SMWUpdateJob($title);
         $updatejob->run();
     }
     echo "\nbot finished";
     global $smwgDefaultStore;
     if ($smwgDefaultStore == 'SMWTripleStore' || $smwgDefaultStore == 'SMWTripleStoreQuad') {
         define('SMWH_FORCE_TS_UPDATE', 'TRUE');
         smwfGetStore()->initialize(true);
     }
     return '';
 }
 public function getExhibitionItems(Title $title)
 {
     wfProfileIn(__METHOD__);
     if (class_exists('CategoryDataService')) {
         $cacheKey = $this->getExhibitionItemsCacheKey($title->getText());
         $items = $this->wg->memc->get($cacheKey);
         if (!is_array($items)) {
             $exh = CategoryDataService::getMostVisited($title->getDBkey(), null, self::EXHIBITION_ITEMS_LIMIT);
             $ids = array_keys($exh);
             $length = count($ids);
             $items = array();
             for ($i = 0; $i < $length; $i++) {
                 $pageId = $ids[$i];
                 $imgRespnse = $this->app->sendRequest('ImageServing', 'index', array('ids' => array($pageId), 'height' => 150, 'width' => 150, 'count' => 1));
                 $img = $imgRespnse->getVal('result');
                 if (!empty($img[$pageId])) {
                     $img = $img[$pageId][0]['url'];
                 } else {
                     $img = false;
                 }
                 $oTitle = Title::newFromID($pageId);
                 $items[] = ['img' => $img, 'title' => $oTitle->getText(), 'url' => $oTitle->getFullURL()];
             }
             $this->wg->memc->set($cacheKey, $items, self::CACHE_TTL_EXHIBITION);
         }
         wfProfileOut(__METHOD__);
         return $items;
     }
     wfProfileOut(__METHOD__);
     return false;
 }
Ejemplo n.º 15
0
 /**
  * Fill the internal arrays with the set of articles to be displayed (possibly plus one additional
  * article that indicates further results).
  */
 protected function doQuery()
 {
     global $wgContLang;
     // ask for the list of articles that use the web service
     $options = new SMWRequestOptions();
     $options->limit = $this->limit + 1;
     $options->sort = true;
     $reverse = false;
     if ($this->mFromArticle != '') {
         $options->boundary = $this->mFromArticle;
         $options->ascending = true;
         $options->include_boundary = true;
     } elseif ($this->mUntilArticle != '') {
         $options->boundary = $this->mUntilArticle;
         $options->ascending = false;
         $options->include_boundary = false;
         $reverse = true;
     }
     $articleIDs = WSStorage::getDatabase()->getWSArticles($this->getTitle()->getArticleID(), $options);
     foreach ($articleIDs as $articleId) {
         $this->mArticles[] = Title::newFromID($articleId);
     }
     if ($reverse) {
         $this->mArticles = array_reverse($this->mArticles);
     }
     foreach ($this->mArticles as $title) {
         $this->articles_start_char[] = $wgContLang->convert($wgContLang->firstChar($title->getText()));
     }
 }
Ejemplo n.º 16
0
 function formatValue($name, $value)
 {
     global $wgContLang;
     switch ($name) {
         case 'article_title':
             $articleId = $this->mCurrentRow->article_id;
             $title = Title::newFromID($articleId);
             return $title ? Linker::link($title) : '(unknown, id: ' . $articleId . ')';
             break;
         case 'page_ns':
             return ($value != 0 ? $wgContLang->getNsText($value) : $this->mainNamespaceText) . " [{$value}]";
             break;
         case 'average_time':
         case 'minimum_time':
         case 'maximum_time':
             return $value . " s";
             break;
         case 'wikitext_size':
         case 'html_size':
             return sprintf("%.1f kb", $value / 1000);
             break;
         default:
             return $value;
     }
 }
Ejemplo n.º 17
0
 /**
  * Constructor from a page id
  * @param int $id article ID to load
  * @return ImagePage|null
  */
 public static function newFromID($id)
 {
     $t = Title::newFromID($id);
     # @todo FIXME: Doesn't inherit right
     return $t == null ? null : new self($t);
     # return $t == null ? null : new static( $t ); // PHP 5.3
 }
 /**
  * Returns information to summarize an article with a snippet of text and a picture if applicable.
  */
 public function blurb()
 {
     wfProfileIn(__METHOD__);
     $idStr = $this->request->getVal('ids');
     $ids = explode(',', $idStr);
     $summary = array();
     # Iterate through each title per wiki ID
     foreach ($ids as $id) {
         $title = Title::newFromID($id);
         if (empty($title)) {
             $summary[$this->wg->CityId]['error'][] = "Unable to find title for ID {$id}";
             break;
         }
         $service = new ArticleService($id);
         $snippet = $service->getTextSnippet();
         $imageServing = new ImageServing(array($id), 200, array('w' => 2, 'h' => 1));
         $images = $imageServing->getImages(1);
         // get just one image per article
         $imageURL = '';
         if (isset($images[$id])) {
             $imageURL = $images[$id][0]['url'];
         }
         $summary[$id] = array('wiki' => $this->wg->Sitename, 'wikiUrl' => $this->wg->Server, 'titleDBkey' => $title->getPrefixedDBkey(), 'titleText' => $title->getFullText(), 'articleId' => $title->getArticleID(), 'imageUrl' => $imageURL, 'url' => $title->getFullURL(), 'snippet' => $snippet);
     }
     wfProfileOut(__METHOD__);
     $this->summary = $summary;
 }
Ejemplo n.º 19
0
 function addLinkToRandomArticleInSameCategory($t, $summary = "Weaving the web of links", $linktext = null)
 {
     global $wgOut;
     $cats = array_keys($t->getParentCategories());
     $found = false;
     while (sizeof($cats) > 0) {
         $cat = array_shift($cats);
         $cat = preg_replace("@^Category:@", "", $cat);
         $cat = Title::newFromText($cat);
         if (in_array($cat->getText(), self::$ignore_cats)) {
             #echo "ignoring cat {$cat->getText()}\n";
             continue;
         }
         #echo "using cat {$cat->getText()} for {$t->getFullText()}\n";
         $dbr = wfGetDB(DB_SLAVE);
         $id = $dbr->selectField(array('categorylinks', 'page'), array('cl_from'), array('cl_to' => $cat->getDBKey(), 'page_id = cl_from', 'page_namespace' => NS_MAIN, 'page_is_redirect' => 0), "AddRelatedLinks::execute", array("ORDER BY" => "rand()", "LIMIT" => 1));
         if (!$id) {
             $wgOut->addHTML("<li>Couldn't get a category/enough results for <b>{$t->getText()}</b></li>\n");
             continue;
         }
         $src = Title::newFromID($id);
         #$wgOut->addHTML("<li>Linked from <b>{$src->getText()}</b> to <b>{$t->getText()}</b> by picking a random article from the same category</li>\n");
         #kecho("Linked from {$src->getText()} to {$t->getText()} by picking a random article from the same category</li>\n");
         MarkRelated::addRelated($src, $t, $summary, true, $linktext);
         $found = true;
         return $src;
     }
     #if (!$found)
     #echo "Count'd find anything for {$t->getFullText()} " . print_r(array_keys($t->getParentCategories()), true) . "\n";
     return null;
 }
 /**
  * The content for an article page. This is included on the index (for the current title)
  * if lazy loading is disabled, otherwise it is requested via AJAX.
  */
 public function content()
 {
     //this is coming via ajax we need to set correct wgTitle ourselves
     global $wgTitle;
     wfProfileIn(__METHOD__);
     $articleId = $this->request->getVal('articleId', null);
     $page = $this->request->getVal('page', 1);
     $title = null;
     if (!empty($articleId)) {
         $wgTitle = $title = Title::newFromID($articleId);
     }
     if (!$title instanceof Title) {
         $title = $this->wg->title;
     }
     // If articleId is invalid, don't trigger a fatal error, just throw a 404 and return nothing.
     if ($title === null) {
         $this->response->setCode(404);
         $this->skipRendering();
         wfProfileOut(__METHOD__);
         return;
     }
     $this->getCommentsData($title, $page);
     $this->isMiniEditorEnabled = ArticleComment::isMiniEditorEnabled();
     // Uncomment this when surrogate key purging works
     //$this->wg->Out->tagWithSurrogateKeys( ArticleComment::getSurrogateKey($articleId) );
     // When lazy loading this request it shouldn't be cached in the browser
     if (!empty($this->wg->ArticleCommentsLoadOnDemand)) {
         $this->response->setCachePolicy(WikiaResponse::CACHE_PRIVATE);
         $this->response->setCacheValidity(WikiaResponse::CACHE_DISABLED);
     }
     if (F::app()->checkSkin('venus')) {
         $this->overrideTemplate('VenusContent');
     }
     wfProfileOut(__METHOD__);
 }
 function execute()
 {
     wfProfileIn(__METHOD__);
     global $wgOut, $wgRequest;
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         wfProfileOut(__METHOD__);
         return;
     }
     $articleID = $wgRequest->getInt('articleid');
     $title = Title::newFromID($articleID);
     if (!is_null($title) && $title->exists()) {
         if (strpos($_SERVER['HTTP_USER_AGENT'], 'facebook') === false && strpos($_SERVER['HTTP_USER_AGENT'], 'bitlybot') === false) {
             $sharerID = $wgRequest->getInt('userid');
             $viewerIP = $wgRequest->getIP();
             $awardingService = new AchAwardingService();
             $awardingService->processSharing($articleID, $sharerID, $viewerIP);
         }
     } else {
         $title = Title::newMainPage();
     }
     // this works only for Wikia and only in current varnish configuration
     if (!headers_sent()) {
         header('X-Pass-Cache-Control: no-store, private, no-cache, must-revalidate');
     }
     $wgOut->redirect($title->getLocalURL());
     wfProfileOut(__METHOD__);
 }
 function execute()
 {
     // Get the parameters
     $params = $this->extractRequestParams();
     $result = $this->getResult();
     $module = $this->getModuleName();
     $error = '';
     $id = $params['id'];
     $name = $params['name'];
     $title = null;
     if ($id) {
         $title = Title::newFromID($id);
     } elseif ($name) {
         $title = Title::newFromURL($name);
     }
     if (!$title || !$title->exists()) {
         $error = 'Title not found';
     } else {
         $revid = $params['revid'];
         $downloader = new MobileArticleDownloader();
         $articleResult = $downloader->getArticleData($title, $revid);
         $result->addValue(null, $module, $articleResult);
     }
     if ($error) {
         $result->addValue(null, $module, array('error' => $error));
     }
     return true;
 }
Ejemplo n.º 23
0
 public function execute()
 {
     global $wgCityId;
     $db = wfGetDB(DB_MASTER);
     (new WikiaSQL())->SELECT('*')->FROM('page')->WHERE('page_is_redirect')->EQUAL_TO(1)->runLoop($db, function ($a, $row) use($db) {
         $title = Title::newFromID($row->page_id);
         if (!$title->isDeleted()) {
             $rev = Revision::newFromTitle($title);
             $text = $rev->getText();
             $rt = Title::newFromRedirectRecurse($text);
             if (!$rt) {
                 // page is marked as redirect but $text is not valid redirect
                 $this->output('Fixed ID: ' . $title->getArticleID() . ' Title: ' . $title->getText() . "\n");
                 // Fix page table
                 (new WikiaSQL())->UPDATE('page')->SET('page_is_redirect', 0)->WHERE('page_id')->EQUAL_TO($row->page_id)->RUN($db);
                 // remove redirect from redirect table
                 (new WikiaSQL())->DELETE('redirect')->WHERE('rd_from')->EQUAL_TO($row->page_id)->RUN($db);
                 // clear cache
                 LinkCache::singleton()->addGoodLinkObj($row->page_id, $title, strlen($text), 0, $rev->getId());
                 if ($title->getNamespace() == NS_FILE) {
                     RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($title);
                 }
             }
         }
     });
 }
 function newAttachmentData($id)
 {
     $obj = $this->cacheManager->retrieveAtachmentData($id);
     if ($obj instanceof \PageAttachment\Attachment\AttachmentData) {
         $pageAttachmentData = $obj;
     } else {
         $title = \Title::newFromID($id);
         $article = new \Article($title, NS_FILE);
         $file = \wfFindFile($title);
         $size = $file->getSize();
         $description = $this->replaceHtmlTags($file->getDescriptionText());
         $dateUploaded = $article->getTimestamp();
         $uploadedBy = null;
         if ($this->runtimeConfig->isShowUserRealName()) {
             $uploadedBy = \User::whoIsReal($article->getUser());
         }
         if ($uploadedBy == null) {
             $uploadedBy = \User::whoIs($article->getUser());
         }
         $attachedToPages = null;
         if ($this->securityManager->isRemoveAttachmentPermanentlyEnabled()) {
             $attachedToPages = $this->getAttachedToPages($id);
         }
         $pageAttachmentData = new AttachmentData($id, $title, $size, $description, $dateUploaded, $uploadedBy, $attachedToPages);
         $this->cacheManager->storeAttachmentData($pageAttachmentData);
     }
     return $pageAttachmentData;
 }
 public static function createWatchedItem($pageId, $modifiedByUserId, $modificationType, $modificationTime)
 {
     $title = \Title::newFromID($pageId);
     $pageTitle = $title->getText();
     $watchers = self::loadWatchers($title, $modifiedByUserId);
     $watched = count($watchers) > 0 ? true : false;
     return new WatchedItem($pageId, $pageTitle, $modifiedByUserId, $modificationType, $modificationTime, $watched, $watchers);
 }
function smwf_ws_deleteWWSD($wsId)
{
    global $smwgDIIP, $wgUser;
    require_once $smwgDIIP . '/specials/WebServices/SMW_WSStorage.php';
    $pageName = Title::newFromID($wsId)->getFullText();
    smwf_om_DeleteArticle($pageName, $wgUser->getName(), 'Deleted via the WebServiceRepository special page.');
    return $wsId;
}
 public static function addVote($page_id, $user_id, $author_id = null)
 {
     if ($author_id === null) {
         $author_id = self::getPageAuthor(Title::newFromID($page_id))->getId();
     }
     $dbw = wfGetDB(DB_MASTER);
     $dbw->insert('author_rating', array('user_id' => $user_id, 'author_user_id' => $author_id, 'page_id' => $page_id, 'created_at' => time()));
 }
Ejemplo n.º 28
0
 public function execute()
 {
     global $wgUser, $wgArticleFeedbackRatingTypes, $wgArticleFeedbackSMaxage, $wgArticleFeedbackNamespaces;
     $params = $this->extractRequestParams();
     // Anon token check
     if ($wgUser->isAnon()) {
         if (!isset($params['anontoken'])) {
             $this->dieUsageMsg(array('missingparam', 'anontoken'));
         } elseif (strlen($params['anontoken']) != 32) {
             $this->dieUsage('The anontoken is not 32 characters', 'invalidtoken');
         }
         $token = $params['anontoken'];
     } else {
         $token = '';
     }
     // Load check, is this page ArticleFeedback-enabled ?
     // Keep in sync with ext.articleFeedback.startup.js
     $title = Title::newFromID($params['pageid']);
     if (is_null($title) || !in_array($title->getNamespace(), $wgArticleFeedbackNamespaces) || $title->isRedirect()) {
         // ...then error out
         $this->dieUsage('ArticleFeedback is not enabled on this page', 'invalidpage');
     }
     $dbw = wfGetDB(DB_MASTER);
     // Query the latest ratings by this user for this page,
     // possibly for an older revision
     // Select from the master to prevent replag-induced bugs
     $res = $dbw->select('article_feedback', array('aa_rating_id', 'aa_rating_value', 'aa_revision'), array('aa_user_text' => $wgUser->getName(), 'aa_page_id' => $params['pageid'], 'aa_rating_id' => array_keys($wgArticleFeedbackRatingTypes), 'aa_user_anon_token' => $token), __METHOD__, array('ORDER BY' => 'aa_revision DESC', 'LIMIT' => count($wgArticleFeedbackRatingTypes)));
     $lastRatings = array();
     foreach ($res as $row) {
         $lastRatings[$row->aa_rating_id]['value'] = $row->aa_rating_value;
         $lastRatings[$row->aa_rating_id]['revision'] = $row->aa_revision;
     }
     $pageId = $params['pageid'];
     $revisionId = $params['revid'];
     foreach ($wgArticleFeedbackRatingTypes as $ratingID => $unused) {
         $lastPageRating = false;
         $lastRevRating = false;
         if (isset($lastRatings[$ratingID])) {
             $lastPageRating = intval($lastRatings[$ratingID]['value']);
             if (intval($lastRatings[$ratingID]['revision']) == $revisionId) {
                 $lastRevRating = $lastPageRating;
             }
         }
         $thisRating = false;
         if (isset($params["r{$ratingID}"])) {
             $thisRating = intval($params["r{$ratingID}"]);
         }
         $this->insertRevisionRating($pageId, $revisionId, $ratingID, $thisRating - $lastRevRating, $thisRating, $lastRevRating);
         $this->insertPageRating($pageId, $ratingID, $thisRating - $lastPageRating, $thisRating, $lastPageRating);
         $this->insertUserRatings($pageId, $revisionId, $wgUser, $token, $ratingID, $thisRating, $params['bucket']);
     }
     $this->insertProperties($revisionId, $wgUser, $token, $params);
     $squidUpdate = new SquidUpdate(array(wfAppendQuery(wfScript('api'), array('action' => 'query', 'format' => 'json', 'list' => 'articlefeedback', 'afpageid' => $pageId, 'afanontoken' => '', 'afuserrating' => 0, 'maxage' => 0, 'smaxage' => $wgArticleFeedbackSMaxage))));
     $squidUpdate->doUpdate();
     wfRunHooks('ArticleFeedbackChangeRating', array($params));
     $r = array('result' => 'Success');
     $this->getResult()->addValue(null, $this->getModuleName(), $r);
 }
Ejemplo n.º 29
0
 /**
  * Parse the request to get the Title object
  *
  * @return Title object to be $wgTitle
  */
 private function parseTitle()
 {
     global $wgContLang;
     $request = $this->context->getRequest();
     $curid = $request->getInt('curid');
     $title = $request->getVal('title');
     $action = $request->getVal('action', 'view');
     if ($request->getCheck('search')) {
         // Compatibility with old search URLs which didn't use Special:Search
         // Just check for presence here, so blank requests still
         // show the search page when using ugly URLs (bug 8054).
         $ret = SpecialPage::getTitleFor('Search');
     } elseif ($curid) {
         // URLs like this are generated by RC, because rc_title isn't always accurate
         $ret = Title::newFromID($curid);
     } elseif ($title == '' && $action != 'delete') {
         $ret = Title::newMainPage();
         /* Wikia change begin - @author: Macbre */
         /* Add hook to allow modification of page user is redirected to when title is not specified in URL */
         if (!$request->getInt('diff') && !$request->getInt('oldid')) {
             wfRunHooks('InitialQueriesMainPage', array(&$ret));
         }
         /* Wikia change end */
     } else {
         $ret = Title::newFromURL($title);
         // Alias NS_MEDIA page URLs to NS_FILE...we only use NS_MEDIA
         // in wikitext links to tell Parser to make a direct file link
         if (!is_null($ret) && $ret->getNamespace() == NS_MEDIA) {
             $ret = Title::makeTitle(NS_FILE, $ret->getDBkey());
         }
         // Check variant links so that interwiki links don't have to worry
         // about the possible different language variants
         if (count($wgContLang->getVariants()) > 1 && !is_null($ret) && $ret->getArticleID() == 0) {
             $wgContLang->findVariantLink($title, $ret);
         }
     }
     // For non-special titles, check for implicit titles
     if (is_null($ret) || !$ret->isSpecialPage()) {
         // We can have urls with just ?diff=,?oldid= or even just ?diff=
         $oldid = $request->getInt('oldid');
         $oldid = $oldid ? $oldid : $request->getInt('diff');
         // Allow oldid to override a changed or missing title
         if ($oldid) {
             $rev = Revision::newFromId($oldid);
             $ret = $rev ? $rev->getTitle() : $ret;
         }
     }
     /* Wikia change begin - @author: nAndy */
     /* Add hook to allow modification of page user is redirected to when title is not specified in URL */
     /* It can be used for redirects but it changes url in end user's browser so it might not be what you want it to be */
     wfRunHooks('AfterCheckInitialQueries', array(&$title, &$action, &$ret));
     /* Wikia change end */
     if ($ret === null || $ret->getDBkey() == '' && $ret->getInterwiki() == '') {
         $ret = SpecialPage::getTitleFor('Badtitle');
     }
     return $ret;
 }
 public function initEmail()
 {
     $pageTitle = $this->request->getVal('pageTitle');
     $titleNamespace = $this->request->getVal('namespace', NS_MAIN);
     $pageAddedToCategoryId = $this->getVal('childArticleID');
     $this->categoryPage = \Title::newFromText($pageTitle, $titleNamespace);
     $this->pageAddedToCategory = \Title::newFromID($pageAddedToCategoryId);
     $this->assertValidParams();
 }