Ejemplo n.º 1
0
 public function execute($parameters)
 {
     global $wgOut, $wgRequest, $wgDisableTextSearch, $wgScript;
     $this->setHeaders();
     list($limit, $offset) = wfCheckLimits();
     $wgOut->addWikiText(wfMsgForContentNoTrans('proofreadpage_specialpage_text'));
     $this->searchList = null;
     $this->searchTerm = $wgRequest->getText('key');
     $this->suppressSqlOffset = false;
     if (!$wgDisableTextSearch) {
         $self = $this->getTitle();
         $wgOut->addHTML(Xml::openElement('form', array('action' => $wgScript)) . Html::hidden('title', $this->getTitle()->getPrefixedText()) . Xml::input('limit', false, $limit, array('type' => 'hidden')) . Xml::openElement('fieldset') . Xml::element('legend', null, wfMsg('proofreadpage_specialpage_legend')) . Xml::input('key', 20, $this->searchTerm) . ' ' . Xml::submitButton(wfMsg('ilsubmit')) . Xml::closeElement('fieldset') . Xml::closeElement('form'));
         if ($this->searchTerm) {
             $index_namespace = $this->index_namespace;
             $index_ns_index = MWNamespace::getCanonicalIndex(strtolower(str_replace(' ', '_', $index_namespace)));
             $searchEngine = SearchEngine::create();
             $searchEngine->setLimitOffset($limit, $offset);
             $searchEngine->setNamespaces(array($index_ns_index));
             $searchEngine->showRedirects = false;
             $textMatches = $searchEngine->searchText($this->searchTerm);
             $escIndex = preg_quote($index_namespace, '/');
             $this->searchList = array();
             while ($result = $textMatches->next()) {
                 $title = $result->getTitle();
                 if ($title->getNamespace() == $index_ns_index) {
                     array_push($this->searchList, $title->getDBkey());
                 }
             }
             $this->suppressSqlOffset = true;
         }
     }
     parent::execute($parameters);
 }
Ejemplo n.º 2
0
function efGroupPortal_MediaWikiPerformAction($output, $article, $title, $user, $request)
{
    $action = $request->getVal('action', 'view');
    $redirect = $request->getVal('redirect');
    if ($action === 'view' && $redirect === null) {
        if ($title->equals(Title::newMainPage())) {
            $groupPortals = spliti("\n", wfMsgForContentNoTrans('groupportal'));
            $groups = $user->getGroups();
            $targetPortal = '';
            foreach ($groupPortals as $groupPortal) {
                $mcount = preg_match('/^(.+)\\|(.+)$/', $groupPortal, $matches);
                if ($mcount > 0) {
                    if (in_array($matches[1], $groups) || $matches[1] == '*' && empty($targetPortal)) {
                        $targetPortal = $matches[2];
                    }
                }
            }
            if (!empty($targetPortal)) {
                $target = Title::newFromText($targetPortal);
                if (is_object($target)) {
                    $output->redirect($target->getLocalURL());
                    return false;
                }
            }
        }
    }
    return true;
}
Ejemplo n.º 3
0
function wfCreatePageLoadPreformattedContent($editpage)
{
    global $wgRequest;
    if ($wgRequest->getCheck('useFormat')) {
        $editpage->textbox1 = wfMsgForContentNoTrans('newpagelayout');
    }
    return true;
}
Ejemplo n.º 4
0
function wfMetaKeywordInput($type)
{
    global $wgContLang, $wgMemc, $wgDBname;
    $params = wfMsgForContentNoTrans("meta{$type}");
    $opts = array(0);
    if (!wfEmptyMsg("meta{$type}", $params)) {
        $opts = wfMetaKeywordParse($params);
    }
    return $opts;
}
function getValidProjects() {
	global $wgOut;

	$validProjects = wfMsgForContentNoTrans( 'todoTasksValidProjects' );
	if ( $validProjects == '' ) {
		$wgOut->addWikiText( wfMsg( 'tasklistnoprojects' ) );
		return;
	}
	return $validProjects;
}
Ejemplo n.º 6
0
 function execute()
 {
     global $wgOut, $wgUser, $wgParser, $wgHooks, $wgCiteDefaultText;
     $wgHooks['ParserGetVariableValueTs'][] = array($this, 'timestamp');
     $msg = wfMsgForContentNoTrans('cite_text');
     if ($msg == '') {
         $msg = $wgCiteDefaultText;
     }
     $this->mArticle->fetchContent($this->mId, false);
     $ret = $wgParser->parse($msg, $this->mTitle, $this->mParserOptions, false, true, $this->mArticle->getRevIdFetched());
     $wgOut->addHTML($ret->getText());
 }
Ejemplo n.º 7
0
/**
 * Determine if an image exists on the 'bad image list'.
 *
 * The format of MediaWiki:Bad_image_list is as follows:
 *    * Only list items (lines starting with "*") are considered
 *    * The first link on a line must be a link to a bad image
 *    * Any subsequent links on the same line are considered to be exceptions,
 *      i.e. articles where the image may occur inline.
 *
 * @param $name string the image name to check
 * @param $contextTitle Title|bool the page on which the image occurs, if known
 * @return bool
 */
function wfIsBadImage($name, $contextTitle = false)
{
    static $badImages = false;
    wfProfileIn(__METHOD__);
    # Handle redirects
    $redirectTitle = RepoGroup::singleton()->checkRedirect(Title::makeTitle(NS_FILE, $name));
    if ($redirectTitle) {
        $name = $redirectTitle->getDbKey();
    }
    # Run the extension hook
    $bad = false;
    if (!wfRunHooks('BadImage', array($name, &$bad))) {
        wfProfileOut(__METHOD__);
        return $bad;
    }
    if (!$badImages) {
        # Build the list now
        $badImages = array();
        $lines = explode("\n", wfMsgForContentNoTrans('bad_image_list'));
        foreach ($lines as $line) {
            # List items only
            if (substr($line, 0, 1) !== '*') {
                continue;
            }
            # Find all links
            $m = array();
            if (!preg_match_all('/\\[\\[:?(.*?)\\]\\]/', $line, $m)) {
                continue;
            }
            $exceptions = array();
            $imageDBkey = false;
            foreach ($m[1] as $i => $titleText) {
                $title = Title::newFromText($titleText);
                if (!is_null($title)) {
                    if ($i == 0) {
                        $imageDBkey = $title->getDBkey();
                    } else {
                        $exceptions[$title->getPrefixedDBkey()] = true;
                    }
                }
            }
            if ($imageDBkey !== false) {
                $badImages[$imageDBkey] = $exceptions;
            }
        }
    }
    $contextKey = $contextTitle ? $contextTitle->getPrefixedDBkey() : false;
    $bad = isset($badImages[$name]) && !isset($badImages[$name][$contextKey]);
    wfProfileOut(__METHOD__);
    return $bad;
}
Ejemplo n.º 8
0
/**
 * Fills the textbox of a new page with content.
 */
function lw_templatePreload(&$textbox, Title &$title)
{
    $lwVars = getLyricWikiVariables();
    $titleStr = $title->getText();
    // only use templates in the main namespace
    $ns = $title->getNamespace();
    if ($ns != NS_MAIN && $ns != NS_TALK) {
        return true;
    }
    $tempType = "";
    $pageType = "";
    if (isset($_GET['template'])) {
        $pageType = strtolower($_GET['template']);
    }
    if ($pageType == "") {
        $pageType = $lwVars["pagetype"];
    }
    # pull template from database and replace placeholds
    if ($pageType == "none") {
        $textbox = "";
    } else {
        $extra = trim(wfMsgForContentNoTrans("lwtemp-extra-templates"));
        if ($extra != "") {
            $extras = explode("\n", $extra);
            foreach ($extras as $item) {
                if (strpos($item, "|")) {
                    $parts = explode("|", $item);
                    if (0 < preg_match("/{$parts[0]}/", $titleStr, $m)) {
                        $pageType = $parts[1];
                    }
                }
            }
        }
        $template = wfMsgForContentNoTrans("lwtemp-{$pageType}-template");
        // only display a template if the template actually exists
        if ($template != "<{$pageType}Template>" and $template != "&lt;{$pageType}Template&gt;") {
            $textbox = $template;
            $lwVars = getLyricWikiVariables();
            $replace = array();
            $with = array();
            foreach ($lwVars as $key => $value) {
                $replace[] = "{{" . strtoupper($key) . "}}";
                $with[] = $value;
            }
            $textbox = str_replace($replace, $with, $textbox);
        }
    }
    return true;
}
Ejemplo n.º 9
0
function wfLoadGadgetsStructured($forceNewText = NULL)
{
    global $wgContLang;
    global $wgMemc, $wgDBname;
    static $gadgets = NULL;
    if ($gadgets !== NULL && $forceNewText !== NULL) {
        return $gadgets;
    }
    $key = "{$wgDBname}:gadgets-definition";
    if ($forceNewText == NULL) {
        //cached?
        $gadgets = $wgMemc->get($key);
        if ($gadgets !== NULL) {
            return $gadgets;
        }
        $g = wfMsgForContentNoTrans("gadgets-definition");
        if (wfEmptyMsg("gadgets-definition", $g)) {
            $gadgets = false;
            return $gadgets;
        }
    } else {
        $g = $forceNewText;
    }
    $g = preg_replace('/<!--.*-->/s', '', $g);
    $g = preg_split('/(\\r\\n|\\r|\\n)+/', $g);
    $gadgets = array();
    $section = '';
    foreach ($g as $line) {
        if (preg_match('/^==+ *([^*:\\s|]+?)\\s*==+\\s*$/', $line, $m)) {
            $section = $m[1];
        } else {
            if (preg_match('/^\\*+ *([a-zA-Z](?:[-_:.\\w\\d ]*[a-zA-Z0-9])?)\\s*((\\|[^|]*)+)\\s*$/', $line, $m)) {
                //NOTE: the gadget name is used as part of the name of a form field,
                //      and must follow the rules defined in http://www.w3.org/TR/html4/types.html#type-cdata
                //      Also, title-normalization applies.
                $name = str_replace(' ', '_', $m[1]);
                $code = preg_split('/\\s*\\|\\s*/', $m[2], -1, PREG_SPLIT_NO_EMPTY);
                if ($code) {
                    $gadgets[$section][$name] = $code;
                }
            }
        }
    }
    //cache for a while. gets purged automatically when MediaWiki:Gadgets-definition is edited
    $wgMemc->set($key, $gadgets, 900);
    wfDebug("wfLoadGadgetsStructured: MediaWiki:Gadgets-definition parsed, cache entry {$key} updated\n");
    return $gadgets;
}
Ejemplo n.º 10
0
/**
 * Constructor
 */
function wfSpecialRecentchanges($par, $specialPage)
{
    global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
    global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
    global $wgAllowCategorizedRecentChanges;
    $fname = 'wfSpecialRecentchanges';
    $userGroups = $wgUser->getGroups();
    if (!$wgUser->isAllowed('patrol') || in_array('patrolblock', $userGroups)) {
        $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
        return;
    }
    # Get query parameters
    $feedFormat = $wgRequest->getVal('feed');
    /* Checkbox values can't be true by default, because
     * we cannot differentiate between unset and not set at all
     */
    $defaults = array('days' => $wgUser->getDefaultOption('rcdays'), 'limit' => $wgUser->getDefaultOption('rclimit'), 'hideminor' => false, 'hidebots' => true, 'hideanons' => false, 'hideliu' => false, 'hidepatrolled' => false, 'hidemyself' => false, 'from' => '', 'namespace' => null, 'invert' => false, 'categories_any' => false, 'reverse' => false, 'featured' => false, 'categories_any' => false);
    extract($defaults);
    $days = $wgUser->getOption('rcdays', $defaults['days']);
    $days = $wgRequest->getInt('days', $days);
    $limit = $wgUser->getOption('rclimit', $defaults['limit']);
    #	list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
    $limit = $wgRequest->getInt('limit', $limit);
    /* order of selection: url > preferences > default */
    $hideminor = $wgRequest->getBool('hideminor', $wgUser->getOption('hideminor') ? true : $defaults['hideminor']);
    # As a feed, use limited settings only
    if ($feedFormat) {
        global $wgFeedLimit;
        if ($limit > $wgFeedLimit) {
            $limit = $wgFeedLimit;
        }
    } else {
        $namespace = $wgRequest->getIntOrNull('namespace');
        $invert = $wgRequest->getBool('invert', $defaults['invert']);
        //XXADDED
        $reverse = $wgRequest->getBool('reverse', $defaults['reverse']);
        $featured = $wgRequest->getBool('featured', $defaults['featured']);
        $hidebots = $wgRequest->getBool('hidebots', $defaults['hidebots']);
        $hideanons = $wgRequest->getBool('hideanons', $defaults['hideanons']);
        $hideliu = $wgRequest->getBool('hideliu', $defaults['hideliu']);
        $hidepatrolled = $wgRequest->getBool('hidepatrolled', $defaults['hidepatrolled']);
        $hidemyself = $wgRequest->getBool('hidemyself', $defaults['hidemyself']);
        $from = $wgRequest->getVal('from', $defaults['from']);
        # Get query parameters from path
        if ($par) {
            $bits = preg_split('/\\s*,\\s*/', trim($par));
            foreach ($bits as $bit) {
                if ('hidebots' == $bit) {
                    $hidebots = 1;
                }
                if ('bots' == $bit) {
                    $hidebots = 0;
                }
                if ('hideminor' == $bit) {
                    $hideminor = 1;
                }
                if ('minor' == $bit) {
                    $hideminor = 0;
                }
                if ('hideliu' == $bit) {
                    $hideliu = 1;
                }
                if ('hidepatrolled' == $bit) {
                    $hidepatrolled = 1;
                }
                if ('hideanons' == $bit) {
                    $hideanons = 1;
                }
                if ('hidemyself' == $bit) {
                    $hidemyself = 1;
                }
                if (is_numeric($bit)) {
                    $limit = $bit;
                }
                $m = array();
                if (preg_match('/^limit=(\\d+)$/', $bit, $m)) {
                    $limit = $m[1];
                }
                if (preg_match('/^days=(\\d+)$/', $bit, $m)) {
                    $days = $m[1];
                }
            }
        }
    }
    if ($limit < 0 || $limit > 5000) {
        $limit = $defaults['limit'];
    }
    # Database connection and caching
    $dbr = wfGetDB(DB_SLAVE);
    list($recentchanges, $watchlist) = $dbr->tableNamesN('recentchanges', 'watchlist');
    $cutoff_unixtime = time() - $days * 86400;
    $cutoff_unixtime = $cutoff_unixtime - $cutoff_unixtime % 86400;
    $cutoff = $dbr->timestamp($cutoff_unixtime);
    if (preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW, $cutoff)) {
        $cutoff = $dbr->timestamp($from);
    } else {
        $from = $defaults['from'];
    }
    # 10 seconds server-side caching max
    $wgOut->setSquidMaxage(0);
    # Get last modified date, for client caching
    # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
    $lastmod = $dbr->selectField('recentchanges', 'MAX(rc_timestamp)', false, $fname);
    if ($feedFormat || !$wgUseRCPatrol) {
        if ($lastmod && $wgOut->checkLastModified($lastmod)) {
            # Client cache fresh and headers sent, nothing more to do.
            return;
        }
    }
    # It makes no sense to hide both anons and logged-in users
    # Where this occurs, force anons to be shown
    if ($hideanons && $hideliu) {
        $hideanons = false;
    }
    # Form WHERE fragments for all the options
    $hidem = $hideminor ? 'AND rc_minor = 0' : '';
    $hidem .= $hidebots ? ' AND rc_bot = 0' : '';
    $hidem .= $hideliu ? ' AND rc_user = 0' : '';
    $hidem .= $wgUseRCPatrol && $hidepatrolled ? ' AND rc_patrolled = 0' : '';
    $hidem .= $hideanons ? ' AND rc_user != 0' : '';
    if ($hidemyself) {
        if ($wgUser->getID()) {
            $hidem .= ' AND rc_user != ' . $wgUser->getID();
        } else {
            $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes($wgUser->getName());
        }
    }
    # Namespace filtering
    $hidem .= is_null($namespace) ? '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace;
    //XXADDED
    $order = $reverse ? " ASC" : "DESC";
    $ft = $featured ? " AND page_is_featured = 1 " : "";
    // This is the big thing!
    $uid = $wgUser->getID();
    //XXCHANGED
    // Perform query
    $forceclause = $dbr->useIndexClause("rc_timestamp");
    $sql2 = "SELECT * FROM {$recentchanges} {$forceclause}" . ($uid ? "LEFT OUTER JOIN {$watchlist} ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . " LEFT OUTER JOIN page ON page_title=rc_title AND page_namespace=rc_namespace " . "WHERE rc_timestamp >= '{$cutoff}' {$hidem} {$ft} " . "ORDER BY rc_timestamp {$order} ";
    $sql2 = $dbr->limitResult($sql2, $limit, 0);
    $res = $dbr->query($sql2, $fname);
    // Fetch results, prepare a batch link existence check query
    $rows = array();
    $batch = new LinkBatch();
    while ($row = $dbr->fetchObject($res)) {
        $rows[] = $row;
        if (!$feedFormat) {
            // User page and talk links
            $batch->add(NS_USER, $row->rc_user_text);
            $batch->add(NS_USER_TALK, $row->rc_user_text);
        }
    }
    $dbr->freeResult($res);
    if ($feedFormat) {
        rcOutputFeed($rows, $feedFormat, $limit, $hideminor, $lastmod);
    } else {
        # Web output...
        // Run existence checks
        $batch->execute();
        $any = $wgRequest->getBool('categories_any', $defaults['categories_any']);
        // Output header
        if (!$specialPage->including()) {
            $wgOut->addWikiText('<div class="minor_text">' . wfMsgForContentNoTrans("recentchangestext") . '<br /></div>');
            // Dump everything here
            $nondefaults = array();
            wfAppendToArrayIfNotDefault('days', $days, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('limit', $limit, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hideminor', $hideminor, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hidebots', $hidebots, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hideanons', $hideanons, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hideliu', $hideliu, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hidemyself', $hidemyself, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('from', $from, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('namespace', $namespace, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('invert', $invert, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('categories_any', $any, $defaults, $nondefaults);
            // Add end of the texts
            $wgOut->addHTML('<div class="rcoptions">' . rcOptionsPanel($defaults, $nondefaults) . "\n");
            //XXCHANGED
            $wgOut->addHTML(rcNamespaceForm($namespace, $invert, $reverse, $featured, $nondefaults, $any) . '</div>' . "\n");
            //XXADDED
            global $wgLanguageCode;
            if ($wgUser->getID() > 0 && $wgLanguageCode == 'en') {
                $sk = $wgUser->getSkin();
                $url = $wgRequest->getRequestURL();
                if ($wgRequest->getVal('refresh', null) != null) {
                    $url = str_replace("&refresh=1", "", $url);
                    $url = str_replace("?refresh=1", "", $url);
                    $wgOut->addHTML("<a href='{$url}' class='button secondary'>" . wfMsg('rc_turn_refresh_off') . "</a>");
                } else {
                    if (strpos($url, "?") !== false) {
                        $url .= "&refresh=1";
                    } else {
                        $url .= "?refresh=1";
                    }
                    $wgOut->addHTML("<a href='{$url}' class='button secondary'>" . wfMsg('rc_turn_refresh_on') . "</a>");
                }
                $wgOut->addHTML("&nbsp;<a class='button secondary' href='#' onclick=\"open('/index.php?title=Special:RCBuddy&hidepatrolled=1&limit=200&featured=1', '', 'scrollbars=no,status=no,width=570,height=200,resizable=yes,titlebar=no');\">RC Buddy</a>");
            }
        }
        // And now for the content
        $wgOut->setSyndicated(true);
        $list = ChangesList::newFromUser($wgUser);
        if ($wgAllowCategorizedRecentChanges) {
            $categories = trim($wgRequest->getVal('categories', ""));
            $categories = str_replace("|", "\n", $categories);
            $categories = explode("\n", $categories);
            rcFilterByCategories($rows, $categories, $any);
        }
        $s = $list->beginRecentChangesList();
        $s .= "<div id='recentchanges'>\n";
        $counter = 1;
        $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption('shownumberswatching');
        $watcherCache = array();
        foreach ($rows as $obj) {
            if ($limit == 0) {
                break;
            }
            if (!($hideminor && $obj->rc_minor) && !($hidepatrolled && $obj->rc_patrolled)) {
                $rc = RecentChange::newFromRow($obj);
                $rc->counter = $counter++;
                if ($wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) && $obj->rc_timestamp >= $obj->wl_notificationtimestamp) {
                    $rc->notificationtimestamp = true;
                } else {
                    $rc->notificationtimestamp = false;
                }
                $rc->numberofWatchingusers = 0;
                // Default
                if ($showWatcherCount && $obj->rc_namespace >= 0) {
                    if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
                        $watcherCache[$obj->rc_namespace][$obj->rc_title] = $dbr->selectField('watchlist', 'COUNT(*)', array('wl_namespace' => $obj->rc_namespace, 'wl_title' => $obj->rc_title), __METHOD__ . '-watchers');
                    }
                    $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
                }
                $rc->show_namespace = $namespace;
                $rc->invert = $invert;
                $rc->reverse = $reverse;
                $rc->featured = $featured;
                $s .= $list->recentChangesLine($rc, !empty($obj->wl_user));
                --$limit;
            }
        }
        $s .= $list->endRecentChangesList();
        $s .= "</div>\n";
        $wgOut->addHTML($s);
    }
}
Ejemplo n.º 11
0
 /**
  * @param User $target
  */
 function __construct($target, $par)
 {
     global $wgRequest, $wgUser;
     $this->wasPosted = $wgRequest->wasPosted();
     $this->formType = $wgRequest->getText('formtype', $par);
     # Check for type in [[Special:Contact/type]]: change pagetext and prefill form fields
     if ($this->formType != '') {
         $message = 'contactpage-pagetext-' . $this->formType;
         $text = wfMsgExt($message, 'parse');
         if (!wfEmptyMsg($message, $text)) {
             $this->formularText = $text;
         } else {
             $this->formularText = wfMsgExt('contactpage-pagetext', 'parse');
         }
         $message = 'contactpage-subject-' . $this->formType;
         $text = wfMsgForContentNoTrans($message);
         if (!wfEmptyMsg($message, $text)) {
             $this->subject = $wgRequest->getText('wpSubject', $text);
         } else {
             $this->subject = $wgRequest->getText('wpSubject');
         }
         $message = 'contactpage-text-' . $this->formType;
         $text = wfMsgForContentNoTrans($message);
         if (!wfEmptyMsg($message, $text)) {
             $this->text = $wgRequest->getText('wpText', $text);
         } else {
             $this->text = $wgRequest->getText('wpText');
         }
     } else {
         $this->formularText = wfMsgExt('contactpage-pagetext', 'parse');
         $this->text = $wgRequest->getText('wpText');
         $this->subject = $wgRequest->getText('wpSubject');
     }
     $this->target = $target;
     $this->cc_me = $wgRequest->getBool('wpCCMe');
     $this->includeIP = $wgRequest->getBool('wpIncludeIP');
     $this->fromname = $wgRequest->getText('wpFromName');
     $this->fromaddress = $wgRequest->getText('wpFromAddress');
     if ($wgUser->isLoggedIn()) {
         if (!$this->fromname) {
             $this->fromname = $wgUser->getName();
         }
         if (!$this->fromaddress) {
             $this->fromaddress = $wgUser->getEmail();
         }
     }
     // prepare captcha if applicable
     if ($this->useCaptcha()) {
         $captcha = ConfirmEditHooks::getInstance();
         $captcha->trigger = 'contactpage';
         $captcha->action = 'contact';
     }
 }
Ejemplo n.º 12
0
function wfGetCachedNotice($name)
{
    global $wgOut, $wgRenderHashAppend, $parserMemc;
    $fname = 'wfGetCachedNotice';
    wfProfileIn($fname);
    $needParse = false;
    if ($name === 'default') {
        // special case
        global $wgSiteNotice;
        $notice = $wgSiteNotice;
        if (empty($notice)) {
            wfProfileOut($fname);
            return false;
        }
    } else {
        $notice = wfMsgForContentNoTrans($name);
        if (wfEmptyMsg($name, $notice) || $notice == '-') {
            wfProfileOut($fname);
            return false;
        }
    }
    // Use the extra hash appender to let eg SSL variants separately cache.
    $key = wfMemcKey($name . $wgRenderHashAppend);
    $cachedNotice = $parserMemc->get($key);
    if (is_array($cachedNotice)) {
        if (md5($notice) == $cachedNotice['hash']) {
            $notice = $cachedNotice['html'];
        } else {
            $needParse = true;
        }
    } else {
        $needParse = true;
    }
    if ($needParse) {
        if (is_object($wgOut)) {
            $parsed = $wgOut->parse($notice);
            $parserMemc->set($key, array('html' => $parsed, 'hash' => md5($notice)), 600);
            $notice = $parsed;
        } else {
            wfDebug('wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n");
            $notice = '';
        }
    }
    wfProfileOut($fname);
    return $notice;
}
Ejemplo n.º 13
0
function wfGetCachedNotice($name)
{
    global $wgOut, $parserMemc;
    $fname = 'wfGetCachedNotice';
    wfProfileIn($fname);
    $needParse = false;
    if ($name === 'default') {
        // special case
        global $wgSiteNotice;
        $notice = $wgSiteNotice;
        if (empty($notice)) {
            wfProfileOut($fname);
            return false;
        }
    } else {
        $notice = wfMsgForContentNoTrans($name);
        if (wfEmptyMsg($name, $notice) || $notice == '-') {
            wfProfileOut($fname);
            return false;
        }
    }
    $cachedNotice = $parserMemc->get(wfMemcKey($name));
    if (is_array($cachedNotice)) {
        if (md5($notice) == $cachedNotice['hash']) {
            $notice = $cachedNotice['html'];
        } else {
            $needParse = true;
        }
    } else {
        $needParse = true;
    }
    if ($needParse) {
        if (is_object($wgOut)) {
            $parsed = $wgOut->parse($notice);
            $parserMemc->set(wfMemcKey($name), array('html' => $parsed, 'hash' => md5($notice)), 600);
            $notice = $parsed;
        } else {
            wfDebug('wfGetCachedNotice called for ' . $name . ' with no $wgOut available');
            $notice = '';
        }
    }
    wfProfileOut($fname);
    return $notice;
}
Ejemplo n.º 14
0
 /**
  * main entry point
  *
  * @access public
  */
 public function run()
 {
     global $wgUser, $wgTitle, $wgErrorLog;
     wfProfileIn(__METHOD__);
     $oldValue = $wgErrorLog;
     $wgErrorLog = true;
     /**
      * overwrite $wgUser for ~~~~ expanding
      */
     $sysop = trim(wfMsgForContent("welcome-user"));
     if (!in_array($sysop, array("@disabled", "-"))) {
         $tmpUser = $wgUser;
         $wgUser = User::newFromName(self::WELCOMEUSER);
         $flags = 0;
         $bot_message = trim(wfMsgForContent("welcome-bot"));
         if ($bot_message == '@bot' || $wgUser && $wgUser->isAllowed('bot')) {
             $flags = EDIT_FORCE_BOT;
         }
         wfDebug(__METHOD__ . "-user: "******"-talk: " . $talkPage->getFullUrl());
             if ($talkPage) {
                 $this->mSysop = $this->getLastSysop();
                 $gEG = $this->mSysop->getEffectiveGroups();
                 $isSysop = in_array('sysop', $gEG);
                 $isStaff = in_array('staff', $gEG);
                 unset($gEG);
                 $tmpTitle = $wgTitle;
                 $sysopPage = $this->mSysop->getUserPage()->getTalkPage();
                 $signature = $this->expandSig();
                 $wgTitle = $talkPage;
                 $welcomeMsg = false;
                 $talkArticle = new Article($talkPage, 0);
                 if (!self::isPosted($talkArticle, $this->mUser)) {
                     if ($this->mAnon) {
                         if ($this->isEnabled("message-anon")) {
                             if ($isStaff && !$isSysop) {
                                 $key = $this->getMessageKey("anon-staff");
                             } else {
                                 $key = $this->getMessageKey("anon");
                             }
                             $welcomeMsg = wfMsgNoTrans($key, array($this->getPrefixedText(), $sysopPage->getPrefixedText(), $signature, wfEscapeWikiText($this->mUser->getName())));
                         } else {
                             wfDebug(__METHOD__ . "-talk: message-anon disabled");
                         }
                     } else {
                         /**
                          * now create user page (if not exists of course)
                          */
                         if ($this->isEnabled("page-user")) {
                             $userPage = $this->mUser->getUserPage();
                             if ($userPage) {
                                 $wgTitle = $userPage;
                                 $userArticle = new Article($userPage, 0);
                                 wfDebug(__METHOD__ . "-userpage: " . $userPage->getFullUrl());
                                 if (!$userArticle->exists()) {
                                     $pageMsg = wfMsgForContentNoTrans('welcome-user-page', $this->mUser->getName());
                                     $userArticle->doEdit($pageMsg, false, $flags);
                                 }
                             } else {
                                 wfDebug(__METHOD__ . "-page: user page already exists.");
                             }
                         } else {
                             wfDebug(__METHOD__ . "-page: page-user disabled");
                         }
                         if ($this->isEnabled("message-user")) {
                             if ($isStaff && !$isSysop) {
                                 $key = $this->getMessageKey("user-staff");
                             } else {
                                 $key = $this->getMessageKey("user");
                             }
                             $welcomeMsg = wfMsgNoTrans($key, array($this->getPrefixedText(), $sysopPage->getPrefixedText(), $signature, wfEscapeWikiText($this->mUser->getName())));
                         } else {
                             wfDebug(__METHOD__ . "-talk: message-user disabled");
                         }
                     }
                     if ($welcomeMsg) {
                         $wgTitle = $talkPage;
                         /** is it necessary there? **/
                         //we posting it on talk page even when we have message wall
                         //hack for notification problem
                         global $wgCityId, $wgServer;
                         $wgServer = WikiFactory::getVarValueByName('wgServer', $wgCityId);
                         $this->doPost($talkArticle, $flags, wfMsgForContent("welcome-message-log"), $welcomeMsg, $wgUser, $this->mUser, $this->mSysop);
                     }
                 }
                 $wgTitle = $tmpTitle;
             }
         }
         $wgUser = $tmpUser;
         $wgErrorLog = $oldValue;
     } else {
         wfDebug(__METHOD__ . "-disabled: " . $sysop);
     }
     wfProfileOut(__METHOD__);
     return true;
 }
	/**
	 * Perform an action on a given group/key/code
	 *
	 * @param $action \string Options: 'import', 'conflict' or 'ignore'
	 * @param $group MessageGroup Group object
	 * @param $key \string Message key
	 * @param $code \string Language code
	 * @param $message \string contents for the $key/code combination
	 * @param $comment \string edit summary (default: empty) - see Article::doEdit
	 * @param $user User User that will make the edit (default: null - $wgUser) - see Article::doEdit
	 * @param $editFlags Integer bitfield: see Article::doEdit
	 * @return \string Action result
	 */
	public static function doAction( $action, $group, $key, $code, $message, $comment = '', $user = null, $editFlags = 0 ) {
		global $wgTranslateDocumentationLanguageCode;

		$title = self::makeTranslationTitle( $group, $key, $code );

		if ( $action === 'import' || $action === 'conflict' ) {
			if ( $action === 'import' ) {
				$comment = wfMsgForContentNoTrans( 'translate-manage-import-summary' );
			} else {
				$comment = wfMsgForContentNoTrans( 'translate-manage-conflict-summary' );
				$message = self::makeTextFuzzy( $message );
			}

			return self::doImport( $title, $message, $comment, $user, $editFlags );
		} elseif ( $action === 'ignore' ) {
			return array( 'translate-manage-import-ignore', $key );
		} elseif ( $action === 'fuzzy' && $code !== 'en' && $code !== $wgTranslateDocumentationLanguageCode ) {
			$message = self::makeTextFuzzy( $message );

			return self::doImport( $title, $message, $comment, $user, $editFlags );
		} elseif ( $action === 'fuzzy' && $code == 'en' ) {
			return self::doFuzzy( $title, $message, $comment, $user, $editFlags );
		} else {
			throw new MWException( "Unhandled action $action" );
		}
	}
Ejemplo n.º 16
0
 /**
  * Static function to get a template
  * Can be overridden via ParserOptions::setTemplateCallback().
  */
 static function statelessFetchTemplate($title, $parser = false)
 {
     $text = $skip = false;
     $finalTitle = $title;
     $deps = array();
     // Loop to fetch the article, with up to 1 redirect
     for ($i = 0; $i < 2 && is_object($title); $i++) {
         # Give extensions a chance to select the revision instead
         $id = false;
         // Assume current
         wfRunHooks('BeforeParserFetchTemplateAndtitle', array($parser, &$title, &$skip, &$id));
         if ($skip) {
             $text = false;
             $deps[] = array('title' => $title, 'page_id' => $title->getArticleID(), 'rev_id' => null);
             break;
         }
         $rev = $id ? Revision::newFromId($id) : Revision::newFromTitle($title);
         $rev_id = $rev ? $rev->getId() : 0;
         // If there is no current revision, there is no page
         if ($id === false && !$rev) {
             $linkCache = LinkCache::singleton();
             $linkCache->addBadLinkObj($title);
         }
         $deps[] = array('title' => $title, 'page_id' => $title->getArticleID(), 'rev_id' => $rev_id);
         if ($rev) {
             $text = $rev->getText();
         } elseif ($title->getNamespace() == NS_MEDIAWIKI) {
             global $wgContLang;
             $message = $wgContLang->lcfirst($title->getText());
             $text = wfMsgForContentNoTrans($message);
             if (wfEmptyMsg($message, $text)) {
                 $text = false;
                 break;
             }
         } else {
             break;
         }
         if ($text === false) {
             break;
         }
         // Redirect?
         $finalTitle = $title;
         $title = Title::newFromRedirect($text);
     }
     return array('text' => $text, 'finalTitle' => $finalTitle, 'deps' => $deps);
 }
Ejemplo n.º 17
0
/**
 * This function provides the message source for messages to be edited which are *not* stored in the database.
 * @param $key String:
 */
function wfMsgWeirdKey($key)
{
    $subsource = str_replace(' ', '_', $key);
    $source = wfMsgForContentNoTrans($subsource);
    if (wfEmptyMsg($subsource, $source)) {
        # Try again with first char lower case
        $subsource = strtolower(substr($subsource, 0, 1)) . substr($subsource, 1);
        $source = wfMsgForContentNoTrans($subsource);
    }
    if (wfEmptyMsg($subsource, $source)) {
        # Didn't work either, return blank text
        $source = "";
    }
    return $source;
}
Ejemplo n.º 18
0
 function getArticleText()
 {
     $found = false;
     $text = '';
     if ($this->mTitle) {
         // If it's a MediaWiki message we can just hit the message cache
         if ($this->mTitle->getNamespace() == NS_MEDIAWIKI) {
             $key = $this->mTitle->getDBkey();
             $text = wfMsgForContentNoTrans($key);
             # If the message doesn't exist, return a blank
             if ($text == '&lt;' . $key . '&gt;') {
                 $text = '';
             }
             $found = true;
         } else {
             // Get it from the DB
             $rev = Revision::newFromTitle($this->mTitle, $this->mOldId);
             if ($rev) {
                 $lastmod = wfTimestamp(TS_RFC2822, $rev->getTimestamp());
                 header("Last-modified: {$lastmod}");
                 $text = $rev->getText();
                 $found = true;
             }
         }
     }
     # Bad title or page does not exist
     if (!$found && $this->mContentType == 'text/x-wiki') {
         # Don't return a 404 response for CSS or JavaScript;
         # 404s aren't generally cached and it would create
         # extra hits when user CSS/JS are on and the user doesn't
         # have the pages.
         header("HTTP/1.0 404 Not Found");
     }
     return $this->parseArticleText($text);
 }
Ejemplo n.º 19
0
 private function createCardPage($gatherer)
 {
     $title = Title::newFromText($this->name);
     $info = array();
     $i = 0;
     foreach ($gatherer->sets as $set => $stuff) {
         $image = wfStripIllegalFilenameChars(str_replace(':', '', $this->name)) . ' ' . $gatherer->rels[$set]['abbr'] . '.jpg';
         if (isset($gatherer->borders[$set]) && $gatherer->borders[$set]) {
             $border = $gatherer->rels[$set]['border'];
             $info['image' . ++$i] = "{{Border|[[Image:{$image}]]|{$border}}}";
         } else {
             $info['image' . ++$i] = "[[Image:{$image}]]";
         }
         foreach ($stuff as $rarity => $meh) {
             switch ($rarity) {
                 case 'R':
                     $rarity = 'Rare';
                     break;
                 case 'U':
                     $rarity = 'Uncommon';
                     break;
                 case 'C':
                     $rarity = 'Common';
                     break;
                 case 'S':
                     if ($set == 'Time Spiral "Timeshifted"') {
                         $rarity = 'Timeshifted';
                         $set = 'Time Spiral';
                     } else {
                         $rarity = 'Special';
                     }
                     break;
                 case 'M':
                     $rarity = 'Mythic Rare';
                     break;
                 case 'L':
                     $rarity = 'Land';
                     break;
             }
             $set = wfStripIllegalFilenameChars(str_replace(':', '', $set));
             $info['p/r' . $i] = "{{Rarity|{$set}|{$rarity}}}";
         }
     }
     for ($i = 1; $i <= 15; $i++) {
         if (!isset($info['image' . $i])) {
             $info['image' . $i] = '';
         }
         if (!isset($info['p/r' . $i])) {
             $info['p/r' . $i] = '';
         }
     }
     $article = new WikiPage($title);
     $article->doEdit(wfMsgForContentNoTrans('gatherer-cardpage', array($gatherer->info['name'], $gatherer->info['type'], $gatherer->info['cost'], $gatherer->info['cmc'], $gatherer->info['rules'], $gatherer->info['flavor'], $gatherer->info['p/t'], $gatherer->info['planeswalker'], $info['image1'], $info['p/r1'], $info['image2'], $info['p/r2'], $info['image3'], $info['p/r3'], $info['image4'], $info['p/r4'], $info['image5'], $info['p/r5'], $info['image6'], $info['p/r6'], $info['image7'], $info['p/r7'], $info['image8'], $info['p/r8'], $info['image9'], $info['p/r9'], $info['image10'], $info['p/r10'], $info['image11'], $info['p/r11'], $info['image12'], $info['p/r12'], $info['image13'], $info['p/r13'], $info['image14'], $info['p/r14'], $info['image15'], $info['p/r15'])), wfMsg('gatherer-cardpage-com'));
 }
Ejemplo n.º 20
0
 /**
  * Add content from plain text
  * @since 1.17
  * @param &$bar array
  * @param $text string
  */
 function addToSidebarPlain(&$bar, $text)
 {
     $lines = explode("\n", $text);
     $wikiBar = array();
     # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
     $heading = '';
     foreach ($lines as $line) {
         if (strpos($line, '*') !== 0) {
             continue;
         }
         if (strpos($line, '**') !== 0) {
             $heading = trim($line, '* ');
             if (!array_key_exists($heading, $bar)) {
                 $bar[$heading] = array();
             }
         } else {
             $line = trim($line, '* ');
             if (strpos($line, '|') !== false) {
                 // sanity check
                 $line = array_map('trim', explode('|', $line, 2));
                 $link = wfMsgForContent($line[0]);
                 if ($link == '-') {
                     continue;
                 }
                 $text = wfMsgExt($line[1], 'parsemag');
                 if (wfEmptyMsg($line[1], $text)) {
                     $text = $line[1];
                 }
                 if (wfEmptyMsg($line[0], $link)) {
                     $link = $line[0];
                 }
                 if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $link)) {
                     $href = $link;
                 } else {
                     $title = Title::newFromText($link);
                     if ($title) {
                         $title = $title->fixSpecialName();
                         $href = $title->getLocalURL();
                     } else {
                         $href = 'INVALID-TITLE';
                     }
                 }
                 $bar[$heading][] = array('text' => $text, 'href' => $href, 'id' => 'n-' . strtr($line[1], ' ', '-'), 'active' => false);
             } else {
                 if (substr($line, 0, 2) == '{{' && substr($line, -2) == '}}') {
                     global $wgParser, $wgTitle;
                     $line = substr($line, 2, strlen($line) - 4);
                     $options = new ParserOptions();
                     $options->setEditSection(false);
                     $options->setInterfaceMessage(true);
                     $wikiBar[$heading] = $wgParser->parse(wfMsgForContentNoTrans($line), $wgTitle, $options)->getText();
                 } else {
                     continue;
                 }
             }
         }
     }
     if (count($wikiBar) > 0) {
         $bar = array_merge($bar, $wikiBar);
     }
     return $bar;
 }
	function formatRow( $row ) {
		global $wgWikilogExtSummaries;
		$skin = $this->getSkin();
		$header = $footer = '';

		# Retrieve article parser output and other data.
		$item = WikilogItem::newFromRow( $row );
		list( $article, $parserOutput ) = WikilogUtils::parsedArticle( $item->mTitle );
		list( $summary, $content ) = WikilogUtils::splitSummaryContent( $parserOutput );

		# Retrieve the common header and footer parameters.
		$params = $item->getMsgParams( $wgWikilogExtSummaries, $parserOutput );

		# Article title heading, with direct link article page and optional
		# edit link (if user can edit the article).
		$titleText = Sanitizer::escapeHtmlAllowEntities( $item->mName );
		if ( !$item->getIsPublished() )
			$titleText .= wfMsgForContent( 'wikilog-draft-title-mark' );
		$heading = $skin->link( $item->mTitle, $titleText, array(), array(),
			array( 'known', 'noclasses' )
		);
		if ( $this->mShowEditLink && $item->mTitle->quickUserCan( 'edit' ) ) {
			$heading = $this->doEditLink( $item->mTitle, $item->mName ) . $heading;
		}
		$heading = Xml::tags( 'h2', null, $heading );

		# Sumary entry header.
		$key = $this->mQuery->isSingleWikilog()
			? 'wikilog-summary-header-single'
			: 'wikilog-summary-header';
		$msg = wfMsgExt( $key, array( 'content', 'parsemag' ), $params );
		if ( !empty( $msg ) ) {
			$header = WikilogUtils::wrapDiv( 'wl-summary-header', $this->parse( $msg ) );
		}

		# Summary entry text.
		if ( $summary ) {
			$more = $this->parse( wfMsgForContentNoTrans( 'wikilog-summary-more', $params ) );
			$summary = WikilogUtils::wrapDiv( 'wl-summary', $summary . $more );
		} else {
			$summary = WikilogUtils::wrapDiv( 'wl-summary', $content );
		}

		# Summary entry footer.
		$key = $this->mQuery->isSingleWikilog()
			? 'wikilog-summary-footer-single'
			: 'wikilog-summary-footer';
		$msg = wfMsgExt( $key, array( 'content', 'parsemag' ), $params );
		if ( !empty( $msg ) ) {
			$footer = WikilogUtils::wrapDiv( 'wl-summary-footer', $this->parse( $msg ) );
		}

		# Assembly the entry div.
		$divclass = array( 'wl-entry', 'visualClear' );
		if ( !$item->getIsPublished() )
			$divclass[] = 'wl-draft';
		$entry = WikilogUtils::wrapDiv(
			implode( ' ', $divclass ),
			$heading . $header . $summary . $footer
		);
		return $entry;
	}
Ejemplo n.º 22
0
 /**
  * Retrieve the unit text from actual messages
  * @param  $dimension String
  * @param  $unit String
  * @param  $prefix String
  * @param  $string String
  * @param  $number String the actual value (for {{PLURAL}} etc)
  * @param  $link Bool
  * @param  $abbreviate Bool
  * @param  $language Language|Bool|null
  * @return String
  */
 protected function getTextFromMessage($dimension, $unit, $prefix, $string, $number, $link, $abbreviate, $language)
 {
     $abbr = $abbreviate ? '-abbr' : '';
     $prefix = $prefix === null ? '' : wfMsgExt("pfunc-convert-prefix-{$prefix}{$abbr}", array('parsemag', 'language' => $language));
     $text = wfMsgExt("pfunc-convert-unit-{$dimension}-{$unit}{$abbr}", array('parsemag', 'language' => $language), $number, $prefix);
     if ($link && !wfEmptyMsg("pfunc-convert-unit-{$dimension}-{$unit}-link")) {
         $title = Title::newFromText(wfMsgForContentNoTrans("pfunc-convert-unit-{$dimension}-{$unit}-link"), $prefix);
         if ($title instanceof Title) {
             $text = "[[{$title->getFullText()}|{$text}]]";
         }
     }
     return $text;
 }
Ejemplo n.º 23
0
 /**
  * Generate the labels to pass to the
  * 'cite_references_link_many_format' message, the format is an
  * arbitary number of tokens separated by [\t\n ]
  */
 function genBacklinkLabels()
 {
     wfProfileIn(__METHOD__);
     $text = wfMsgForContentNoTrans('cite_references_link_many_format_backlink_labels');
     $this->mBacklinkLabels = preg_split('#[\\n\\t ]#', $text);
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 24
0
 function getArticleText()
 {
     $found = false;
     $text = '';
     if ($this->mTitle) {
         // If it's a MediaWiki message we can just hit the message cache
         if ($this->mUseMessageCache && $this->mTitle->getNamespace() == NS_MEDIAWIKI) {
             $key = $this->mTitle->getDBkey();
             $text = wfMsgForContentNoTrans($key);
             # If the message doesn't exist, return a blank
             if (wfEmptyMsg($key, $text)) {
                 $text = '';
             }
             $found = true;
         } else {
             // Get it from the DB
             $rev = Revision::newFromTitle($this->mTitle, $this->mOldId);
             if ($rev) {
                 $lastmod = wfTimestamp(TS_RFC2822, $rev->getTimestamp());
                 header("Last-modified: {$lastmod}");
                 if (!is_null($this->mSection)) {
                     global $wgParser;
                     $text = $wgParser->getSection($rev->getText(), $this->mSection);
                 } else {
                     $text = $rev->getText();
                 }
                 $found = true;
             }
         }
     }
     # Bad title or page does not exist
     if (!$found && $this->mContentType == 'text/x-wiki') {
         # Don't return a 404 response for CSS or JavaScript;
         # 404s aren't generally cached and it would create
         # extra hits when user CSS/JS are on and the user doesn't
         # have the pages.
         header("HTTP/1.0 404 Not Found");
     }
     // Special-case for empty CSS/JS
     //
     // Internet Explorer for Mac handles empty files badly;
     // particularly so when keep-alive is active. It can lead
     // to long timeouts as it seems to sit there waiting for
     // more data that never comes.
     //
     // Give it a comment...
     if (strlen($text) == 0 && ($this->mContentType == 'text/css' || $this->mContentType == 'text/javascript')) {
         return "/* Empty */";
     }
     return $this->parseArticleText($text);
 }
Ejemplo n.º 25
0
 /**
  * Send the text to be displayed above the options
  *
  * @param $opts FormOptions
  */
 function setTopText(FormOptions $opts)
 {
     global $wgContLang;
     $this->getOutput()->addWikiText(Html::rawElement('p', array('lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir()), "\n" . wfMsgForContentNoTrans('recentchangestext') . "\n"), false, false);
 }
Ejemplo n.º 26
0
 /**
  * Fetch definitions from database.
  * @return \array Array of messages keys with definitions.
  */
 public function getDefinitions()
 {
     $definitions = array();
     // In theory the page could have templates that are substitued
     $contents = wfMsg($this->source);
     $contents = preg_replace('~^\\s*#.*$~m', '', $contents);
     $messages = preg_split('/\\s+/', $contents);
     foreach ($messages as $message) {
         if (!$message) {
             continue;
         }
         $definitions[$message] = wfMsgForContentNoTrans($message);
     }
     return $definitions;
 }
Ejemplo n.º 27
0
 /**
  * Add content from a sidebar system message
  * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
  *
  * This is just a wrapper around addToSidebarPlain() for backwards compatibility
  *
  * @param &$bar array
  * @param $message String
  */
 function addToSidebar(&$bar, $message)
 {
     $this->addToSidebarPlain($bar, wfMsgForContentNoTrans($message));
 }
Ejemplo n.º 28
0
 /**
  * Auto convert a Title object to a readable string in the
  * preferred variant.
  *
  *@param $title Object: a object of Title
  *@return String: converted title text
  */
 public function convertTitle($title)
 {
     $variant = $this->getPreferredVariant();
     $index = $title->getNamespace();
     if ($index === NS_MAIN) {
         $text = '';
     } else {
         // first let's check if a message has given us a converted name
         $nsConvKey = 'conversion-ns' . $index;
         if (!wfEmptyMsg($nsConvKey)) {
             $text = wfMsgForContentNoTrans($nsConvKey);
         } else {
             // the message does not exist, try retrieve it from the current
             // variant's namespace names.
             $langObj = $this->mLangObj->factory($variant);
             $text = $langObj->getFormattedNsText($index);
         }
         $text .= ':';
     }
     $text .= $title->getText();
     $text = $this->translate($text, $variant);
     return $text;
 }
/**
 * Constructor
 */
function wfSpecialRecentchanges($par, $specialPage)
{
    global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
    global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
    global $wgAllowCategorizedRecentChanges;
    $fname = 'wfSpecialRecentchanges';
    # Get query parameters
    $feedFormat = $wgRequest->getVal('feed');
    /* Checkbox values can't be true by default, because
     * we cannot differentiate between unset and not set at all
     */
    $defaults = array('days' => $wgUser->getDefaultOption('rcdays'), 'limit' => $wgUser->getDefaultOption('rclimit'), 'hideminor' => false, 'hidebots' => true, 'hideanons' => false, 'hideliu' => false, 'hidepatrolled' => false, 'hidemyself' => false, 'from' => '', 'namespace' => null, 'invert' => false, 'categories_any' => false);
    extract($defaults);
    $days = $wgUser->getOption('rcdays', $defaults['days']);
    $days = $wgRequest->getInt('days', $days);
    $limit = $wgUser->getOption('rclimit', $defaults['limit']);
    #	list( $limit, $offset ) = wfCheckLimits( 100, 'rclimit' );
    $limit = $wgRequest->getInt('limit', $limit);
    /* order of selection: url > preferences > default */
    $hideminor = $wgRequest->getBool('hideminor', $wgUser->getOption('hideminor') ? true : $defaults['hideminor']);
    # As a feed, use limited settings only
    if ($feedFormat) {
        global $wgFeedLimit;
        if ($limit > $wgFeedLimit) {
            $limit = $wgFeedLimit;
        }
    } else {
        $namespace = $wgRequest->getIntOrNull('namespace');
        $invert = $wgRequest->getBool('invert', $defaults['invert']);
        $hidebots = $wgRequest->getBool('hidebots', $defaults['hidebots']);
        $hideanons = $wgRequest->getBool('hideanons', $defaults['hideanons']);
        $hideliu = $wgRequest->getBool('hideliu', $defaults['hideliu']);
        $hidepatrolled = $wgRequest->getBool('hidepatrolled', $defaults['hidepatrolled']);
        $hidemyself = $wgRequest->getBool('hidemyself', $defaults['hidemyself']);
        $from = $wgRequest->getVal('from', $defaults['from']);
        # Get query parameters from path
        if ($par) {
            $bits = preg_split('/\\s*,\\s*/', trim($par));
            foreach ($bits as $bit) {
                if ('hidebots' == $bit) {
                    $hidebots = 1;
                }
                if ('bots' == $bit) {
                    $hidebots = 0;
                }
                if ('hideminor' == $bit) {
                    $hideminor = 1;
                }
                if ('minor' == $bit) {
                    $hideminor = 0;
                }
                if ('hideliu' == $bit) {
                    $hideliu = 1;
                }
                if ('hidepatrolled' == $bit) {
                    $hidepatrolled = 1;
                }
                if ('hideanons' == $bit) {
                    $hideanons = 1;
                }
                if ('hidemyself' == $bit) {
                    $hidemyself = 1;
                }
                if (is_numeric($bit)) {
                    $limit = $bit;
                }
                $m = array();
                if (preg_match('/^limit=(\\d+)$/', $bit, $m)) {
                    $limit = $m[1];
                }
                if (preg_match('/^days=(\\d+)$/', $bit, $m)) {
                    $days = $m[1];
                }
            }
        }
    }
    if ($limit < 0 || $limit > 5000) {
        $limit = $defaults['limit'];
    }
    # Database connection and caching
    $dbr = wfGetDB(DB_SLAVE);
    list($recentchanges, $watchlist) = $dbr->tableNamesN('recentchanges', 'watchlist');
    $cutoff_unixtime = time() - $days * 86400;
    $cutoff_unixtime = $cutoff_unixtime - $cutoff_unixtime % 86400;
    $cutoff = $dbr->timestamp($cutoff_unixtime);
    if (preg_match('/^[0-9]{14}$/', $from) and $from > wfTimestamp(TS_MW, $cutoff)) {
        $cutoff = $dbr->timestamp($from);
    } else {
        $from = $defaults['from'];
    }
    # 10 seconds server-side caching max
    $wgOut->setSquidMaxage(10);
    # Get last modified date, for client caching
    # Don't use this if we are using the patrol feature, patrol changes don't update the timestamp
    $lastmod = $dbr->selectField('recentchanges', 'MAX(rc_timestamp)', false, $fname);
    if ($feedFormat || !$wgUseRCPatrol) {
        if ($lastmod && $wgOut->checkLastModified($lastmod)) {
            # Client cache fresh and headers sent, nothing more to do.
            return;
        }
    }
    # It makes no sense to hide both anons and logged-in users
    # Where this occurs, force anons to be shown
    if ($hideanons && $hideliu) {
        $hideanons = false;
    }
    # Form WHERE fragments for all the options
    $hidem = $hideminor ? 'AND rc_minor = 0' : '';
    $hidem .= $hidebots ? ' AND rc_bot = 0' : '';
    $hidem .= $hideliu ? ' AND rc_user = 0' : '';
    $hidem .= $wgUseRCPatrol && $hidepatrolled ? ' AND rc_patrolled = 0' : '';
    $hidem .= $hideanons ? ' AND rc_user != 0' : '';
    if ($hidemyself) {
        if ($wgUser->getID()) {
            $hidem .= ' AND rc_user != ' . $wgUser->getID();
        } else {
            $hidem .= ' AND rc_user_text != ' . $dbr->addQuotes($wgUser->getName());
        }
    }
    # Namespace filtering
    $hidem .= is_null($namespace) ? '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace;
    // This is the big thing!
    $uid = $wgUser->getID();
    // Perform query
    $forceclause = $dbr->useIndexClause("rc_timestamp");
    $sql2 = "SELECT * FROM {$recentchanges} {$forceclause}" . ($uid ? "LEFT OUTER JOIN {$watchlist} ON wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace " : "") . "WHERE rc_timestamp >= '{$cutoff}' {$hidem} " . "ORDER BY rc_timestamp DESC";
    $sql2 = $dbr->limitResult($sql2, $limit, 0);
    $res = $dbr->query($sql2, $fname);
    // Fetch results, prepare a batch link existence check query
    $rows = array();
    $batch = new LinkBatch();
    while ($row = $dbr->fetchObject($res)) {
        $rows[] = $row;
        if (!$feedFormat) {
            // User page link
            $title = Title::makeTitleSafe(NS_USER, $row->rc_user_text);
            $batch->addObj($title);
            // User talk
            $title = Title::makeTitleSafe(NS_USER_TALK, $row->rc_user_text);
            $batch->addObj($title);
        }
    }
    $dbr->freeResult($res);
    if ($feedFormat) {
        rcOutputFeed($rows, $feedFormat, $limit, $hideminor, $lastmod);
    } else {
        # Web output...
        // Run existence checks
        $batch->execute();
        $any = $wgRequest->getBool('categories_any', $defaults['categories_any']);
        // Output header
        if (!$specialPage->including()) {
            $wgOut->addWikiText(wfMsgForContentNoTrans("recentchangestext"));
            // Dump everything here
            $nondefaults = array();
            wfAppendToArrayIfNotDefault('days', $days, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('limit', $limit, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hideminor', $hideminor, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hidebots', $hidebots, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hideanons', $hideanons, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hideliu', $hideliu, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hidepatrolled', $hidepatrolled, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('hidemyself', $hidemyself, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('from', $from, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('namespace', $namespace, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('invert', $invert, $defaults, $nondefaults);
            wfAppendToArrayIfNotDefault('categories_any', $any, $defaults, $nondefaults);
            // Add end of the texts
            $wgOut->addHTML('<div class="rcoptions">' . rcOptionsPanel($defaults, $nondefaults) . "\n");
            $wgOut->addHTML(rcNamespaceForm($namespace, $invert, $nondefaults, $any) . '</div>' . "\n");
        }
        // And now for the content
        $list = ChangesList::newFromUser($wgUser);
        if ($wgAllowCategorizedRecentChanges) {
            $categories = trim($wgRequest->getVal('categories', ""));
            $categories = str_replace("|", "\n", $categories);
            $categories = explode("\n", $categories);
            rcFilterByCategories($rows, $categories, $any);
        }
        $s = $list->beginRecentChangesList();
        $counter = 1;
        foreach ($rows as $obj) {
            if ($limit == 0) {
                break;
            }
            if (!($hideminor && $obj->rc_minor) && !($hidepatrolled && $obj->rc_patrolled)) {
                $rc = RecentChange::newFromRow($obj);
                $rc->counter = $counter++;
                if ($wgShowUpdatedMarker && !empty($obj->wl_notificationtimestamp) && $obj->rc_timestamp >= $obj->wl_notificationtimestamp) {
                    $rc->notificationtimestamp = true;
                } else {
                    $rc->notificationtimestamp = false;
                }
                if ($wgRCShowWatchingUsers && $wgUser->getOption('shownumberswatching')) {
                    $sql3 = "SELECT COUNT(*) AS n FROM {$watchlist} WHERE wl_title='" . $dbr->strencode($obj->rc_title) . "' AND wl_namespace={$obj->rc_namespace}";
                    $res3 = $dbr->query($sql3, 'wfSpecialRecentChanges');
                    $x = $dbr->fetchObject($res3);
                    $rc->numberofWatchingusers = $x->n;
                } else {
                    $rc->numberofWatchingusers = 0;
                }
                $s .= $list->recentChangesLine($rc, !empty($obj->wl_user));
                --$limit;
            }
        }
        $s .= $list->endRecentChangesList();
        $wgOut->addHTML($s);
    }
}
Ejemplo n.º 30
0
 /**
  * Send the text to be displayed above the options
  *
  * @param $out OutputPage
  * @param $opts FormOptions
  */
 function setTopText(OutputPage $out, FormOptions $opts)
 {
     $out->addWikiText(wfMsgForContentNoTrans('recentchangestext'));
 }