Índice
1 Orden de los cuadros[editar]
Para que el orden sea el correcto en los cuadros, se ha redefinido una función de JavaScript (ver código).
2 Enlaces con conversión a mayúscula[editar]
Es bastante sencillo y se basa en una expresión regular y el hook InternalParseBeforeLinks.
<?php if (!defined('MEDIAWIKI')) die(); function WLrex_rep($m) { return '[[' . strtoupper($m[1]) . $m[2] . '|' . $m[1] . $m[2] . ']]'; } function WLreplaceUpperLinks(&$parser, &$text) { $rex = '/\[\[\'(.)(.*?)]]/'; $text = preg_replace_callback($rex, "WLrex_rep", $text); return true; } $wgHooks['InternalParseBeforeLinks'][] = 'WLreplaceUpperLinks';
3 Mensaje de patrulla en los artículos[editar]
La siguiente función es la encargada de ello. Está escrita a partir del estudio de la base de datos y también un poco de prueba y error. Está incluida en el archivo de apariencia de la Wikilengua, así que no ha sido necesario parchear nada. [Actualizado a 2010-03-11.]
function getPatrolStatus() { global $wgTitle, $wgRequest, $wgLang, $wgUser, $wgOut; $artId = intval ( $wgTitle->getArticleId() ); $dbr = wfGetDB(DB_SLAVE); $oldidVal = $wgRequest->getVal('oldid'); if ( !$wgUser->isLoggedIn() ) { $draftVal = $wgRequest->getVal('draft'); } $ttl = $wgTitle->getText(); $last = $dbr->selectRow( 'recentchanges', array("rc_id","rc_patrolled","rc_type","rc_cur_id","rc_this_oldid"), "rc_cur_id=$artId ORDER BY rc_id DESC"); # $lastTime sive tambien como marca de "nuevo" (= "") $lastTime == ""; # $last puede ser nulo si hace tiempo que no se cambia y ya no está en recentchanges. Se da por confirmado: if ( $last && !$last->rc_patrolled ) { $lastPatr = $dbr->selectRow( 'recentchanges', array("rc_id","rc_timestamp","rc_patrolled","rc_cur_id","rc_this_oldid"), "rc_patrolled=1 AND rc_cur_id=$artId ORDER BY rc_id DESC"); # mejor order por timestamp? # lastPatr puede ser nulo si todas están patrulladas: if ( $lastPatr ) { # Hay version patrullada, así que se toma el id y la fecha de esa version, # salvo si el ultimo es nuevo (es decir, solo hay esa version). if ( $last->rc_type != RC_NEW ) { $patrRev = $lastPatr->rc_this_oldid; $lastTime = $lastPatr->rc_timestamp; } } else { # Hay que ver si el más antiguo en recentchanges es nuevo. Si lo es: lastTime = "" # Si no, hay versiones anteriores que no están en recentchanges; se toma la anterior version, # que se da por confirmada. if ( $dbr->selectField( 'recentchanges', 'rc_type', "rc_cur_id=$artId ORDER BY rc_id" ) != RC_NEW ) { $patrRev = $dbr->selectField( 'recentchanges', 'rc_this_oldid', "rc_cur_id=$artId ORDER BY rc_id" ); # $tempRev = $dbr->selectField( 'revision', 'rev_id', "rev_page=$artId ORDER BY rev_id DESC"); if ( $patrRev ) { # $patrRev = $dbr->selectField( 'revision', 'rev_id', "rev_page=$patrRev ORDER BY rev_id DESC"); $patrRev = $wgTitle->getPreviousRevisionID( $patrRev ); if ( $patrRev ) { $lastTime = $dbr->selectField( 'revision', 'rev_timestamp', "rev_id=$patrRev" ); } } } } # :-/ Se esta dando por hecho que hay un $lastUser en recentchanges. # Crucemos los dedos... if ( !$wgUser->isLoggedIn() ) { $lastUser = $dbr->selectRow( 'recentchanges', array("rc_id","rc_user","rc_timestamp","rc_cur_id","rc_this_oldid"), "rc_user!=0 AND rc_cur_id=$artId ORDER BY rc_id DESC"); # Si la última edicion es anonima if ( $lastUser && $lastUser->rc_this_oldid > $patrRev ) { $stabRev = $lastUser->rc_this_oldid; } else { $stabRev = $patrRev; } # OJO: Se cancela el 'fragmento' (ie, #), como en las notas al pie. # Tarea: Hacer como funcin. if ( is_null($oldidVal) && is_null($draftVal) && $last->rc_id != $lastUser->rc_id ) { return "<script>window.location = '/index.php?title=$ttl&oldid=$stabRev&draft=0'</script>"; } } } $s = ""; # Hay un problema con la navegación si hay direction, pues oldid no es el actual if ( (is_null($oldidVal) && is_null($draftVal)) || $draftVal == '0' ) { if ( $draftVal == '0' && $stabRev != "") { $last = $dbr->selectRow( 'recentchanges', array("rc_id","rc_timestamp","rc_patrolled","rc_cur_id","rc_this_oldid"), "rc_this_oldid=$stabRev ORDER BY rc_id DESC"); } if ( $last && !$last->rc_patrolled ) { $s .= "<h6 style='color:#b40;'>Sin supervisar</h6>\n"; if ( $lastTime != "" ) { $timestamp = $wgLang->date($lastTime, true, 'Y-m-d') . " a las " . $wgLang->time($lastTime, true); // date('Y-m-d', strtotime($lastTime)) $s .= "<p>La última versión supervisada es de <a href='/index.php?title=$ttl&oldid=$patrRev'>$timestamp</a>" . " <small>(<a href='/index.php?title=$ttl&diff={$last->rc_this_oldid}&oldid=$patrRev'>comparar</a>)</small></p>"; } else { $s .= "<p>Es un artículo nuevo y todavía no hay versión supervisada.</p>"; } } else { $s .= "<h6>Supervisado</h6>"; } } else { $s = ( $s == "" ? "<h6>Supervisión</h6>" : $s ); if ( is_null($draftVal) ) { $s .= "<ul><li><a href='/index.php?title=$ttl'>Ir a la versión actual</a></li>" . "<li><a href='/index.php?title=$ttl&oldid=$patrRev'>Ir a la última supervisada</a></li></ul>"; } } if ( !is_null($draftVal) ) { if ( $draftVal == '0' ) { $s .= "<h6 id='wl-has-draft'><span class='ayuda'><a style='color:white;' href='/index.php/Ayuda:Borrador'>?</a></span>Hay borrador</h6>" . "<p>Esta versión es la última estable. Hay un borrador posterior pendiente de supervisión.<br />" . "<a href='/index.php?title=$ttl&draft=1'>» Ir al borrador</a></p>"; } else { #d63 $s = "<h6 style='color:#b40;'><span class='ayuda'><a style='color:white;' href='/index.php/Ayuda:Borrador'>?</a></span>Borrador</h6>" . "<p>Esta versión es un borrador pendiente de supervisión.<br />" . "<a href='/index.php?title=$ttl&oldid=$stabRev&draft=0'>» Ir a la última versión que no es borrador.</a>" . " <small>(<a href='/index.php?title=$ttl&diff={$last->rc_this_oldid}&oldid=$stabRev&rcid={$last->rc_id}'>comparar</a>)</small></p>"; } } return $s; }
4 Usuarios en portada[editar]
La lista de usuario en la portada se obtiene con el siguiente código. Obsérvese que es completamente ad hoc y que se puede optimizar (en particular la supervisión, que copié del código de arriba).
$wgExtensionFunctions[] = 'wfRecentUsers_Setup'; $wgHooks['LanguageGetMagic'][] = 'wfRecentUsers_Magic'; function wfRecentUsers_Setup() { global $wgParser; $wgParser->setFunctionHook('recentusers', 'wfRecentUsers_Render'); } function wfRecentUsers_Magic(&$magicWords, $langCode) { $magicWords['recentusers'] = array(0, 'recentusers'); return true; } function wfRecentUsers_Render( &$parser ) { $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query("SELECT DISTINCT `wl_page`.page_namespace as " . "page_namespace,`wl_page`.page_title as page_title, rev_user, " . "rev_user_text, rev_timestamp FROM `wl_revision` AS rev, `wl_page` " . "WHERE 1=1 AND `wl_page`.page_namespace IN ('0') " . "AND `wl_page`.page_is_redirect=0 AND `wl_page`.page_id=rev.rev_page " . "AND rev.rev_timestamp=( SELECT MAX(rev_aux.rev_timestamp) " . "FROM `wl_revision` AS rev_aux WHERE rev_aux.rev_page=rev.rev_page ) " . "ORDER BY rev_timestamp DESC LIMIT 0, 75"); $userList = array(); while ($row = $dbr->fetchObject($res)) { $userList[] = $row->rev_user; } $userList = array_unique($userList); $s = ''; $userCnt = 0; foreach ($userList as $user) { $user = User::newFromId($user)->getName(); $article = new Article(Title::makeTitle(NS_USER, $user)); $templates = $article->getUsedTemplates(); /* == Para tomar la patrulla == */ $Id = $article->getId(); $curr = $dbr->selectField( 'recentchanges', 'rc_id', 'rc_cur_id=' . $Id . ' ORDER BY rc_id DESC'); $last = $dbr->selectField( 'recentchanges', 'rc_id', 'rc_patrolled=1 AND rc_cur_id=' . $Id . ' ORDER BY rc_id DESC'); if ( $curr == $last ) { /* == == */ if ((array_search("Plantilla:usuario portada", $templates) !== FALSE) && $userCnt < 5) { $userCnt++; $s .= "{{usuario_portada_formato|$user}}"; } } } /* == == */ $dbr->freeResult( $res ); return array($s, 'noparse' => false, 'isHTML' => false); }
5 Columna de datos del artículo[editar]
El código que la genera va a continuación, aunque luego hay que hacer que aparezca en la plantilla con un $this->infobar()
en el sitio apropiado. En cuanto a las definiciones de CSS, se pueden ver fácilmente con Firebug en Firefox. Para getPatrolStatus
, véase el código de arriba. También hay que definir un array con las redes.
Tiene un problema obvio: una vez que se ha visto si la página tiene la plantilla sobre
, buesca en el cuerpo del texto sin tener en cuenta el contexto, es decir, si está en un comentario HTML.
function infoBar () { global $wgOut, $wgTitle, $wgShareThisSiteList, $wgArticle, $wgParser, $wgRequest; $s = ''; if ( $wgOut->isArticle() and $wgTitle->getNamespace() == 0 and $wgTitle->getText() != "Portada" ) { # Supervisión $s .= $this->getPatrolStatus(); # Incluye título con h6. } if ( $wgOut->isArticle() and $wgTitle->getText() != "Portada" ) { $text = ''; # para evitar un fetchContent doble # Relacionados $templates = $wgArticle->getUsedTemplates(); if ((array_search("Plantilla:sobre", $templates) !== FALSE)) { $text = $wgArticle->fetchContent(); if (preg_match('/{{sobre\|(.*?)}}/s',$text, $matches)) { $s .= "" # <h6>Relacionados</h6>\n<p>" . $wgOut->parse('{{sobre/' . $matches[1] . '}}') . "\n</p>"; } } if ((array_search("Plantilla:véase", $templates) !== FALSE)) { if ($text == '') { $text = $wgArticle->fetchContent(); } if (preg_match('/{{véase\|(.*?)}}/s',$text, $matches)) { $s .= "<h6>Véase también</h6>\n<p>" . $wgOut->parse($matches[1]) . "\n</p>"; } } # Comentarios # Anulado de momento $talkPage = $wgTitle->getTalkPage(); if ( $talkPage->exists() ) { # $s .= "<br /><span id='patrol'>Este artículo tiene " . $this->makeLinkObj( $talkPage, 'comentarios' ) . "</span>"; ### $s .= ' ' . $talkPage->getArticleId()->getTimestamp() . ' '; } else { # $s .= "<br /><span id='patrol'>Escriba el primer " . $this->makeLinkObj( $talkPage, 'comentario', 'section=new' ) . " a este artículo </span>"; } } # Categorías if( count( $wgOut->mCategoryLinks ) != 0 ) { $s .= "<h6>Categorías</h6>\n" . "<ul><li>" . implode ( "</li>\n<li>" , $wgOut->mCategoryLinks ) . "</li></ul>"; } # Compartir en redes $s .= "<h6>Compartir</h6>\n<p>"; uksort($wgShareThisSiteList, 'strcasecmp'); foreach ($wgShareThisSiteList as $name=>$url) { $url = str_replace('$1', urlencode($wgTitle->getFullURL()), $url); $url = str_replace('$2', urlencode($wgTitle->getText()), $url); $s .= " <a href='$url' title='Compartir en $name'>" . "<img src='/skins/common/images/sharethis/$name.png' alt='Compartir en $name'/></a>"; } $s .= "</p>"; if ($wgTitle->getNamespace() == NS_SPECIAL or $wgRequest->getVal('action') == 'edit' or $wgRequest->getVal('action') == 'submit' or $wgRequest->getVal('printable') == 'yes') { $s = ''; } if ( $s != '') { $s = "\n<div id='infobar'>" . $s . "</div>"; } return $s; }