public function getDefinitions()
 {
     $groups = MessageGroups::getAllGroups();
     $keys = array();
     /**
      * @var $g MessageGroup
      */
     foreach ($groups as $g) {
         $states = $g->getMessageGroupStates()->getStates();
         foreach (array_keys($states) as $state) {
             $keys["Translate-workflow-state-{$state}"] = $state;
         }
     }
     $defs = TranslateUtils::getContents(array_keys($keys), $this->getNamespace());
     foreach ($keys as $key => $state) {
         if (!isset($defs[$key])) {
             // @todo Use jobqueue
             $title = Title::makeTitleSafe($this->getNamespace(), $key);
             $page = new WikiPage($title);
             $content = ContentHandler::makeContent($state, $title);
             $page->doEditContent($content, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser());
         } else {
             // Use the wiki translation as definition if available.
             // getContents returns array( content, last author )
             list($content, ) = $defs[$key];
             $keys[$key] = $content;
         }
     }
     return $keys;
 }
 function formatResult(&$skin, $row)
 {
     global $wgContLang;
     $title = Title::makeTitleSafe(NS_IMAGE, $row->title);
     $label = htmlspecialchars($wgContLang->convert($title->getText()));
     return $skin->makeKnownLinkObj($title, $label);
 }
 public function testUpdate_iwlinks()
 {
     list($t, $po) = $this->makeTitleAndParserOutput("Testing", 111);
     $target = Title::makeTitleSafe(NS_MAIN, "Foo", '', 'linksupdatetest');
     $po->addInterwikiLink($target);
     $this->assertLinksUpdate($t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(array('linksupdatetest', 'Foo')));
 }
 /**
  * Create category.
  *
  * @param $category String: Name of category to create.
  * @param $code String: Code of language that the category is for.
  * @param $level String: Level that the category is for.
  */
 public static function create($category, $code, $level = null)
 {
     $category = strip_tags($category);
     $title = Title::makeTitleSafe(NS_CATEGORY, $category);
     if ($title === null || $title->exists()) {
         return;
     }
     global $wgLanguageCode;
     $language = BabelLanguageCodes::getName($code, $wgLanguageCode);
     if ($level === null) {
         $text = wfMsgForContent('babel-autocreate-text-main', $language, $code);
     } else {
         $text = wfMsgForContent('babel-autocreate-text-levels', $level, $language, $code);
     }
     $user = self::user();
     # Do not add a message if the username is invalid or if the account that adds it, is blocked
     if (!$user || $user->isBlocked()) {
         return;
     }
     if (!$title->quickUserCan('create', $user)) {
         return;
         # The Babel AutoCreate account is not allowed to create the page
     }
     /* $article->doEdit will call $wgParser->parse.
      * Calling Parser::parse recursively is baaaadd... (bug 29245)
      * @todo FIXME: surely there is a better way?
      */
     global $wgParser, $wgParserConf;
     $oldParser = $wgParser;
     $parserClass = $wgParserConf['class'];
     $wgParser = new $parserClass($wgParserConf);
     $article = new Article($title, 0);
     $article->doEdit($text, wfMsgForContent('babel-autocreate-reason', wfMsgForContent('babel-url')), EDIT_FORCE_BOT, false, $user);
     $wgParser = $oldParser;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     global $wgFeed, $wgFeedClasses, $wgSitename, $wgLanguageCode;
     if (!$wgFeed) {
         $this->dieUsage('Syndication feeds are not available', 'feed-unavailable');
     }
     if (!isset($wgFeedClasses[$params['feedformat']])) {
         $this->dieUsage('Invalid subscription feed type', 'feed-invalid');
     }
     global $wgMiserMode;
     if ($params['showsizediff'] && $wgMiserMode) {
         $this->dieUsage('Size difference is disabled in Miser Mode', 'sizediffdisabled');
     }
     $msg = wfMessage('Contributions')->inContentLanguage()->text();
     $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
     $feedUrl = SpecialPage::getTitleFor('Contributions', $params['user'])->getFullURL();
     $target = $params['user'] == 'newbies' ? 'newbies' : Title::makeTitleSafe(NS_USER, $params['user'])->getText();
     $feed = new $wgFeedClasses[$params['feedformat']]($feedTitle, htmlspecialchars($msg), $feedUrl);
     $pager = new ContribsPager($this->getContext(), array('target' => $target, 'namespace' => $params['namespace'], 'year' => $params['year'], 'month' => $params['month'], 'tagFilter' => $params['tagfilter'], 'deletedOnly' => $params['deletedonly'], 'topOnly' => $params['toponly'], 'showSizeDiff' => $params['showsizediff']));
     $feedItems = array();
     if ($pager->getNumRows() > 0) {
         foreach ($pager->mResult as $row) {
             $feedItems[] = $this->feedItem($row);
         }
     }
     ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
 }
 function setTypeAndPossibleValues()
 {
     $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty);
     if ($proptitle === null) {
         return;
     }
     $store = smwfGetStore();
     // this returns an array of objects
     $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value");
     $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format");
     $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty);
     $this->mPropertyType = $propValue->findPropertyTypeID();
     foreach ($allowed_values as $allowed_value) {
         // HTML-unencode each value
         $this->mPossibleValues[] = html_entity_decode($allowed_value);
         if (count($label_formats) > 0) {
             $label_format = $label_formats[0];
             $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType);
             $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value);
             $label_value->setOutputFormat($label_format);
             $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue());
         }
     }
     // HACK - if there were any possible values, set the property
     // type to be 'enumeration', regardless of what the actual type is
     if (count($this->mPossibleValues) > 0) {
         $this->mPropertyType = 'enumeration';
     }
 }
 /**
  * @param $context ResourceLoaderContext
  * @return array
  */
 protected function getPages(ResourceLoaderContext $context)
 {
     $username = $context->getUser();
     if ($username === null) {
         return array();
     }
     // Get the normalized title of the user's user page
     $userpageTitle = Title::makeTitleSafe(NS_USER, $username);
     if (!$userpageTitle instanceof Title) {
         return array();
     }
     $userpage = $userpageTitle->getPrefixedDBkey();
     // Needed so $excludepages works
     $pages = array("{$userpage}/common.js" => array('type' => 'script'), "{$userpage}/" . $context->getSkin() . '.js' => array('type' => 'script'), "{$userpage}/common.css" => array('type' => 'style'), "{$userpage}/" . $context->getSkin() . '.css' => array('type' => 'style'));
     // Hack for bug 26283: if we're on a preview page for a CSS/JS page,
     // we need to exclude that page from this module. In that case, the excludepage
     // parameter will be set to the name of the page we need to exclude.
     $excludepage = $context->getRequest()->getVal('excludepage');
     if (isset($pages[$excludepage])) {
         // This works because $excludepage is generated with getPrefixedDBkey(),
         // just like the keys in $pages[] above
         unset($pages[$excludepage]);
     }
     return $pages;
 }
 public function execute()
 {
     global $wgUser;
     $username = $this->getOption('username', false);
     if ($username === false) {
         $user = User::newSystemUser('ScriptImporter', ['steal' => true]);
     } else {
         $user = User::newFromName($username);
     }
     $wgUser = $user;
     $baseUrl = $this->getArg(1);
     $pageList = $this->fetchScriptList();
     $this->output('Importing ' . count($pageList) . " pages\n");
     foreach ($pageList as $page) {
         $title = Title::makeTitleSafe(NS_MEDIAWIKI, $page);
         if (!$title) {
             $this->error("{$page} is an invalid title; it will not be imported\n");
             continue;
         }
         $this->output("Importing {$page}\n");
         $url = wfAppendQuery($baseUrl, ['action' => 'raw', 'title' => "MediaWiki:{$page}"]);
         $text = Http::get($url, [], __METHOD__);
         $wikiPage = WikiPage::factory($title);
         $content = ContentHandler::makeContent($text, $wikiPage->getTitle());
         $wikiPage->doEditContent($content, "Importing from {$url}", 0, false, $user);
     }
 }
 function execute()
 {
     global $wgOut;
     $this->limit = min($this->request->getInt('limit', 50), 5000);
     if ($this->limit <= 0) {
         $this->limit = 50;
     }
     $this->from = $this->request->getInt('from');
     $this->back = $this->request->getInt('back');
     $targetString = isset($this->par) ? $this->par : $this->request->getVal('target');
     if (is_null($targetString)) {
         $wgOut->addHTML($this->whatlinkshereForm());
         return;
     }
     $this->target = Title::newFromURL($targetString);
     if (!$this->target) {
         $wgOut->addHTML($this->whatlinkshereForm());
         return;
     }
     $this->selfTitle = Title::makeTitleSafe(NS_SPECIAL, 'Whatlinkshere/' . $this->target->getPrefixedDBkey());
     $wgOut->setPageTitle(wfMsg('whatlinkshere-title', $this->target->getPrefixedText()));
     $wgOut->setSubtitle(wfMsg('linklistsub'));
     $wgOut->addHTML(wfMsgExt('whatlinkshere-barrow', array('escapenoentities')) . ' ' . $this->skin->makeLinkObj($this->target, '', 'redirect=no') . "<br />\n");
     $this->showIndirectLinks(0, $this->target, $this->limit, $this->from, $this->back);
 }
 function ifcategory(&$parser, $category = '', $then = '', $else = '', $pagename = '')
 {
     if ($category === '') {
         return $then;
     }
     if ($pagename === '') {
         $title = $parser->getTitle();
         $page = $title->getDBkey();
         $ns = $title->getNamespace();
     } else {
         $title = Title::newFromText($pagename);
         if (!$title instanceof Title || !$title->exists()) {
             return $else;
         }
         $page = $title->getDBkey();
         $ns = $title->getNamespace();
     }
     $cattitle = Title::makeTitleSafe(NS_CATEGORY, $category);
     if (!$cattitle instanceof Title) {
         return $else;
     }
     $catkey = $cattitle->getDBkey();
     $db = wfGetDB(DB_SLAVE);
     $res = $db->select(array('page', 'categorylinks'), 'cl_from', array('page_id=cl_from', 'page_namespace' => $ns, 'page_title' => $page, 'cl_to' => $catkey), __METHOD__, array('LIMIT' => 1));
     if ($db->numRows($res) == 0) {
         return $else;
     }
     return $then;
 }
 function formatValue($name, $value)
 {
     global $wgLang, $wgContLang;
     static $linker = null;
     if (empty($linker)) {
         $linker = class_exists('DummyLinker') ? new DummyLinker() : new Linker();
     }
     $row = $this->mCurrentRow;
     $ns = $row->page_namespace;
     $title = $row->page_title;
     if (is_null($ns)) {
         $ns = $row->thread_article_namespace;
         $title = $row->thread_article_title;
     }
     switch ($name) {
         case 'thread_subject':
             $title = Title::makeTitleSafe($ns, $title);
             $link = $linker->link($title, $value, array(), array(), array('known'));
             return Html::rawElement('div', array('dir' => $wgContLang->getDir()), $link);
         case 'th_timestamp':
             $formatted = $wgLang->timeanddate($value);
             $title = Title::makeTitleSafe($ns, $title);
             return $linker->link($title, $formatted, array(), array('lqt_oldid' => $row->th_id));
         default:
             return parent::formatValue($name, $value);
     }
 }
Exemple #12
0
 function execute($par)
 {
     global $wgRequest, $wgOut;
     $this->setHeaders();
     $this->outputHeader();
     $file = !is_null($par) ? $par : $wgRequest->getText('file');
     $title = Title::makeTitleSafe(NS_FILE, $file);
     if (!$title instanceof Title || $title->getNamespace() != NS_FILE) {
         $this->showForm($title);
     } else {
         $file = wfFindFile($title);
         if ($file && $file->exists()) {
             $url = $file->getURL();
             $width = $wgRequest->getInt('width', -1);
             $height = $wgRequest->getInt('height', -1);
             if ($width != -1) {
                 $mto = $file->transform(array('width' => $width, 'height' => $height));
                 if ($mto && !$mto->isError()) {
                     $url = $mto->getURL();
                 }
             }
             $wgOut->redirect($url);
         } else {
             $wgOut->setStatusCode(404);
             $this->showForm($title);
         }
     }
 }
 /**
  * @param $username string
  * @return CollaborationListContent
  */
 public static function makeMemberList($username, $initialDescription)
 {
     $linkToUserpage = Title::makeTitleSafe(NS_USER, $username)->getPrefixedText();
     $newMemberList = ["displaymode" => "members", "columns" => [["items" => [["title" => $linkToUserpage]]]], "options" => ["mode" => "normal"], "description" => "{$initialDescription}"];
     $newMemberListJson = FormatJson::encode($newMemberList, "\t", FormatJson::ALL_OK);
     return new CollaborationListContent($newMemberListJson);
 }
 function setTypeAndPossibleValues()
 {
     // The presence of "-" at the beginning of a property name
     // (which happens if SF tries to parse an inverse query)
     // leads to an error in SMW - just exit if that's the case.
     if (strpos($this->mSemanticProperty, '-') === 0) {
         return;
     }
     $proptitle = Title::makeTitleSafe(SMW_NS_PROPERTY, $this->mSemanticProperty);
     if ($proptitle === null) {
         return;
     }
     $store = SFUtils::getSMWStore();
     // this returns an array of objects
     $allowed_values = SFUtils::getSMWPropertyValues($store, $proptitle, "Allows value");
     $label_formats = SFUtils::getSMWPropertyValues($store, $proptitle, "Has field label format");
     $propValue = SMWDIProperty::newFromUserLabel($this->mSemanticProperty);
     $this->mPropertyType = $propValue->findPropertyTypeID();
     foreach ($allowed_values as $allowed_value) {
         // HTML-unencode each value
         $this->mPossibleValues[] = html_entity_decode($allowed_value);
         if (count($label_formats) > 0) {
             $label_format = $label_formats[0];
             $prop_instance = SMWDataValueFactory::findTypeID($this->mPropertyType);
             $label_value = SMWDataValueFactory::newTypeIDValue($prop_instance, $wiki_value);
             $label_value->setOutputFormat($label_format);
             $this->mValueLabels[$wiki_value] = html_entity_decode($label_value->getWikiValue());
         }
     }
     // HACK - if there were any possible values, set the property
     // type to be 'enumeration', regardless of what the actual type is
     if (count($this->mPossibleValues) > 0) {
         $this->mPropertyType = 'enumeration';
     }
 }
 /**
  * The category list template. Used by article pages on view and edit save.
  */
 public function categories()
 {
     wfProfileIn(__METHOD__);
     $categories = $this->request->getVal('categories', array());
     $data = array();
     // Because $out->getCategoryLinks doesn't maintain the order of the stored category data,
     // we have to build this information ourselves manually. This is essentially the same
     // code from $out->addCategoryLinks() but it results in a different data format.
     foreach ($categories as $category) {
         // Support category name or category data object
         $name = is_array($category) ? $category['name'] : $category;
         $originalName = $name;
         $title = Title::makeTitleSafe(NS_CATEGORY, $name);
         if ($title != null) {
             $this->wg->ContLang->findVariantLink($name, $title, true);
             if ($name != $originalName && array_key_exists($name, $data)) {
                 continue;
             }
             $text = $this->wg->ContLang->convertHtml($title->getText());
             $data[$name] = array('link' => Linker::link($title, $text), 'name' => $text, 'type' => CategoryHelper::getCategoryType($originalName));
         } else {
             \Wikia\Logger\WikiaLogger::instance()->warning("Unsafe category provided", ['name' => $name]);
         }
     }
     $this->response->setVal('categories', $data);
     wfProfileOut(__METHOD__);
 }
/**
 * Main execution point
 * @param $par Namespace to select the redirect from
 */
function wfSpecialRandomredirect($par = NULL)
{
    global $wgOut, $wgExtraRandompageSQL, $wgContLang;
    $fname = 'wfSpecialRandomredirect';
    # Validate the namespace
    $namespace = $wgContLang->getNsIndex($par);
    if ($namespace === false || $namespace < NS_MAIN) {
        $namespace = NS_MAIN;
    }
    # Same logic as RandomPage
    $randstr = wfRandom();
    $dbr =& wfGetDB(DB_SLAVE);
    $use_index = $dbr->useIndexClause('page_random');
    $page = $dbr->tableName('page');
    $extra = $wgExtraRandompageSQL ? "AND ({$wgExtraRandompageSQL})" : '';
    $sql = "SELECT page_id,page_title\n\t\tFROM {$page} {$use_index}\n\t\tWHERE page_namespace = {$namespace} AND page_is_redirect = 1 {$extra}\n\t\tAND page_random > {$randstr}\n\t\tORDER BY page_random";
    $sql = $dbr->limitResult($sql, 1, 0);
    $res = $dbr->query($sql, $fname);
    $title = NULL;
    if ($row = $dbr->fetchObject($res)) {
        $title = Title::makeTitleSafe($namespace, $row->page_title);
    }
    # Catch dud titles and return to the main page
    if (is_null($title)) {
        $title = Title::newMainPage();
    }
    $wgOut->reportTime();
    $wgOut->redirect($title->getFullUrl('redirect=no'));
}
 public function testUpdateUserParams()
 {
     $p = FRUserCounters::getUserParams(-1);
     # Assumes (main) IN content namespace
     $title = Title::makeTitleSafe(0, 'helloworld');
     $article = new Article($title);
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "Manual edit comment");
     $this->assertEquals($p['editComments'] + 1, $copyP['editComments'], "Manual summary");
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "/* section */");
     $this->assertEquals($p['editComments'], $copyP['editComments'], "Auto summary");
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "edit summary");
     $this->assertEquals($p['totalContentEdits'] + 1, $copyP['totalContentEdits'], "Content edit count on content edit");
     $expected = $p['uniqueContentPages'];
     $expected[] = 0;
     $this->assertEquals($expected, $copyP['uniqueContentPages'], "Unique content pages on content edit");
     # Assumes (user) NOT IN content namespace
     $title = Title::makeTitleSafe(NS_USER, 'helloworld');
     $article = new Article($title);
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "Manual edit comment");
     $this->assertEquals($p['editComments'] + 1, $copyP['editComments'], "Manual summary");
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "/* section */");
     $this->assertEquals($p['editComments'], $copyP['editComments'], "Auto summary");
     $title = Title::makeTitleSafe(NS_USER, 'helloworld');
     $article = new Article($title);
     $copyP = $p;
     FRUserCounters::updateUserParams($copyP, $article, "edit summary");
     $this->assertEquals($p['totalContentEdits'], $copyP['totalContentEdits'], "Content edit count on non-content edit");
     $this->assertEquals($p['uniqueContentPages'], $copyP['uniqueContentPages'], "Unique content pages on non-content edit");
 }
 function getSQL()
 {
     $dbr = wfGetDB(DB_SLAVE);
     $dMsgText = wfMsgForContent('disambiguationspage');
     $linkBatch = new LinkBatch();
     # If the text can be treated as a title, use it verbatim.
     # Otherwise, pull the titles from the links table
     $dp = Title::newFromText($dMsgText);
     if ($dp) {
         if ($dp->getNamespace() != NS_TEMPLATE) {
             # FIXME we assume the disambiguation message is a template but
             # the page can potentially be from another namespace :/
             wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
         }
         $linkBatch->addObj($dp);
     } else {
         # Get all the templates linked from the Mediawiki:Disambiguationspage
         $disPageObj = Title::makeTitleSafe(NS_MEDIAWIKI, 'disambiguationspage');
         $res = $dbr->select(array('pagelinks', 'page'), 'pl_title', array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), __METHOD__);
         while ($row = $dbr->fetchObject($res)) {
             $linkBatch->addObj(Title::makeTitle(NS_TEMPLATE, $row->pl_title));
         }
         $dbr->freeResult($res);
     }
     $set = $linkBatch->constructSet('lb.tl', $dbr);
     if ($set === false) {
         # We must always return a valid sql query, but this way DB will always quicly return an empty result
         $set = 'FALSE';
         wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
     }
     list($page, $pagelinks, $templatelinks) = $dbr->tableNamesN('page', 'pagelinks', 'templatelinks');
     $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace," . " pb.page_title AS title, la.pl_from AS value" . " FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa" . " WHERE {$set}" . ' AND pa.page_id = la.pl_from' . ' AND pa.page_namespace = ' . NS_MAIN . ' AND pb.page_id = lb.tl_from' . ' AND pb.page_namespace = la.pl_namespace' . ' AND pb.page_title = la.pl_title' . ' ORDER BY lb.tl_namespace, lb.tl_title';
     return $sql;
 }
 function execute()
 {
     global $wgOut;
     $this->limit = min($this->request->getInt('limit', 50), 5000);
     if ($this->limit <= 0) {
         $this->limit = 50;
     }
     $this->from = $this->request->getInt('from');
     $this->dir = $this->request->getText('dir', 'next');
     if ($this->dir != 'prev') {
         $this->dir = 'next';
     }
     $targetString = isset($this->par) ? $this->par : $this->request->getVal('target');
     if (is_null($targetString)) {
         $wgOut->showErrorPage('notargettitle', 'notargettext');
         return;
     }
     $this->target = Title::newFromURL($targetString);
     if (!$this->target) {
         $wgOut->showErrorPage('notargettitle', 'notargettext');
         return;
     }
     $this->selfTitle = Title::makeTitleSafe(NS_SPECIAL, 'Whatlinkshere/' . $this->target->getPrefixedDBkey());
     $wgOut->setPagetitle($this->target->getPrefixedText());
     $wgOut->setSubtitle(wfMsg('linklistsub'));
     $wgOut->addHTML(wfMsg('whatlinkshere-barrow') . ' ' . $this->skin->makeLinkObj($this->target, '', 'redirect=no') . "<br />\n");
     $this->showIndirectLinks(0, $this->target, $this->limit, $this->from, $this->dir);
 }
 /**
  * Callback function to output a restriction
  */
 function formatRow($row)
 {
     global $wgUser, $wgLang, $wgContLang;
     wfProfileIn(__METHOD__);
     static $skin = null;
     if (is_null($skin)) {
         $skin = $wgUser->getSkin();
     }
     $title = Title::makeTitleSafe($row->page_namespace, $row->page_title);
     $link = $skin->makeLinkObj($title);
     $description_items = array();
     $protType = wfMsgHtml('restriction-level-' . $row->pr_level);
     $description_items[] = $protType;
     if ($row->pr_cascade) {
         $description_items[] = wfMsg('protect-summary-cascade');
     }
     $expiry_description = '';
     $stxt = '';
     if ($row->pr_expiry != 'infinity' && strlen($row->pr_expiry)) {
         $expiry = Block::decodeExpiry($row->pr_expiry);
         $expiry_description = wfMsgForContent('protect-expiring', $wgLang->timeanddate($expiry));
         $description_items[] = $expiry_description;
     }
     if (!is_null($size = $row->page_len)) {
         if ($size == 0) {
             $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
         } else {
             $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum($size)) . '</small>';
         }
         $stxt = $wgContLang->getDirMark() . $stxt;
     }
     wfProfileOut(__METHOD__);
     return '<li>' . wfSpecialList($link . $stxt, implode($description_items, ', ')) . "</li>\n";
 }
 /**
  * Main execution function
  * @param $par Parameters passed to the page
  */
 function execute($par)
 {
     global $wgOut, $wgUser;
     wfLoadExtensionMessages('Gadgets');
     $skin = $wgUser->getSkin();
     $this->setHeaders();
     $wgOut->setPagetitle(wfMsg("gadgets-title"));
     $wgOut->addWikiText(wfMsg("gadgets-pagetext"));
     $gadgets = wfLoadGadgetsStructured();
     if (!$gadgets) {
         return;
     }
     $listOpen = false;
     $msgOpt = array('parseinline', 'parsemag');
     foreach ($gadgets as $section => $entries) {
         if ($section !== false && $section !== '') {
             $t = Title::makeTitleSafe(NS_MEDIAWIKI, "Gadget-section-{$section}");
             $lnk = $t ? $skin->makeLinkObj($t, wfMsgHTML("edit")) : htmlspecialchars($section);
             $ttext = wfMsgExt("gadget-section-{$section}", $msgOpt);
             if ($listOpen) {
                 $wgOut->addHTML('</ul>');
                 $listOpen = false;
             }
             $wgOut->addHTML("\n<h2>{$ttext} &nbsp; &nbsp; [{$lnk}]</h2>\n");
         }
         foreach ($entries as $gname => $code) {
             $t = Title::makeTitleSafe(NS_MEDIAWIKI, "Gadget-{$gname}");
             if (!$t) {
                 continue;
             }
             $lnk = $skin->makeLinkObj($t, wfMsgHTML("edit"));
             $ttext = wfMsgExt("gadget-{$gname}", $msgOpt);
             if (!$listOpen) {
                 $listOpen = true;
                 $wgOut->addHTML('<ul>');
             }
             $wgOut->addHTML("<li>");
             $wgOut->addHTML("{$ttext} &nbsp; &nbsp; [{$lnk}]<br/>");
             $wgOut->addHTML(wfMsgHTML("gadgets-uses") . ": ");
             $first = true;
             foreach ($code as $codePage) {
                 $t = Title::makeTitleSafe(NS_MEDIAWIKI, "Gadget-{$codePage}");
                 if (!$t) {
                     continue;
                 }
                 if ($first) {
                     $first = false;
                 } else {
                     $wgOut->addHTML(", ");
                 }
                 $lnk = $skin->makeLinkObj($t, htmlspecialchars($t->getText()));
                 $wgOut->addHTML($lnk);
             }
             $wgOut->addHtml("</li>");
         }
     }
     if ($listOpen) {
         $wgOut->addHTML('</ul>');
     }
 }
 protected function getMessageParameters()
 {
     $params = parent::getMessageParameters();
     /* Current format:
      * 1,2,3: normal logformatter params
      * 4: old username
      *    (legaciest doesn't have this at all, all in comment)
      *    (legacier uses this as new name and stores old name in target)
      * 5: new username
      * 6: number of edits the user had at the time
      *    (not available except in newest log entries)
      * Note that the arrays are zero-indexed, while message parameters
      * start from 1, so substract one to get array entries below.
      */
     if (!isset($params[3])) {
         // The oldest format
         return $params;
     } elseif (!isset($params[4])) {
         // See comments above
         $params[4] = $params[3];
         $params[3] = $this->entry->getTarget()->getText();
     }
     // Nice link to old user page
     $title = Title::makeTitleSafe(NS_USER, $params[3]);
     $link = $this->myPageLink($title, $params[3]);
     $params[3] = Message::rawParam($link);
     // Nice link to new user page
     $title = Title::makeTitleSafe(NS_USER, $params[4]);
     $link = $this->myPageLink($title, $params[4]);
     $params[4] = Message::rawParam($link);
     return $params;
 }
 function getQueryInfo()
 {
     $dbr = wfGetDB(DB_SLAVE);
     $dMsgText = wfMsgForContent('disambiguationspage');
     $linkBatch = new LinkBatch();
     # If the text can be treated as a title, use it verbatim.
     # Otherwise, pull the titles from the links table
     $dp = Title::newFromText($dMsgText);
     if ($dp) {
         if ($dp->getNamespace() != NS_TEMPLATE) {
             # @todo FIXME: We assume the disambiguation message is a template but
             # the page can potentially be from another namespace :/
             wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
         }
         $linkBatch->addObj($dp);
     } else {
         # Get all the templates linked from the Mediawiki:Disambiguationspage
         $disPageObj = Title::makeTitleSafe(NS_MEDIAWIKI, 'disambiguationspage');
         $res = $dbr->select(array('pagelinks', 'page'), 'pl_title', array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), __METHOD__);
         foreach ($res as $row) {
             $linkBatch->addObj(Title::makeTitle(NS_TEMPLATE, $row->pl_title));
         }
     }
     $set = $linkBatch->constructSet('tl', $dbr);
     if ($set === false) {
         # We must always return a valid SQL query, but this way
         # the DB will always quickly return an empty result
         $set = 'FALSE';
         wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
     }
     // @todo FIXME: What are pagelinks and p2 doing here?
     return array('tables' => array('templatelinks', 'p1' => 'page', 'pagelinks', 'p2' => 'page'), 'fields' => array('p1.page_namespace AS namespace', 'p1.page_title AS title', 'pl_from AS value'), 'conds' => array($set, 'p1.page_id = tl_from', 'pl_namespace = p1.page_namespace', 'pl_title = p1.page_title', 'p2.page_id = pl_from', 'p2.page_namespace' => MWNamespace::getContentNamespaces()));
 }
Exemple #24
0
function formatImageLink($imageName, $linkTarget, $altText)
{
    if (preg_match('/^(http|ftp)/', $imageName)) {
        $imageUrl = $imageName;
        $sizeAttrs = "";
    } else {
        $imageTitle = Title::makeTitleSafe(NS_IMAGE, $imageName);
        if (is_null($imageTitle)) {
            return "(invalid image name)";
        }
        $image = wfFindFile($imageTitle);
        if (is_null($image)) {
            return "(invalid image)";
        }
        $imageUrl = $image->getViewURL();
        $sizeAttrs = 'width="' . IntVal($image->getWidth()) . '" height="' . IntVal($image->getHeight()) . '"';
    }
    if (preg_match('/^(http|ftp)/', $linkTarget)) {
        $linkUrl = $linkTarget;
    } else {
        $linkTitle = Title::newFromText($linkTarget);
        if (is_null($linkTitle)) {
            return "(invalid link target)";
        }
        $linkUrl = $linkTitle->getLocalUrl();
    }
    return '<a href="' . htmlspecialchars($linkUrl) . '"><img src="' . htmlspecialchars($imageUrl) . '" ' . $sizeAttrs . ' alt="' . htmlspecialchars($altText) . '" title="' . htmlspecialchars($altText) . '" /></a>';
}
 /**
  * @param IContextSource $context
  * @param array $par (Default null)
  * @param bool $including Whether this page is being transcluded in
  * another page
  */
 function __construct(IContextSource $context = null, $par = null, $including = null)
 {
     if ($context) {
         $this->setContext($context);
     }
     $request = $this->getRequest();
     $par = $par !== null ? $par : '';
     $parms = explode('/', $par);
     $symsForAll = array('*', 'user');
     if ($parms[0] != '' && (in_array($par, User::getAllGroups()) || in_array($par, $symsForAll))) {
         $this->requestedGroup = $par;
         $un = $request->getText('username');
     } elseif (count($parms) == 2) {
         $this->requestedGroup = $parms[0];
         $un = $parms[1];
     } else {
         $this->requestedGroup = $request->getVal('group');
         $un = $par != '' ? $par : $request->getText('username');
     }
     if (in_array($this->requestedGroup, $symsForAll)) {
         $this->requestedGroup = '';
     }
     $this->editsOnly = $request->getBool('editsOnly');
     $this->creationSort = $request->getBool('creationSort');
     $this->including = $including;
     $this->mDefaultDirection = $request->getBool('desc') ? IndexPager::DIR_DESCENDING : IndexPager::DIR_ASCENDING;
     $this->requestedUser = '';
     if ($un != '') {
         $username = Title::makeTitleSafe(NS_USER, $un);
         if (!is_null($username)) {
             $this->requestedUser = $username->getText();
         }
     }
     parent::__construct();
 }
 /**
  * Callback function to output a restriction
  *
  * @param object $row Database row
  * @return string
  */
 function formatRow($row)
 {
     wfProfileIn(__METHOD__);
     static $infinity = null;
     if (is_null($infinity)) {
         $infinity = wfGetDB(DB_SLAVE)->getInfinity();
     }
     $title = Title::makeTitleSafe($row->pt_namespace, $row->pt_title);
     if (!$title) {
         wfProfileOut(__METHOD__);
         return Html::rawElement('li', array(), Html::element('span', array('class' => 'mw-invalidtitle'), Linker::getInvalidTitleDescription($this->getContext(), $row->pt_namespace, $row->pt_title))) . "\n";
     }
     $link = Linker::link($title);
     $description_items = array();
     $protType = $this->msg('restriction-level-' . $row->pt_create_perm)->escaped();
     $description_items[] = $protType;
     $lang = $this->getLanguage();
     $expiry = strlen($row->pt_expiry) ? $lang->formatExpiry($row->pt_expiry, TS_MW) : $infinity;
     if ($expiry != $infinity) {
         $user = $this->getUser();
         $description_items[] = $this->msg('protect-expiring-local', $lang->userTimeAndDate($expiry, $user), $lang->userDate($expiry, $user), $lang->userTime($expiry, $user))->escaped();
     }
     wfProfileOut(__METHOD__);
     // @todo i18n: This should use a comma separator instead of a hard coded comma, right?
     return '<li>' . $lang->specialList($link, implode($description_items, ', ')) . "</li>\n";
 }
 /**
  * @param $skin Skin
  * @param $result
  * @return string
  */
 function formatResult($skin, $result)
 {
     $title = Title::makeTitleSafe($result->namespace, $result->title);
     $count = $this->msg('ncategories')->numParams($result->value)->escaped();
     $link = Linker::link($title);
     return $this->getLanguage()->specialList($link, $count);
 }
 function trySubmit()
 {
     global $wgOut, $wgUser;
     $errors = array();
     $ip = $this->mUnblockIP;
     if (!IP::isIPAddress($ip) && strlen($ip)) {
         $errors[] = array('globalblocking-unblock-ipinvalid', $ip);
         $ip = '';
     }
     if (0 == ($id = GlobalBlocking::getGlobalBlockId($ip))) {
         $errors[] = array('globalblocking-notblocked', $ip);
     }
     if (count($errors) > 0) {
         return $errors;
     }
     $dbw = GlobalBlocking::getGlobalBlockingMaster();
     $dbw->delete('globalblocks', array('gb_id' => $id), __METHOD__);
     $page = new LogPage('gblblock');
     $page->addEntry('gunblock', Title::makeTitleSafe(NS_USER, $ip), $this->mReason);
     $successmsg = wfMsgExt('globalblocking-unblock-unblocked', array('parse'), $ip, $id);
     $wgOut->addHTML($successmsg);
     $link = $wgUser->getSkin()->makeKnownLinkObj(SpecialPage::getTitleFor('GlobalBlockList'), wfMsg('globalblocking-return'));
     $wgOut->addHTML($link);
     $wgOut->setSubtitle(wfMsg('globalblocking-unblock-successsub'));
     return array();
 }
 /**
  * @param $user User
  * @param $output OutputPage
  */
 protected function showLogFragment($user, $output)
 {
     $pageTitle = Title::makeTitleSafe(NS_USER, $user->getName());
     $logPage = new LogPage('gblrights');
     $output->addHTML(Xml::element('h2', null, $logPage->getName()->text() . "\n"));
     LogEventsList::showLogExtract($output, 'gblrights', $pageTitle->getPrefixedText());
 }
 /**
  * Callback function to output a restriction
  * @param $row object Protected title
  * @return string Formatted <li> element
  */
 public function formatRow($row)
 {
     wfProfileIn(__METHOD__);
     static $infinity = null;
     if (is_null($infinity)) {
         $infinity = wfGetDB(DB_SLAVE)->getInfinity();
     }
     $title = Title::makeTitleSafe($row->page_namespace, $row->page_title);
     $link = Linker::link($title);
     $description_items = array();
     $protType = wfMsgHtml('restriction-level-' . $row->pr_level);
     $description_items[] = $protType;
     if ($row->pr_cascade) {
         $description_items[] = wfMsg('protect-summary-cascade');
     }
     $stxt = '';
     $lang = $this->getLanguage();
     $expiry = $lang->formatExpiry($row->pr_expiry, TS_MW);
     if ($expiry != $infinity) {
         $expiry_description = wfMsg('protect-expiring-local', $lang->timeanddate($expiry, true), $lang->date($expiry, true), $lang->time($expiry, true));
         $description_items[] = htmlspecialchars($expiry_description);
     }
     if (!is_null($size = $row->page_len)) {
         $stxt = $lang->getDirMark() . ' ' . Linker::formatRevisionSize($size);
     }
     # Show a link to the change protection form for allowed users otherwise a link to the protection log
     if ($this->getUser()->isAllowed('protect')) {
         $changeProtection = ' (' . Linker::linkKnown($title, wfMsgHtml('protect_change'), array(), array('action' => 'unprotect')) . ')';
     } else {
         $ltitle = SpecialPage::getTitleFor('Log');
         $changeProtection = ' (' . Linker::linkKnown($ltitle, wfMsgHtml('protectlogpage'), array(), array('type' => 'protect', 'page' => $title->getPrefixedText())) . ')';
     }
     wfProfileOut(__METHOD__);
     return Html::rawElement('li', array(), $lang->specialList($link . $stxt, $lang->commaList($description_items), false) . $changeProtection) . "\n";
 }